Slider

Struct Slider 

Source
pub struct Slider<'a, T, Message, Theme = Theme>
where Theme: Catalog,
{ /* private fields */ }
Expand description

An horizontal bar and a handle that selects a single value from a range of values.

A Slider will try to fill the horizontal space of its container.

The Slider range of numeric values is generic and its step size defaults to 1 unit.

§Example

use iced::widget::slider;

struct State {
   value: f32,
}

#[derive(Debug, Clone)]
enum Message {
    ValueChanged(f32),
}

fn view(state: &State) -> Element<'_, Message> {
    slider(0.0..=100.0, state.value, Message::ValueChanged).into()
}

fn update(state: &mut State, message: Message) {
    match message {
        Message::ValueChanged(value) => {
            state.value = value;
        }
    }
}

Implementations§

Source§

impl<'a, T, Message, Theme> Slider<'a, T, Message, Theme>
where T: Copy + From<u8> + PartialOrd, Message: Clone, Theme: Catalog,

Source

pub const DEFAULT_HEIGHT: f32 = 16f32

The default height of a Slider.

Source

pub fn new<F>(range: RangeInclusive<T>, value: T, on_change: F) -> Self
where F: 'a + Fn(T) -> Message,

Creates a new Slider.

It expects:

  • an inclusive range of possible values
  • the current value of the Slider
  • a function that will be called when the Slider is dragged. It receives the new value of the Slider and must produce a Message.
Source

pub fn default(self, default: impl Into<T>) -> Self

Sets the optional default value for the Slider.

If set, the Slider will reset to this value when ctrl-clicked or command-clicked.

Source

pub fn on_release(self, on_release: Message) -> Self

Sets the release message of the Slider. This is called when the mouse is released from the slider.

Typically, the user’s interaction with the slider is finished when this message is produced. This is useful if you need to spawn a long-running task from the slider’s result, where the default on_change message could create too many events.

Source

pub fn width(self, width: impl Into<Length>) -> Self

Sets the width of the Slider.

Source

pub fn height(self, height: impl Into<Pixels>) -> Self

Sets the height of the Slider.

Source

pub fn step(self, step: impl Into<T>) -> Self

Sets the step size of the Slider.

Source

pub fn shift_step(self, shift_step: impl Into<T>) -> Self

Sets the optional “shift” step for the Slider.

If set, this value is used as the step while the shift key is pressed.

Source

pub fn style(self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self
where Theme::Class<'a>: From<StyleFn<'a, Theme>>,

Sets the style of the Slider.

Source

pub fn class(self, class: impl Into<Theme::Class<'a>>) -> Self

Available on crate feature advanced only.

Sets the style class of the Slider.

Trait Implementations§

Source§

impl<'a, T, Message, Theme, Renderer> From<Slider<'a, T, Message, Theme>> for Element<'a, Message, Theme, Renderer>
where T: Copy + Into<f64> + FromPrimitive + 'a, Message: Clone + 'a, Theme: Catalog + 'a, Renderer: Renderer + 'a,

Source§

fn from( slider: Slider<'a, T, Message, Theme>, ) -> Element<'a, Message, Theme, Renderer>

Converts to this type from the input type.
Source§

impl<T, Message, Theme, Renderer> Widget<Message, Theme, Renderer> for Slider<'_, T, Message, Theme>
where T: Copy + Into<f64> + FromPrimitive, Message: Clone, Theme: Catalog, Renderer: Renderer,

Source§

fn tag(&self) -> Tag

Returns the Tag of the Widget.
Source§

fn state(&self) -> State

Returns the State of the Widget.
Source§

fn size(&self) -> Size<Length>

Returns the Size of the Widget in lengths.
Source§

fn layout( &mut self, _tree: &mut Tree, _renderer: &Renderer, limits: &Limits, ) -> Node

Returns the layout::Node of the Widget. Read more
Source§

fn update( &mut self, tree: &mut Tree, event: &Event, layout: Layout<'_>, cursor: Cursor, _renderer: &Renderer, _clipboard: &mut dyn Clipboard, shell: &mut Shell<'_, Message>, _viewport: &Rectangle, )

Processes a runtime Event. Read more
Source§

fn draw( &self, _tree: &Tree, renderer: &mut Renderer, theme: &Theme, _style: &Style, layout: Layout<'_>, _cursor: Cursor, _viewport: &Rectangle, )

Draws the Widget using the associated Renderer.
Source§

fn mouse_interaction( &self, tree: &Tree, layout: Layout<'_>, cursor: Cursor, _viewport: &Rectangle, _renderer: &Renderer, ) -> Interaction

Returns the current mouse::Interaction of the Widget. Read more
Source§

fn size_hint(&self) -> Size<Length>

Returns a Size hint for laying out the Widget. Read more
Source§

fn children(&self) -> Vec<Tree>

Returns the state Tree of the children of the Widget.
Source§

fn diff(&self, tree: &mut Tree)

Reconciles the Widget with the provided Tree.
Source§

fn operate( &mut self, _tree: &mut Tree, _layout: Layout<'_>, _renderer: &Renderer, _operation: &mut dyn Operation, )

Applies an Operation to the Widget.
Source§

fn overlay<'a>( &'a mut self, _tree: &'a mut Tree, _layout: Layout<'a>, _renderer: &Renderer, _viewport: &Rectangle, _translation: Vector, ) -> Option<Element<'a, Message, Theme, Renderer>>

Returns the overlay of the Widget, if there is any.

Auto Trait Implementations§

§

impl<'a, T, Message, Theme> Freeze for Slider<'a, T, Message, Theme>
where T: Freeze, <Theme as Catalog>::Class<'a>: Freeze, Message: Freeze,

§

impl<'a, T, Message, Theme = Theme> !RefUnwindSafe for Slider<'a, T, Message, Theme>

§

impl<'a, T, Message, Theme = Theme> !Send for Slider<'a, T, Message, Theme>

§

impl<'a, T, Message, Theme = Theme> !Sync for Slider<'a, T, Message, Theme>

§

impl<'a, T, Message, Theme> Unpin for Slider<'a, T, Message, Theme>
where T: Unpin, <Theme as Catalog>::Class<'a>: Unpin, Message: Unpin,

§

impl<'a, T, Message, Theme = Theme> !UnwindSafe for Slider<'a, T, Message, Theme>

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.