Skip to content

Commit bf10b5d

Browse files
committed
Merge branch 'main' of https://github.com/stayhydated/gpui-component into tree-sitter-optional
2 parents b288b84 + 8752104 commit bf10b5d

22 files changed

Lines changed: 647 additions & 73 deletions

File tree

crates/story/examples/dock.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use gpui_component::{
55
button::{Button, ButtonVariants as _},
66
dock::{ClosePanel, DockArea, DockAreaState, DockEvent, DockItem, DockPlacement, ToggleZoom},
77
menu::DropdownMenu,
8+
status_bar::StatusBar,
89
};
910

1011
use gpui_component_assets::Assets;
@@ -513,7 +514,40 @@ impl Render for StoryWorkspace {
513514
.flex()
514515
.flex_col()
515516
.child(self.title_bar.clone())
516-
.child(self.dock_area.clone())
517+
.child(div().flex_1().min_h_0().child(self.dock_area.clone()))
518+
.child(
519+
StatusBar::new()
520+
.left(
521+
Button::new("toggle-left-dock").ghost().xsmall()
522+
.icon(IconName::PanelLeft)
523+
.tooltip("Toggle Left Dock")
524+
.on_click(cx.listener(|this, _, window, cx| {
525+
this.dock_area.update(cx, |area, cx| {
526+
area.toggle_dock(DockPlacement::Left, window, cx);
527+
});
528+
})),
529+
)
530+
.left(
531+
Button::new("toggle-bottom-dock").ghost().xsmall()
532+
.icon(IconName::PanelBottom)
533+
.tooltip("Toggle Bottom Dock")
534+
.on_click(cx.listener(|this, _, window, cx| {
535+
this.dock_area.update(cx, |area, cx| {
536+
area.toggle_dock(DockPlacement::Bottom, window, cx);
537+
});
538+
})),
539+
)
540+
.child(
541+
Button::new("toggle-right-dock").ghost().xsmall()
542+
.icon(IconName::PanelRight)
543+
.tooltip("Toggle Right Dock")
544+
.on_click(cx.listener(|this, _, window, cx| {
545+
this.dock_area.update(cx, |area, cx| {
546+
area.toggle_dock(DockPlacement::Right, window, cx);
547+
});
548+
})),
549+
),
550+
)
517551
.children(sheet_layer)
518552
.children(dialog_layer)
519553
.children(notification_layer)

crates/story/examples/editor.rs

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use gpui_component::{
2020
},
2121
list::ListItem,
2222
resizable::{h_resizable, resizable_panel},
23+
status_bar::StatusBar,
2324
tree::{TreeItem, TreeState, tree},
2425
v_flex,
2526
};
@@ -972,7 +973,7 @@ impl Example {
972973
&self,
973974
_: &mut Window,
974975
cx: &mut Context<Self>,
975-
) -> impl IntoElement {
976+
) -> Button {
976977
Button::new("line-number")
977978
.when(self.line_number, |this| this.icon(IconName::Check))
978979
.label("Line Number")
@@ -987,7 +988,7 @@ impl Example {
987988
}))
988989
}
989990

990-
fn render_soft_wrap_button(&self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
991+
fn render_soft_wrap_button(&self, _: &mut Window, cx: &mut Context<Self>) -> Button {
991992
Button::new("soft-wrap")
992993
.ghost()
993994
.xsmall()
@@ -1006,7 +1007,7 @@ impl Example {
10061007
&self,
10071008
_: &mut Window,
10081009
cx: &mut Context<Self>,
1009-
) -> impl IntoElement {
1010+
) -> Button {
10101011
Button::new("show-whitespace")
10111012
.ghost()
10121013
.xsmall()
@@ -1025,7 +1026,7 @@ impl Example {
10251026
&self,
10261027
_: &mut Window,
10271028
cx: &mut Context<Self>,
1028-
) -> impl IntoElement {
1029+
) -> Button {
10291030
Button::new("indent-guides")
10301031
.ghost()
10311032
.xsmall()
@@ -1040,7 +1041,7 @@ impl Example {
10401041
}))
10411042
}
10421043

1043-
fn render_folding_button(&self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
1044+
fn render_folding_button(&self, _: &mut Window, cx: &mut Context<Self>) -> Button {
10441045
Button::new("folding")
10451046
.ghost()
10461047
.xsmall()
@@ -1076,7 +1077,7 @@ impl Example {
10761077
&self,
10771078
_: &mut Window,
10781079
cx: &mut Context<Self>,
1079-
) -> impl IntoElement {
1080+
) -> Button {
10801081
Button::new("scroll-beyond-last-line")
10811082
.ghost()
10821083
.xsmall()
@@ -1097,7 +1098,7 @@ impl Example {
10971098
&self,
10981099
_: &mut Window,
10991100
cx: &mut Context<Self>,
1100-
) -> impl IntoElement {
1101+
) -> Button {
11011102
Button::new("cursor-surrounding-lines")
11021103
.ghost()
11031104
.xsmall()
@@ -1114,7 +1115,7 @@ impl Example {
11141115
}))
11151116
}
11161117

1117-
fn render_go_to_line_button(&self, _: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
1118+
fn render_go_to_line_button(&self, _: &mut Window, cx: &mut Context<Self>) -> Button {
11181119
let position = self.editor.read(cx).cursor_position();
11191120
let cursor = self.editor.read(cx).cursor();
11201121

@@ -1127,6 +1128,7 @@ impl Example {
11271128
position.character + 1,
11281129
cursor
11291130
))
1131+
.tooltip("Go to Line/Column")
11301132
.on_click(cx.listener(Self::go_to_line))
11311133
}
11321134
}
@@ -1173,27 +1175,15 @@ impl Render for Example {
11731175
),
11741176
)
11751177
.child(
1176-
h_flex()
1177-
.justify_between()
1178-
.text_sm()
1179-
.bg(cx.theme().background)
1180-
.py_1p5()
1181-
.px_4()
1182-
.border_t_1()
1183-
.border_color(cx.theme().border)
1184-
.text_color(cx.theme().muted_foreground)
1185-
.child(
1186-
h_flex()
1187-
.gap_3()
1188-
.child(self.render_line_number_button(window, cx))
1189-
.child(self.render_soft_wrap_button(window, cx))
1190-
.child(self.render_show_whitespaces_button(window, cx))
1191-
.child(self.render_indent_guides_button(window, cx))
1192-
.child(self.render_folding_button(window, cx))
1193-
.child(self.render_scroll_beyond_last_line_button(window, cx))
1194-
.child(self.render_cursor_surrounding_lines_button(window, cx)),
1195-
)
1196-
.child(self.render_go_to_line_button(window, cx)),
1178+
StatusBar::new()
1179+
.left(self.render_line_number_button(window, cx))
1180+
.left(self.render_soft_wrap_button(window, cx))
1181+
.left(self.render_show_whitespaces_button(window, cx))
1182+
.left(self.render_indent_guides_button(window, cx))
1183+
.left(self.render_folding_button(window, cx))
1184+
.left(self.render_scroll_beyond_last_line_button(window, cx))
1185+
.left(self.render_cursor_surrounding_lines_button(window, cx))
1186+
.right(self.render_go_to_line_button(window, cx)),
11971187
),
11981188
)
11991189
}

