mirror of
https://github.com/obsqrbtz/egui_knob.git
synced 2026-04-08 20:19:17 +03:00
fix: mark reponse changed when knob was dragged
This commit is contained in:
@@ -23,11 +23,14 @@ impl eframe::App for KnobExample {
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.add(
|
||||
if ui.add(
|
||||
Knob::new(&mut self.value, 0.0, 100.0, egui_knob::KnobStyle::Dot)
|
||||
.with_label("Gain", egui_knob::LabelPosition::Bottom)
|
||||
.with_size(50.0),
|
||||
);
|
||||
).changed(){
|
||||
println!("Value changed");
|
||||
}
|
||||
|
||||
ui.add(
|
||||
Knob::new(&mut self.value, 0.0, 100.0, egui_knob::KnobStyle::Wiper)
|
||||
.with_label("Gain", egui_knob::LabelPosition::Bottom)
|
||||
|
||||
@@ -104,13 +104,14 @@ impl Widget for Knob<'_> {
|
||||
knob_size.y + label_size.y + label_padding * 6.0,
|
||||
);
|
||||
|
||||
let (rect, response) = ui.allocate_exact_size(adjusted_size, Sense::drag());
|
||||
let (rect, mut response) = ui.allocate_exact_size(adjusted_size, Sense::drag());
|
||||
|
||||
if response.dragged() {
|
||||
let delta = response.drag_delta().y;
|
||||
let range = self.max - self.min;
|
||||
let step = range * 0.005;
|
||||
*self.value = (*self.value - delta * step).clamp(self.min, self.max);
|
||||
response.mark_changed();
|
||||
}
|
||||
|
||||
let painter = ui.painter();
|
||||
|
||||
Reference in New Issue
Block a user