ltk

Struct VSlider

Source
pub struct VSlider<Msg: Clone> {
    pub value: f32,
    pub width: Length,
    pub height: Length,
    pub on_change: Option<Arc<dyn Fn(f32) -> Msg>>,
    pub track_surface: &'static str,
    pub fill_surface: &'static str,
}
Expand description

A vertical slider — a rounded pill that fills from bottom to top to indicate its value.

Unlike Slider, which is horizontal and designed to stretch across whatever width its parent allocates, a VSlider has fixed pill dimensions (56 × 160 px by default) configurable via VSlider::size. The widget reports those dimensions as its preferred size and ignores the max_width the parent offers — it is intrinsically sized, not filler.

The widget renders a rounded track in palette.surface_alt and, on top, a rising pill in palette.accent whose height is proportional to VSlider::value. No separate thumb is drawn; the top edge of the fill itself acts as the value indicator.

use ltk::{ stack, vslider, img_widget, HAlign, VAlign };

// Plain vertical slider.
let _: ltk::VSlider<Msg> = vslider( self.volume ).on_change( Msg::SetVolume );

// With a speaker icon overlaid at the top. Stacked image children are
// non-interactive, so drag events still reach the slider underneath.
stack::<Msg>()
    .push( vslider( self.volume ).on_change( Msg::SetVolume ) )
    .push_aligned(
        img_widget( speaker_rgba, speaker_w, speaker_h ),
        HAlign::Center, VAlign::Top,
    )
.into()

Fields§

§value: f32

Current value in [0.0, 1.0]. 0.0 paints no fill; 1.0 fills the whole pill.

§width: Length

Width of the pill. Defaults to 56 px; accepts any Length.

§height: Length

Height of the pill. Defaults to 160 px; accepts any Length.

§on_change: Option<Arc<dyn Fn(f32) -> Msg>>

Callback invoked with the new value when the slider is tapped or dragged. Arc (not Box) so the layout pass can clone it into the per-leaf handler snapshot for O(1) dispatch on input events.

§track_surface: &'static str

Theme slot id for the unfilled track. Defaults to surface-slider-track. Override with VSlider::track_surface when the slider lives inside a panel that already provides its own backdrop blur — point the slot at a *-flat variant (no backdrop field) so the pipeline does not run a redundant backdrop snapshot per slider per frame.

§fill_surface: &'static str

Theme slot id for the filled portion. Same role as Self::track_surface but for the rising fill.

Implementations§

Source§

impl<Msg: Clone> VSlider<Msg>

Source

pub fn new(value: f32) -> Self

Create a vertical slider at the given value (clamped to [0.0, 1.0]).

Source

pub fn track_surface(self, id: &'static str) -> Self

Override the theme slot id used for the unfilled track. See Self::track_surface for the use case.

Source

pub fn fill_surface(self, id: &'static str) -> Self

Override the theme slot id used for the rising fill. See Self::track_surface for the use case.

Source

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

Override the pill size. Accepts logical f32 pixels or any Length variant (e.g. Length::vw(16.0) for 16 % of the viewport width). Both are clamped to a minimum of 2.0 after viewport-relative values resolve, so a rounded pill can always be drawn.

Source

pub fn on_change(self, f: impl Fn(f32) -> Msg + 'static) -> Self

Set the callback invoked when the slider value changes.

Source

pub fn preferred_size(&self, _max_width: f32, canvas: &Canvas) -> (f32, f32)

Return the preferred (width, height). max_width is ignored — see the type-level docs on intrinsic sizing.

Source

pub fn value_from_y(&self, rect: Rect, y: f32) -> f32

Compute the value [0.0, 1.0] from a tap/drag y position within rect.

Source

pub fn paint_bounds(&self, rect: Rect) -> Rect

VSlider paints strictly inside its layout rect — no hover halo, no thumb overshoot. The partial-redraw path gets a tight bound.

Source

pub fn draw(&self, canvas: &mut Canvas, rect: Rect, _focused: bool)

Draw the slider into canvas at rect. The track fills rect as a rounded pill; the value rises from the bottom edge.

The track and fill both resolve to Glass surfaces when the active theme ships the surface-slider-track / surface-slider-fill slots (the default does). When the slots are absent we fall back to a flat pill in palette.surface_alt / palette.accent — this is how a bare-bones third-party theme still paints a usable slider without having to replicate the full inset-shadow stack.

Trait Implementations§

Source§

impl<Msg: Clone + 'static> From<VSlider<Msg>> for Element<Msg>

Source§

fn from(s: VSlider<Msg>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Msg> Freeze for VSlider<Msg>

§

impl<Msg> !RefUnwindSafe for VSlider<Msg>

§

impl<Msg> !Send for VSlider<Msg>

§

impl<Msg> !Sync for VSlider<Msg>

§

impl<Msg> Unpin for VSlider<Msg>

§

impl<Msg> !UnwindSafe for VSlider<Msg>

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
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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