Merge pull request #2908 from pml68/feat/toggler-is-toggled
Add the current toggle state to `toggler::Status::Disabled`
This commit is contained in:
commit
5e9660a0d5
1 changed files with 23 additions and 8 deletions
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue