Merge pull request #2908 from pml68/feat/toggler-is-toggled

Add the current toggle state to `toggler::Status::Disabled`
This commit is contained in:
Héctor 2025-11-25 22:09:47 +01:00 • committed by GitHub
commit 5e9660a0d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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