mirror of
https://github.com/obsqrbtz/egui_knob.git
synced 2026-04-08 20:19:17 +03:00
chore: restructured the project
docs: added contributing guidelines and updated rreadme
This commit is contained in:
82
README.md
82
README.md
@@ -1,18 +1,23 @@
|
||||
# egui_knob
|
||||
|
||||

|
||||
[](https://crates.io/crates/egui_knob)
|
||||
[](https://docs.rs/egui_knob)
|
||||
[](LICENSE)
|
||||
|
||||
Simple knob widget for egui.
|
||||
A simple, customizable knob widget for egui.
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
- Adjustable size, font size, and stroke width.
|
||||
- Customizable colors for the knob, indicator and text.
|
||||
- Label positions (Top, Bottom, Left, Right).
|
||||
- Label formatting.
|
||||
- Two styles: Wiper and Dot.
|
||||
- Adjustable size, font size, and stroke width
|
||||
- Customizable colors for the knob, indicator, and text
|
||||
- Label positions (Top, Bottom, Left, Right)
|
||||
- Custom label formatting
|
||||
- Two visual styles: Wiper and Dot
|
||||
- Configurable sweep range
|
||||
- Background arc with filled segments
|
||||
- Adjustable drag sensitivity
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -22,14 +27,16 @@ 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.4"
|
||||
egui_knob = "0.3.5"
|
||||
```
|
||||
|
||||
## Usage example
|
||||
## Usage
|
||||
|
||||
### Basic Example
|
||||
|
||||
```rust
|
||||
use egui_knob::{Knob, KnobStyle, LabelPosition};
|
||||
use eframe::{egui};
|
||||
use eframe::egui;
|
||||
|
||||
struct KnobApp {
|
||||
value: f32,
|
||||
@@ -56,12 +63,55 @@ impl eframe::App for KnobApp {
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let options = eframe::NativeOptions::default();
|
||||
fn main() -> eframe::Result<()> {
|
||||
eframe::run_native(
|
||||
"Minimal",
|
||||
options,
|
||||
Box::new(|_cc| Ok(Box::new(KnobApp::default()) as Box<dyn eframe::App>)),
|
||||
).unwrap();
|
||||
"Knob Example",
|
||||
eframe::NativeOptions::default(),
|
||||
Box::new(|_cc| Ok(Box::new(KnobApp::default()))),
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
### Advanced Examples
|
||||
|
||||
#### Custom Sweep Range
|
||||
```rust
|
||||
// 270° sweep starting from the left (9 o'clock position)
|
||||
Knob::new(&mut value, 0.0, 100.0, KnobStyle::Wiper)
|
||||
.with_sweep_range(0.25, 0.75)
|
||||
.with_label("Gain", LabelPosition::Bottom);
|
||||
```
|
||||
|
||||
#### Multi-Turn Knob
|
||||
```rust
|
||||
// 2.5 full rotations
|
||||
Knob::new(&mut value, 0.0, 1.0, KnobStyle::Dot)
|
||||
.with_sweep_range(0.0, 2.5);
|
||||
```
|
||||
|
||||
#### Stepped Values
|
||||
```rust
|
||||
// Snap to 0.1 increments
|
||||
Knob::new(&mut value, 0.0, 1.0, KnobStyle::Wiper)
|
||||
.with_step(Some(0.1))
|
||||
.with_label_format(|v| format!("{:.1}", v));
|
||||
```
|
||||
|
||||
#### Custom Formatting
|
||||
```rust
|
||||
// Display as percentage
|
||||
Knob::new(&mut value, 0.0, 1.0, KnobStyle::Wiper)
|
||||
.with_label_format(|v| format!("{:.0}%", v * 100.0));
|
||||
```
|
||||
|
||||
## Running demo app
|
||||
|
||||
```bash
|
||||
cargo run --example example_knob
|
||||
```
|
||||
|
||||
Demo app is available at [examples/example_knob.rs](examples/example_knob.rs).
|
||||
|
||||
## Contributing
|
||||
|
||||
Contributions are welcome. Feel free to open an issue or submit a PR.
|
||||
|
||||
Reference in New Issue
Block a user