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

@ -3,62 +3,9 @@ pub use gpui::{
ViewContext, WindowContext,
};
pub use crate::clickable::*;
pub use crate::fixed::*;
pub use crate::selectable::*;
pub use crate::StyledExt;
pub use crate::{ButtonVariant, Color};
pub use theme::ActiveTheme;
use strum::EnumIter;
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
pub enum IconSide {
#[default]
Left,
Right,
}
#[derive(Default, PartialEq, Copy, Clone, EnumIter, strum::Display)]
pub enum InteractionState {
/// An element that is enabled and not hovered, active, focused, or disabled.
///
/// This is often referred to as the "default" state.
#[default]
Enabled,
/// An element that is hovered.
Hovered,
/// An element has an active mouse down or touch start event on it.
Active,
/// An element that is focused using the keyboard.
Focused,
/// An element that is disabled.
Disabled,
/// A toggleable element that is selected, like the active button in a
/// button toggle group.
Selected,
}
impl InteractionState {
pub fn if_enabled(&self, enabled: bool) -> Self {
if enabled {
*self
} else {
InteractionState::Disabled
}
}
}
#[derive(Debug, Default, PartialEq, Eq, Hash, Clone, Copy)]
pub enum Selection {
#[default]
Unselected,
Indeterminate,
Selected,
}
impl Selection {
pub fn inverse(&self) -> Self {
match self {
Self::Unselected | Self::Indeterminate => Self::Selected,
Self::Selected => Self::Unselected,
}
}
}