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:
+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