diff --git a/widget/src/toggler.rs b/widget/src/toggler.rs index 8eaf3372..1810d906 100644 --- a/widget/src/toggler.rs +++ b/widget/src/toggler.rs @@ -287,8 +287,8 @@ where |limits| { if let Some(label) = self.label.as_deref() { let state = tree - .state - .downcast_mut::>(); + .state + .downcast_mut::>(); widget::text::layout( state, @@ -343,7 +343,9 @@ where } let current_status = if self.on_toggle.is_none() { - Status::Disabled + Status::Disabled { + is_toggled: self.is_toggled, + } } else if cursor.is_over(layout.bounds()) { Status::Hovered { is_toggled: self.is_toggled, @@ -400,8 +402,12 @@ where let mut children = layout.children(); let toggler_layout = children.next().unwrap(); - let style = theme - .style(&self.class, self.last_status.unwrap_or(Status::Disabled)); + let style = theme.style( + &self.class, + self.last_status.unwrap_or(Status::Disabled { + is_toggled: self.is_toggled, + }), + ); if self.label.is_some() { let label_layout = children.next().unwrap(); @@ -500,7 +506,10 @@ pub enum Status { is_toggled: bool, }, /// The [`Toggler`] is disabled. - Disabled, + Disabled { + /// Indicates whether the [`Toggler`] is toggled. + is_toggled: bool, + }, } /// The appearance of a toggler. @@ -563,7 +572,13 @@ pub fn default(theme: &Theme, status: Status) -> Style { palette.background.strong.color } } - Status::Disabled => palette.background.weak.color, + Status::Disabled { is_toggled } => { + if is_toggled { + palette.background.strong.color + } else { + palette.background.weak.color + } + } }; let foreground = match status { @@ -584,7 +599,7 @@ pub fn default(theme: &Theme, status: Status) -> Style { palette.background.weak.color } } - Status::Disabled => palette.background.weakest.color, + Status::Disabled { .. } => palette.background.weakest.color, }; Style {