239 lines
5.7 KiB
Rust
239 lines
5.7 KiB
Rust
pub use gpui2::{
|
|
div, Component, Element, ElementId, ParentElement, SharedString, StatefulInteractive,
|
|
StatelessInteractive, Styled, ViewContext, WindowContext,
|
|
};
|
|
|
|
pub use crate::elevation::*;
|
|
pub use crate::ButtonVariant;
|
|
pub use theme2::ActiveTheme;
|
|
|
|
use gpui2::Hsla;
|
|
use strum::EnumIter;
|
|
|
|
/// Represents a person with a Zed account's public profile.
|
|
/// All data in this struct should be considered public.
|
|
pub struct PublicActor {
|
|
pub username: SharedString,
|
|
pub avatar: SharedString,
|
|
pub is_contact: bool,
|
|
}
|
|
|
|
impl PublicActor {
|
|
pub fn new(username: impl Into<SharedString>, avatar: impl Into<SharedString>) -> Self {
|
|
Self {
|
|
username: username.into(),
|
|
avatar: avatar.into(),
|
|
is_contact: false,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
|
|
pub enum FileSystemStatus {
|
|
#[default]
|
|
None,
|
|
Conflict,
|
|
Deleted,
|
|
}
|
|
|
|
impl std::fmt::Display for FileSystemStatus {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(
|
|
f,
|
|
"{}",
|
|
match self {
|
|
Self::None => "None",
|
|
Self::Conflict => "Conflict",
|
|
Self::Deleted => "Deleted",
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
|
|
pub enum GitStatus {
|
|
#[default]
|
|
None,
|
|
Created,
|
|
Modified,
|
|
Deleted,
|
|
Conflict,
|
|
Renamed,
|
|
}
|
|
|
|
impl GitStatus {
|
|
pub fn hsla(&self, cx: &WindowContext) -> Hsla {
|
|
match self {
|
|
Self::None => cx.theme().styles.system.transparent,
|
|
Self::Created => cx.theme().styles.git.created,
|
|
Self::Modified => cx.theme().styles.git.modified,
|
|
Self::Deleted => cx.theme().styles.git.deleted,
|
|
Self::Conflict => cx.theme().styles.git.conflict,
|
|
Self::Renamed => cx.theme().styles.git.renamed,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for GitStatus {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(
|
|
f,
|
|
"{}",
|
|
match self {
|
|
Self::None => "None",
|
|
Self::Created => "Created",
|
|
Self::Modified => "Modified",
|
|
Self::Deleted => "Deleted",
|
|
Self::Conflict => "Conflict",
|
|
Self::Renamed => "Renamed",
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
|
|
pub enum DiagnosticStatus {
|
|
#[default]
|
|
None,
|
|
Error,
|
|
Warning,
|
|
Info,
|
|
}
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
|
|
pub enum IconSide {
|
|
#[default]
|
|
Left,
|
|
Right,
|
|
}
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
|
|
pub enum OrderMethod {
|
|
#[default]
|
|
Ascending,
|
|
Descending,
|
|
MostRecent,
|
|
}
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
|
|
pub enum Shape {
|
|
#[default]
|
|
Circle,
|
|
RoundedRectangle,
|
|
}
|
|
|
|
#[derive(Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
|
|
pub enum DisclosureControlVisibility {
|
|
#[default]
|
|
OnHover,
|
|
Always,
|
|
}
|
|
|
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, EnumIter)]
|
|
pub enum DisclosureControlStyle {
|
|
/// Shows the disclosure control only when hovered where possible.
|
|
///
|
|
/// More compact, but not available everywhere.
|
|
ChevronOnHover,
|
|
/// Shows an icon where possible, otherwise shows a chevron.
|
|
///
|
|
/// For example, in a file tree a folder or file icon is shown
|
|
/// instead of a chevron
|
|
Icon,
|
|
/// Always shows a chevron.
|
|
Chevron,
|
|
/// Completely hides the disclosure control where possible.
|
|
None,
|
|
}
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, EnumIter)]
|
|
pub enum OverflowStyle {
|
|
Hidden,
|
|
Wrap,
|
|
}
|
|
|
|
#[derive(Default, PartialEq, Copy, Clone, EnumIter, strum::Display)]
|
|
pub enum InteractionState {
|
|
#[default]
|
|
Enabled,
|
|
Hovered,
|
|
Active,
|
|
Focused,
|
|
Disabled,
|
|
}
|
|
|
|
impl InteractionState {
|
|
pub fn if_enabled(&self, enabled: bool) -> Self {
|
|
if enabled {
|
|
*self
|
|
} else {
|
|
InteractionState::Disabled
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Default, PartialEq)]
|
|
pub enum SelectedState {
|
|
#[default]
|
|
Unselected,
|
|
PartiallySelected,
|
|
Selected,
|
|
}
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
|
|
pub enum Toggleable {
|
|
Toggleable(ToggleState),
|
|
#[default]
|
|
NotToggleable,
|
|
}
|
|
|
|
impl Toggleable {
|
|
pub fn is_toggled(&self) -> bool {
|
|
match self {
|
|
Self::Toggleable(ToggleState::Toggled) => true,
|
|
_ => false,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<ToggleState> for Toggleable {
|
|
fn from(state: ToggleState) -> Self {
|
|
Self::Toggleable(state)
|
|
}
|
|
}
|
|
|
|
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq)]
|
|
pub enum ToggleState {
|
|
/// The "on" state of a toggleable element.
|
|
///
|
|
/// Example:
|
|
/// - A collasable list that is currently expanded
|
|
/// - A toggle button that is currently on.
|
|
Toggled,
|
|
/// The "off" state of a toggleable element.
|
|
///
|
|
/// Example:
|
|
/// - A collasable list that is currently collapsed
|
|
/// - A toggle button that is currently off.
|
|
#[default]
|
|
NotToggled,
|
|
}
|
|
|
|
impl From<Toggleable> for ToggleState {
|
|
fn from(toggleable: Toggleable) -> Self {
|
|
match toggleable {
|
|
Toggleable::Toggleable(state) => state,
|
|
Toggleable::NotToggleable => ToggleState::NotToggled,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<bool> for ToggleState {
|
|
fn from(toggled: bool) -> Self {
|
|
if toggled {
|
|
ToggleState::Toggled
|
|
} else {
|
|
ToggleState::NotToggled
|
|
}
|
|
}
|
|
}
|