pub struct Radio<Msg: Clone> { /* private fields */ }Expand description
One option inside a mutually-exclusive group.
Renders a circle with a centred dot when selected. Unlike
Checkbox, a radio is meaningful only as
part of a group: the group is the application’s responsibility — define
an enum for the choices, store the current value, and build one Radio
per variant with selected = current == this_variant.
#[ derive( Clone, PartialEq ) ]
enum Priority { Low, Medium, High }
// In view():
column()
.push( radio( self.priority == Priority::Low ).label( "Low" ).on_select( Msg::SetPriority( Priority::Low ) ) )
.push( radio( self.priority == Priority::Medium ).label( "Medium" ).on_select( Msg::SetPriority( Priority::Medium ) ) )
.push( radio( self.priority == Priority::High ).label( "High" ).on_select( Msg::SetPriority( Priority::High ) ) )
.into()ltk does not enforce mutual exclusion automatically; the application’s
update decides which variant becomes active when a radio is selected.
Implementations§
Source§impl<Msg: Clone> Radio<Msg>
impl<Msg: Clone> Radio<Msg>
Sourcepub fn new(selected: bool) -> Self
pub fn new(selected: bool) -> Self
Create a radio in the given state, with no label and no callback.
Sourcepub fn on_select(self, msg: Msg) -> Self
pub fn on_select(self, msg: Msg) -> Self
Set the message emitted when this option is picked. The
application’s update is responsible for flipping the group’s
current value.
Sourcepub fn label(self, label: impl Into<String>) -> Self
pub fn label(self, label: impl Into<String>) -> Self
Set a text label rendered to the right of the circle.
Sourcepub fn height(self, h: impl Into<Length>) -> Self
pub fn height(self, h: impl Into<Length>) -> Self
Override the preferred height (default: the theme row height,
theme::HEIGHT design px). Accepts any Length so dense
layouts can tie the row height to the viewport. The resolved
value is floored at the outer circle size so the ring never
clips; the circle keeps its theme size and stays centred.
pub fn preferred_size(&self, max_width: f32, canvas: &Canvas) -> (f32, f32)
Sourcepub fn paint_bounds(&self, rect: Rect) -> Rect
pub fn paint_bounds(&self, rect: Rect) -> Rect
Focus ring on the outer circle extends FOCUS_W + 2 + FOCUS_W/2 ≈ 6.5 px
beyond the circle (which sits flush with the widget’s left edge).
pub fn draw(&self, canvas: &mut Canvas, rect: Rect, focused: bool)
Trait Implementations§
Auto Trait Implementations§
impl<Msg> Freeze for Radio<Msg>where
Msg: Freeze,
impl<Msg> RefUnwindSafe for Radio<Msg>where
Msg: RefUnwindSafe,
impl<Msg> Send for Radio<Msg>where
Msg: Send,
impl<Msg> Sync for Radio<Msg>where
Msg: Sync,
impl<Msg> Unpin for Radio<Msg>where
Msg: Unpin,
impl<Msg> UnwindSafe for Radio<Msg>where
Msg: UnwindSafe,
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> DowncastSync for T
impl<T> DowncastSync for T
§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