Skip to main content

Roller

Struct Roller 

Source
pub struct Roller<'a, C: PixelColor, M: Clone> { /* private fields */ }
Expand description

Vertical wheel / drum selector.

Renders its options as a vertically scrollable drum with a fixed center highlight band. The host owns the ScrollState and the selected index; the roller reads the state, draws, and emits messages.

Implementations§

Source§

impl<'a, C: PixelColor + 'a, M: Clone + 'a> Roller<'a, C, M>

Source

pub fn new() -> Self

Create an empty roller. Supply options via Roller::options or Roller::option, and the host state via Roller::scroll_state. Position and size are assigned by the parent container via arrange.

Source

pub fn options(self, options: &[&str]) -> Self

Replace all options from a slice of string slices.

Source

pub fn option(self, label: impl Into<String>) -> Self

Append a single option label.

Source

pub fn scroll_state(self, state: &ScrollState) -> Self

Supply the host-owned ScrollState read this frame.

Source

pub fn selected(self, index: usize) -> Self

The host’s currently selected option index. Used to colour the centered row at rest before any scroll has happened.

Source

pub fn id(self, id: WidgetId) -> Self

Set a stable id so this roller can participate in focus traversal.

Source

pub fn item_height(self, height: u32) -> Self

Pixel height of one option row (default 36).

Source

pub fn visible_count(self, count: u32) -> Self

Number of rows shown in the viewport (default 5). Kept odd so exactly one row sits under the highlight band.

Source

pub fn font(self, font: &'a MonoFont<'a>) -> Self

Override the option font (defaults to theme.typography.body).

Source

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

Width sizing intent (height is driven by visible * item_height).

Source

pub fn on_scroll<F>(self, f: F) -> Self
where F: Fn(ScrollMsg) -> M + 'a,

Callback mapping a ScrollMsg to the host message. Apply the message to the owned ScrollState in update().

Source

pub fn on_select<F>(self, f: F) -> Self
where F: Fn(usize) -> M + 'a,

Callback fired with the centered option index whenever it changes (during drag, fling, or settle).

Source

pub fn on_action<F>(self, f: F) -> Self
where F: Fn(UiAction) -> M + 'a,

Callback fired with semantic actions while the roller is focused.

Source§

impl<'a, C: PixelColor + 'a, M: Clone + 'a> Roller<'a, C, M>

Source

pub fn centered_for( state: &ScrollState, item_height: u32, count: usize, ) -> usize

The option index currently under the highlight band for a given host ScrollState and item_height. The host calls this in its update() after applying a ScrollMsg (or after a ScrollState::tick) to learn which option is centered, without rebuilding the widget tree.

item_height must match the value configured on the widget (default: 36 pixels).

Source

pub fn select_msg(&self, previous: usize) -> Option<M>

Build the on_select message for the currently-centered option when it differs from previous, or whenever the drum has settled to rest. Returns None if no on_select callback is set or the selection is unchanged mid-motion.

The host typically calls this from update() after applying a ScrollMsg/tick so the selection follows the drum as it spins and commits when it settles.

Trait Implementations§

Source§

impl<'a, C: PixelColor + 'a, M: Clone + 'a> Default for Roller<'a, C, M>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, C: PixelColor + 'a, M: Clone + 'a> Widget<C, M> for Roller<'a, C, M>

Source§

fn measure(&mut self, constraints: Constraints) -> Size

Report the size this widget wants within constraints.
Source§

fn preferred_size(&self) -> (Length, Length)

Per-axis sizing intent set via .width(...) / .height(...). Containers consult this during layout to allocate fixed slots, query intrinsic sizes, and split residual space among Fill / FillPortion children. Default is Length::Fill on both axes.
Source§

fn arrange(&mut self, rect: Rectangle)

Commit the final rectangle, recursively arranging any children.
Source§

fn rect(&self) -> Rectangle

The current arranged rectangle.
Source§

fn handle_touch(&mut self, point: Point, phase: TouchPhase) -> Option<M>

Dispatch a touch event. Returns a message if consumed.
Source§

fn mark_pressed(&mut self, _point: Point)

Set this widget’s pressed flag if point hits. No message emit. Containers forward to children. Default no-op.
Source§

fn widget_id(&self) -> Option<WidgetId>

Stable id of this widget, if it participates in focus.
Source§

fn is_focusable(&self) -> bool

True if this widget should appear in focus traversal.
Source§

fn handle_action(&mut self, action: UiAction) -> Option<M>

Handle a semantic action directed at this widget.
Source§

fn sync_focus(&mut self, focused: Option<WidgetId>)

Synchronize focused state against the runtime’s currently-focused id.
Source§

fn focus_at(&self, point: Point) -> Option<WidgetId>

Focusable widget id at point, if any.
Source§

fn draw<'t>( &self, renderer: &mut dyn Renderer<C>, theme: &Theme<'t, C>, ) -> Result<(), RenderError>

Paint into renderer at rect.
Source§

fn collect_focusable(&self, out: &mut Vec<WidgetId>)

Append focusable widget ids in traversal order.
Source§

fn route_action(&mut self, target: WidgetId, action: UiAction) -> Option<M>

Route a semantic action to the widget with id target.
Source§

fn navigate_focus(&self, target: WidgetId, action: UiAction) -> Option<WidgetId>

Request a focus movement relative to target for directional actions.
Source§

fn focus_rect(&self, target: WidgetId) -> Option<Rectangle>

Rectangle currently occupied by the focusable target, if any.

Auto Trait Implementations§

§

impl<'a, C, M> Freeze for Roller<'a, C, M>

§

impl<'a, C, M> !RefUnwindSafe for Roller<'a, C, M>

§

impl<'a, C, M> !Send for Roller<'a, C, M>

§

impl<'a, C, M> !Sync for Roller<'a, C, M>

§

impl<'a, C, M> Unpin for Roller<'a, C, M>
where C: Unpin,

§

impl<'a, C, M> UnsafeUnpin for Roller<'a, C, M>

§

impl<'a, C, M> !UnwindSafe for Roller<'a, C, M>

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

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
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<'a, C, M, W> IntoElement<'a, C, M> for W
where C: PixelColor + 'a, M: Clone + 'a, W: Widget<C, M> + 'a,

Source§

fn into_element(self) -> Element<'a, C, M>

Wrap self.
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.