From b8cd36eeb2f4e0961fc0575ec6d3accb5d78ed81 Mon Sep 17 00:00:00 2001 From: mostafaei2002 Date: Wed, 12 Jun 2024 18:49:53 +0330 Subject: [PATCH] fix: impl Display for XvbMode --- src/app/panels/middle/xvb.rs | 26 +++++++++++--------------- src/disk/state.rs | 20 +++++++++++++++++--- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/app/panels/middle/xvb.rs b/src/app/panels/middle/xvb.rs index fc10c21..c02ce59 100644 --- a/src/app/panels/middle/xvb.rs +++ b/src/app/panels/middle/xvb.rs @@ -152,25 +152,21 @@ impl crate::disk::state::Xvb { ui.vertical_centered(|ui| { ui.horizontal(|ui| { - - let selected_text = match self.mode { - XvbMode::Auto => "Auto".to_string(), - XvbMode::Hero => "Hero".to_string(), - XvbMode::ManualXvb => "Manual Xvb".to_string(), - XvbMode::ManualP2pool => "Manual P2pool".to_string(), - XvbMode::ManualDonationLevel => "Manual Donation Level".to_string() - }; - egui::ComboBox::from_label("") - .selected_text(selected_text) + .selected_text(self.mode.to_string()) .show_ui(ui, |ui| { - ui.selectable_value(&mut self.mode, XvbMode::Auto, "Auto"); - ui.selectable_value(&mut self.mode, XvbMode::Hero, "Hero"); - ui.selectable_value(&mut self.mode, XvbMode::ManualXvb, "Manual Xvb") + ui.selectable_value(&mut self.mode, XvbMode::Auto, + XvbMode::Auto.to_string()); + ui.selectable_value(&mut self.mode, XvbMode::Hero, + XvbMode::Hero.to_string()); + ui.selectable_value(&mut self.mode, XvbMode::ManualXvb, + XvbMode::ManualXvb.to_string()) .on_hover_text(XVB_MODE_MANUAL_XVB_HELP); - ui.selectable_value(&mut self.mode, XvbMode::ManualP2pool, "Manual P2pool") + ui.selectable_value(&mut self.mode, XvbMode::ManualP2pool, + XvbMode::ManualP2pool.to_string()) .on_hover_text(XVB_MODE_MANUAL_P2POOL_HELP); - ui.selectable_value(&mut self.mode, XvbMode::ManualDonationLevel, "Manual Donation Level") + ui.selectable_value(&mut self.mode, XvbMode::ManualDonationLevel, + XvbMode::ManualDonationLevel.to_string()) .on_hover_text(XVB_MODE_MANUAL_DONATION_LEVEL_HELP); }); if self.mode == XvbMode::ManualXvb || self.mode == XvbMode::ManualP2pool { diff --git a/src/disk/state.rs b/src/disk/state.rs index b57018f..d378a97 100644 --- a/src/disk/state.rs +++ b/src/disk/state.rs @@ -265,6 +265,20 @@ pub enum XvbMode { ManualDonationLevel, } +impl Display for XvbMode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let text = match self { + Self::Auto => "Auto", + Self::Hero => "Hero", + Self::ManualXvb => "Manual Xvb", + Self::ManualP2pool => "Manual P2pool", + Self::ManualDonationLevel => "Manual Donation Level" + }; + + write!(f, "{}", text) + } +} + #[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)] pub enum ManualDonationLevel { #[default] @@ -405,11 +419,11 @@ impl Default for Xvb { simple: true, token: "".to_string(), simple_hero_mode: false, - mode: XvbMode::Auto, + mode: XvbMode::default(), manual_amount_raw: 0.0, manual_slider_amount: 0.0, - manual_donation_level: ManualDonationLevel::Donor, - manual_donation_metric: ManualDonationMetric::Hash, + manual_donation_level: ManualDonationLevel::default(), + manual_donation_metric: ManualDonationMetric::default(), } } }