mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-17 14:51:04 +02:00
Merge pull request #119 from JakeStanger/feat/slider-step
Custom slider widget step option
This commit is contained in:
commit
618e97f1e8
3 changed files with 46 additions and 12 deletions
|
@ -289,9 +289,10 @@ For details on available modules and each of their config options, check the sid
|
||||||
|
|
||||||
For information on the `Script` type, and embedding scripts in strings, see [here](script).
|
For information on the `Script` type, and embedding scripts in strings, see [here](script).
|
||||||
|
|
||||||
|
#### Events
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|-------------------|--------------------|---------|--------------------------------------------------------------------------------------------------------------------|
|
|-------------------|--------------------|---------|--------------------------------------------------------------------------------------------------------------------|
|
||||||
| `show_if` | `Script [polling]` | `null` | Polls the script to check its exit code. If exit code is zero, the module is shown. For other codes, it is hidden. |
|
|
||||||
| `on_click_left` | `Script [oneshot]` | `null` | Runs the script when the module is left clicked. |
|
| `on_click_left` | `Script [oneshot]` | `null` | Runs the script when the module is left clicked. |
|
||||||
| `on_click_middle` | `Script [oneshot]` | `null` | Runs the script when the module is middle clicked. |
|
| `on_click_middle` | `Script [oneshot]` | `null` | Runs the script when the module is middle clicked. |
|
||||||
| `on_click_right` | `Script [oneshot]` | `null` | Runs the script when the module is right clicked. |
|
| `on_click_right` | `Script [oneshot]` | `null` | Runs the script when the module is right clicked. |
|
||||||
|
@ -299,4 +300,19 @@ For information on the `Script` type, and embedding scripts in strings, see [her
|
||||||
| `on_scroll_down` | `Script [oneshot]` | `null` | Runs the script when the module is scrolled down on. |
|
| `on_scroll_down` | `Script [oneshot]` | `null` | Runs the script when the module is scrolled down on. |
|
||||||
| `on_mouse_enter` | `Script [oneshot]` | `null` | Runs the script when the module is hovered over. |
|
| `on_mouse_enter` | `Script [oneshot]` | `null` | Runs the script when the module is hovered over. |
|
||||||
| `on_mouse_exit` | `Script [oneshot]` | `null` | Runs the script when the module is no longer hovered over. |
|
| `on_mouse_exit` | `Script [oneshot]` | `null` | Runs the script when the module is no longer hovered over. |
|
||||||
|
|
||||||
|
#### Visibility
|
||||||
|
|
||||||
|
|
||||||
|
| Name | Type | Default | Description |
|
||||||
|
|-----------------------|-------------------------------------------------------|---------------|--------------------------------------------------------------------------------------------------------------------|
|
||||||
|
| `show_if` | `Script [polling]` | `null` | Polls the script to check its exit code. If exit code is zero, the module is shown. For other codes, it is hidden. |
|
||||||
|
| `transition_type` | `slide_start` or `slide_end` or `crossfade` or `none` | `slide_start` | The transition animation to use when showing/hiding the widget. |
|
||||||
|
| `transition_duration` | `Integer` | `250` | The length of the transition animation to use when showing/hiding the widget. |
|
||||||
|
|
||||||
|
#### Other
|
||||||
|
|
||||||
|
|
||||||
|
| Name | Type | Default | Description |
|
||||||
|
|-------------------|--------------------|---------|--------------------------------------------------------------------------------------------------------------------|
|
||||||
| `tooltip` | `string` | `null` | Shows this text on hover. Supports embedding scripts between `{{double braces}}`. |
|
| `tooltip` | `string` | `null` | Shows this text on hover. Supports embedding scripts between `{{double braces}}`. |
|
|
@ -77,7 +77,7 @@ Note that `on_change` will provide the **floating point** value as an argument.
|
||||||
If your input program requires an integer, you will need to round it.
|
If your input program requires an integer, you will need to round it.
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|---------------|----------------------------------------------------|--------------|------------------------------------------------------------------------------|
|
|---------------|----------------------------------------------------|--------------|---------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `src` | `image` | `null` | Image source. See [here](images) for information on images. |
|
| `src` | `image` | `null` | Image source. See [here](images) for information on images. |
|
||||||
| `size` | `integer` | `null` | Width/height of the image. Aspect ratio is preserved. |
|
| `size` | `integer` | `null` | Width/height of the image. Aspect ratio is preserved. |
|
||||||
| `orientation` | `horizontal` or `vertical` (shorthand: `h` or `v`) | `horizontal` | Orientation of the slider. |
|
| `orientation` | `horizontal` or `vertical` (shorthand: `h` or `v`) | `horizontal` | Orientation of the slider. |
|
||||||
|
@ -85,6 +85,7 @@ If your input program requires an integer, you will need to round it.
|
||||||
| `on_change` | `string [command]` | `null` | Command to execute when the slider changes. More on this [below](#commands). |
|
| `on_change` | `string [command]` | `null` | Command to execute when the slider changes. More on this [below](#commands). |
|
||||||
| `min` | `float` | `0` | Minimum slider value. |
|
| `min` | `float` | `0` | Minimum slider value. |
|
||||||
| `max` | `float` | `100` | Maximum slider value. |
|
| `max` | `float` | `100` | Maximum slider value. |
|
||||||
|
| `step` | `float` | - | The increment to change when scrolling with the mouse wheel. If left blank, will use the default determined by the environment. |
|
||||||
| `length` | `integer` | `null` | Slider length. GTK will automatically size if left unset. |
|
| `length` | `integer` | `null` | Slider length. GTK will automatically size if left unset. |
|
||||||
|
|
||||||
The example slider widget below shows a volume control for MPC,
|
The example slider widget below shows a volume control for MPC,
|
||||||
|
|
|
@ -7,6 +7,7 @@ use gtk::prelude::*;
|
||||||
use gtk::Scale;
|
use gtk::Scale;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
use std::ops::Neg;
|
||||||
use tokio::spawn;
|
use tokio::spawn;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
|
@ -21,6 +22,7 @@ pub struct SliderWidget {
|
||||||
min: f64,
|
min: f64,
|
||||||
#[serde(default = "default_max")]
|
#[serde(default = "default_max")]
|
||||||
max: f64,
|
max: f64,
|
||||||
|
step: Option<f64>,
|
||||||
length: Option<i32>,
|
length: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,11 +55,26 @@ impl CustomWidget for SliderWidget {
|
||||||
if let Some(on_change) = self.on_change {
|
if let Some(on_change) = self.on_change {
|
||||||
let min = self.min;
|
let min = self.min;
|
||||||
let max = self.max;
|
let max = self.max;
|
||||||
|
let step = self.step;
|
||||||
let tx = context.tx.clone();
|
let tx = context.tx.clone();
|
||||||
|
|
||||||
// GTK will spam the same value over and over
|
// GTK will spam the same value over and over
|
||||||
let prev_value = Cell::new(scale.value());
|
let prev_value = Cell::new(scale.value());
|
||||||
|
|
||||||
|
scale.connect_scroll_event(move |scale, event| {
|
||||||
|
let value = scale.value();
|
||||||
|
let delta = event.delta().1.neg();
|
||||||
|
|
||||||
|
let delta = match (step, delta.is_sign_positive()) {
|
||||||
|
(Some(step), true) => step,
|
||||||
|
(Some(step), false) => -step,
|
||||||
|
(None, _) => delta,
|
||||||
|
};
|
||||||
|
|
||||||
|
scale.set_value(value + delta);
|
||||||
|
Inhibit(false)
|
||||||
|
});
|
||||||
|
|
||||||
scale.connect_change_value(move |scale, _, val| {
|
scale.connect_change_value(move |scale, _, val| {
|
||||||
// GTK will send values outside min/max range
|
// GTK will send values outside min/max range
|
||||||
let val = val.clamp(min, max);
|
let val = val.clamp(min, max);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue