mirror of
https://github.com/obsqrbtz/egui_knob.git
synced 2026-04-08 20:19:17 +03:00
Merge pull request #10 from elwerene/update_egui
update egui and fix clippy warnings
This commit is contained in:
722
Cargo.lock
generated
722
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -21,7 +21,7 @@ name = "example_knob"
|
|||||||
path = "examples/example_knob.rs"
|
path = "examples/example_knob.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
egui = "0.33"
|
egui = "0.34"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
eframe = { version = "0.33", features = ["default_fonts"] }
|
eframe = { version = "0.34", features = ["default_fonts"] }
|
||||||
|
|||||||
@@ -43,89 +43,86 @@ impl Default for KnobDemo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl eframe::App for KnobDemo {
|
impl eframe::App for KnobDemo {
|
||||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
ui.heading("Knob demo");
|
||||||
ui.heading("Knob demo");
|
ui.separator();
|
||||||
ui.separator();
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Global Settings:");
|
ui.label("Global Settings:");
|
||||||
ui.checkbox(&mut self.show_bg_arc, "Background arc");
|
ui.checkbox(&mut self.show_bg_arc, "Background arc");
|
||||||
ui.checkbox(&mut self.show_filled, "Filled segment");
|
ui.checkbox(&mut self.show_filled, "Filled segment");
|
||||||
ui.checkbox(&mut self.use_step, "Step (0.02)");
|
ui.checkbox(&mut self.use_step, "Step (0.02)");
|
||||||
ui.checkbox(&mut self.logarithmic_scaling, "Logarithmic");
|
ui.checkbox(&mut self.logarithmic_scaling, "Logarithmic");
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
ui.label("Color Theme:");
|
|
||||||
ui.color_edit_button_srgba(&mut self.knob_color);
|
|
||||||
ui.label("Knob");
|
|
||||||
ui.color_edit_button_srgba(&mut self.line_color);
|
|
||||||
ui.label("Indicator");
|
|
||||||
ui.color_edit_button_srgba(&mut self.text_color);
|
|
||||||
ui.label("Text");
|
|
||||||
});
|
|
||||||
|
|
||||||
ui.separator();
|
|
||||||
|
|
||||||
ui.add_space(10.0);
|
|
||||||
egui::Grid::new("knob_grid")
|
|
||||||
.num_columns(3)
|
|
||||||
.spacing([30.0, 20.0])
|
|
||||||
.show(ui, |ui| {
|
|
||||||
for (i, (label, config)) in [
|
|
||||||
("Basic Dot", KnobStyle::Dot),
|
|
||||||
("Wiper, Sweep", KnobStyle::Wiper),
|
|
||||||
("Thick Stroke", KnobStyle::Wiper),
|
|
||||||
("360° Sweep", KnobStyle::Wiper),
|
|
||||||
("Multi-Turn", KnobStyle::Dot),
|
|
||||||
("Large Font", KnobStyle::Wiper),
|
|
||||||
]
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
{
|
|
||||||
ui.vertical(|ui| {
|
|
||||||
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)
|
|
||||||
.with_colors(self.knob_color, self.line_color, self.text_color)
|
|
||||||
.with_step(self.use_step.then_some(0.02))
|
|
||||||
.with_double_click_reset(0.5)
|
|
||||||
.with_middle_scroll();
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
if *label == "Thick Stroke" {
|
|
||||||
knob = knob.with_stroke_width(4.0).with_size(60.0);
|
|
||||||
}
|
|
||||||
if *label == "360° Sweep" {
|
|
||||||
knob = knob.with_sweep_range(0.5, 1.0);
|
|
||||||
}
|
|
||||||
if *label == "Multi-Turn" {
|
|
||||||
knob = knob.with_sweep_range(0.0, 2.5);
|
|
||||||
}
|
|
||||||
if *label == "Large Font" {
|
|
||||||
knob = knob.with_size(70.0).with_font_size(18.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.add(knob);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (i + 1) % 3 == 0 {
|
|
||||||
ui.end_row();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ui.add_space(10.0);
|
|
||||||
ui.separator();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
ui.label("Color Theme:");
|
||||||
|
ui.color_edit_button_srgba(&mut self.knob_color);
|
||||||
|
ui.label("Knob");
|
||||||
|
ui.color_edit_button_srgba(&mut self.line_color);
|
||||||
|
ui.label("Indicator");
|
||||||
|
ui.color_edit_button_srgba(&mut self.text_color);
|
||||||
|
ui.label("Text");
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
|
ui.add_space(10.0);
|
||||||
|
egui::Grid::new("knob_grid")
|
||||||
|
.num_columns(3)
|
||||||
|
.spacing([30.0, 20.0])
|
||||||
|
.show(ui, |ui| {
|
||||||
|
for (i, (label, config)) in [
|
||||||
|
("Basic Dot", KnobStyle::Dot),
|
||||||
|
("Wiper, Sweep", KnobStyle::Wiper),
|
||||||
|
("Thick Stroke", KnobStyle::Wiper),
|
||||||
|
("360° Sweep", KnobStyle::Wiper),
|
||||||
|
("Multi-Turn", KnobStyle::Dot),
|
||||||
|
("Large Font", KnobStyle::Wiper),
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
{
|
||||||
|
ui.vertical(|ui| {
|
||||||
|
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)
|
||||||
|
.with_colors(self.knob_color, self.line_color, self.text_color)
|
||||||
|
.with_step(self.use_step.then_some(0.02))
|
||||||
|
.with_double_click_reset(0.5)
|
||||||
|
.with_middle_scroll();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
if *label == "Thick Stroke" {
|
||||||
|
knob = knob.with_stroke_width(4.0).with_size(60.0);
|
||||||
|
}
|
||||||
|
if *label == "360° Sweep" {
|
||||||
|
knob = knob.with_sweep_range(0.5, 1.0);
|
||||||
|
}
|
||||||
|
if *label == "Multi-Turn" {
|
||||||
|
knob = knob.with_sweep_range(0.0, 2.5);
|
||||||
|
}
|
||||||
|
if *label == "Large Font" {
|
||||||
|
knob = knob.with_size(70.0).with_font_size(18.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.add(knob);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (i + 1) % 3 == 0 {
|
||||||
|
ui.end_row();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.add_space(10.0);
|
||||||
|
ui.separator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,17 +209,15 @@ impl Widget for Knob<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
response.mark_changed();
|
response.mark_changed();
|
||||||
} else if response.hovered() & self.config.allow_scroll {
|
} else if response.hovered() & self.config.allow_scroll && let Some(scoll) = ui.input(|input| {
|
||||||
if let Some(scoll) = ui.input(|input| {
|
|
||||||
input.events.iter().find_map(|e| match e {
|
input.events.iter().find_map(|e| match e {
|
||||||
egui::Event::MouseWheel { delta, .. } => Some(*delta),
|
egui::Event::MouseWheel { delta, .. } => Some(*delta),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
}) {
|
}) {
|
||||||
raw = (raw
|
raw = (raw
|
||||||
+ scoll.y * self.config.step.unwrap_or(self.config.drag_sensitivity))
|
+ scoll.y * self.config.step.unwrap_or(self.config.drag_sensitivity))
|
||||||
.clamp(0.0, 1.0);
|
.clamp(0.0, 1.0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*self.value = if self.config.logarithmic_scaling {
|
*self.value = if self.config.logarithmic_scaling {
|
||||||
@@ -228,11 +226,10 @@ impl Widget for Knob<'_> {
|
|||||||
remap(raw, 0.0..=1.0, self.min..=self.max)
|
remap(raw, 0.0..=1.0, self.min..=self.max)
|
||||||
};
|
};
|
||||||
|
|
||||||
if response.double_clicked() {
|
if response.double_clicked()
|
||||||
if let Some(reset_value) = self.config.reset_value {
|
&& let Some(reset_value) = self.config.reset_value {
|
||||||
*self.value = reset_value
|
*self.value = reset_value
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let knob_rect = renderer.calculate_knob_rect(rect);
|
let knob_rect = renderer.calculate_knob_rect(rect);
|
||||||
let center = knob_rect.center();
|
let center = knob_rect.center();
|
||||||
|
|||||||
Reference in New Issue
Block a user