mirror of
https://github.com/obsqrbtz/egui_knob.git
synced 2026-04-09 12:37:52 +03:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c1db9a2e5b | |||
| 750d8afb25 | |||
| 4e8975c955 | |||
|
|
824b492b92 |
27
.github/workflows/publish.yml
vendored
Normal file
27
.github/workflows/publish.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
name: Publish to crates.io
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Check if version matches tag
|
||||
run: |
|
||||
TAG=${GITHUB_REF#refs/tags/v}
|
||||
CARGO_VERSION=$(grep '^version' Cargo.toml | head -1 | cut -d'"' -f2)
|
||||
if [ "$TAG" != "$CARGO_VERSION" ]; then
|
||||
echo "Tag version ($TAG) doesn't match Cargo.toml version ($CARGO_VERSION)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Publish to crates.io
|
||||
run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.3.8] - 2026-01-12
|
||||
|
||||
### 🚀 Features
|
||||
|
||||
- added `with_double_click_reset` option ([#PR6](https://github.com/obsqrbtz/egui_knob/pull/6) by [maor1993](https://github.com/maor1993))
|
||||
|
||||
## [0.3.7] - 2026-01-06
|
||||
|
||||
### 🛠 Maintenance
|
||||
|
||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -869,7 +869,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "egui_knob"
|
||||
version = "0.3.7"
|
||||
version = "0.3.8"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"egui",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "egui_knob"
|
||||
version = "0.3.7"
|
||||
version = "0.3.8"
|
||||
edition = "2024"
|
||||
authors = ["Daniel Dada"]
|
||||
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]
|
||||
egui = "0.33"
|
||||
eframe = "0.33"
|
||||
egui_knob = "0.3.6"
|
||||
egui_knob = "0.3.8"
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -87,7 +87,8 @@ impl eframe::App for KnobDemo {
|
||||
.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_step(self.use_step.then_some(0.02))
|
||||
.with_double_click_reset(0.5);
|
||||
|
||||
if *label == "Wiper, Sweep" {
|
||||
knob = knob.with_sweep_range(0.25, 0.75).with_size(50.0);
|
||||
|
||||
@@ -16,6 +16,7 @@ pub struct KnobConfig {
|
||||
pub(crate) show_filled_segments: bool,
|
||||
pub(crate) min_angle: f32,
|
||||
pub(crate) max_angle: f32,
|
||||
pub(crate) reset_value: Option<f32>,
|
||||
}
|
||||
|
||||
impl KnobConfig {
|
||||
@@ -36,6 +37,7 @@ impl KnobConfig {
|
||||
drag_sensitivity: 0.005,
|
||||
show_background_arc: true,
|
||||
show_filled_segments: true,
|
||||
reset_value: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ impl<'a> Knob<'a> {
|
||||
return self;
|
||||
}
|
||||
|
||||
self.config.min_angle =
|
||||
self.config.min_angle =
|
||||
start_angle_normalized.rem_euclid(1.0) * std::f32::consts::TAU + std::f32::consts::PI / 2.0;
|
||||
self.config.max_angle = self.config.min_angle + range.max(0.0) * std::f32::consts::TAU;
|
||||
self
|
||||
@@ -156,6 +156,11 @@ impl<'a> Knob<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets a reset value to return to on doubleclick event.
|
||||
pub fn with_double_click_reset(mut self, reset_value: f32) -> Self {
|
||||
self.config.reset_value = Some(reset_value);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for Knob<'_> {
|
||||
@@ -168,7 +173,7 @@ impl Widget for Knob<'_> {
|
||||
let renderer = KnobRenderer::new(&self.config, current_value, self.min, self.max);
|
||||
let adjusted_size = renderer.calculate_size(ui);
|
||||
|
||||
let (rect, response) = ui.allocate_exact_size(adjusted_size, Sense::drag());
|
||||
let (rect, response) = ui.allocate_exact_size(adjusted_size, Sense::click_and_drag());
|
||||
|
||||
let mut response = response;
|
||||
if response.dragged() {
|
||||
@@ -189,6 +194,10 @@ impl Widget for Knob<'_> {
|
||||
}
|
||||
|
||||
response.mark_changed();
|
||||
} else if response.double_clicked() {
|
||||
if let Some(reset_value) = self.config.reset_value {
|
||||
*self.value = reset_value
|
||||
}
|
||||
}
|
||||
|
||||
let knob_rect = renderer.calculate_knob_rect(rect);
|
||||
|
||||
Reference in New Issue
Block a user