layout: replace dock with simple titlebar and panel row

This commit is contained in:
2026-11-15 10:08:24 +07:00
parent 33f8856bc2
commit 2d85db215b
13 changed files with 836 additions and 2442 deletions
View File
+151
View File
@@ -0,0 +1,151 @@
#![cfg(feature = "panel")]
//! The panel row: the main island fills the window; splitting makes two
//! half-width islands with a drag divider that resizes them.
use gpui::{
AnyView, AppContext as _, Context, InteractiveElement as _, IntoElement, Modifiers,
MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _, Render,
SharedString, Styled as _, TestAppContext, VisualTestContext, Window, div, point, px, size,
};
use gpui_native_layout::panel::Panel;
use gpui_native_theme::Theme;
const WINDOW_WIDTH: f32 = 1024.0;
const WINDOW_HEIGHT: f32 = 768.0;
/// A full-size marker the tests measure through its debug selector.
struct TagView {
selector: SharedString,
}
impl TagView {
fn new(selector: &'static str) -> Self {
Self {
selector: SharedString::from(selector),
}
}
}
impl Render for TagView {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let selector = self.selector.clone();
div()
.debug_selector(move || selector.to_string())
.size_full()
}
}
struct PanelHarness {
split: bool,
main: AnyView,
split_view: AnyView,
}
impl Render for PanelHarness {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let panel = Panel::new("panel-harness").main(self.main.clone());
let panel = if self.split {
panel.split(self.split_view.clone())
} else {
panel
};
div().size_full().child(panel)
}
}
fn panel_window(cx: &mut TestAppContext, split: bool) -> VisualTestContext {
let (main, split_view) = cx.update(|cx| {
Theme::init(cx);
let main = cx.new(|_| TagView::new("panel-test-main"));
let split = cx.new(|_| TagView::new("panel-test-split"));
(main, split)
});
let window = cx.open_window(size(px(WINDOW_WIDTH), px(WINDOW_HEIGHT)), |_, _| {
PanelHarness {
split,
main: main.into(),
split_view: split_view.into(),
}
});
let cx = VisualTestContext::from_window(window.into(), cx);
cx.run_until_parked();
cx
}
#[gpui::test]
fn main_fills_the_row_without_a_split(cx: &mut TestAppContext) {
let mut cx = panel_window(cx, false);
let main = cx
.debug_bounds("panel-test-main")
.expect("main panel laid out");
// The row's padding and the island's inset are all main gives up.
assert!(main.size.width >= px(WINDOW_WIDTH - 40.0));
assert!(main.size.height >= px(WINDOW_HEIGHT - 40.0));
assert!(main.origin.x >= px(0.0));
}
#[gpui::test]
fn split_makes_two_half_width_panels(cx: &mut TestAppContext) {
let mut cx = panel_window(cx, true);
let main = cx
.debug_bounds("panel-test-main")
.expect("main panel laid out");
let split = cx
.debug_bounds("panel-test-split")
.expect("split panel laid out");
// Both islands share the row at half width, main first, and neither
// leaves the viewport. The divider's width lands on the remainder pane.
assert!(
(main.size.width - split.size.width).abs() <= px(10.0),
"main={:?} split={:?}",
main.size.width,
split.size.width
);
assert!(main.size.width < px(WINDOW_WIDTH / 2.0));
assert!(main.right() <= split.left());
assert!(split.right() <= px(WINDOW_WIDTH));
assert!(main.size.height >= px(WINDOW_HEIGHT - 40.0));
}
#[gpui::test]
fn dragging_the_divider_resizes_the_panels(cx: &mut TestAppContext) {
let mut cx = panel_window(cx, true);
let before = cx
.debug_bounds("panel-test-main")
.expect("main panel laid out");
// Press the divider between the islands and drag it 100px to the right.
let seam = point(before.right() + px(13.0), px(400.0));
cx.simulate_event(MouseDownEvent {
position: seam,
button: MouseButton::Left,
modifiers: Modifiers::default(),
click_count: 1,
first_mouse: false,
});
cx.simulate_event(MouseMoveEvent {
position: point(seam.x + px(100.0), seam.y),
pressed_button: Some(MouseButton::Left),
modifiers: Modifiers::default(),
});
cx.simulate_event(MouseUpEvent {
position: point(seam.x + px(100.0), seam.y),
button: MouseButton::Left,
modifiers: Modifiers::default(),
click_count: 1,
});
cx.run_until_parked();
// The main panel grew by the drag; the split panel gave up the space.
let after = cx
.debug_bounds("panel-test-main")
.expect("main panel laid out after the drag");
assert_eq!(after.size.width, before.size.width + px(100.0));
}