crates/story/src/gallery.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
use gpui::{prelude::*, *};
22
use gpui_component::{
3-
ActiveTheme as _, Icon, IconName, h_flex,
3+
ActiveTheme as _, Icon, IconName, Sizable as _,
4+
button::{Button, ButtonVariants as _},
5+
h_flex,
46
input::{Input, InputEvent, InputState},
57
resizable::{h_resizable, resizable_panel},
8+
separator::Separator,
69
sidebar::{Sidebar, SidebarGroup, SidebarHeader, SidebarMenu, SidebarMenuItem},
10+
status_bar::StatusBar,
711
v_flex,
812
};
913

@@ -85,6 +89,7 @@ impl Gallery {
8589
StoryContainer::panel::<SkeletonStory>(window, cx),
8690
StoryContainer::panel::<SliderStory>(window, cx),
8791
StoryContainer::panel::<SpinnerStory>(window, cx),
92+
StoryContainer::panel::<StatusBarStory>(window, cx),
8893
StoryContainer::panel::<StepperStory>(window, cx),
8994
StoryContainer::panel::<SwitchStory>(window, cx),
9095
StoryContainer::panel::<DataTableStory>(window, cx),
@@ -163,7 +168,10 @@ impl Render for Gallery {
163168
("".into(), "".into())
164169
};
165170

166-
h_resizable("gallery-container")
171+
let current_story = story_name.clone();
172+
let total_components: usize = self.stories.iter().map(|(_, items)| items.len()).sum();
173+
174+
let body = h_resizable("gallery-container")
167175
.child(
168176
resizable_panel()
169177
.size(px(255.))
@@ -301,6 +309,31 @@ impl Render for Gallery {
301309
}),
302310
)
303311
.into_any_element(),
312+
);
313+
314+
v_flex()
315+
.size_full()
316+
.child(div().flex_1().min_h_0().child(body))
317+
.child(
318+
StatusBar::new()
319+
.child(Icon::new(IconName::GalleryVerticalEnd).xsmall())
320+
.child(format!("{total_components} components"))
321+
.child(Separator::vertical())
322+
.when(!current_story.is_empty(), |this| {
323+
this.child(current_story.clone())
324+
})
325+
.right(cx.theme().theme_name().clone())
326+
.right(format!("v{}", env!("CARGO_PKG_VERSION")))
327+
.right(
328+
Button::new("assistant")
329+
.ghost()
330+
.xsmall()
331+
.icon(IconName::Github)
332+
.tooltip("GPUI Component GitHub repository")
333+
.on_click(|_, _, cx| {
334+
cx.open_url("https://github.com/longbridge/gpui-component")
335+
}),
336+
),
304337
)
305338
}
306339
}

crates/story/src/stories/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ mod sidebar_story;
5050
mod skeleton_story;
5151
mod slider_story;
5252
mod spinner_story;
53+
mod status_bar_story;
5354
mod stepper_story;
5455
mod switch_story;
5556
mod table_story;
@@ -112,6 +113,7 @@ pub use sidebar_story::SidebarStory;
112113
pub use skeleton_story::SkeletonStory;
113114
pub use slider_story::SliderStory;
114115
pub use spinner_story::SpinnerStory;
116+
pub use status_bar_story::StatusBarStory;
115117
pub use stepper_story::StepperStory;
116118
pub use switch_story::SwitchStory;
117119
pub use table_story::TableStory;

0 commit comments

Comments
 (0)