update
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run
This commit is contained in:
@@ -10,6 +10,7 @@ use gpui::{
|
||||
Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div, px,
|
||||
};
|
||||
|
||||
use crate::components::tabs::Tab;
|
||||
use crate::layout::StyledExt as _;
|
||||
use crate::layout::resizable::{Resizable, ResizableState};
|
||||
use crate::theme::ActiveTheme as _;
|
||||
@@ -21,6 +22,19 @@ pub trait Panel: Render + 'static {
|
||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||
None
|
||||
}
|
||||
|
||||
/// The title shown in the panel's tab.
|
||||
fn title(&self, cx: &App) -> SharedString;
|
||||
|
||||
/// The element drawn before the tab's title, e.g. an avatar or icon.
|
||||
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Whether the tab shows the loading spinner.
|
||||
fn loading(&self, cx: &App) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// An object-safe handle to a panel, so apps can hold panels by kind.
|
||||
@@ -33,6 +47,28 @@ pub trait PanelView: 'static {
|
||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||
None
|
||||
}
|
||||
|
||||
/// The panel's title, read live from the panel.
|
||||
fn title(&self, cx: &App) -> SharedString;
|
||||
|
||||
/// The panel's tab prefix, read live from the panel.
|
||||
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Whether the panel's tab shows the loading spinner.
|
||||
fn loading(&self, cx: &App) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
/// Builds the panel's tab from its title, prefix, and loading state.
|
||||
fn tab(&self, key: ElementId, cx: &App) -> Tab {
|
||||
let mut tab = Tab::new(key, self.title(cx)).busy(self.loading(cx));
|
||||
if let Some(prefix) = self.prefix(cx) {
|
||||
tab = tab.lead(prefix);
|
||||
}
|
||||
tab
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Panel> PanelView for Entity<T> {
|
||||
@@ -43,6 +79,18 @@ impl<T: Panel> PanelView for Entity<T> {
|
||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||
self.read(cx).kind(cx)
|
||||
}
|
||||
|
||||
fn title(&self, cx: &App) -> SharedString {
|
||||
self.read(cx).title(cx)
|
||||
}
|
||||
|
||||
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||
self.read(cx).prefix(cx)
|
||||
}
|
||||
|
||||
fn loading(&self, cx: &App) -> bool {
|
||||
self.read(cx).loading(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: PanelView + ?Sized> PanelView for Arc<P> {
|
||||
@@ -53,6 +101,18 @@ impl<P: PanelView + ?Sized> PanelView for Arc<P> {
|
||||
fn kind(&self, cx: &App) -> Option<SharedString> {
|
||||
(**self).kind(cx)
|
||||
}
|
||||
|
||||
fn title(&self, cx: &App) -> SharedString {
|
||||
(**self).title(cx)
|
||||
}
|
||||
|
||||
fn prefix(&self, cx: &App) -> Option<AnyElement> {
|
||||
(**self).prefix(cx)
|
||||
}
|
||||
|
||||
fn loading(&self, cx: &App) -> bool {
|
||||
(**self).loading(cx)
|
||||
}
|
||||
}
|
||||
|
||||
/// The layout the cached panel content lays out with.
|
||||
|
||||
+113
-5
@@ -2,11 +2,14 @@
|
||||
//! half-width islands with a drag divider that resizes them.
|
||||
|
||||
use gpui::{
|
||||
AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, Modifiers, MouseButton,
|
||||
MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _, Render, SharedString,
|
||||
Styled as _, TestAppContext, VisualTestContext, Window, div, point, px, size,
|
||||
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||
Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _,
|
||||
Render, SharedString, Styled as _, TestAppContext, VisualTestContext, Window, div, point, px,
|
||||
size,
|
||||
};
|
||||
use ui::layout::panel::{Panel, PanelRow};
|
||||
use ui::common::v_flex;
|
||||
use ui::layout::panel::{Panel, PanelRow, PanelView};
|
||||
use ui::tabs::Tabs;
|
||||
use ui::theme::Theme;
|
||||
|
||||
const WINDOW_WIDTH: f32 = 1024.0;
|
||||
@@ -34,7 +37,11 @@ impl Render for TagView {
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for TagView {}
|
||||
impl Panel for TagView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
self.selector.clone()
|
||||
}
|
||||
}
|
||||
|
||||
struct PanelHarness {
|
||||
split: bool,
|
||||
@@ -150,3 +157,104 @@ fn dragging_the_divider_resizes_the_panels(cx: &mut TestAppContext) {
|
||||
.expect("main panel laid out after the drag");
|
||||
assert_eq!(after.size.width, before.size.width + px(100.0));
|
||||
}
|
||||
|
||||
struct MetaView {
|
||||
loading: bool,
|
||||
prefix: bool,
|
||||
}
|
||||
|
||||
impl Render for MetaView {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div().size_full()
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for MetaView {
|
||||
fn title(&self, _cx: &App) -> SharedString {
|
||||
SharedString::from("Meta")
|
||||
}
|
||||
|
||||
fn prefix(&self, _cx: &App) -> Option<AnyElement> {
|
||||
self.prefix.then(|| {
|
||||
div()
|
||||
.debug_selector(|| "meta-prefix".to_string())
|
||||
.into_any_element()
|
||||
})
|
||||
}
|
||||
|
||||
fn loading(&self, _cx: &App) -> bool {
|
||||
self.loading
|
||||
}
|
||||
}
|
||||
|
||||
struct MetaStripHarness {
|
||||
busy: Entity<MetaView>,
|
||||
idle: Entity<MetaView>,
|
||||
prefixed: Entity<MetaView>,
|
||||
}
|
||||
|
||||
impl Render for MetaStripHarness {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let busy = self.busy.clone();
|
||||
let idle = self.idle.clone();
|
||||
let prefixed = self.prefixed.clone();
|
||||
v_flex()
|
||||
.size_full()
|
||||
.gap_1()
|
||||
.child(
|
||||
Tabs::new("busy-strip")
|
||||
.tabs(move |_, cx| vec![busy.tab("busy".into(), cx).closeable(false)]),
|
||||
)
|
||||
.child(
|
||||
Tabs::new("idle-strip")
|
||||
.tabs(move |_, cx| vec![idle.tab("idle".into(), cx).closeable(false)]),
|
||||
)
|
||||
.child(
|
||||
Tabs::new("prefix-strip")
|
||||
.tabs(move |_, cx| vec![prefixed.tab("prefix".into(), cx).closeable(false)]),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn panel_tab_uses_title_prefix_and_loading(cx: &mut TestAppContext) {
|
||||
cx.update(Theme::init);
|
||||
let busy = cx.new(|_| MetaView {
|
||||
loading: true,
|
||||
prefix: false,
|
||||
});
|
||||
let idle = cx.new(|_| MetaView {
|
||||
loading: false,
|
||||
prefix: false,
|
||||
});
|
||||
let prefixed = cx.new(|_| MetaView {
|
||||
loading: false,
|
||||
prefix: true,
|
||||
});
|
||||
let window = cx.open_window(size(px(800.), px(600.)), |_, _| MetaStripHarness {
|
||||
busy,
|
||||
idle,
|
||||
prefixed,
|
||||
});
|
||||
let mut cx = VisualTestContext::from_window(window.into(), cx);
|
||||
cx.run_until_parked();
|
||||
|
||||
assert!(
|
||||
cx.debug_bounds("busy-strip-tab-Meta").is_some(),
|
||||
"title becomes the tab label"
|
||||
);
|
||||
assert!(
|
||||
cx.debug_bounds("meta-prefix").is_some(),
|
||||
"prefix becomes the tab lead"
|
||||
);
|
||||
let busy = cx
|
||||
.debug_bounds("busy-strip-tab-Meta")
|
||||
.expect("busy tab laid out");
|
||||
let idle = cx
|
||||
.debug_bounds("idle-strip-tab-Meta")
|
||||
.expect("idle tab laid out");
|
||||
assert!(
|
||||
busy.size.width > idle.size.width,
|
||||
"loading adds the spinner to the tab"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user