mirror of
https://github.com/obsqrbtz/egui_knob.git
synced 2026-04-09 20:47:40 +03:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| fb3f9d75dc | |||
| 45ce317879 | |||
| 15021b8cfa | |||
|
|
ad468ae18a | ||
|
|
2c5b209571 |
@@ -2,6 +2,12 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [0.3.9] - 2026-01-13
|
||||||
|
|
||||||
|
### 🚀 Features
|
||||||
|
|
||||||
|
- added support for using mouse scroll wheel to change values ([#PR7](https://github.com/obsqrbtz/egui_knob/pull/7) by [maor1993](https://github.com/maor1993))
|
||||||
|
|
||||||
## [0.3.8] - 2026-01-12
|
## [0.3.8] - 2026-01-12
|
||||||
|
|
||||||
### 🚀 Features
|
### 🚀 Features
|
||||||
|
|||||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -869,7 +869,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "egui_knob"
|
name = "egui_knob"
|
||||||
version = "0.3.8"
|
version = "0.3.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui",
|
"egui",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "egui_knob"
|
name = "egui_knob"
|
||||||
version = "0.3.8"
|
version = "0.3.9"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ["Daniel Dada"]
|
authors = ["Daniel Dada"]
|
||||||
description = "A simple knob widget for egui"
|
description = "A simple knob widget for egui"
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ To use the Knob widget in your project, add the following to your `Cargo.toml`:
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
egui = "0.33"
|
egui = "0.33"
|
||||||
eframe = "0.33"
|
eframe = "0.33"
|
||||||
egui_knob = "0.3.8"
|
egui_knob = "0.3.9"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|||||||
@@ -88,7 +88,8 @@ impl eframe::App for KnobDemo {
|
|||||||
.with_show_filled_segments(self.show_filled)
|
.with_show_filled_segments(self.show_filled)
|
||||||
.with_colors(self.knob_color, self.line_color, self.text_color)
|
.with_colors(self.knob_color, self.line_color, self.text_color)
|
||||||
.with_step(self.use_step.then_some(0.02))
|
.with_step(self.use_step.then_some(0.02))
|
||||||
.with_double_click_reset(0.5);
|
.with_double_click_reset(0.5)
|
||||||
|
.with_middle_scroll();
|
||||||
|
|
||||||
if *label == "Wiper, Sweep" {
|
if *label == "Wiper, Sweep" {
|
||||||
knob = knob.with_sweep_range(0.25, 0.75).with_size(50.0);
|
knob = knob.with_sweep_range(0.25, 0.75).with_size(50.0);
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ pub struct KnobConfig {
|
|||||||
pub(crate) min_angle: f32,
|
pub(crate) min_angle: f32,
|
||||||
pub(crate) max_angle: f32,
|
pub(crate) max_angle: f32,
|
||||||
pub(crate) reset_value: Option<f32>,
|
pub(crate) reset_value: Option<f32>,
|
||||||
|
pub(crate) allow_scroll: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KnobConfig {
|
impl KnobConfig {
|
||||||
@@ -38,6 +39,7 @@ impl KnobConfig {
|
|||||||
show_background_arc: true,
|
show_background_arc: true,
|
||||||
show_filled_segments: true,
|
show_filled_segments: true,
|
||||||
reset_value: None,
|
reset_value: None,
|
||||||
|
allow_scroll:false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,6 +161,13 @@ impl<'a> Knob<'a> {
|
|||||||
self.config.reset_value = Some(reset_value);
|
self.config.reset_value = Some(reset_value);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Allows user to use scroll wheel to change knob value
|
||||||
|
/// Uses config.step for the increment value
|
||||||
|
pub fn with_middle_scroll(mut self) -> Self {
|
||||||
|
self.config.allow_scroll = true;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for Knob<'_> {
|
impl Widget for Knob<'_> {
|
||||||
@@ -198,6 +205,17 @@ impl Widget for Knob<'_> {
|
|||||||
if let Some(reset_value) = self.config.reset_value {
|
if let Some(reset_value) = self.config.reset_value {
|
||||||
*self.value = reset_value
|
*self.value = reset_value
|
||||||
}
|
}
|
||||||
|
} else if response.hovered() & self.config.allow_scroll {
|
||||||
|
if let Some(scoll) = ui.input(|input| {
|
||||||
|
input.events.iter().find_map(|e| match e {
|
||||||
|
egui::Event::MouseWheel { delta, .. } => Some(*delta),
|
||||||
|
_ => None,
|
||||||
|
})
|
||||||
|
}) {
|
||||||
|
*self.value = (*self.value
|
||||||
|
+ scoll.y * self.config.step.unwrap_or(self.config.drag_sensitivity))
|
||||||
|
.clamp(self.min, self.max);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let knob_rect = renderer.calculate_knob_rect(rect);
|
let knob_rect = renderer.calculate_knob_rect(rect);
|
||||||
|
|||||||
Reference in New Issue
Block a user