feat: add is_toggled field to toggler::Status's Disabled variant
This commit is contained in:
parent
e163333161
commit
2a7a09cb9b
1 changed files with 23 additions and 8 deletions
|
|
@ -287,8 +287,8 @@ where
|
|||
|limits| {
|
||||
if let Some(label) = self.label.as_deref() {
|
||||
let state = tree
|
||||
.state
|
||||
.downcast_mut::<widget::text::State<Renderer::Paragraph>>();
|
||||
.state
|
||||
.downcast_mut::<widget::text::State<Renderer::Paragraph>>();
|
||||
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue