feat(modals): allow user of slider() to specify a step value

Progress bars default to step = 1.
This commit is contained in:
Gianguido Sorà 2022-11-17 17:19:20 +01:00
parent aa44834fbd
commit 8bd0ce3f60
4 changed files with 7 additions and 0 deletions

View file

@ -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,

View file

@ -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<u32, xous::Error> {
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())

View file

@ -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(

View file

@ -104,6 +104,7 @@ pub fn spawn_test() {
0,
100,
50,
1,
).expect("slider test failed");
modals.show_notification(&format!("Slider value: {}", result), None)