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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 51 deletions

View file

@ -172,6 +172,7 @@ pub struct ButtonLike {
id: ElementId,
pub(super) style: ButtonStyle2,
pub(super) disabled: bool,
pub(super) selected: bool,
size: ButtonSize2,
tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView>>,
on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
@ -184,6 +185,7 @@ impl ButtonLike {
id: id.into(),
style: ButtonStyle2::default(),
disabled: false,
selected: false,
size: ButtonSize2::Default,
tooltip: None,
children: SmallVec::new(),
@ -199,6 +201,13 @@ impl Disableable for ButtonLike {
}
}
impl Selectable for ButtonLike {
fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
}
impl Clickable for ButtonLike {
fn on_click(mut self, handler: impl Fn(&ClickEvent, &mut WindowContext) + 'static) -> Self {
self.on_click = Some(Box::new(handler));
@ -206,19 +215,6 @@ impl Clickable for ButtonLike {
}
}
// impl Selectable for ButtonLike {
// fn selected(&mut self, selected: bool) -> &mut Self {
// todo!()
// }
// fn selected_tooltip(
// &mut self,
// tooltip: Box<dyn Fn(&mut WindowContext) -> AnyView + 'static>,
// ) -> &mut Self {
// todo!()
// }
// }
impl ButtonCommon for ButtonLike {
fn id(&self) -> &ElementId {
&self.id