fix: slider always enabled

This commit is contained in:
mostafaei2002 2024-06-12 18:39:32 +03:30
parent 9949a4c4fb
commit ce9e378633

View file

@ -177,7 +177,6 @@ impl crate::disk::state::Xvb {
ui.add_space(space_h); ui.add_space(space_h);
let mut is_slider_enabled = true;
let mut hashrate_xmrig = { let mut hashrate_xmrig = {
if lock!(gui_api_xmrig).hashrate_raw_15m > 0.0 { if lock!(gui_api_xmrig).hashrate_raw_15m > 0.0 {
lock!(gui_api_xmrig).hashrate_raw_15m lock!(gui_api_xmrig).hashrate_raw_15m
@ -186,7 +185,6 @@ impl crate::disk::state::Xvb {
} else if lock!(gui_api_xmrig).hashrate_raw > 0.0 { } else if lock!(gui_api_xmrig).hashrate_raw > 0.0 {
lock!(gui_api_xmrig).hashrate_raw lock!(gui_api_xmrig).hashrate_raw
} else { } else {
is_slider_enabled = false;
1000.0 1000.0
} }
}; };
@ -204,27 +202,25 @@ impl crate::disk::state::Xvb {
XVB_MANUAL_SLIDER_MANUAL_P2POOL_HELP XVB_MANUAL_SLIDER_MANUAL_P2POOL_HELP
}; };
ui.add_enabled_ui(is_slider_enabled, |ui| { ui.horizontal(|ui| {
ui.horizontal(|ui| { ui.spacing_mut().slider_width = width * 0.5;
ui.spacing_mut().slider_width = width * 0.5; ui.add_sized(
ui.add_sized( [width, text_edit],
[width, text_edit], egui::Slider::new(&mut self.manual_slider_amount, 0.0..=(hashrate_xmrig as f64)).max_decimals(3)
egui::Slider::new(&mut self.manual_slider_amount, 0.0..=(hashrate_xmrig as f64)).max_decimals(3) ).on_hover_text(slider_help_text);
).on_hover_text(slider_help_text);
if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Hash, "H/s")).clicked() { if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Hash, "H/s")).clicked() {
self.manual_donation_metric = ManualDonationMetric::Hash; self.manual_donation_metric = ManualDonationMetric::Hash;
self.manual_slider_amount = self.manual_amount_raw; self.manual_slider_amount = self.manual_amount_raw;
} }
if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Kilo, "kH/s")).clicked() { if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Kilo, "KH/s")).clicked() {
self.manual_donation_metric = ManualDonationMetric::Kilo; self.manual_donation_metric = ManualDonationMetric::Kilo;
self.manual_slider_amount = self.manual_amount_raw / 1000.0; self.manual_slider_amount = self.manual_amount_raw / 1000.0;
}; };
if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Mega, "MH/s")).clicked() { if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Mega, "MH/s")).clicked() {
self.manual_donation_metric = ManualDonationMetric::Mega; self.manual_donation_metric = ManualDonationMetric::Mega;
self.manual_slider_amount = self.manual_amount_raw / 1_000_000.0; self.manual_slider_amount = self.manual_amount_raw / 1_000_000.0;
}; };
});
}); });
} }