From f34a9b01a0b855b2147b17c57e142a7cb9fba4cb Mon Sep 17 00:00:00 2001 From: reo Date: Thu, 25 Sep 2025 13:01:02 +0300 Subject: [PATCH] Add imgui slider command to the debug ui buffer implementation --- core/src/debug_ui.rs | 10 ++++++++++ game/src/main.rs | 9 +++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/src/debug_ui.rs b/core/src/debug_ui.rs index 18d846f..df3b9f1 100644 --- a/core/src/debug_ui.rs +++ b/core/src/debug_ui.rs @@ -1,6 +1,7 @@ pub enum UICommand { Text(String), Separator, + SliderF32 { label: String, min: f32, max: f32, value: std::rc::Rc> }, } pub struct DebugUIBuffer { @@ -21,6 +22,11 @@ impl DebugUIBuffer { self.cmds.push(UICommand::Separator); } + pub fn slider_f32>(&mut self, label: T, min: f32, max: f32, value: std::rc::Rc>) { + 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); + } } } } diff --git a/game/src/main.rs b/game/src/main.rs index b1b5c2c..05ae11e 100644 --- a/game/src/main.rs +++ b/game/src/main.rs @@ -34,10 +34,14 @@ impl System for UpdateAspectRatioSystem { } #[derive(Default)] -struct RenderingTestSystem; +struct RenderingTestSystem { + rotation_speed: std::rc::Rc>, +} impl System for RenderingTestSystem { fn load_world(&mut self, ctx: &mut SystemContext) { + self.rotation_speed = std::rc::Rc::new(std::cell::RefCell::new(5.0)); + ctx.scene.world.spawn((Camera { eye: Vec3::new(0.0, 0.0, 2.0), center: Vec3::ZERO, @@ -67,11 +71,12 @@ impl System for RenderingTestSystem { dbg_ui.text("Hello World!".to_owned()); dbg_ui.text(format!("Frame Delta: {}", ctx.platform_context.time_ctx.frame_dt)); dbg_ui.text(format!("Fixed Delta: {}", ctx.platform_context.time_ctx.fixed_dt)); + dbg_ui.slider_f32("Rotation Speed", -10.0, 10.0, self.rotation_speed.clone()); } fn fixed_update(&mut self, ctx: &mut SystemContext) { ctx.scene.world.query_mut::<(&mut Transform, &ModelHandle)>().into_iter().for_each(|(_, (t, _))| { - t.rotation *= Quat::from_rotation_y(10.0 * ctx.platform_context.time_ctx.fixed_dt); + t.rotation *= Quat::from_rotation_y(*self.rotation_speed.borrow() * ctx.platform_context.time_ctx.fixed_dt); }); }