layout: initialize split pane widths on first render

This commit is contained in:
2026-11-15 10:46:49 +07:00
parent 2d85db215b
commit 45ea41b93b
2 changed files with 20 additions and 1 deletions
+9 -1
View File
@@ -5,7 +5,7 @@
use gpui::{ use gpui::{
AnyElement, AnyView, App, Axis, Div, ElementId, IntoElement, ParentElement as _, RenderOnce, AnyElement, AnyView, App, Axis, Div, ElementId, IntoElement, ParentElement as _, RenderOnce,
StyleRefinement, Styled as _, Window, div, StyleRefinement, Styled as _, Window, div, rems,
}; };
use gpui_native_theme::ActiveTheme as _; use gpui_native_theme::ActiveTheme as _;
@@ -70,6 +70,7 @@ impl RenderOnce for Panel {
let theme = cx.theme(); let theme = cx.theme();
let app_background = theme.colors.muted; let app_background = theme.colors.muted;
let id = self.id.clone(); let id = self.id.clone();
let gutter = rems(0.5).to_pixels(window.rem_size());
let main = island( let main = island(
div() div()
@@ -85,6 +86,13 @@ impl RenderOnce for Panel {
.use_keyed_state("panel-sizes", cx, |_, _| ResizableState::default()) .use_keyed_state("panel-sizes", cx, |_, _| ResizableState::default())
.clone() .clone()
}); });
let extent = window.viewport_size().width - gutter * 2.0;
if sizes.read(cx).sizes().is_empty() {
sizes.update(cx, |state, cx| {
state.set_pane_width(0, (extent - gutter) / 2.0, cx)
});
}
div().w_full().h_full().child( div().w_full().h_full().child(
Resizable::new((id.clone(), "split"), sizes) Resizable::new((id.clone(), "split"), sizes)
+11
View File
@@ -105,6 +105,17 @@ impl ResizableState {
} }
} }
/// Sets pane `ix`'s width, backfilling earlier panes.
pub fn set_pane_width(&mut self, ix: usize, width: Pixels, cx: &mut Context<Self>) {
while self.sizes.len() <= ix {
self.sizes.push(width);
}
if self.sizes[ix] != width {
self.sizes[ix] = width;
cx.notify();
}
}
/// Restores pane `ix` to the equal split, as a double-click does. /// Restores pane `ix` to the equal split, as a double-click does.
fn reset_pane(&mut self, ix: usize, pane_count: usize, cx: &mut Context<Self>) { fn reset_pane(&mut self, ix: usize, pane_count: usize, cx: &mut Context<Self>) {
let split = self.equal_split(pane_count); let split = self.equal_split(pane_count);