From 37d07921754fd48a8e595f9fb31ce0e4eb90fcc1 Mon Sep 17 00:00:00 2001 From: Julius Schmitt Date: Thu, 22 Jan 2026 20:56:48 +0100 Subject: [PATCH] add example option, clean up --- examples/example_knob.rs | 11 +++++++++-- src/widget.rs | 15 +++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/example_knob.rs b/examples/example_knob.rs index b0271c2..8169019 100644 --- a/examples/example_knob.rs +++ b/examples/example_knob.rs @@ -21,6 +21,7 @@ struct KnobDemo { show_bg_arc: bool, show_filled: bool, use_step: bool, + logarithmic_scaling: bool, knob_color: egui::Color32, line_color: egui::Color32, text_color: egui::Color32, @@ -33,6 +34,7 @@ impl Default for KnobDemo { show_bg_arc: true, show_filled: true, use_step: false, + logarithmic_scaling: false, knob_color: egui::Color32::DARK_GRAY, line_color: egui::Color32::LIGHT_BLUE, text_color: egui::Color32::WHITE, @@ -51,6 +53,8 @@ impl eframe::App for KnobDemo { ui.checkbox(&mut self.show_bg_arc, "Background arc"); ui.checkbox(&mut self.show_filled, "Filled segment"); ui.checkbox(&mut self.use_step, "Step (0.02)"); + ui.checkbox(&mut self.logarithmic_scaling, "Logarithmic"); + }); ui.horizontal(|ui| { @@ -82,7 +86,7 @@ impl eframe::App for KnobDemo { .enumerate() { ui.vertical(|ui| { - let mut knob = Knob::new(&mut self.values[i], 0., 3., *config) + let mut knob = Knob::new(&mut self.values[i], 0., 1., *config) .with_label(*label, LabelPosition::Bottom) .with_background_arc(self.show_bg_arc) .with_show_filled_segments(self.show_filled) @@ -90,7 +94,10 @@ impl eframe::App for KnobDemo { .with_step(self.use_step.then_some(0.02)) .with_double_click_reset(0.5) .with_middle_scroll(); - //.with_logarithmic_scaling(); + + if self.logarithmic_scaling { + knob = knob.with_logarithmic_scaling(); + } if *label == "Wiper, Sweep" { knob = knob.with_sweep_range(0.25, 0.75).with_size(50.0); diff --git a/src/widget.rs b/src/widget.rs index c224670..84c1053 100644 --- a/src/widget.rs +++ b/src/widget.rs @@ -194,20 +194,19 @@ impl Widget for Knob<'_> { let mut response = response; if response.dragged() { let delta = response.drag_delta().y; - let range = 1.0; - let step = self.config.step.unwrap_or(range * self.config.drag_sensitivity); + let step = self.config.step.unwrap_or(self.config.drag_sensitivity); raw = (raw - delta * step).clamp(0.0,1.0); - /*raw = if let Some(step) = self.config.step { - let steps = ((raw - 1.0) / step).round(); - (steps * step).clamp(1.0, 2.0) + raw = if let Some(step) = self.config.step { + let steps = (raw / step).round(); + (steps * step).clamp(0.0, 1.0) } else { raw - };*/ + }; - /*if self.value.is_nan() { + if self.value.is_nan() { *self.value = 0.0; - }*/ + } response.mark_changed(); } else if response.hovered() & self.config.allow_scroll {