pub struct ToggleRoot { /* private fields */ }Expand description
A Radix-shaped Toggle root configuration surface.
Upstream supports a controlled/uncontrolled pressed state (pressed + defaultPressed). In
Fret this maps to either:
- a caller-provided
Model<bool>(controlled), or - an internal
Model<bool>stored in element state (uncontrolled).
Implementations§
Source§impl ToggleRoot
impl ToggleRoot
pub fn new() -> Self
Sourcepub fn pressed(self, pressed: Option<Model<bool>>) -> Self
pub fn pressed(self, pressed: Option<Model<bool>>) -> Self
Sets the controlled pressed model (Some) or selects uncontrolled mode (None).
Sourcepub fn default_pressed(self, default_pressed: bool) -> Self
pub fn default_pressed(self, default_pressed: bool) -> Self
Sets the uncontrolled initial pressed value (Radix defaultPressed).
pub fn disabled(self, disabled: bool) -> Self
pub fn a11y_label(self, label: impl Into<Arc<str>>) -> Self
Sourcepub fn new_controllable<H: UiHost>(
cx: &mut ElementContext<'_, H>,
pressed: Option<Model<bool>>,
default_pressed: impl FnOnce() -> bool,
) -> Self
pub fn new_controllable<H: UiHost>( cx: &mut ElementContext<'_, H>, pressed: Option<Model<bool>>, default_pressed: impl FnOnce() -> bool, ) -> Self
Creates a toggle root with a controlled/uncontrolled pressed model (Radix pressed /
defaultPressed).
Notes:
- The internal model (uncontrolled mode) is stored in element state at the call site.
- Call this from a stable subtree (key the node if you need state to survive reordering).
Sourcepub fn use_pressed_model<H: UiHost>(
&self,
cx: &mut ElementContext<'_, H>,
) -> ControllableModel<bool>
pub fn use_pressed_model<H: UiHost>( &self, cx: &mut ElementContext<'_, H>, ) -> ControllableModel<bool>
Returns a Model<bool> that behaves like Radix useControllableState for pressed.
pub fn pressed_model<H: UiHost>( &self, cx: &mut ElementContext<'_, H>, ) -> Model<bool>
Sourcepub fn is_pressed<H: UiHost>(&self, cx: &mut ElementContext<'_, H>) -> bool
pub fn is_pressed<H: UiHost>(&self, cx: &mut ElementContext<'_, H>) -> bool
Reads the current pressed value from the derived pressed model.
Sourcepub fn into_element<H: UiHost, I, T>(
self,
cx: &mut ElementContext<'_, H>,
props: PressableProps,
f: impl FnOnce(&mut ElementContext<'_, H>, PressableState, bool) -> I,
) -> AnyElementwhere
I: IntoIterator<Item = T>,
T: IntoUiElement<H>,
pub fn into_element<H: UiHost, I, T>(
self,
cx: &mut ElementContext<'_, H>,
props: PressableProps,
f: impl FnOnce(&mut ElementContext<'_, H>, PressableState, bool) -> I,
) -> AnyElementwhere
I: IntoIterator<Item = T>,
T: IntoUiElement<H>,
Renders a toggle-like pressable, wiring Radix-like pressed state and a11y.
Notes:
- Activation toggles the boolean model (disabled guards apply).
- This does not apply any visual skin. Pass the desired
PressableProps.
Trait Implementations§
Source§impl Clone for ToggleRoot
impl Clone for ToggleRoot
Source§fn clone(&self) -> ToggleRoot
fn clone(&self) -> ToggleRoot
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ToggleRoot
impl Debug for ToggleRoot
Source§impl Default for ToggleRoot
impl Default for ToggleRoot
Source§fn default() -> ToggleRoot
fn default() -> ToggleRoot
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ToggleRoot
impl !RefUnwindSafe for ToggleRoot
impl !Send for ToggleRoot
impl !Sync for ToggleRoot
impl Unpin for ToggleRoot
impl UnsafeUnpin for ToggleRoot
impl !UnwindSafe for ToggleRoot
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
Mutably borrows from an owned value. Read more