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 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

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 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.

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