History

Bring UI crate up to date (#3013)

Merges various in-progress gpui2 component branches with the new `ui` crate.

Nate Butler committed 3 years ago

Commit a5e055f2 parents 5083ab7 30b105a25 files · +1090 −210Browse files

Unified · Split

25 files
  1. crates/ui/doc/elevation.md +57 −0
  2. crates/ui/src/components.rs +4 −0
  3. crates/ui/src/components/list_item.rs +48 −24
  4. crates/ui/src/components/list_section_header.rs +88 −0
  5. crates/ui/src/components/palette_item.rs +63 −0
  6. crates/ui/src/elements/icon.rs +23 −22
  7. crates/ui/src/elements/label.rs +30 −4
  8. crates/ui/src/lib.rs +7 −0
  9. crates/ui/src/modules.rs +4 −10
  10. crates/ui/src/modules/list.rs +64 −0
  11. crates/ui/src/modules/palette.rs +124 −0
  12. crates/ui/src/modules/project_panel.rs +0 −94
  13. crates/ui/src/prelude.rs +15 −0
  14. crates/ui/src/static_data.rs +166 −0
  15. crates/ui/src/templates.rs +17 −0
  16. crates/ui/src/templates/chat_panel.rs +4 −4
  17. crates/ui/src/templates/collab_panel.rs +177 −0
  18. crates/ui/src/templates/command_palette.rs +31 −0
  19. crates/ui/src/templates/project_panel.rs +62 −0
  20. crates/ui/src/templates/status_bar.rs +3 −4
  21. crates/ui/src/templates/tab_bar.rs +5 −5
  22. crates/ui/src/templates/title_bar.rs +0 −0
  23. crates/ui/src/templates/workspace.rs +80 −0
  24. crates/ui/src/tokens.rs +18 −0
  25. docs/ui/states.md +0 −43
crates/ui/doc/elevation.md+57−0
@@ -0,0 +1,57 @@
1# Elevation
2
3Elevation in Zed applies to all surfaces and components. Elevation is categorized into levels.
4
5Elevation accomplishes the following:
6- Allows surfaces to move in front of or behind others, such as content scrolling beneath app top bars.
7- Reflects spatial relationships, for instance, how a floating action button’s shadow intimates its disconnection from a collection of cards.
8- Directs attention to structures at the highest elevation, like a temporary dialog arising in front of other surfaces.
9
10Elevations are the initial elevation values assigned to components by default.
11
12Components may transition to a higher elevation in some cases, like user interations.
13
14On such occasions, components transition to predetermined dynamic elevation offsets. These are the typical elevations to which components move when they are not at rest.
15
16## Understanding Elevation
17
18Elevation can be thought of as the physical closeness of an element to the user. Elements with lower elevations are physically further away from the user on the z-axis and appear to be underneath elements with higher elevations.
19
20Material Design 3 has a some great visualizations of elevation that may be helpful to understanding the mental modal of elevation. [Material Design – Elevation](https://m3.material.io/styles/elevation/overview)
21
22## Elevation Levels
23
24Zed integrates six unique elevation levels in its design system. The elevation of a surface is expressed as a whole number ranging from 0 to 5, both numbers inclusive. A component’s elevation is ascertained by combining the component’s resting elevation with any dynamic elevation offsets.
25
26The levels are detailed as follows:
27
280. App Background
291. UI Surface
302. Elevated Elements
313. Wash
324. Focused Element
335. Dragged Element
34
35### 0. App Background
36
37The app background constitutes the lowest elevation layer, appearing behind all other surfaces and components. It is predominantly used for the background color of the app.
38
39### 1. UI Surface
40
41The UI Surface is the standard elevation for components and is placed above the app background. It is generally used for the background color of the app bar, card, and sheet.
42
43### 2. Elevated Elements
44
45Elevated elements appear above the UI surface layer surfaces and components. Elevated elements are predominantly used for creating popovers, context menus, and tooltips.
46
47### 3. Wash
48
49Wash denotes a distinct elevation reserved to isolate app UI layers from high elevation components such as modals, notifications, and overlaid panels. The wash may not consistently be visible when these components are active. This layer is often referred to as a scrim or overlay and the background color of the wash is typically deployed in its design.
50
51### 4. Focused Element
52
53Focused elements obtain a higher elevation above surfaces and components at wash elevation. They are often used for modals, notifications, and overlaid panels and indicate that they are the sole element the user is interacting with at the moment.
54
55### 5. Dragged Element
56
57Dragged elements gain the highest elevation, thus appearing above surfaces and components at the elevation of focused elements. These are typically used for elements that are being dragged, following the cursor
crates/ui/src/components.rs+4−0
@@ -1,12 +1,16 @@
1mod facepile;1mod facepile;
2mod follow_group;2mod follow_group;
3mod list_item;3mod list_item;
4mod list_section_header;
5mod palette_item;
4mod tab;6mod tab;
5mod traffic_lights;7mod traffic_lights;
6 8
7pub use facepile::*;9pub use facepile::*;
8pub use follow_group::*;10pub use follow_group::*;
9pub use list_item::*;11pub use list_item::*;
12pub use list_section_header::*;
13pub use palette_item::*;
10pub use tab::*;14pub use tab::*;
11pub use traffic_lights::*;15pub use traffic_lights::*;
12 16
crates/ui/src/components/list_item.rs+48−24
@@ -1,17 +1,18 @@
1use gpui2::elements::div;1use crate::prelude::{DisclosureControlVisibility, InteractionState, ToggleState};
2use gpui2::geometry::rems;2use crate::theme::theme;
3use crate::tokens::token;
4use crate::{icon, IconAsset, Label};
3use gpui2::style::{StyleHelpers, Styleable};5use gpui2::style::{StyleHelpers, Styleable};
4use gpui2::{Element, IntoElement, ParentElement, ViewContext};6use gpui2::{elements::div, IntoElement};
7use gpui2::{Element, ParentElement, ViewContext};
5 8
6use crate::prelude::*;9#[derive(Element, Clone)]
7use crate::{icon, theme, IconAsset, Label};
8
9#[derive(Element)]
10pub struct ListItem {10pub struct ListItem {
11 label: Label,11 label: Label,
12 left_icon: Option<IconAsset>,12 left_icon: Option<IconAsset>,
13 indent_level: u32,13 indent_level: u32,
14 state: InteractionState,14 state: InteractionState,
15 disclosure_control_style: DisclosureControlVisibility,
15 toggle: Option<ToggleState>,16 toggle: Option<ToggleState>,
16}17}
17 18
@@ -20,6 +21,7 @@ pub fn list_item(label: Label) -> ListItem { · 2 unmodified lines
20 label,21 label,
21 indent_level: 0,22 indent_level: 0,
22 left_icon: None,23 left_icon: None,
24 disclosure_control_style: DisclosureControlVisibility::default(),
23 state: InteractionState::default(),25 state: InteractionState::default(),
24 toggle: None,26 toggle: None,
25 }27 }
@@ -46,8 +48,30 @@ impl ListItem { · 20 unmodified lines
46 self48 self
47 }49 }
48 50
51 pub fn disclosure_control_style(
52 mut self,
53 disclosure_control_style: DisclosureControlVisibility,
54 ) -> Self {
55 self.disclosure_control_style = disclosure_control_style;
56 self
57 }
58
49 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {59 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
50 let theme = theme(cx);60 let theme = theme(cx);
61 let token = token();
62 let mut disclosure_control = match self.toggle {
63 Some(ToggleState::NotToggled) => Some(div().child(icon(IconAsset::ChevronRight))),
64 Some(ToggleState::Toggled) => Some(div().child(icon(IconAsset::ChevronDown))),
65 None => Some(div()),
66 };
67
68 match self.disclosure_control_style {
69 DisclosureControlVisibility::OnHover => {
70 disclosure_control =
71 disclosure_control.map(|c| div().absolute().neg_left_5().child(c));
72 }
73 DisclosureControlVisibility::Always => {}
74 }
51 75
52 div()76 div()
53 .fill(theme.middle.base.default.background)77 .fill(theme.middle.base.default.background)
@@ -56,31 +80,31 @@ impl ListItem { · 2 unmodified lines
56 .active()80 .active()
57 .fill(theme.middle.base.pressed.background)81 .fill(theme.middle.base.pressed.background)
58 .relative()82 .relative()
83 .py_1()
59 .child(84 .child(
60 div()85 div()
61 .h_7()86 .h_6()
62 .px_2()87 .px_2()
63 // .ml(rems(0.75 * self.indent_level as f32))88 // .ml(rems(0.75 * self.indent_level as f32))
64 .children((0..self.indent_level).map(|_| {89 .children((0..self.indent_level).map(|_| {
65 div().w(rems(0.75)).h_full().flex().justify_center().child(90 div()
66 div()91 .w(token.list_indent_depth)
67 .w_px()92 .h_full()
68 .h_full()93 .flex()
69 .fill(theme.middle.base.default.border)94 .justify_center()
70 .hover()95 .child(
71 .fill(theme.middle.warning.default.border)96 div()
72 .active()97 .ml_px()
73 .fill(theme.middle.negative.default.border),98 .w_px()
74 )99 .h_full()
100 .fill(theme.middle.base.default.border),
101 )
75 }))102 }))
76 .flex()103 .flex()
77 .gap_2()104 .gap_1()
78 .items_center()105 .items_center()
79 .children(match self.toggle {106 .relative()
80 Some(ToggleState::NotToggled) => Some(icon(IconAsset::ChevronRight)),107 .children(disclosure_control)
81 Some(ToggleState::Toggled) => Some(icon(IconAsset::ChevronDown)),
82 None => None,
83 })
84 .children(self.left_icon.map(|i| icon(i)))108 .children(self.left_icon.map(|i| icon(i)))
85 .child(self.label.clone()),109 .child(self.label.clone()),
86 )110 )
crates/ui/src/components/list_section_header.rs+88−0
@@ -0,0 +1,88 @@
1use crate::prelude::{InteractionState, ToggleState};
2use crate::theme::theme;
3use crate::tokens::token;
4use crate::{icon, label, IconAsset, LabelColor, LabelSize};
5use gpui2::style::{StyleHelpers, Styleable};
6use gpui2::{elements::div, IntoElement};
7use gpui2::{Element, ParentElement, ViewContext};
8
9#[derive(Element, Clone, Copy)]
10pub struct ListSectionHeader {
11 label: &'static str,
12 left_icon: Option<IconAsset>,
13 state: InteractionState,
14 toggle: Option<ToggleState>,
15}
16
17pub fn list_section_header(label: &'static str) -> ListSectionHeader {
18 ListSectionHeader {
19 label,
20 left_icon: None,
21 state: InteractionState::default(),
22 toggle: None,
23 }
24}
25
26impl ListSectionHeader {
27 pub fn set_toggle(mut self, toggle: ToggleState) -> Self {
28 self.toggle = Some(toggle);
29 self
30 }
31
32 pub fn left_icon(mut self, left_icon: Option<IconAsset>) -> Self {
33 self.left_icon = left_icon;
34 self
35 }
36
37 pub fn state(mut self, state: InteractionState) -> Self {
38 self.state = state;
39 self
40 }
41
42 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
43 let theme = theme(cx);
44 let token = token();
45
46 let disclosure_control = match self.toggle {
47 Some(ToggleState::NotToggled) => Some(div().child(icon(IconAsset::ChevronRight))),
48 Some(ToggleState::Toggled) => Some(div().child(icon(IconAsset::ChevronDown))),
49 None => Some(div()),
50 };
51
52 div()
53 .flex()
54 .flex_1()
55 .w_full()
56 .fill(theme.middle.base.default.background)
57 .hover()
58 .fill(theme.middle.base.hovered.background)
59 .active()
60 .fill(theme.middle.base.pressed.background)
61 .relative()
62 .py_1()
63 .child(
64 div()
65 .h_6()
66 .px_2()
67 .flex()
68 .flex_1()
69 .w_full()
70 .gap_1()
71 .items_center()
72 .justify_between()
73 .child(
74 div()
75 .flex()
76 .gap_1()
77 .items_center()
78 .children(self.left_icon.map(|i| icon(i)))
79 .child(
80 label(self.label.clone())
81 .color(LabelColor::Muted)
82 .size(LabelSize::Small),
83 ),
84 )
85 .children(disclosure_control),
86 )
87 }
88}
crates/ui/src/components/palette_item.rs+63−0
@@ -0,0 +1,63 @@
1use crate::theme::theme;
2use crate::{label, LabelColor, LabelSize};
3use gpui2::elements::div;
4use gpui2::style::StyleHelpers;
5use gpui2::{Element, IntoElement};
6use gpui2::{ParentElement, ViewContext};
7
8#[derive(Element)]
9pub struct PaletteItem {
10 pub label: &'static str,
11 pub keybinding: Option<&'static str>,
12}
13
14pub fn palette_item(label: &'static str, keybinding: Option<&'static str>) -> PaletteItem {
15 PaletteItem { label, keybinding }
16}
17
18impl PaletteItem {
19 pub fn label(mut self, label: &'static str) -> Self {
20 self.label = label;
21 self
22 }
23
24 pub fn keybinding(mut self, keybinding: Option<&'static str>) -> Self {
25 self.keybinding = keybinding;
26 self
27 }
28
29 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
30 let theme = theme(cx);
31
32 let keybinding_label = match self.keybinding {
33 Some(keybind) => label(keybind)
34 .color(LabelColor::Muted)
35 .size(LabelSize::Small),
36 None => label(""),
37 };
38
39 div()
40 .flex()
41 .flex_row()
42 .grow()
43 .justify_between()
44 .child(label(self.label))
45 .child(
46 self.keybinding
47 .map(|_| {
48 div()
49 .flex()
50 .items_center()
51 .justify_center()
52 .px_1()
53 .py_0()
54 .my_0p5()
55 .rounded_md()
56 .text_sm()
57 .fill(theme.lowest.on.default.background)
58 .child(keybinding_label)
59 })
60 .unwrap_or_else(|| div()),
61 )
62 }
63}
crates/ui/src/elements/icon.rs+23−22
@@ -1,29 +1,30 @@
1use crate::theme::theme;
1use gpui2::elements::svg;2use gpui2::elements::svg;
2use gpui2::style::StyleHelpers;3use gpui2::style::StyleHelpers;
3use gpui2::{Element, IntoElement, ViewContext};4use gpui2::IntoElement;
4 5use gpui2::{Element, ViewContext};
5use crate::theme;
6
7// Icon::Hash
8// icon(IconAsset::Hash).color(IconColor::Warning)
9// Icon::new(IconAsset::Hash).color(IconColor::Warning)
10 6
11#[derive(Default, PartialEq, Copy, Clone)]7#[derive(Default, PartialEq, Copy, Clone)]
12pub enum IconAsset {8pub enum IconAsset {
13 Ai,9 Ai,
14 ArrowLeft,10 ArrowLeft,
15 ArrowRight,11 ArrowRight,
16 #[default]
17 ArrowUpRight,12 ArrowUpRight,
18 Bolt,13 Bolt,
19 Hash,
20 File,
21 Folder,
22 FolderOpen,
23 ChevronDown,14 ChevronDown,
24 ChevronUp,
25 ChevronLeft,15 ChevronLeft,
26 ChevronRight,16 ChevronRight,
17 ChevronUp,
18 #[default]
19 File,
20 FileDoc,
21 FileGit,
22 FileLock,
23 FileRust,
24 FileToml,
25 Folder,
26 FolderOpen,
27 Hash,
27}28}
28 29
29impl IconAsset {30impl IconAsset {
@@ -34,14 +35,19 @@ impl IconAsset { · 4 unmodified lines
34 IconAsset::ArrowRight => "icons/arrow_right.svg",35 IconAsset::ArrowRight => "icons/arrow_right.svg",
35 IconAsset::ArrowUpRight => "icons/arrow_up_right.svg",36 IconAsset::ArrowUpRight => "icons/arrow_up_right.svg",
36 IconAsset::Bolt => "icons/bolt.svg",37 IconAsset::Bolt => "icons/bolt.svg",
37 IconAsset::Hash => "icons/hash.svg",
38 IconAsset::ChevronDown => "icons/chevron_down.svg",38 IconAsset::ChevronDown => "icons/chevron_down.svg",
39 IconAsset::ChevronUp => "icons/chevron_up.svg",
40 IconAsset::ChevronLeft => "icons/chevron_left.svg",39 IconAsset::ChevronLeft => "icons/chevron_left.svg",
41 IconAsset::ChevronRight => "icons/chevron_right.svg",40 IconAsset::ChevronRight => "icons/chevron_right.svg",
41 IconAsset::ChevronUp => "icons/chevron_up.svg",
42 IconAsset::File => "icons/file_icons/file.svg",42 IconAsset::File => "icons/file_icons/file.svg",
43 IconAsset::FileDoc => "icons/file_icons/book.svg",
44 IconAsset::FileGit => "icons/file_icons/git.svg",
45 IconAsset::FileLock => "icons/file_icons/lock.svg",
46 IconAsset::FileRust => "icons/file_icons/rust.svg",
47 IconAsset::FileToml => "icons/file_icons/toml.svg",
43 IconAsset::Folder => "icons/file_icons/folder.svg",48 IconAsset::Folder => "icons/file_icons/folder.svg",
44 IconAsset::FolderOpen => "icons/file_icons/folder_open.svg",49 IconAsset::FolderOpen => "icons/file_icons/folder_open.svg",
50 IconAsset::Hash => "icons/hash.svg",
45 }51 }
46 }52 }
47}53}
@@ -55,19 +61,14 @@ pub fn icon(asset: IconAsset) -> Icon { · 7 unmodified lines
55 Icon { asset }61 Icon { asset }
56}62}
57 63
58// impl Icon {
59// pub fn new(asset: IconAsset) -> Icon {
60// Icon { asset }
61// }
62// }
63
64impl Icon {64impl Icon {
65 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {65 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
66 let theme = theme(cx);66 let theme = theme(cx);
67 67
68 svg()68 svg()
69 .flex_none()
69 .path(self.asset.path())70 .path(self.asset.path())
70 .size_4()71 .size_4()
71 .fill(theme.lowest.base.default.foreground)72 .fill(theme.lowest.variant.default.foreground)
72 }73 }
73}74}
crates/ui/src/elements/label.rs+30−4
@@ -1,29 +1,40 @@
1use crate::theme::theme;
1use gpui2::elements::div;2use gpui2::elements::div;
2use gpui2::style::StyleHelpers;3use gpui2::style::StyleHelpers;
3use gpui2::{Element, IntoElement, ParentElement, ViewContext};4use gpui2::{Element, ViewContext};
4 5use gpui2::{IntoElement, ParentElement};
5use crate::theme;
6 6
7#[derive(Default, PartialEq, Copy, Clone)]7#[derive(Default, PartialEq, Copy, Clone)]
8pub enum LabelColor {8pub enum LabelColor {
9 #[default]9 #[default]
10 Default,10 Default,
11 Muted,
11 Created,12 Created,
12 Modified,13 Modified,
13 Deleted,14 Deleted,
14 Hidden,15 Hidden,
16 Placeholder,
17}
18
19#[derive(Default, PartialEq, Copy, Clone)]
20pub enum LabelSize {
21 #[default]
22 Default,
23 Small,
15}24}
16 25
17#[derive(Element, Clone)]26#[derive(Element, Clone)]
18pub struct Label {27pub struct Label {
19 label: &'static str,28 label: &'static str,
20 color: LabelColor,29 color: LabelColor,
30 size: LabelSize,
21}31}
22 32
23pub fn label(label: &'static str) -> Label {33pub fn label(label: &'static str) -> Label {
24 Label {34 Label {
25 label,35 label,
26 color: LabelColor::Default,36 color: LabelColor::Default,
37 size: LabelSize::Default,
27 }38 }
28}39}
29 40
@@ -33,17 +44,32 @@ impl Label { · 3 unmodified lines
33 self44 self
34 }45 }
35 46
47 pub fn size(mut self, size: LabelSize) -> Self {
48 self.size = size;
49 self
50 }
51
36 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {52 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
37 let theme = theme(cx);53 let theme = theme(cx);
38 54
39 let color = match self.color {55 let color = match self.color {
40 LabelColor::Default => theme.lowest.base.default.foreground,56 LabelColor::Default => theme.lowest.base.default.foreground,
57 LabelColor::Muted => theme.lowest.variant.default.foreground,
41 LabelColor::Created => theme.lowest.positive.default.foreground,58 LabelColor::Created => theme.lowest.positive.default.foreground,
42 LabelColor::Modified => theme.lowest.warning.default.foreground,59 LabelColor::Modified => theme.lowest.warning.default.foreground,
43 LabelColor::Deleted => theme.lowest.negative.default.foreground,60 LabelColor::Deleted => theme.lowest.negative.default.foreground,
44 LabelColor::Hidden => theme.lowest.variant.default.foreground,61 LabelColor::Hidden => theme.lowest.variant.default.foreground,
62 LabelColor::Placeholder => theme.lowest.base.disabled.foreground,
45 };63 };
46 64
47 div().text_sm().text_color(color).child(self.label.clone())65 let mut div = div();
66
67 if self.size == LabelSize::Small {
68 div = div.text_xs();
69 } else {
70 div = div.text_sm();
71 }
72
73 div.text_color(color).child(self.label.clone())
48 }74 }
49}75}
crates/ui/src/lib.rs+7−0
@@ -5,10 +5,17 @@ mod element_ext; · 4 unmodified lines
5mod elements;5mod elements;
6mod modules;6mod modules;
7pub mod prelude;7pub mod prelude;
8mod static_data;
9mod templates;
8mod theme;10mod theme;
11mod tokens;
9 12
10pub use crate::theme::*;13pub use crate::theme::*;
11pub use components::*;14pub use components::*;
12pub use element_ext::*;15pub use element_ext::*;
13pub use elements::*;16pub use elements::*;
14pub use modules::*;17pub use modules::*;
18pub use prelude::*;
19pub use static_data::*;
20pub use templates::*;
21pub use tokens::*;
crates/ui/src/modules.rs+4−10
@@ -1,11 +1,5 @@
1mod chat_panel;1mod list;
2mod project_panel;2mod palette;
3mod status_bar;
4mod tab_bar;
5mod title_bar;
6 3
7pub use chat_panel::*;4pub use list::*;
8pub use project_panel::*;5pub use palette::*;
9pub use status_bar::*;
10pub use tab_bar::*;
11pub use title_bar::*;
crates/ui/src/modules/list.rs+64−0
@@ -0,0 +1,64 @@
1use crate::theme::theme;
2use crate::tokens::token;
3use crate::{icon, label, prelude::*, IconAsset, LabelColor, ListItem, ListSectionHeader};
4use gpui2::style::StyleHelpers;
5use gpui2::{elements::div, IntoElement};
6use gpui2::{Element, ParentElement, ViewContext};
7
8#[derive(Element)]
9pub struct List {
10 header: Option<ListSectionHeader>,
11 items: Vec<ListItem>,
12 empty_message: &'static str,
13 toggle: Option<ToggleState>,
14 // footer: Option<ListSectionFooter>,
15}
16
17pub fn list(items: Vec<ListItem>) -> List {
18 List {
19 header: None,
20 items,
21 empty_message: "No items",
22 toggle: None,
23 }
24}
25
26impl List {
27 pub fn header(mut self, header: ListSectionHeader) -> Self {
28 self.header = Some(header);
29 self
30 }
31
32 pub fn empty_message(mut self, empty_message: &'static str) -> Self {
33 self.empty_message = empty_message;
34 self
35 }
36
37 pub fn set_toggle(mut self, toggle: ToggleState) -> Self {
38 self.toggle = Some(toggle);
39 self
40 }
41
42 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
43 let theme = theme(cx);
44 let token = token();
45
46 let disclosure_control = match self.toggle {
47 Some(ToggleState::NotToggled) => Some(icon(IconAsset::ChevronRight)),
48 Some(ToggleState::Toggled) => Some(icon(IconAsset::ChevronDown)),
49 None => None,
50 };
51
52 div()
53 .py_1()
54 .flex()
55 .flex_col()
56 .children(self.header.map(|h| h))
57 .children(
58 self.items
59 .is_empty()
60 .then(|| label(self.empty_message).color(LabelColor::Muted)),
61 )
62 .children(self.items.iter().cloned())
63 }
64}
crates/ui/src/modules/palette.rs+124−0
@@ -0,0 +1,124 @@
1use std::marker::PhantomData;
2
3use crate::prelude::OrderMethod;
4use crate::theme::theme;
5use crate::{label, palette_item, LabelColor, PaletteItem};
6use gpui2::elements::div::ScrollState;
7use gpui2::style::{StyleHelpers, Styleable};
8use gpui2::{elements::div, IntoElement};
9use gpui2::{Element, ParentElement, ViewContext};
10
11#[derive(Element)]
12pub struct Palette<V: 'static> {
13 view_type: PhantomData<V>,
14 scroll_state: ScrollState,
15 input_placeholder: &'static str,
16 empty_string: &'static str,
17 items: Vec<PaletteItem>,
18 default_order: OrderMethod,
19}
20
21pub fn palette<V: 'static>(scroll_state: ScrollState) -> Palette<V> {
22 Palette {
23 view_type: PhantomData,
24 scroll_state,
25 input_placeholder: "Find something...",
26 empty_string: "No items found.",
27 items: vec![],
28 default_order: OrderMethod::default(),
29 }
30}
31
32impl<V: 'static> Palette<V> {
33 pub fn items(mut self, mut items: Vec<PaletteItem>) -> Self {
34 items.sort_by_key(|item| item.label);
35 self.items = items;
36 self
37 }
38
39 pub fn placeholder(mut self, input_placeholder: &'static str) -> Self {
40 self.input_placeholder = input_placeholder;
41 self
42 }
43
44 pub fn empty_string(mut self, empty_string: &'static str) -> Self {
45 self.empty_string = empty_string;
46 self
47 }
48
49 // TODO: Hook up sort order
50 pub fn default_order(mut self, default_order: OrderMethod) -> Self {
51 self.default_order = default_order;
52 self
53 }
54
55 fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
56 let theme = theme(cx);
57
58 div()
59 .w_96()
60 .rounded_lg()
61 .fill(theme.lowest.base.default.background)
62 .border()
63 .border_color(theme.lowest.base.default.border)
64 .flex()
65 .flex_col()
66 .child(
67 div()
68 .flex()
69 .flex_col()
70 .gap_px()
71 .child(
72 div().py_0p5().px_1().flex().flex_col().child(
73 div().px_2().py_0p5().child(
74 label(self.input_placeholder).color(LabelColor::Placeholder),
75 ),
76 ),
77 )
78 .child(div().h_px().w_full().fill(theme.lowest.base.default.border))
79 .child(
80 div()
81 .py_0p5()
82 .px_1()
83 .flex()
84 .flex_col()
85 .grow()
86 .max_h_96()
87 .overflow_y_scroll(self.scroll_state.clone())
88 .children(
89 vec![if self.items.is_empty() {
90 Some(
91 div()
92 .flex()
93 .flex_row()
94 .justify_between()
95 .px_2()
96 .py_1()
97 .child(
98 label(self.empty_string).color(LabelColor::Muted),
99 ),
100 )
101 } else {
102 None
103 }]
104 .into_iter()
105 .flatten(),
106 )
107 .children(self.items.iter().map(|item| {
108 div()
109 .flex()
110 .flex_row()
111 .justify_between()
112 .px_2()
113 .py_0p5()
114 .rounded_lg()
115 .hover()
116 .fill(theme.lowest.base.hovered.background)
117 .active()
118 .fill(theme.lowest.base.pressed.background)
119 .child(palette_item(item.label, item.keybinding))
120 })),
121 ),
122 )
123 }
124}
crates/ui/src/modules/project_panel.rs+0−94
@@ -1,94 +0,0 @@
1use std::marker::PhantomData;
2
3use gpui2::elements::div;
4use gpui2::elements::div::ScrollState;
5use gpui2::style::StyleHelpers;
6use gpui2::{Element, IntoElement, ParentElement, ViewContext};
7
8use crate::prelude::*;
9use crate::{details, input, label, list_item, theme, IconAsset, LabelColor};
10
11#[derive(Element)]
12pub struct ProjectPanel<V: 'static> {
13 view_type: PhantomData<V>,
14 scroll_state: ScrollState,
15}
16
17pub fn project_panel<V: 'static>(scroll_state: ScrollState) -> ProjectPanel<V> {
18 ProjectPanel {
19 view_type: PhantomData,
20 scroll_state,
21 }
22}
23
24impl<V: 'static> ProjectPanel<V> {
25 fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
26 let theme = theme(cx);
27
28 div()
29 .w_56()
30 .h_full()
31 .flex()
32 .flex_col()
33 .fill(theme.middle.base.default.background)
34 .child(
35 div()
36 .w_56()
37 .flex()
38 .flex_col()
39 .overflow_y_scroll(self.scroll_state.clone())
40 .child(details("This is a long string that should wrap when it keeps going for a long time.").meta_text("6 h ago)"))
41 .child(
42 div().flex().flex_col().children(
43 std::iter::repeat_with(|| {
44 vec![
45 list_item(label("sqlez").color(LabelColor::Modified))
46 .left_icon(IconAsset::FolderOpen.into())
47 .indent_level(0)
48 .set_toggle(ToggleState::NotToggled),
49 list_item(label("storybook").color(LabelColor::Modified))
50 .left_icon(IconAsset::FolderOpen.into())
51 .indent_level(0)
52 .set_toggle(ToggleState::Toggled),
53 list_item(label("docs").color(LabelColor::Default))
54 .left_icon(IconAsset::Folder.into())
55 .indent_level(1)
56 .set_toggle(ToggleState::Toggled),
57 list_item(label("src").color(LabelColor::Modified))
58 .left_icon(IconAsset::FolderOpen.into())
59 .indent_level(2)
60 .set_toggle(ToggleState::Toggled),
61 list_item(label("ui").color(LabelColor::Modified))
62 .left_icon(IconAsset::FolderOpen.into())
63 .indent_level(3)
64 .set_toggle(ToggleState::Toggled),
65 list_item(label("component").color(LabelColor::Created))
66 .left_icon(IconAsset::FolderOpen.into())
67 .indent_level(4)
68 .set_toggle(ToggleState::Toggled),
69 list_item(label("facepile.rs").color(LabelColor::Default))
70 .left_icon(IconAsset::File.into())
71 .indent_level(5),
72 list_item(label("follow_group.rs").color(LabelColor::Default))
73 .left_icon(IconAsset::File.into())
74 .indent_level(5),
75 list_item(label("list_item.rs").color(LabelColor::Created))
76 .left_icon(IconAsset::File.into())
77 .indent_level(5),
78 list_item(label("tab.rs").color(LabelColor::Default))
79 .left_icon(IconAsset::File.into())
80 .indent_level(5),
81 ]
82 })
83 .take(10)
84 .flatten(),
85 ),
86 ),
87 )
88 .child(
89 input("Find something...")
90 .value("buffe".to_string())
91 .state(InteractionState::Focused),
92 )
93 }
94}
crates/ui/src/prelude.rs+15−0
@@ -1,3 +1,11 @@
1#[derive(Default, PartialEq)]
2pub enum OrderMethod {
3 #[default]
4 Ascending,
5 Descending,
6 MostRecent,
7}
8
1#[derive(Default, PartialEq)]9#[derive(Default, PartialEq)]
2pub enum ButtonVariant {10pub enum ButtonVariant {
3 #[default]11 #[default]
@@ -19,6 +27,13 @@ pub enum Shape { · 15 unmodified lines
19 RoundedRectangle,27 RoundedRectangle,
20}28}
21 29
30#[derive(Default, PartialEq, Clone, Copy)]
31pub enum DisclosureControlVisibility {
32 #[default]
33 OnHover,
34 Always,
35}
36
22#[derive(Default, PartialEq, Clone, Copy)]37#[derive(Default, PartialEq, Clone, Copy)]
23pub enum InteractionState {38pub enum InteractionState {
24 #[default]39 #[default]
crates/ui/src/static_data.rs+166−0
@@ -0,0 +1,166 @@
1use crate::{
2 label, list_item, palette_item, IconAsset, LabelColor, ListItem, PaletteItem, ToggleState,
3};
4
5pub fn static_project_panel_project_items() -> Vec<ListItem> {
6 vec![
7 list_item(label("zed"))
8 .left_icon(IconAsset::FolderOpen.into())
9 .indent_level(0)
10 .set_toggle(ToggleState::Toggled),
11 list_item(label(".cargo"))
12 .left_icon(IconAsset::Folder.into())
13 .indent_level(1),
14 list_item(label(".config"))
15 .left_icon(IconAsset::Folder.into())
16 .indent_level(1),
17 list_item(label(".git").color(LabelColor::Hidden))
18 .left_icon(IconAsset::Folder.into())
19 .indent_level(1),
20 list_item(label(".cargo"))
21 .left_icon(IconAsset::Folder.into())
22 .indent_level(1),
23 list_item(label(".idea").color(LabelColor::Hidden))
24 .left_icon(IconAsset::Folder.into())
25 .indent_level(1),
26 list_item(label("assets"))
27 .left_icon(IconAsset::Folder.into())
28 .indent_level(1)
29 .set_toggle(ToggleState::Toggled),
30 list_item(label("cargo-target").color(LabelColor::Hidden))
31 .left_icon(IconAsset::Folder.into())
32 .indent_level(1),
33 list_item(label("crates"))
34 .left_icon(IconAsset::FolderOpen.into())
35 .indent_level(1)
36 .set_toggle(ToggleState::Toggled),
37 list_item(label("activity_indicator"))
38 .left_icon(IconAsset::Folder.into())
39 .indent_level(2),
40 list_item(label("ai"))
41 .left_icon(IconAsset::Folder.into())
42 .indent_level(2),
43 list_item(label("audio"))
44 .left_icon(IconAsset::Folder.into())
45 .indent_level(2),
46 list_item(label("auto_update"))
47 .left_icon(IconAsset::Folder.into())
48 .indent_level(2),
49 list_item(label("breadcrumbs"))
50 .left_icon(IconAsset::Folder.into())
51 .indent_level(2),
52 list_item(label("call"))
53 .left_icon(IconAsset::Folder.into())
54 .indent_level(2),
55 list_item(label("sqlez").color(LabelColor::Modified))
56 .left_icon(IconAsset::Folder.into())
57 .indent_level(2)
58 .set_toggle(ToggleState::NotToggled),
59 list_item(label("gpui2"))
60 .left_icon(IconAsset::FolderOpen.into())
61 .indent_level(2)
62 .set_toggle(ToggleState::Toggled),
63 list_item(label("src"))
64 .left_icon(IconAsset::FolderOpen.into())
65 .indent_level(3)
66 .set_toggle(ToggleState::Toggled),
67 list_item(label("derrive_element.rs"))
68 .left_icon(IconAsset::FileRust.into())
69 .indent_level(4),
70 list_item(label("storybook").color(LabelColor::Modified))
71 .left_icon(IconAsset::FolderOpen.into())
72 .indent_level(1)
73 .set_toggle(ToggleState::Toggled),
74 list_item(label("docs").color(LabelColor::Default))
75 .left_icon(IconAsset::Folder.into())
76 .indent_level(2)
77 .set_toggle(ToggleState::Toggled),
78 list_item(label("src").color(LabelColor::Modified))
79 .left_icon(IconAsset::FolderOpen.into())
80 .indent_level(3)
81 .set_toggle(ToggleState::Toggled),
82 list_item(label("ui").color(LabelColor::Modified))
83 .left_icon(IconAsset::FolderOpen.into())
84 .indent_level(4)
85 .set_toggle(ToggleState::Toggled),
86 list_item(label("component").color(LabelColor::Created))
87 .left_icon(IconAsset::FolderOpen.into())
88 .indent_level(5)
89 .set_toggle(ToggleState::Toggled),
90 list_item(label("facepile.rs").color(LabelColor::Default))
91 .left_icon(IconAsset::FileRust.into())
92 .indent_level(6),
93 list_item(label("follow_group.rs").color(LabelColor::Default))
94 .left_icon(IconAsset::FileRust.into())
95 .indent_level(6),
96 list_item(label("list_item.rs").color(LabelColor::Created))
97 .left_icon(IconAsset::FileRust.into())
98 .indent_level(6),
99 list_item(label("tab.rs").color(LabelColor::Default))
100 .left_icon(IconAsset::FileRust.into())
101 .indent_level(6),
102 list_item(label("target").color(LabelColor::Hidden))
103 .left_icon(IconAsset::Folder.into())
104 .indent_level(1),
105 list_item(label(".dockerignore"))
106 .left_icon(IconAsset::File.into())
107 .indent_level(1),
108 list_item(label(".DS_Store").color(LabelColor::Hidden))
109 .left_icon(IconAsset::File.into())
110 .indent_level(1),
111 list_item(label("Cargo.lock"))
112 .left_icon(IconAsset::FileLock.into())
113 .indent_level(1),
114 list_item(label("Cargo.toml"))
115 .left_icon(IconAsset::FileToml.into())
116 .indent_level(1),
117 list_item(label("Dockerfile"))
118 .left_icon(IconAsset::File.into())
119 .indent_level(1),
120 list_item(label("Procfile"))
121 .left_icon(IconAsset::File.into())
122 .indent_level(1),
123 list_item(label("README.md"))
124 .left_icon(IconAsset::FileDoc.into())
125 .indent_level(1),
126 ]
127}
128
129pub fn static_project_panel_single_items() -> Vec<ListItem> {
130 vec![
131 list_item(label("todo.md"))
132 .left_icon(IconAsset::FileDoc.into())
133 .indent_level(0),
134 list_item(label("README.md"))
135 .left_icon(IconAsset::FileDoc.into())
136 .indent_level(0),
137 list_item(label("config.json"))
138 .left_icon(IconAsset::File.into())
139 .indent_level(0),
140 ]
141}
142
143pub fn example_editor_actions() -> Vec<PaletteItem> {
144 vec![
145 palette_item("New File", Some("Ctrl+N")),
146 palette_item("Open File", Some("Ctrl+O")),
147 palette_item("Save File", Some("Ctrl+S")),
148 palette_item("Cut", Some("Ctrl+X")),
149 palette_item("Copy", Some("Ctrl+C")),
150 palette_item("Paste", Some("Ctrl+V")),
151 palette_item("Undo", Some("Ctrl+Z")),
152 palette_item("Redo", Some("Ctrl+Shift+Z")),
153 palette_item("Find", Some("Ctrl+F")),
154 palette_item("Replace", Some("Ctrl+R")),
155 palette_item("Jump to Line", None),
156 palette_item("Select All", None),
157 palette_item("Deselect All", None),
158 palette_item("Switch Document", None),
159 palette_item("Insert Line Below", None),
160 palette_item("Insert Line Above", None),
161 palette_item("Move Line Up", None),
162 palette_item("Move Line Down", None),
163 palette_item("Toggle Comment", None),
164 palette_item("Delete Line", None),
165 ]
166}
crates/ui/src/templates.rs+17−0
@@ -0,0 +1,17 @@
1mod chat_panel;
2mod collab_panel;
3mod command_palette;
4mod project_panel;
5mod status_bar;
6mod tab_bar;
7mod title_bar;
8mod workspace;
9
10pub use chat_panel::*;
11pub use collab_panel::*;
12pub use command_palette::*;
13pub use project_panel::*;
14pub use status_bar::*;
15pub use tab_bar::*;
16pub use title_bar::*;
17pub use workspace::*;
crates/ui/src/templates/chat_panel.rsrenamed from crates/ui/src/modules/chat_panel.rs+4−4
@@ -1,11 +1,11 @@
1use std::marker::PhantomData;1use std::marker::PhantomData;
2 2
3use gpui2::elements::div;3use crate::icon_button;
4use crate::theme::theme;
4use gpui2::elements::div::ScrollState;5use gpui2::elements::div::ScrollState;
5use gpui2::style::StyleHelpers;6use gpui2::style::StyleHelpers;
6use gpui2::{Element, IntoElement, ParentElement, ViewContext};7use gpui2::{elements::div, IntoElement};
7 8use gpui2::{Element, ParentElement, ViewContext};
8use crate::{icon_button, theme};
9 9
10#[derive(Element)]10#[derive(Element)]
11pub struct ChatPanel<V: 'static> {11pub struct ChatPanel<V: 'static> {
crates/ui/src/templates/collab_panel.rs+177−0
@@ -0,0 +1,177 @@
1use crate::theme::{theme, Theme};
2use gpui2::{
3 elements::{div, div::ScrollState, img, svg},
4 style::{StyleHelpers, Styleable},
5 ArcCow, Element, IntoElement, ParentElement, ViewContext,
6};
7use std::marker::PhantomData;
8
9#[derive(Element)]
10pub struct CollabPanelElement<V: 'static> {
11 view_type: PhantomData<V>,
12 scroll_state: ScrollState,
13}
14
15// When I improve child view rendering, I'd like to have V implement a trait that
16// provides the scroll state, among other things.
17pub fn collab_panel<V: 'static>(scroll_state: ScrollState) -> CollabPanelElement<V> {
18 CollabPanelElement {
19 view_type: PhantomData,
20 scroll_state,
21 }
22}
23
24impl<V: 'static> CollabPanelElement<V> {
25 fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
26 let theme = theme(cx);
27
28 // Panel
29 div()
30 .w_64()
31 .h_full()
32 .flex()
33 .flex_col()
34 .font("Zed Sans Extended")
35 .text_color(theme.middle.base.default.foreground)
36 .border_color(theme.middle.base.default.border)
37 .border()
38 .fill(theme.middle.base.default.background)
39 .child(
40 div()
41 .w_full()
42 .flex()
43 .flex_col()
44 .overflow_y_scroll(self.scroll_state.clone())
45 // List Container
46 .child(
47 div()
48 .fill(theme.lowest.base.default.background)
49 .pb_1()
50 .border_color(theme.lowest.base.default.border)
51 .border_b()
52 //:: https://tailwindcss.com/docs/hover-focus-and-other-states#styling-based-on-parent-state
53 // .group()
54 // List Section Header
55 .child(self.list_section_header("#CRDB", true, theme))
56 // List Item Large
57 .child(self.list_item(
58 "http://github.com/maxbrunsfeld.png?s=50",
59 "maxbrunsfeld",
60 theme,
61 )),
62 )
63 .child(
64 div()
65 .py_2()
66 .flex()
67 .flex_col()
68 .child(self.list_section_header("CHANNELS", true, theme)),
69 )
70 .child(
71 div()
72 .py_2()
73 .flex()
74 .flex_col()
75 .child(self.list_section_header("CONTACTS", true, theme))
76 .children(
77 std::iter::repeat_with(|| {
78 vec![
79 self.list_item(
80 "http://github.com/as-cii.png?s=50",
81 "as-cii",
82 theme,
83 ),
84 self.list_item(
85 "http://github.com/nathansobo.png?s=50",
86 "nathansobo",
87 theme,
88 ),
89 self.list_item(
90 "http://github.com/maxbrunsfeld.png?s=50",
91 "maxbrunsfeld",
92 theme,
93 ),
94 ]
95 })
96 .take(3)
97 .flatten(),
98 ),
99 ),
100 )
101 .child(
102 div()
103 .h_7()
104 .px_2()
105 .border_t()
106 .border_color(theme.middle.variant.default.border)
107 .flex()
108 .items_center()
109 .child(
110 div()
111 .text_sm()
112 .text_color(theme.middle.variant.default.foreground)
113 .child("Find..."),
114 ),
115 )
116 }
117
118 fn list_section_header(
119 &self,
120 label: impl Into<ArcCow<'static, str>>,
121 expanded: bool,
122 theme: &Theme,
123 ) -> impl Element<V> {
124 div()
125 .h_7()
126 .px_2()
127 .flex()
128 .justify_between()
129 .items_center()
130 .child(div().flex().gap_1().text_sm().child(label))
131 .child(
132 div().flex().h_full().gap_1().items_center().child(
133 svg()
134 .path(if expanded {
135 "icons/caret_down.svg"
136 } else {
137 "icons/caret_up.svg"
138 })
139 .w_3p5()
140 .h_3p5()
141 .fill(theme.middle.variant.default.foreground),
142 ),
143 )
144 }
145
146 fn list_item(
147 &self,
148 avatar_uri: impl Into<ArcCow<'static, str>>,
149 label: impl Into<ArcCow<'static, str>>,
150 theme: &Theme,
151 ) -> impl Element<V> {
152 div()
153 .h_7()
154 .px_2()
155 .flex()
156 .items_center()
157 .hover()
158 .fill(theme.lowest.variant.hovered.background)
159 .active()
160 .fill(theme.lowest.variant.pressed.background)
161 .child(
162 div()
163 .flex()
164 .items_center()
165 .gap_1()
166 .text_sm()
167 .child(
168 img()
169 .uri(avatar_uri)
170 .size_3p5()
171 .rounded_full()
172 .fill(theme.middle.positive.default.foreground),
173 )
174 .child(label),
175 )
176 }
177}
crates/ui/src/templates/command_palette.rs+31−0
@@ -0,0 +1,31 @@
1use gpui2::elements::div;
2use gpui2::{elements::div::ScrollState, ViewContext};
3use gpui2::{Element, IntoElement, ParentElement};
4use std::marker::PhantomData;
5
6use crate::{example_editor_actions, palette, OrderMethod};
7
8#[derive(Element)]
9pub struct CommandPalette<V: 'static> {
10 view_type: PhantomData<V>,
11 scroll_state: ScrollState,
12}
13
14pub fn command_palette<V: 'static>(scroll_state: ScrollState) -> CommandPalette<V> {
15 CommandPalette {
16 view_type: PhantomData,
17 scroll_state,
18 }
19}
20
21impl<V: 'static> CommandPalette<V> {
22 fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
23 div().child(
24 palette(self.scroll_state.clone())
25 .items(example_editor_actions())
26 .placeholder("Execute a command...")
27 .empty_string("No items found.")
28 .default_order(OrderMethod::Ascending),
29 )
30 }
31}
crates/ui/src/templates/project_panel.rs+62−0
@@ -0,0 +1,62 @@
1use crate::{
2 input, list, list_section_header, prelude::*, static_project_panel_project_items,
3 static_project_panel_single_items, theme,
4};
5
6use gpui2::{
7 elements::{div, div::ScrollState},
8 style::StyleHelpers,
9 ParentElement, ViewContext,
10};
11use gpui2::{Element, IntoElement};
12use std::marker::PhantomData;
13
14#[derive(Element)]
15pub struct ProjectPanel<V: 'static> {
16 view_type: PhantomData<V>,
17 scroll_state: ScrollState,
18}
19
20pub fn project_panel<V: 'static>(scroll_state: ScrollState) -> ProjectPanel<V> {
21 ProjectPanel {
22 view_type: PhantomData,
23 scroll_state,
24 }
25}
26
27impl<V: 'static> ProjectPanel<V> {
28 fn render(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
29 let theme = theme(cx);
30
31 div()
32 .w_56()
33 .h_full()
34 .flex()
35 .flex_col()
36 .fill(theme.middle.base.default.background)
37 .child(
38 div()
39 .w_56()
40 .flex()
41 .flex_col()
42 .overflow_y_scroll(self.scroll_state.clone())
43 .child(
44 list(static_project_panel_single_items())
45 .header(list_section_header("FILES").set_toggle(ToggleState::Toggled))
46 .empty_message("No files in directory")
47 .set_toggle(ToggleState::Toggled),
48 )
49 .child(
50 list(static_project_panel_project_items())
51 .header(list_section_header("PROJECT").set_toggle(ToggleState::Toggled))
52 .empty_message("No folders in directory")
53 .set_toggle(ToggleState::Toggled),
54 ),
55 )
56 .child(
57 input("Find something...")
58 .value("buffe".to_string())
59 .state(InteractionState::Focused),
60 )
61 }
62}
crates/ui/src/templates/status_bar.rsrenamed from crates/ui/src/modules/status_bar.rs+3−4
@@ -1,11 +1,10 @@
1use std::marker::PhantomData;1use std::marker::PhantomData;
2 2
3use gpui2::elements::div;
4use gpui2::style::StyleHelpers;
5use gpui2::{Element, IntoElement, ParentElement, ViewContext};
6
7use crate::theme::{theme, Theme};3use crate::theme::{theme, Theme};
8use crate::{icon_button, text_button, tool_divider};4use crate::{icon_button, text_button, tool_divider};
5use gpui2::style::StyleHelpers;
6use gpui2::{elements::div, IntoElement};
7use gpui2::{Element, ParentElement, ViewContext};
9 8
10#[derive(Default, PartialEq)]9#[derive(Default, PartialEq)]
11pub enum Tool {10pub enum Tool {
crates/ui/src/templates/tab_bar.rsrenamed from crates/ui/src/modules/tab_bar.rs+5−5
@@ -1,12 +1,12 @@
1use std::marker::PhantomData;1use std::marker::PhantomData;
2 2
3use gpui2::elements::div;3use crate::prelude::InteractionState;
4use crate::theme::theme;
5use crate::{icon_button, tab};
4use gpui2::elements::div::ScrollState;6use gpui2::elements::div::ScrollState;
5use gpui2::style::StyleHelpers;7use gpui2::style::StyleHelpers;
6use gpui2::{Element, IntoElement, ParentElement, ViewContext};8use gpui2::{elements::div, IntoElement};
7 9use gpui2::{Element, ParentElement, ViewContext};
8use crate::prelude::InteractionState;
9use crate::{icon_button, tab, theme};
10 10
11#[derive(Element)]11#[derive(Element)]
12pub struct TabBar<V: 'static> {12pub struct TabBar<V: 'static> {
crates/ui/src/templates/title_bar.rsrenamed from crates/ui/src/modules/title_bar.rs+0−0

File renamed without changes.

crates/ui/src/templates/workspace.rs+80−0
@@ -0,0 +1,80 @@
1use crate::{chat_panel, collab_panel, project_panel, status_bar, tab_bar, theme, title_bar};
2
3use gpui2::{
4 elements::{div, div::ScrollState},
5 style::StyleHelpers,
6 Element, IntoElement, ParentElement, ViewContext,
7};
8
9#[derive(Element, Default)]
10struct WorkspaceElement {
11 project_panel_scroll_state: ScrollState,
12 collab_panel_scroll_state: ScrollState,
13 right_scroll_state: ScrollState,
14 tab_bar_scroll_state: ScrollState,
15 palette_scroll_state: ScrollState,
16}
17
18pub fn workspace<V: 'static>() -> impl Element<V> {
19 WorkspaceElement::default()
20}
21
22impl WorkspaceElement {
23 fn render<V: 'static>(&mut self, _: &mut V, cx: &mut ViewContext<V>) -> impl IntoElement<V> {
24 let theme = theme(cx);
25
26 div()
27 // Elevation Level 0
28 .size_full()
29 .flex()
30 .flex_col()
31 .font("Zed Sans Extended")
32 .gap_0()
33 .justify_start()
34 .items_start()
35 .text_color(theme.lowest.base.default.foreground)
36 .fill(theme.lowest.base.default.background)
37 .relative()
38 // Elevation Level 1
39 .child(title_bar())
40 .child(
41 div()
42 .flex_1()
43 .w_full()
44 .flex()
45 .flex_row()
46 .overflow_hidden()
47 .child(project_panel(self.project_panel_scroll_state.clone()))
48 .child(collab_panel(self.collab_panel_scroll_state.clone()))
49 .child(
50 div()
51 .h_full()
52 .flex_1()
53 .fill(theme.highest.base.default.background)
54 .child(
55 div()
56 .flex()
57 .flex_col()
58 .flex_1()
59 .child(tab_bar(self.tab_bar_scroll_state.clone())),
60 ),
61 )
62 .child(chat_panel(self.right_scroll_state.clone())),
63 )
64 .child(status_bar())
65 // Elevation Level 3
66 // .child(
67 // div()
68 // .absolute()
69 // .top_0()
70 // .left_0()
71 // .size_full()
72 // .flex()
73 // .justify_center()
74 // .items_center()
75 // // .fill(theme.lowest.base.default.background)
76 // // Elevation Level 4
77 // .child(command_palette(self.palette_scroll_state.clone())),
78 // )
79 }
80}
crates/ui/src/tokens.rs+18−0
@@ -0,0 +1,18 @@
1use gpui2::geometry::AbsoluteLength;
2
3#[derive(Clone, Copy)]
4pub struct Token {
5 pub list_indent_depth: AbsoluteLength,
6}
7
8impl Default for Token {
9 fn default() -> Self {
10 Self {
11 list_indent_depth: AbsoluteLength::Rems(0.5),
12 }
13 }
14}
15
16pub fn token() -> Token {
17 Token::default()
18}
docs/ui/states.md+0−43
@@ -1,43 +0,0 @@
1## Interaction State
2
3**Enabled**
4
5An enabled state communicates an interactive component or element.
6
7**Disabled**
8
9A disabled state communicates a inoperable component or element.
10
11**Hover**
12
13A hover state communicates when a user has placed a cursor above an interactive element.
14
15**Focused**
16
17A focused state communicates when a user has highlighted an element, using an input method such as a keyboard or voice.
18
19**Activated**
20
21An activated state communicates a highlighted destination, whether initiated by the user or by default.
22
23**Pressed**
24
25A pressed state communicates a user tap.
26
27**Dragged**
28
29A dragged state communicates when a user presses and moves an element.
30
31## Selected State
32
33**Unselected**
34
35dfa
36
37**Partially Selected**
38
39daf
40
41**Selected**
42
43dfa

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t