layout: replace panel descriptors with panel trait

This commit is contained in:
2026-11-11 18:25:11 +07:00
parent 4db2f14865
commit 4469a4c280
2 changed files with 465 additions and 367 deletions
+75 -84
View File
@@ -3,6 +3,7 @@
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::Arc;
use gpui::prelude::FluentBuilder as _;
use gpui::{
@@ -27,65 +28,59 @@ const MIN_SPLIT_RATIO: f32 = 0.1;
/// The fraction a split opens at, and what a double-click on the seam restores.
const DEFAULT_SPLIT_RATIO: f32 = 0.5;
/// Builds the view a panel opens as, once per open.
type PanelBuilder = Box<dyn Fn(&mut Window, &mut App) -> AnyView>;
/// Builds a panel's view entity the first time its tab opens.
type PanelBuilder = Box<dyn Fn(&mut Window, &mut App) -> Arc<dyn PanelView>>;
/// Runs when a panel with a right sidebar activates, so the app can open it.
type OpenRightSidebarHandler = Rc<dyn Fn(&mut App)>;
/// A registered panel: its identity, chrome, and how its view is built.
#[must_use]
pub struct PanelDescriptor {
id: SharedString,
title: Option<SharedString>,
lead: Option<Rc<dyn Fn() -> AnyElement>>,
build: PanelBuilder,
right_sidebar: Option<PanelBuilder>,
}
impl PanelDescriptor {
/// Creates a panel descriptor that opens through `build`.
pub fn new<I, F>(id: I, build: F) -> Self
where
I: Into<SharedString>,
F: Fn(&mut Window, &mut App) -> AnyView + 'static,
{
Self {
id: id.into(),
title: None,
lead: None,
build: Box::new(build),
right_sidebar: None,
}
/// A dockable panel.
#[allow(unused_variables)]
pub trait Panel: Render + 'static {
/// The panel's tab label.
fn title(&self, cx: &App) -> Option<SharedString> {
None
}
/// Shows `title` as the panel's tab label.
pub fn title<T>(mut self, title: T) -> Self
where
T: Into<SharedString>,
{
self.title = Some(title.into());
self
/// An element, e.g. an icon or avatar, leading the tab label.
fn lead(&self, cx: &App) -> Option<AnyElement> {
None
}
/// Shows an element, e.g. an icon or avatar, leading the tab label.
pub fn lead<F, E>(mut self, build: F) -> Self
where
F: Fn() -> E + 'static,
E: IntoElement,
{
self.lead = Some(Rc::new(move || build().into_any_element()));
self
}
/// Sets the view the right sidebar shows while this panel is active.
/// The view the right sidebar shows while this panel is active.
///
/// Activating the panel opens the right sidebar.
pub fn right_sidebar<F>(mut self, build: F) -> Self
where
F: Fn(&mut Window, &mut App) -> AnyView + 'static,
{
self.right_sidebar = Some(Box::new(build));
self
fn right_sidebar(&mut self, window: &mut Window, cx: &mut App) -> Option<AnyView> {
None
}
}
/// Object-safe handle to an open panel entity.
pub trait PanelView: 'static {
/// The panel's view.
fn view(&self) -> AnyView;
/// The tab label, read live from the panel.
fn title(&self, cx: &App) -> Option<SharedString>;
/// The element leading the tab label, read live from the panel.
fn lead(&self, cx: &App) -> Option<AnyElement>;
/// The right sidebar view, built through the panel.
fn right_sidebar(&self, window: &mut Window, cx: &mut App) -> Option<AnyView>;
}
impl<T: Panel> PanelView for Entity<T> {
fn view(&self) -> AnyView {
self.clone().into()
}
fn title(&self, cx: &App) -> Option<SharedString> {
self.read(cx).title(cx)
}
fn lead(&self, cx: &App) -> Option<AnyElement> {
self.read(cx).lead(cx)
}
fn right_sidebar(&self, window: &mut Window, cx: &mut App) -> Option<AnyView> {
self.update(cx, |panel, cx| panel.right_sidebar(window, cx))
}
}
@@ -140,12 +135,10 @@ impl Render for DragPreview {
}
}
/// One open panel view.
/// One open panel: its dock id, live handle, and right sidebar view.
struct PanelTab {
panel: SharedString,
title: Option<SharedString>,
lead: Option<Rc<dyn Fn() -> AnyElement>>,
view: AnyView,
handle: Arc<dyn PanelView>,
right_view: Option<AnyView>,
}
@@ -173,7 +166,7 @@ enum Node {
/// The dock's pane tree, owned by the application.
pub struct DockState {
root: Node,
panels: HashMap<SharedString, PanelDescriptor>,
panels: HashMap<SharedString, PanelBuilder>,
/// The pane new panels open into, kept on the last activated pane.
active_pane: u64,
next_key: u64,
@@ -205,9 +198,18 @@ impl DockState {
self.on_open_right_sidebar = Some(Rc::new(handler));
}
/// Registers a panel descriptor, replacing any earlier one with its id.
pub fn register_panel(&mut self, panel: PanelDescriptor) {
self.panels.insert(panel.id.clone(), panel);
/// Registers a panel under `id`, replacing any earlier one with it.
pub fn register_panel<I, F, P>(&mut self, id: I, build: F)
where
I: Into<SharedString>,
F: Fn(&mut Window, &mut App) -> Entity<P> + 'static,
P: Panel,
{
let build: PanelBuilder = Box::new(move |window, cx| {
let panel = build(window, cx);
Arc::new(panel)
});
self.panels.insert(id.into(), build);
}
/// Opens a panel into the active pane and activates its tab.
@@ -217,20 +219,16 @@ impl DockState {
return;
}
let Some(panel) = self.panels.get(id) else {
let Some(build) = self.panels.get(id) else {
return;
};
let right_view = panel
.right_sidebar
.as_ref()
.map(|build| (build)(window, cx));
let handle = build(window, cx);
let right_view = handle.right_sidebar(window, cx);
let tab = PanelTab {
panel: SharedString::from(id),
title: panel.title.clone(),
lead: panel.lead.clone(),
view: (panel.build)(window, cx),
handle,
right_view,
};
@@ -692,9 +690,7 @@ impl DockState {
.iter()
.map(|tab| TabView {
panel: tab.panel.clone(),
title: tab.title.clone(),
lead: tab.lead.clone(),
view: tab.view.clone(),
handle: tab.handle.clone(),
})
.collect(),
active: pane.active.clone(),
@@ -750,13 +746,11 @@ impl DockState {
}
}
/// One open panel view, per frame.
/// One open panel's handle, per frame.
#[derive(Clone)]
struct TabView {
panel: SharedString,
title: Option<SharedString>,
lead: Option<Rc<dyn Fn() -> AnyElement>>,
view: AnyView,
handle: Arc<dyn PanelView>,
}
#[derive(Clone)]
@@ -1013,7 +1007,7 @@ fn render_pane(
.tabs
.iter()
.find(|tab| Some(&tab.panel) == pane.active.as_ref())
.map(|tab| tab.view.clone());
.map(|tab| tab.handle.view());
// The cache keeps an un-notified panel from re-rendering on dock frames.
let content_id = SharedString::from(format!("{dock_id}-content-{}", pane.key));
@@ -1056,28 +1050,25 @@ fn render_pane(
.selected(selected)
.tabs({
let tabs = pane.tabs.clone();
move |_, _| {
move |_, cx| {
tabs.iter()
.map(|tab| {
Tab::new(tab.panel.clone(), tab.title.clone().unwrap_or_default())
.when_some(tab.lead.as_ref().map(|build| build()), |entry, lead| {
entry.lead(lead)
})
Tab::new(tab.panel.clone(), tab.handle.title(cx).unwrap_or_default())
.when_some(tab.handle.lead(cx), |entry, lead| entry.lead(lead))
.closeable(true)
.wrap({
let panel = tab.panel.clone();
let title = tab.title.clone();
let handle = tab.handle.clone();
move |tab| {
tab.on_drag(
PanelDrag {
panel: panel.clone(),
},
{
let title = title.clone();
let handle = handle.clone();
move |_, _, _, cx| {
cx.new(|_| DragPreview {
title: title.clone(),
})
let title = handle.title(cx);
cx.new(move |_| DragPreview { title })
}
},
)
+390 -283
View File
@@ -3,10 +3,10 @@ use std::time::Duration;
use gpui::prelude::FluentBuilder as _;
use gpui::{
App, AppContext as _, Axis, Bounds, Context, Entity, FontWeight, InteractiveElement as _,
IntoElement, KeyBinding, ListAlignment, ListState, ParentElement as _, Pixels, Render,
SharedString, Styled as _, UniformListScrollHandle, WeakEntity, Window, WindowBounds,
WindowOptions, actions, div, list, px, rems, size, uniform_list,
AnyView, App, AppContext as _, Axis, Bounds, Context, Entity, FontWeight,
InteractiveElement as _, IntoElement, KeyBinding, ListAlignment, ListState, ParentElement as _,
Pixels, Render, SharedString, Styled as _, UniformListScrollHandle, WeakEntity, Window,
WindowBounds, WindowOptions, actions, div, list, px, rems, size, uniform_list,
};
use gpui_native_core::alert::{Alert, AlertSeverity};
use gpui_native_core::avatar::Avatar;
@@ -49,7 +49,7 @@ use gpui_native_editor::diff::{DiffRowKind, DiffViewState};
use gpui_native_editor::highlight::Language;
use gpui_native_editor::markdown::{ListMarker, MarkdownBlock, MarkdownViewState, TextView};
use gpui_native_icons::{IconAssets, IconRole, icon};
use gpui_native_layout::dock::{Dock, DockSidebar, DockState, PanelDescriptor, SplitDirection};
use gpui_native_layout::dock::{Dock, DockSidebar, DockState, Panel, SplitDirection};
use gpui_native_layout::resizable::{Resizable, ResizableState};
use gpui_native_layout::resize_handle::ResizeHandle;
use gpui_native_layout::shell::{LayoutState, Shell};
@@ -406,295 +406,134 @@ impl Gallery {
) {
let dock_state = cx.entity();
dock.register_panel(
PanelDescriptor::new("welcome", {
let layout_state = layout_state.clone();
let dock_state = dock_state.clone();
let gallery = gallery.clone();
move |_, cx| {
cx.new(|_| WelcomePanel {
layout_state: layout_state.clone(),
dock_state: dock_state.clone(),
gallery: gallery.clone(),
})
.into()
}
})
.title("Welcome")
.right_sidebar(|_, cx| {
cx.new(|_| RightDetails {
title: "Welcome",
body: "Panels can declare this view; activating one opens the sidebar.",
dock.register_panel("welcome", {
let layout_state = layout_state.clone();
let dock_state = dock_state.clone();
let gallery = gallery.clone();
move |_, cx| {
cx.new(|_| WelcomePanel {
layout_state: layout_state.clone(),
dock_state: dock_state.clone(),
gallery: gallery.clone(),
})
.into()
}),
);
dock.register_panel(
PanelDescriptor::new("button", |_, cx| {
cx.new(|_| ButtonDemo { clicks: 0 }).into()
}
});
dock.register_panel("button", |_, cx| cx.new(|_| ButtonDemo { clicks: 0 }));
dock.register_panel("input", |_, cx| cx.new(InputDemo::new));
dock.register_panel("field", |window, cx| {
cx.new(|cx| FieldDemo::new(window, cx))
});
dock.register_panel("combobox", |window, cx| {
cx.new(|cx| ComboboxDemo::new(window, cx))
});
dock.register_panel("status-dot", |_, cx| cx.new(|_| StatusDotDemo));
dock.register_panel("checkbox", |_, cx| {
cx.new(|_| CheckboxDemo { checked: false })
});
dock.register_panel("radio", |_, cx| {
cx.new(|_| RadioDemo {
plan: SharedString::from("starter"),
})
.title("Button"),
);
dock.register_panel(
PanelDescriptor::new("input", |_, cx| cx.new(InputDemo::new).into()).title("Input"),
);
dock.register_panel(
PanelDescriptor::new("field", |window, cx| {
cx.new(|cx| FieldDemo::new(window, cx)).into()
});
dock.register_panel("switch", |_, cx| cx.new(|_| SwitchDemo { checked: true }));
dock.register_panel("toggle", |_, cx| cx.new(|_| ToggleDemo { pressed: false }));
dock.register_panel("slider", |_, cx| cx.new(|_| SliderDemo { volume: 40.0 }));
dock.register_panel("segmented", |_, cx| {
cx.new(|_| SegmentedDemo {
filter: ExploreFilter::default(),
})
.title("Field"),
);
dock.register_panel(
PanelDescriptor::new("combobox", |window, cx| {
cx.new(|cx| ComboboxDemo::new(window, cx)).into()
});
dock.register_panel("select", |_, cx| {
cx.new(|_| SelectDemo {
strategy: Some(Strategy::Curated),
})
.title("Combobox"),
);
dock.register_panel(
PanelDescriptor::new("status-dot", |_, cx| cx.new(|_| StatusDotDemo).into())
.title("Status dot"),
);
dock.register_panel(
PanelDescriptor::new("checkbox", |_, cx| {
cx.new(|_| CheckboxDemo { checked: false }).into()
});
dock.register_panel("link", |_, cx| cx.new(|_| LinkDemo { clicks: 0 }));
dock.register_panel("clipboard", |_, cx| cx.new(|_| ClipboardDemo));
dock.register_panel("badge", |_, cx| cx.new(|_| BadgeDemo));
dock.register_panel("avatar", |_, cx| cx.new(|_| AvatarDemo));
dock.register_panel("progress", |_, cx| cx.new(|_| ProgressDemo));
dock.register_panel("spinner", |_, cx| cx.new(|_| SpinnerDemo));
dock.register_panel("list", |_, cx| cx.new(|_| ListDemo { selected: None }));
dock.register_panel("tree", |_, cx| {
cx.new(|_| TreeDemo {
nodes: TreeDemo::demo(),
selected: None,
})
.title("Checkbox"),
);
dock.register_panel(
PanelDescriptor::new("radio", |_, cx| {
cx.new(|_| RadioDemo {
plan: SharedString::from("starter"),
});
dock.register_panel("tabs", |_, cx| {
cx.new(|_| TabsDemo {
selected: 0,
pill_tabs: vec![
SharedString::from("Explorer"),
SharedString::from("Syncing"),
SharedString::from("Blame"),
],
pill_selected: 0,
lead_selected: 0,
})
});
dock.register_panel("alert", {
let layout_state = layout_state.clone();
move |_, cx| {
cx.new(|_| AlertDemo {
layout_state: layout_state.clone(),
dismissed: false,
})
.into()
})
.title("Radio"),
);
dock.register_panel(
PanelDescriptor::new("switch", |_, cx| {
cx.new(|_| SwitchDemo { checked: true }).into()
})
.title("Switch"),
);
dock.register_panel(
PanelDescriptor::new("toggle", |_, cx| {
cx.new(|_| ToggleDemo { pressed: false }).into()
})
.title("Toggle"),
);
dock.register_panel(
PanelDescriptor::new("slider", |_, cx| {
cx.new(|_| SliderDemo { volume: 40.0 }).into()
})
.title("Slider"),
);
dock.register_panel(
PanelDescriptor::new("segmented", |_, cx| {
cx.new(|_| SegmentedDemo {
filter: ExploreFilter::default(),
}
});
dock.register_panel("toast", {
let layout_state = layout_state.clone();
move |_, cx| {
cx.new(|_| ToastDemo {
layout_state: layout_state.clone(),
})
.into()
})
.title("Segmented"),
);
dock.register_panel(
PanelDescriptor::new("select", |_, cx| {
cx.new(|_| SelectDemo {
strategy: Some(Strategy::Curated),
}
});
dock.register_panel("dialog", {
let gallery = gallery.clone();
move |_, cx| {
cx.new(|_| DialogDemo {
gallery: gallery.clone(),
})
.into()
}
});
dock.register_panel("command-palette", {
let palette = palette.clone();
move |_, cx| cx.new(|cx| CommandPaletteDemo::new(gallery.clone(), palette.clone(), cx))
});
dock.register_panel("menu", |_, cx| cx.new(|_| MenuDemo { open: false }));
dock.register_panel("dropdown-menu", |_, cx| {
cx.new(|_| DropdownMenuDemo {
open_menu: None,
status: None,
})
.title("Select"),
);
dock.register_panel(
PanelDescriptor::new("link", |_, cx| cx.new(|_| LinkDemo { clicks: 0 }).into())
.title("Link"),
);
dock.register_panel(
PanelDescriptor::new("clipboard", |_, cx| cx.new(|_| ClipboardDemo).into())
.title("Clipboard"),
);
dock.register_panel(
PanelDescriptor::new("badge", |_, cx| cx.new(|_| BadgeDemo).into()).title("Badge"),
);
dock.register_panel(
PanelDescriptor::new("avatar", |_, cx| cx.new(|_| AvatarDemo).into()).title("Avatar"),
);
dock.register_panel(
PanelDescriptor::new("progress", |_, cx| cx.new(|_| ProgressDemo).into())
.title("Progress"),
);
dock.register_panel(
PanelDescriptor::new("spinner", |_, cx| cx.new(|_| SpinnerDemo).into())
.title("Spinner"),
);
dock.register_panel(
PanelDescriptor::new("list", |_, cx| {
cx.new(|_| ListDemo { selected: None }).into()
});
dock.register_panel("context-menu", |_, cx| {
cx.new(|_| ContextMenuDemo {
action: SharedString::from("Right-click the card"),
})
.title("List"),
);
dock.register_panel(
PanelDescriptor::new("tree", |_, cx| {
cx.new(|_| TreeDemo {
nodes: TreeDemo::demo(),
selected: None,
})
.into()
});
dock.register_panel("popover", |_, cx| cx.new(|_| PopoverDemo { open: false }));
dock.register_panel("tooltip", |_, cx| cx.new(|_| TooltipDemo));
dock.register_panel("empty-state", |_, cx| cx.new(|_| EmptyStateDemo));
dock.register_panel("scroll-area", |_, cx| cx.new(|_| ScrollAreaDemo));
dock.register_panel("scrollbar", |_, cx| cx.new(|_| ScrollbarDemo::new()));
dock.register_panel("code-view", |_, cx| cx.new(CodeViewDemo::new));
dock.register_panel("diff-view", |_, cx| cx.new(DiffViewDemo::new));
dock.register_panel("markdown-view", |_, cx| cx.new(MarkdownViewDemo::new));
dock.register_panel("text-view", |_, cx| cx.new(TextViewDemo::new));
dock.register_panel("sidebar", |_, cx| {
cx.new(|_| SidebarDemo { selected: None })
});
dock.register_panel("resize-handle", |window, cx| {
cx.new(|_| ResizeDemo {
width: rems(ResizeDemo::WIDTH_DEFAULT_REMS).to_pixels(window.rem_size()),
})
.title("Tree"),
);
dock.register_panel(
PanelDescriptor::new("tabs", |_, cx| {
cx.new(|_| TabsDemo {
selected: 0,
pill_tabs: vec![
SharedString::from("Explorer"),
SharedString::from("Syncing"),
SharedString::from("Blame"),
],
pill_selected: 0,
lead_selected: 0,
})
.into()
})
.title("Tabs"),
);
dock.register_panel(
PanelDescriptor::new("alert", {
let layout_state = layout_state.clone();
move |_, cx| {
cx.new(|_| AlertDemo {
layout_state: layout_state.clone(),
dismissed: false,
})
.into()
}
})
.title("Alert"),
);
dock.register_panel(
PanelDescriptor::new("toast", {
let layout_state = layout_state.clone();
move |_, cx| {
cx.new(|_| ToastDemo {
layout_state: layout_state.clone(),
})
.into()
}
})
.title("Toast"),
);
dock.register_panel(
PanelDescriptor::new("dialog", {
let gallery = gallery.clone();
move |_, cx| {
cx.new(|_| DialogDemo {
gallery: gallery.clone(),
})
.into()
}
})
.title("Dialog"),
);
dock.register_panel(
PanelDescriptor::new("command-palette", {
let palette = palette.clone();
move |_, cx| {
cx.new(|cx| CommandPaletteDemo::new(gallery.clone(), palette.clone(), cx))
.into()
}
})
.title("Command palette"),
);
dock.register_panel(
PanelDescriptor::new("menu", |_, cx| cx.new(|_| MenuDemo { open: false }).into())
.title("Menu"),
);
dock.register_panel(
PanelDescriptor::new("dropdown-menu", |_, cx| {
cx.new(|_| DropdownMenuDemo {
open_menu: None,
status: None,
})
.into()
})
.title("Dropdown menu"),
);
dock.register_panel(
PanelDescriptor::new("context-menu", |_, cx| {
cx.new(|_| ContextMenuDemo {
action: SharedString::from("Right-click the card"),
})
.into()
})
.title("Context menu"),
);
dock.register_panel(
PanelDescriptor::new("popover", |_, cx| {
cx.new(|_| PopoverDemo { open: false }).into()
})
.title("Popover"),
);
dock.register_panel(
PanelDescriptor::new("tooltip", |_, cx| cx.new(|_| TooltipDemo).into())
.title("Tooltip"),
);
dock.register_panel(
PanelDescriptor::new("empty-state", |_, cx| cx.new(|_| EmptyStateDemo).into())
.title("Empty state"),
);
dock.register_panel(
PanelDescriptor::new("scroll-area", |_, cx| cx.new(|_| ScrollAreaDemo).into())
.title("Scroll area"),
);
dock.register_panel(
PanelDescriptor::new("scrollbar", |_, cx| cx.new(|_| ScrollbarDemo::new()).into())
.title("Scrollbar"),
);
dock.register_panel(
PanelDescriptor::new("code-view", |_, cx| cx.new(CodeViewDemo::new).into())
.title("Code view"),
);
dock.register_panel(
PanelDescriptor::new("diff-view", |_, cx| cx.new(DiffViewDemo::new).into())
.title("Diff view"),
);
dock.register_panel(
PanelDescriptor::new("markdown-view", |_, cx| {
cx.new(MarkdownViewDemo::new).into()
})
.title("Markdown view"),
);
dock.register_panel(
PanelDescriptor::new("text-view", |_, cx| cx.new(TextViewDemo::new).into())
.title("Text view"),
);
dock.register_panel(
PanelDescriptor::new("sidebar", |_, cx| {
cx.new(|_| SidebarDemo { selected: None }).into()
})
.title("Sidebar"),
);
dock.register_panel(
PanelDescriptor::new("resize-handle", |window, cx| {
cx.new(|_| ResizeDemo {
width: rems(ResizeDemo::WIDTH_DEFAULT_REMS).to_pixels(window.rem_size()),
})
.into()
})
.title("Resize handle"),
);
dock.register_panel(
PanelDescriptor::new("resizable", |_, cx| cx.new(ResizableDemo::new).into())
.title("Resizable"),
);
dock.register_panel(
PanelDescriptor::new("separator", |_, cx| cx.new(|_| SeparatorDemo).into())
.title("Separator"),
);
dock.register_panel(
PanelDescriptor::new("theme", |_, cx| cx.new(|_| ThemeDemo).into()).title("Theme"),
);
});
dock.register_panel("resizable", |_, cx| cx.new(ResizableDemo::new));
dock.register_panel("separator", |_, cx| cx.new(|_| SeparatorDemo));
dock.register_panel("theme", |_, cx| cx.new(|_| ThemeDemo));
}
}
@@ -733,6 +572,22 @@ struct WelcomePanel {
gallery: WeakEntity<Gallery>,
}
impl Panel for WelcomePanel {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Welcome".into())
}
fn right_sidebar(&mut self, _: &mut Window, cx: &mut App) -> Option<AnyView> {
Some(
cx.new(|_| RightDetails {
title: "Welcome",
body: "Panels can declare this view; activating one opens the sidebar.",
})
.into(),
)
}
}
impl Render for WelcomePanel {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -869,6 +724,12 @@ impl ButtonDemo {
}
}
impl Panel for ButtonDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Button".into())
}
}
impl Render for ButtonDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -1035,6 +896,12 @@ impl InputDemo {
}
}
impl Panel for InputDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Input".into())
}
}
impl Render for InputDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -1119,6 +986,12 @@ impl FieldDemo {
}
}
impl Panel for FieldDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Field".into())
}
}
impl Render for FieldDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -1191,6 +1064,12 @@ impl Render for FieldDemo {
struct StatusDotDemo;
impl Panel for StatusDotDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Status dot".into())
}
}
impl Render for StatusDotDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -1359,6 +1238,12 @@ impl ComboboxDemo {
}
}
impl Panel for ComboboxDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Combobox".into())
}
}
impl Render for ComboboxDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -1428,6 +1313,12 @@ struct CheckboxDemo {
checked: bool,
}
impl Panel for CheckboxDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Checkbox".into())
}
}
impl Render for CheckboxDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -1470,6 +1361,12 @@ struct RadioDemo {
plan: SharedString,
}
impl Panel for RadioDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Radio".into())
}
}
impl Render for RadioDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -1506,6 +1403,12 @@ struct SwitchDemo {
checked: bool,
}
impl Panel for SwitchDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Switch".into())
}
}
impl Render for SwitchDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -1548,6 +1451,12 @@ struct ToggleDemo {
pressed: bool,
}
impl Panel for ToggleDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Toggle".into())
}
}
impl Render for ToggleDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -1585,6 +1494,12 @@ struct SliderDemo {
volume: f32,
}
impl Panel for SliderDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Slider".into())
}
}
impl Render for SliderDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -1622,6 +1537,12 @@ struct SegmentedDemo {
filter: ExploreFilter,
}
impl Panel for SegmentedDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Segmented".into())
}
}
impl Render for SegmentedDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -1704,6 +1625,12 @@ struct SelectDemo {
strategy: Option<Strategy>,
}
impl Panel for SelectDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Select".into())
}
}
impl Render for SelectDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -1752,6 +1679,12 @@ struct LinkDemo {
clicks: usize,
}
impl Panel for LinkDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Link".into())
}
}
impl Render for LinkDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -1800,6 +1733,12 @@ impl Render for LinkDemo {
struct ClipboardDemo;
impl Panel for ClipboardDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Clipboard".into())
}
}
impl Render for ClipboardDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -1834,6 +1773,12 @@ impl Render for ClipboardDemo {
struct SeparatorDemo;
impl Panel for SeparatorDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Separator".into())
}
}
impl Render for SeparatorDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -1886,6 +1831,12 @@ impl ResizableDemo {
}
}
impl Panel for ResizableDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Resizable".into())
}
}
impl Render for ResizableDemo {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -1925,6 +1876,12 @@ impl Render for ResizableDemo {
struct BadgeDemo;
impl Panel for BadgeDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Badge".into())
}
}
impl Render for BadgeDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -1964,6 +1921,12 @@ impl Render for BadgeDemo {
struct AvatarDemo;
impl Panel for AvatarDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Avatar".into())
}
}
impl Render for AvatarDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -1999,6 +1962,12 @@ impl Render for AvatarDemo {
struct ProgressDemo;
impl Panel for ProgressDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Progress".into())
}
}
impl Render for ProgressDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -2024,6 +1993,12 @@ impl Render for ProgressDemo {
struct SpinnerDemo;
impl Panel for SpinnerDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Spinner".into())
}
}
impl Render for SpinnerDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -2066,6 +2041,12 @@ struct ListDemo {
selected: Option<usize>,
}
impl Panel for ListDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("List".into())
}
}
impl Render for ListDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -2241,6 +2222,12 @@ impl TreeDemo {
}
}
impl Panel for TreeDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Tree".into())
}
}
impl Render for TreeDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -2282,6 +2269,12 @@ struct TabsDemo {
lead_selected: usize,
}
impl Panel for TabsDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Tabs".into())
}
}
impl Render for TabsDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -2403,6 +2396,12 @@ struct AlertDemo {
dismissed: bool,
}
impl Panel for AlertDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Alert".into())
}
}
impl Render for AlertDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -2495,6 +2494,12 @@ struct ToastDemo {
layout_state: Entity<LayoutState>,
}
impl Panel for ToastDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Toast".into())
}
}
impl Render for ToastDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let toasts_undo = self.layout_state.clone();
@@ -2565,6 +2570,12 @@ struct DialogDemo {
gallery: WeakEntity<Gallery>,
}
impl Panel for DialogDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Dialog".into())
}
}
impl Render for DialogDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let gallery_dialog = self.gallery.clone();
@@ -2631,6 +2642,12 @@ impl CommandPaletteDemo {
}
}
impl Panel for CommandPaletteDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Command palette".into())
}
}
impl Render for CommandPaletteDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -2697,6 +2714,12 @@ struct MenuDemo {
open: bool,
}
impl Panel for MenuDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Menu".into())
}
}
impl Render for MenuDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -2768,6 +2791,12 @@ impl DropdownMenuDemo {
}
}
impl Panel for DropdownMenuDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Dropdown menu".into())
}
}
impl Render for DropdownMenuDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -2919,6 +2948,12 @@ struct ContextMenuDemo {
action: SharedString,
}
impl Panel for ContextMenuDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Context menu".into())
}
}
impl Render for ContextMenuDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -2974,6 +3009,12 @@ struct PopoverDemo {
open: bool,
}
impl Panel for PopoverDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Popover".into())
}
}
impl Render for PopoverDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -3015,6 +3056,12 @@ impl Render for PopoverDemo {
struct TooltipDemo;
impl Panel for TooltipDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Tooltip".into())
}
}
impl Render for TooltipDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -3060,6 +3107,12 @@ impl Render for TooltipDemo {
struct EmptyStateDemo;
impl Panel for EmptyStateDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Empty state".into())
}
}
impl Render for EmptyStateDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let theme = cx.theme();
@@ -3106,6 +3159,12 @@ impl Render for EmptyStateDemo {
struct ScrollAreaDemo;
impl Panel for ScrollAreaDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Scroll area".into())
}
}
impl Render for ScrollAreaDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let theme = cx.theme();
@@ -3188,6 +3247,12 @@ impl ScrollbarDemo {
}
}
impl Panel for ScrollbarDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Scrollbar".into())
}
}
impl Render for ScrollbarDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let theme = cx.theme();
@@ -3397,6 +3462,12 @@ impl CodeViewDemo {
}
}
impl Panel for CodeViewDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Code view".into())
}
}
impl Render for CodeViewDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -3567,6 +3638,12 @@ impl DiffViewDemo {
}
}
impl Panel for DiffViewDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Diff view".into())
}
}
impl Render for DiffViewDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -3787,6 +3864,12 @@ impl MarkdownViewDemo {
}
}
impl Panel for MarkdownViewDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Markdown view".into())
}
}
impl Render for MarkdownViewDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -3863,6 +3946,12 @@ impl TextViewDemo {
}
}
impl Panel for TextViewDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Text view".into())
}
}
impl Render for TextViewDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let colors = cx.theme().colors;
@@ -3910,6 +3999,12 @@ struct SidebarDemo {
selected: Option<usize>,
}
impl Panel for SidebarDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Sidebar".into())
}
}
impl Render for SidebarDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -4078,6 +4173,12 @@ impl ResizeDemo {
const WIDTH_MAX_REMS: f32 = 20.;
}
impl Panel for ResizeDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Resize handle".into())
}
}
impl Render for ResizeDemo {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let view = cx.entity();
@@ -4156,6 +4257,12 @@ impl Render for ResizeDemo {
struct ThemeDemo;
impl Panel for ThemeDemo {
fn title(&self, _: &App) -> Option<SharedString> {
Some("Theme".into())
}
}
impl Render for ThemeDemo {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let theme = cx.theme();