From 2e18c4c5fb100add237276a6e8c0b695f6bc7104 Mon Sep 17 00:00:00 2001 From: mostafaei2002 Date: Tue, 11 Jun 2024 12:28:29 +0330 Subject: [PATCH] feat: add H/s & kH/s labels for slider --- src/app/panels/middle/xvb.rs | 13 ++++++--- src/disk/state.rs | 51 ++++++++++++++++++++---------------- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/app/panels/middle/xvb.rs b/src/app/panels/middle/xvb.rs index a6a37a1..e2eff7e 100644 --- a/src/app/panels/middle/xvb.rs +++ b/src/app/panels/middle/xvb.rs @@ -6,7 +6,7 @@ use log::debug; use readable::num::Float; use readable::up::Uptime; -use crate::disk::state::{XvbMode, ManualDonationLevel}; +use crate::disk::state::{XvbMode, ManualDonationLevel, ManualDonationMetric}; use crate::helper::xmrig::PubXmrigApi; use crate::helper::xvb::priv_stats::RuntimeMode; use crate::helper::xvb::PubXvbApi; @@ -28,6 +28,7 @@ use crate::{ impl crate::disk::state::Xvb { #[inline(always)] // called once + #[allow(clippy::too_many_arguments)] pub fn show( &mut self, size: Vec2, @@ -184,11 +185,17 @@ impl crate::disk::state::Xvb { ui.add_enabled_ui(is_alive, |ui| { ui.horizontal(|ui| { - ui.spacing_mut().slider_width = width * 0.7; + ui.spacing_mut().slider_width = width * 0.5; ui.add_sized( [width, text_edit], - egui::Slider::new(&mut self.amount, 0.0..=(hashrate_xmrig as f64)).text("H/s") + egui::Slider::new(&mut self.amount, 0.0..=(hashrate_xmrig as f64)) ).on_hover_text(slider_help_text); + + ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Hash, "H/s")); + if ui.add(egui::SelectableLabel::new(self.manual_donation_metric == ManualDonationMetric::Kilo, "kH/s")).clicked() { + self.amount *= 1000.0; + }; + }); }); diff --git a/src/disk/state.rs b/src/disk/state.rs index 744eec9..3230603 100644 --- a/src/disk/state.rs +++ b/src/disk/state.rs @@ -243,26 +243,6 @@ pub struct Xmrig { pub token: String, } -#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)] -pub enum XvbMode { - #[default] - Auto, - ManuallyDonate, - ManuallyKeep, - Hero, - ManualDonationLevel -} - - -#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)] -pub enum ManualDonationLevel { - #[default] - Donor, - DonorVIP, - DonorWhale, - DonorMega -} - #[derive(Clone, PartialEq, Debug, Deserialize, Serialize, Default)] pub struct Xvb { pub simple: bool, @@ -270,7 +250,34 @@ pub struct Xvb { pub simple_hero_mode: bool, pub mode: XvbMode, pub amount: f64, - pub manual_donation_level: ManualDonationLevel + pub manual_donation_level: ManualDonationLevel, + pub manual_donation_metric: ManualDonationMetric, +} + +#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)] +pub enum XvbMode { + #[default] + Auto, + ManuallyDonate, + ManuallyKeep, + Hero, + ManualDonationLevel, +} + +#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)] +pub enum ManualDonationLevel { + #[default] + Donor, + DonorVIP, + DonorWhale, + DonorMega, +} + +#[derive(Clone, Eq, PartialEq, Debug, Deserialize, Serialize, Default)] +pub enum ManualDonationMetric { + #[default] + Hash, + Kilo, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -398,4 +405,4 @@ impl Default for Version { xmrig: XMRIG_VERSION.to_string(), } } -} \ No newline at end of file +}