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:
Marshall Bowers
2023-11-29 18:46:41 -05:00
committed by GitHub
parent 481e42ade9
commit 9d53287341
5 changed files with 45 additions and 51 deletions
+15 -15
View File
@@ -9,7 +9,6 @@ pub struct IconButton {
icon: Icon,
icon_size: IconSize,
icon_color: Color,
selected: bool,
}
impl IconButton {
@@ -19,15 +18,9 @@ impl IconButton {
icon,
icon_size: IconSize::default(),
icon_color: Color::Default,
selected: false,
}
}
pub fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
pub fn icon_size(mut self, icon_size: IconSize) -> Self {
self.icon_size = icon_size;
self
@@ -43,6 +36,20 @@ impl IconButton {
}
}
impl Disableable for IconButton {
fn disabled(mut self, disabled: bool) -> Self {
self.base = self.base.disabled(disabled);
self
}
}
impl Selectable for IconButton {
fn selected(mut self, selected: bool) -> Self {
self.base = self.base.selected(selected);
self
}
}
impl Clickable for IconButton {
fn on_click(
mut self,
@@ -53,13 +60,6 @@ impl Clickable for IconButton {
}
}
impl Disableable for IconButton {
fn disabled(mut self, disabled: bool) -> Self {
self.base = self.base.disabled(disabled);
self
}
}
impl ButtonCommon for IconButton {
fn id(&self) -> &ElementId {
self.base.id()
@@ -87,7 +87,7 @@ impl RenderOnce for IconButton {
fn render(self, _cx: &mut WindowContext) -> Self::Rendered {
let icon_color = if self.base.disabled {
Color::Disabled
} else if self.selected {
} else if self.base.selected {
Color::Selected
} else {
self.icon_color