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>
impl<'a, C: PixelColor + 'a, M: Clone + 'a> Roller<'a, C, M>
Sourcepub fn new() -> Self
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.
Sourcepub fn options(self, options: &[&str]) -> Self
pub fn options(self, options: &[&str]) -> Self
Replace all options from a slice of string slices.
Sourcepub fn scroll_state(self, state: &ScrollState) -> Self
pub fn scroll_state(self, state: &ScrollState) -> Self
Supply the host-owned ScrollState read this frame.
Sourcepub fn selected(self, index: usize) -> Self
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.
Sourcepub fn id(self, id: WidgetId) -> Self
pub fn id(self, id: WidgetId) -> Self
Set a stable id so this roller can participate in focus traversal.
Sourcepub fn item_height(self, height: u32) -> Self
pub fn item_height(self, height: u32) -> Self
Pixel height of one option row (default 36).
Sourcepub fn visible_count(self, count: u32) -> Self
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.
Sourcepub fn font(self, font: &'a MonoFont<'a>) -> Self
pub fn font(self, font: &'a MonoFont<'a>) -> Self
Override the option font (defaults to theme.typography.body).
Sourcepub fn width(self, width: impl Into<Length>) -> Self
pub fn width(self, width: impl Into<Length>) -> Self
Width sizing intent (height is driven by visible * item_height).
Sourcepub fn on_scroll<F>(self, f: F) -> Self
pub fn on_scroll<F>(self, f: F) -> Self
Callback mapping a ScrollMsg to the host message. Apply the
message to the owned ScrollState in update().
Source§impl<'a, C: PixelColor + 'a, M: Clone + 'a> Roller<'a, C, M>
impl<'a, C: PixelColor + 'a, M: Clone + 'a> Roller<'a, C, M>
Sourcepub fn centered_for(
state: &ScrollState,
item_height: u32,
count: usize,
) -> usize
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).
Sourcepub fn select_msg(&self, previous: usize) -> Option<M>
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> Widget<C, M> for Roller<'a, C, M>
impl<'a, C: PixelColor + 'a, M: Clone + 'a> Widget<C, M> for Roller<'a, C, M>
Source§fn measure(&mut self, constraints: Constraints) -> Size
fn measure(&mut self, constraints: Constraints) -> Size
constraints.Source§fn preferred_size(&self) -> (Length, Length)
fn preferred_size(&self) -> (Length, Length)
.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)
fn arrange(&mut self, rect: Rectangle)
Source§fn handle_touch(&mut self, point: Point, phase: TouchPhase) -> Option<M>
fn handle_touch(&mut self, point: Point, phase: TouchPhase) -> Option<M>
Source§fn mark_pressed(&mut self, _point: Point)
fn mark_pressed(&mut self, _point: Point)
point hits. No message emit.
Containers forward to children. Default no-op.Source§fn widget_id(&self) -> Option<WidgetId>
fn widget_id(&self) -> Option<WidgetId>
Source§fn is_focusable(&self) -> bool
fn is_focusable(&self) -> bool
Source§fn handle_action(&mut self, action: UiAction) -> Option<M>
fn handle_action(&mut self, action: UiAction) -> Option<M>
Source§fn sync_focus(&mut self, focused: Option<WidgetId>)
fn sync_focus(&mut self, focused: Option<WidgetId>)
Source§fn draw<'t>(
&self,
renderer: &mut dyn Renderer<C>,
theme: &Theme<'t, C>,
) -> Result<(), RenderError>
fn draw<'t>( &self, renderer: &mut dyn Renderer<C>, theme: &Theme<'t, C>, ) -> Result<(), RenderError>
renderer at rect.Source§fn collect_focusable(&self, out: &mut Vec<WidgetId>)
fn collect_focusable(&self, out: &mut Vec<WidgetId>)
Source§fn route_action(&mut self, target: WidgetId, action: UiAction) -> Option<M>
fn route_action(&mut self, target: WidgetId, action: UiAction) -> Option<M>
target.target for directional actions.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> 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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<'a, C, M, W> IntoElement<'a, C, M> for W
impl<'a, C, M, W> IntoElement<'a, C, M> for W
Source§fn into_element(self) -> Element<'a, C, M>
fn into_element(self) -> Element<'a, C, M>
self.