add sidebar

This commit is contained in:
2026-10-30 14:45:55 +07:00
parent cbd307d3fd
commit b4a996e44c
6 changed files with 530 additions and 3 deletions
+35
View File
@@ -24,6 +24,7 @@ use gpui_native_core::toast::{Toast, ToastSeverity, Toasts, ToastsView};
use gpui_native_core::toggle::Toggle;
use gpui_native_core::tooltip::Tooltip;
use gpui_native_data::list::{List, ListItem};
use gpui_native_data::sidebar::{Sidebar, SidebarEntry};
use gpui_native_data::tabs::{Tab, Tabs};
use gpui_native_data::tree::{Tree, TreeItem};
use gpui_native_icons::{IconAssets, IconRole, icon};
@@ -48,6 +49,7 @@ struct Gallery {
tree_nodes: Vec<GalleryNode>,
tree_selected: Option<usize>,
tab_selected: usize,
sidebar_selected: Option<usize>,
}
/// A demo model for the tree section: the app owns the real tree and its
@@ -474,6 +476,38 @@ impl Render for Gallery {
.items(move |_, _| items.clone())
}),
)
.child(
v_flex()
.gap_2()
.child(section_label(
"sidebar · native refs — NSOutlineView (source list), WinUI NavigationView, Adwaita Sidebar",
colors,
))
.child(div().w(px(280.)).child({
let gallery = gallery.clone();
Sidebar::new("gallery-sidebar")
.selected(self.sidebar_selected)
.on_change(move |selected, _, cx| {
gallery.update(cx, |gallery, cx| {
gallery.sidebar_selected = selected;
cx.notify();
});
})
.entries(|_, _| {
vec![
SidebarEntry::header("Favorites"),
SidebarEntry::row("Documents").icon(IconRole::Folder),
SidebarEntry::row("Pictures")
.icon(IconRole::Folder)
.detail("24"),
SidebarEntry::row("Archive").disabled(true),
SidebarEntry::header("Locations"),
SidebarEntry::row("iCloud").icon(IconRole::Folder),
SidebarEntry::row("Trash"),
]
})
})),
)
.child(
v_flex()
.gap_2()
@@ -1133,6 +1167,7 @@ fn main() {
list_selected: None,
tree_selected: None,
tab_selected: 0,
sidebar_selected: None,
tree_nodes: vec![
GalleryNode {
label: "Workspace".into(),