Implement Selectable
for buttons (#3451)
This PR implements the `Selectable` trait for `ButtonLike`, `Button`, and `IconButton`. Release Notes: - N/A
This commit is contained in:
parent
481e42ade9
commit
9d53287341
5 changed files with 45 additions and 51 deletions
|
@ -8,7 +8,6 @@ pub struct Button {
|
|||
base: ButtonLike,
|
||||
label: SharedString,
|
||||
label_color: Option<Color>,
|
||||
selected: bool,
|
||||
}
|
||||
|
||||
impl Button {
|
||||
|
@ -17,21 +16,29 @@ impl Button {
|
|||
base: ButtonLike::new(id),
|
||||
label: label.into(),
|
||||
label_color: None,
|
||||
selected: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn selected(mut self, selected: bool) -> Self {
|
||||
self.selected = selected;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn color(mut self, label_color: impl Into<Option<Color>>) -> Self {
|
||||
self.label_color = label_color.into();
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Selectable for Button {
|
||||
fn selected(mut self, selected: bool) -> Self {
|
||||
self.base = self.base.selected(selected);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Disableable for Button {
|
||||
fn disabled(mut self, disabled: bool) -> Self {
|
||||
self.base = self.base.disabled(disabled);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Clickable for Button {
|
||||
fn on_click(
|
||||
mut self,
|
||||
|
@ -42,13 +49,6 @@ impl Clickable for Button {
|
|||
}
|
||||
}
|
||||
|
||||
impl Disableable for Button {
|
||||
fn disabled(mut self, disabled: bool) -> Self {
|
||||
self.base = self.base.disabled(disabled);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl ButtonCommon for Button {
|
||||
fn id(&self) -> &ElementId {
|
||||
self.base.id()
|
||||
|
@ -76,7 +76,7 @@ impl RenderOnce for Button {
|
|||
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
|
||||
let label_color = if self.base.disabled {
|
||||
Color::Disabled
|
||||
} else if self.selected {
|
||||
} else if self.base.selected {
|
||||
Color::Selected
|
||||
} else {
|
||||
Color::Default
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue