Add Disableable
trait (#3439)
This PR adds a new `Disableable` trait to use for elements that are capable of being disabled. Release Notes: - N/A
This commit is contained in:
parent
c23a610d52
commit
3e2c517dd1
7 changed files with 27 additions and 16 deletions
|
@ -201,13 +201,11 @@ impl ButtonSize2 {
|
|||
// children: SmallVec<[AnyElement; 2]>,
|
||||
// }
|
||||
|
||||
pub trait ButtonCommon: Clickable {
|
||||
pub trait ButtonCommon: Clickable + Disableable {
|
||||
fn id(&self) -> &ElementId;
|
||||
fn style(self, style: ButtonStyle2) -> Self;
|
||||
fn disabled(self, disabled: bool) -> Self;
|
||||
fn size(self, size: ButtonSize2) -> Self;
|
||||
fn tooltip(self, tooltip: impl Fn(&mut WindowContext) -> AnyView + 'static) -> Self;
|
||||
// fn width(&mut self, width: DefiniteLength) -> &mut Self;
|
||||
}
|
||||
|
||||
// pub struct LabelButton {
|
||||
|
@ -266,14 +264,6 @@ pub struct ButtonLike {
|
|||
}
|
||||
|
||||
impl ButtonLike {
|
||||
pub fn children(
|
||||
&mut self,
|
||||
children: impl IntoIterator<Item = impl Into<AnyElement>>,
|
||||
) -> &mut Self {
|
||||
self.children = children.into_iter().map(Into::into).collect();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn new(id: impl Into<ElementId>) -> Self {
|
||||
Self {
|
||||
id: id.into(),
|
||||
|
@ -287,6 +277,13 @@ impl ButtonLike {
|
|||
}
|
||||
}
|
||||
|
||||
impl Disableable for ButtonLike {
|
||||
fn disabled(mut self, disabled: bool) -> Self {
|
||||
self.disabled = disabled;
|
||||
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));
|
||||
|
@ -317,11 +314,6 @@ impl ButtonCommon for ButtonLike {
|
|||
self
|
||||
}
|
||||
|
||||
fn disabled(mut self, disabled: bool) -> Self {
|
||||
self.disabled = disabled;
|
||||
self
|
||||
}
|
||||
|
||||
fn size(mut self, size: ButtonSize2) -> Self {
|
||||
self.size = size;
|
||||
self
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue