fix: clean up ui and align widgets

This commit is contained in:
mostafaei2002 2024-06-06 17:14:18 +03:30
parent 23a7a7f341
commit 41999f098f

View file

@ -116,25 +116,46 @@ impl crate::disk::state::Xvb {
ui.style_mut().spacing.icon_width = width / 35.0;
ui.style_mut().spacing.icon_spacing = space_h;
egui::ComboBox::from_label("")
.selected_text(format!("{:?}", self.mode))
.show_ui(ui, |ui| {
ui.horizontal(|ui| {
ui.selectable_value(&mut self.mode, XvbMode::Auto, "Automatic");
ui.selectable_value(&mut self.mode, XvbMode::Hero, "Hero Mode");
ui.selectable_value(&mut self.mode, XvbMode::ManuallyDonate, "Manually Donate");
ui.selectable_value(&mut self.mode, XvbMode::ManuallyKeep, "Manually Keep");
})
});
if self.mode == XvbMode::ManuallyDonate || self.mode == XvbMode::ManuallyKeep {
ui.horizontal(|ui| {
ui.add(
TextEdit::singleline(&mut self.amount)
.vertical_align(egui::Align::Center)
).on_hover_text(XVB_MANUAL_HASHRATE_HELP)
});
}
ui.group(|ui| {
ui.vertical_centered(|ui| {
ui.horizontal(|ui| {
egui::ComboBox::from_label("")
.selected_text(format!("{:?}", self.mode))
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.mode, XvbMode::Auto, "Automatic");
ui.selectable_value(&mut self.mode, XvbMode::Hero, "Hero Mode");
ui.selectable_value(&mut self.mode, XvbMode::ManuallyDonate, "Manually Donate");
ui.selectable_value(&mut self.mode, XvbMode::ManuallyKeep, "Manually Keep");
});
if self.mode == XvbMode::ManuallyDonate || self.mode == XvbMode::ManuallyKeep {
let (text, color) = if self.amount.is_empty() {
(
format!(""),
LIGHT_GRAY,
)
} else if self.amount.parse::<u32>().is_ok() {
(format!(""), GREEN)
} else {
(
format!("Invalid hashrate ❌"),
RED,
)
};
ui.add_space(space_h);
ui.colored_label(color, text);
ui.add(
TextEdit::singleline(&mut self.amount)
.vertical_align(egui::Align::Center)
).on_hover_text(XVB_MANUAL_HASHRATE_HELP);
}
});
});
});