Skip to content

Commit

Permalink
Allow the toggle style outside of just the toggle (#475)
Browse files Browse the repository at this point in the history
* Allow the toggle style outside of just the toggle

* clippy
  • Loading branch information
jrmoulton committed May 30, 2024
1 parent 6fe51db commit 20cbfdb
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/views/toggle_button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ pub struct ToggleButton {
///
/// Styles:
/// background color: [style::Background]
/// foreground color: [style::Foreground]
///
/// Toggle color: [style::Foreground]
///
/// inner switch inset: [ToggleButtonInset]
///
/// inner switch (circle) size/radius: [ToggleButtonCircleRad]
///
/// toggle button switch behavior: [ToggleButtonBehavior] / [ToggleHandleBehavior]
///
/// An example using [`RwSignal`](floem_reactive::RwSignal):
Expand Down Expand Up @@ -279,7 +283,7 @@ impl ToggleButton {
let view_state = id.state();
let offset = view_state.borrow_mut().style.next_offset();
let style = create_updater(
move || style(ToggleButtonCustomStyle(Style::new())),
move || style(ToggleButtonCustomStyle::new()),
move |style| id.update_style(offset, style.0),
);
view_state.borrow_mut().style.push(style.0);
Expand All @@ -291,6 +295,10 @@ impl ToggleButton {
pub struct ToggleButtonCustomStyle(Style);

impl ToggleButtonCustomStyle {
pub fn new() -> Self {
Self(Style::new())
}

/// Sets the color of the toggle handle.
///
/// # Arguments
Expand Down Expand Up @@ -338,9 +346,13 @@ impl ToggleButtonCustomStyle {
self
}

/// Apply regular style properties
pub fn style(mut self, style: impl Fn(Style) -> Style + 'static) -> Self {
self = Self(self.0.apply(style(Style::new())));
self
/// Get the inner style
pub fn style(self) -> Style {
self.0
}
}
impl Default for ToggleButtonCustomStyle {
fn default() -> Self {
Self::new()
}
}

0 comments on commit 20cbfdb

Please sign in to comment.