From 8bd0ce3f60169416600deb5787a3219cbdb704cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gianguido=20Sor=C3=A0?= Date: Thu, 17 Nov 2022 17:19:20 +0100 Subject: [PATCH] feat(modals): allow user of slider() to specify a step value Progress bars default to step = 1. --- services/modals/src/api.rs | 2 ++ services/modals/src/lib.rs | 3 +++ services/modals/src/main.rs | 1 + services/modals/src/tests.rs | 1 + 4 files changed, 7 insertions(+) diff --git a/services/modals/src/api.rs b/services/modals/src/api.rs index 1aa6feb4f..513f4a415 100644 --- a/services/modals/src/api.rs +++ b/services/modals/src/api.rs @@ -71,6 +71,8 @@ pub struct ManagedProgress { pub current_work: u32, /// can user interact with it? pub user_interaction: bool, + /// how much should the slider move with each movement? + pub step: u32, } /// This isn't a terribly useful notification -- it's basically read-only, no interactivity, diff --git a/services/modals/src/lib.rs b/services/modals/src/lib.rs index 06a6e033f..9c475f292 100644 --- a/services/modals/src/lib.rs +++ b/services/modals/src/lib.rs @@ -303,6 +303,7 @@ impl Modals { end_work: end, current_work: current, user_interaction: false, + step: 1, }; let buf = Buffer::into_buf(spec).or(Err(xous::Error::InternalError))?; buf.lend(self.conn, Opcode::StartProgress.to_u32().unwrap()) @@ -316,6 +317,7 @@ impl Modals { start: u32, end: u32, current: u32, + step: u32, ) -> Result { self.lock(); let spec = ManagedProgress { @@ -325,6 +327,7 @@ impl Modals { end_work: end, current_work: current, user_interaction: true, + step: step, }; let mut buf = Buffer::into_buf(spec).or(Err(xous::Error::InternalError))?; buf.lend_mut(self.conn, Opcode::Slider.to_u32().unwrap()) diff --git a/services/modals/src/main.rs b/services/modals/src/main.rs index 08b9a3fda..814b3a921 100644 --- a/services/modals/src/main.rs +++ b/services/modals/src/main.rs @@ -612,6 +612,7 @@ fn wrapped_main() -> ! { ); progress_action.set_state(last_percentage); progress_action.set_is_progressbar(!config.user_interaction); + progress_action.step = config.step; #[cfg(feature = "tts")] tts.tts_simple(config.title.as_str().unwrap()).unwrap(); renderer_modal.modify( diff --git a/services/modals/src/tests.rs b/services/modals/src/tests.rs index cf9119f6e..a4b53cfc2 100644 --- a/services/modals/src/tests.rs +++ b/services/modals/src/tests.rs @@ -104,6 +104,7 @@ pub fn spawn_test() { 0, 100, 50, + 1, ).expect("slider test failed"); modals.show_notification(&format!("Slider value: {}", result), None)