refactor: move panel stack state into app root
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run

This commit is contained in:
2026-11-23 08:44:05 +07:00
parent 40c8831bf5
commit 2d07bcd1ed
15 changed files with 647 additions and 374 deletions
+112 -1
View File
@@ -1,6 +1,8 @@
//! The panel row: the main island fills the window; splitting makes two
//! half-width islands with a drag divider that resizes them.
use std::sync::Arc;
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _,
@@ -8,7 +10,7 @@ use gpui::{
point, px, size,
};
use ui::common::v_flex;
use ui::layout::panel::{Panel, PanelRow, PanelView};
use ui::layout::panel::{Panel, PanelRow, PanelView, SubPanels};
use ui::tabs::Tabs;
use ui::theme::Theme;
@@ -333,3 +335,112 @@ fn panel_tab_uses_title_prefix_and_loading(cx: &mut TestAppContext) {
"loading adds the spinner to the tab"
);
}
/// A marker panel that owns sub panels through the standard overrides.
struct SubsView {
selector: SharedString,
subs: SubPanels,
}
impl SubsView {
fn new(selector: &'static str) -> Self {
Self {
selector: SharedString::from(selector),
subs: SubPanels::default(),
}
}
}
impl Render for SubsView {
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()
}
}
impl Panel for SubsView {
fn title(&self, _cx: &App) -> SharedString {
self.selector.clone()
}
fn sub_panels(&self, _cx: &App) -> &SubPanels {
&self.subs
}
fn open_sub_panel(
&mut self,
id: SharedString,
view: Arc<dyn PanelView>,
_cx: &mut Context<Self>,
) -> bool {
self.subs.open(id, view)
}
fn close_sub_panel(&mut self, id: &SharedString, _cx: &mut Context<Self>) -> bool {
self.subs.close(id)
}
}
struct SubsHarness {
main: Entity<SubsView>,
}
impl Render for SubsHarness {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div()
.size_full()
.child(PanelRow::new("subs-harness").main(self.main.clone()))
}
}
/// Owned sub panels tile beside their panel, recursively, main at half width.
#[gpui::test]
fn sub_panels_tile_beside_their_panel(cx: &mut TestAppContext) {
let main = cx.update(|cx| {
Theme::init(cx);
let main = cx.new(|_| SubsView::new("sub-test-main"));
let sub = cx.new(|_| SubsView::new("sub-test-sub"));
let sub_sub = cx.new(|_| TagView::new("sub-test-sub-sub"));
sub.update(cx, |sub, _| {
sub.subs.open("sub-test-sub-sub", Arc::new(sub_sub.clone()));
});
main.update(cx, |main, _| {
main.subs.open("sub-test-sub", Arc::new(sub.clone()));
});
main
});
let window = cx.open_window(size(px(WINDOW_WIDTH), px(WINDOW_HEIGHT)), |_, _| {
SubsHarness { main }
});
let mut cx = VisualTestContext::from_window(window.into(), cx);
cx.run_until_parked();
let main = cx
.debug_bounds("sub-test-main")
.expect("main panel laid out");
let sub = cx.debug_bounds("sub-test-sub").expect("sub panel laid out");
let sub_sub = cx
.debug_bounds("sub-test-sub-sub")
.expect("sub-sub panel laid out");
// Three tiles run left to right, main first, each filling the row's height.
assert!(main.origin.x < sub.origin.x);
assert!(sub.origin.x < sub_sub.origin.x);
assert!(main.size.height >= px(WINDOW_HEIGHT - 40.0));
assert!(sub.size.height >= px(WINDOW_HEIGHT - 40.0));
assert!(sub_sub.size.height >= px(WINDOW_HEIGHT - 40.0));
// The main tile opens seeded at half the row; the sub tiles share the rest.
assert!(
(main.size.width - px(498.0)).abs() <= px(15.0),
"main tile width {:?}",
main.size.width
);
assert!(main.size.width > sub.size.width);
assert!(sub_sub.right() <= px(WINDOW_WIDTH));
}