Add imgui slider command to the debug ui buffer implementation

This commit is contained in:
reo 2025-09-25 13:01:02 +03:00
parent 84ab3a26b1
commit f34a9b01a0
2 changed files with 17 additions and 2 deletions

View file

@ -1,6 +1,7 @@
pub enum UICommand {
Text(String),
Separator,
SliderF32 { label: String, min: f32, max: f32, value: std::rc::Rc<std::cell::RefCell<f32>> },
}
pub struct DebugUIBuffer {
@ -21,6 +22,11 @@ impl DebugUIBuffer {
self.cmds.push(UICommand::Separator);
}
pub fn slider_f32<T: Into<String>>(&mut self, label: T, min: f32, max: f32, value: std::rc::Rc<std::cell::RefCell<f32>>) {
self.cmds.push(UICommand::SliderF32 { label: label.into(), min, max, value });
}
// End of commands
pub fn write_buffer(&self, ui: &imgui::Ui) {
for cmd in &self.cmds {
match cmd {
@ -30,6 +36,10 @@ impl DebugUIBuffer {
UICommand::Separator => {
ui.separator();
}
UICommand::SliderF32 { label, min, max, value } => {
let mut v = value.borrow_mut();
ui.slider_config(label.as_str(), *min, *max).build(&mut *v);
}
}
}
}