Button2 – Part1 (#3420)

## TODO

- [x] Remove `InteractionState`
- [ ] `Selectable` should use `Selection` instead of a boolean
- [x] Clean out ui2 prelude
- [ ] Build out button2 button types
- [ ] Port old buttons

Release Notes:

- N/A

---------

Co-authored-by: Marshall Bowers <1486634+maxdeviant@users.noreply.github.com>
This commit is contained in:
Nate Butler 2023-11-29 12:23:09 -05:00 committed by GitHub
parent 5d59108b97
commit a8bf0834e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 567 additions and 339 deletions

View file

@ -8,7 +8,7 @@ pub struct IconButton {
color: Color,
size: IconSize,
variant: ButtonVariant,
state: InteractionState,
disabled: bool,
selected: bool,
tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView + 'static>>,
on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
@ -18,9 +18,9 @@ impl RenderOnce for IconButton {
type Rendered = Stateful<Div>;
fn render(self, cx: &mut WindowContext) -> Self::Rendered {
let icon_color = match (self.state, self.color) {
(InteractionState::Disabled, _) => Color::Disabled,
(InteractionState::Active, _) => Color::Selected,
let icon_color = match (self.disabled, self.selected, self.color) {
(true, _, _) => Color::Disabled,
(false, true, _) => Color::Selected,
_ => self.color,
};
@ -82,8 +82,8 @@ impl IconButton {
color: Color::default(),
size: Default::default(),
variant: ButtonVariant::default(),
state: InteractionState::default(),
selected: false,
disabled: false,
tooltip: None,
on_click: None,
}
@ -109,13 +109,13 @@ impl IconButton {
self
}
pub fn state(mut self, state: InteractionState) -> Self {
self.state = state;
pub fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
self
}
pub fn selected(mut self, selected: bool) -> Self {
self.selected = selected;
pub fn disabled(mut self, disabled: bool) -> Self {
self.disabled = disabled;
self
}