Skip to main content

Slider

Struct Slider 

Source
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 wheel step a notch, by default the step, 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, at or under the limit, 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

Source

pub fn new(value: Signal<f32>) -> Slider

A slider showing value and writing it back as it is dragged.

Source

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.

Source

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.

Source

pub fn limit(self, max: impl IntoProp<Option<f32>>) -> Slider

Caps what a drag, the wheel, the keys or a screen reader can set, below the range’s end, as a brightness slider held to half in a power saver mode; the track still shows the whole range. None, the default, a cap that isn’t a number or one past the end is the end, and one under the start is the start. With a step, a cap between steps stops at the step under it. A value set from outside past the cap shows where it is, and the next move from there lands at or under the cap.

Source

pub fn wheel_step(self, step: impl IntoProp<f32>) -> Slider

Sets how far one wheel notch or arrow key moves the value, so a slider of whole steps can move 5 a notch. By default, or when it isn’t a number above 0, it is the step, or a twentieth of the range without one. With a step, it is rounded to a whole number of steps, at least one, so 4 on a step of 10 moves 10 and 25 moves 30 (half rounds away from zero).

Source

pub fn vertical(self, vertical: impl IntoProp<bool>) -> Slider

Makes the slider run from the bottom up instead of left to right.

Source

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.

Source

pub fn style(self, style: impl IntoProp<Style>) -> Slider

Sets the track’s style, its size included.

Source

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.

Source

pub fn handle_style(self, style: impl IntoProp<Style>) -> Slider

Sets the handle’s style, its width and height included.

Source

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.

Source

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.

Source

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.

Source

pub fn mapped_geometry(self, geometry: Signal<Rect>) -> Self

Shares where the widget is drawn: the box around it once its own and its ancestors’ translate, scale and rotate have moved it, in the window’s logical pixels, scrolled with any scroll view around it. It is written after each layout that moves it and after each change of a transform or an offset that does, every frame of an animated one. A hidden widget writes nothing. Where the window itself is on its output is unknown: Wayland doesn’t tell a client.

Source

pub fn accessible_name(self, name: impl IntoProp<String>) -> Self

What a screen reader calls the widget, instead of what it shows: a button’s text, a text’s own, or a field’s placeholder. An icon button needs one to be read at all.

Source

pub fn mask_region(self, region: impl IntoProp<Option<Region>>) -> Self

Keeps the widget and everything inside it only within region, given in the widget’s own logical pixels from its top-left corner, with antialiased edges and rounded corners. Nothing shows outside the widget’s box, as with a style’s mask, and both apply when both are set. None, the default, keeps it all.

It changes only what is drawn: the pointer still hits the whole widget, so a click in a hole reaches it. A window’s own mask is what lets clicks through.

A new region repaints the widget’s painted area, its box unless its children overflow it, and never lays the window out, so a region that changes every frame of an animation costs a repaint of that area each frame. A full-screen 1080p picture with a few rounded holes took about 6 to 8 ms a frame at scale 1 and 22 to 25 ms at scale 2 on a 12-core laptop, most of it in the tiles a hole’s edge crosses.

Trait Implementations§

Source§

impl Widget for Slider

Source§

fn into_element(self: Box<Self>) -> Element

Turns the description, and everything inside it, into the element the window builds nodes from. It runs when the window is created or a list item first appears, before the window’s tree is touched and without recording what it reads, so it only describes.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Slider

§

impl !Send for Slider

§

impl !Sync for Slider

§

impl !UnwindSafe for Slider

§

impl Forget for Slider

§

impl Freeze for Slider

§

impl Move for Slider

§

impl Unpin for Slider

§

impl UnsafeUnpin for Slider

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more