pub struct Slider { /* private fields */ }Expand description
A value picked by dragging a handle along a track, as Qt’s Slider.
The slider writes the value back to its signal, and setting the signal
moves the handle.
A press anywhere on the slider moves the value there and drags it from there. The wheel moves it one step a notch, or a twentieth of the range when it has no step, and a touchpad in proportion; so do the arrow keys while it has the keyboard focus, which Tab gives it. The value written is always within the range and on a step, and only a change is written. A value set from outside the range shows at that end, and NaN at the start.
It draws nothing until styled: style sets the track’s box, 120 by 4
logical pixels unless it sets a size, fill_style the part from the
start to the handle, and handle_style the handle, 16 by 16 unless it
sets a size. The slider is as large as the track, or the handle where
that is larger.
use crabshell_ui::{Color, Cx, Slider, Style};
const TRACK: Style = Style::new().width(200.0).height(4.0).radius(2.0)
.background(Color::rgb(0x45, 0x47, 0x5a));
const FILL: Style = Style::new().radius(2.0).background(Color::rgb(0x89, 0xb4, 0xfa));
const HANDLE: Style = Style::new().radius(8.0).background(Color::rgb(0xcd, 0xd6, 0xf4));
fn volume(cx: &Cx) -> Slider {
let volume = cx.signal(50.0);
Slider::new(volume).range(0.0, 100.0).step(5.0)
.style(TRACK).fill_style(FILL).handle_style(HANDLE)
}Implementations§
Source§impl Slider
impl Slider
Sourcepub fn new(value: Signal<f32>) -> Slider
pub fn new(value: Signal<f32>) -> Slider
A slider showing value and writing it back as it is dragged.
Sourcepub fn range(self, min: impl IntoProp<f32>, max: impl IntoProp<f32>) -> Slider
pub fn range(self, min: impl IntoProp<f32>, max: impl IntoProp<f32>) -> Slider
Sets the values at the start and the end, 0 and 1 by default. A range whose end isn’t above its start holds only the start.
Sourcepub fn step(self, step: impl IntoProp<f32>) -> Slider
pub fn step(self, step: impl IntoProp<f32>) -> Slider
Snaps the value to whole steps from the start of the range. 0, the default, or a step that isn’t a number above 0, slides freely.
Sourcepub fn vertical(self, vertical: impl IntoProp<bool>) -> Slider
pub fn vertical(self, vertical: impl IntoProp<bool>) -> Slider
Makes the slider run from the bottom up instead of left to right.
Sourcepub fn enabled(self, enabled: impl IntoProp<bool>) -> Slider
pub fn enabled(self, enabled: impl IntoProp<bool>) -> Slider
Turns the slider on or off, as Button::enabled: off, nothing
moves it and Tab skips it.
Sourcepub fn style(self, style: impl IntoProp<Style>) -> Slider
pub fn style(self, style: impl IntoProp<Style>) -> Slider
Sets the track’s style, its size included.
Sourcepub fn fill_style(self, style: impl IntoProp<Style>) -> Slider
pub fn fill_style(self, style: impl IntoProp<Style>) -> Slider
Sets the style of the part of the track from the start to the handle’s middle. Its size comes from the value.
Sourcepub fn handle_style(self, style: impl IntoProp<Style>) -> Slider
pub fn handle_style(self, style: impl IntoProp<Style>) -> Slider
Sets the handle’s style, its width and height included.
Sourcepub fn dragging(self, dragging: Signal<bool>) -> Slider
pub fn dragging(self, dragging: Signal<bool>) -> Slider
Shares whether the slider is being dragged: true from the press
until the release, as Qt’s pressed. Written only on a change.
Sourcepub fn visible(self, visible: impl IntoProp<bool>) -> Self
pub fn visible(self, visible: impl IntoProp<bool>) -> Self
Shows or hides the widget. Hidden, it is taken out of the layout, so its space goes to the others, and it isn’t drawn, hit or reached by Tab; it drops the keyboard focus and the pointer. Its bindings and state stay, so it shows again as it was. Shown by default.
Sourcepub fn geometry(self, geometry: Signal<Rect>) -> Self
pub fn geometry(self, geometry: Signal<Rect>) -> Self
Shares where the widget is: after each layout that moves or
resizes it, its laid-out rectangle in the window’s logical
pixels, scrolled with any scroll view around it but not moved by
a style’s translate, scale or rotate, is written to geometry. A
hidden widget writes nothing. An effect that reads it may change
the layout: the window is laid out again at once, until nothing
moves.