Skip to main content

Slider

Struct Slider 

Source
pub struct Slider<S> { /* private fields */ }
Expand description

A slider labeled label that sets the i32 signal value.

It is a native <input type="range">, so the browser gives it role="slider", the arrow keys, Page Up, Page Down, Home, and End, and dragging with a pointer or a finger. The input is transparent and lies over a track and a thumb drawn from the value, so the slider looks the same in every browser. The value is shown beside the label, hidden from assistive technology, which reads it from the input.

The thumb is drawn 1rem wide. The browser’s own transparent thumb, which the pointer actually drags, has the width the browser gives it, so the drawn thumb can sit a few pixels off the pointer near either end.

use hypersig::Signals;
use hypersig_ui::Slider;
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize)]
struct Player {
    volume: i32,
}

let volume = Slider::new("Volume", Player::volume()).range(0, 100).step(5);
let html = volume.render().render();
assert!(html.contains(r#"type="range""#));
assert!(html.contains(r#"max="100""#));

Implementations§

Source§

impl<S> Slider<S>

Source

pub fn new(label: impl Into<String>, value: Sig<S, i32>) -> Self

A slider from 0 to 100 in steps of 1, labeled label, bound to value.

Source

pub fn range(self, min: i32, max: i32) -> Self

Sets the lowest and the highest value.

§Panics

Panics if min is not below max.

Source

pub fn step(self, step: i32) -> Self

Sets how far one arrow key press moves the value.

§Panics

Panics if step is not positive.

Source

pub fn value_text(self, text: impl IntoExpr<S, String>) -> Self

Shows text beside the label and gives it to assistive technology as aria-valuetext, for a value that needs a unit, such as “40 %”.

Source

pub fn disabled(self, when: impl IntoExpr<S, bool>) -> Self

Disables the slider while when is true, and dims it.

Source

pub fn render(self) -> El<S>

The label, the shown value, and the slider, in a <div>.

Trait Implementations§

Source§

impl<S: Debug> Debug for Slider<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S> From<Slider<S>> for El<S>

Source§

fn from(slider: Slider<S>) -> Self

Converts to this type from the input type.
Source§

impl<S> From<Slider<S>> for Node<S>

Source§

fn from(slider: Slider<S>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> Freeze for Slider<S>

§

impl<S> RefUnwindSafe for Slider<S>

§

impl<S> Send for Slider<S>

§

impl<S> Sync for Slider<S>

§

impl<S> Unpin for Slider<S>

§

impl<S> UnsafeUnpin for Slider<S>

§

impl<S> UnwindSafe for Slider<S>

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, 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.