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: f32Current value in [0.0, 1.0]. 0.0 paints no fill; 1.0 fills the
whole pill.
width: LengthWidth of the pill. Defaults to 56 px; accepts any Length.
height: LengthHeight 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 strTheme 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 strTheme slot id for the filled portion. Same role as
Self::track_surface but for the rising fill.
Implementations§
Source§impl<Msg: Clone> VSlider<Msg>
impl<Msg: Clone> VSlider<Msg>
Sourcepub fn new(value: f32) -> Self
pub fn new(value: f32) -> Self
Create a vertical slider at the given value (clamped to [0.0, 1.0]).
Sourcepub fn track_surface(self, id: &'static str) -> Self
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.
Sourcepub fn fill_surface(self, id: &'static str) -> Self
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.
Sourcepub fn size(self, width: impl Into<Length>, height: impl Into<Length>) -> Self
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.
Sourcepub fn on_change(self, f: impl Fn(f32) -> Msg + 'static) -> Self
pub fn on_change(self, f: impl Fn(f32) -> Msg + 'static) -> Self
Set the callback invoked when the slider value changes.
Sourcepub fn preferred_size(&self, _max_width: f32, canvas: &Canvas) -> (f32, f32)
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.
Sourcepub fn value_from_y(&self, rect: Rect, y: f32) -> f32
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.
Sourcepub fn paint_bounds(&self, rect: Rect) -> Rect
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.
Sourcepub fn draw(&self, canvas: &mut Canvas, rect: Rect, _focused: bool)
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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