layout: initialize split pane widths on first render
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
|
||||
use gpui::{
|
||||
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 _;
|
||||
|
||||
@@ -70,6 +70,7 @@ impl RenderOnce for Panel {
|
||||
let theme = cx.theme();
|
||||
let app_background = theme.colors.muted;
|
||||
let id = self.id.clone();
|
||||
let gutter = rems(0.5).to_pixels(window.rem_size());
|
||||
|
||||
let main = island(
|
||||
div()
|
||||
@@ -85,6 +86,13 @@ impl RenderOnce for Panel {
|
||||
.use_keyed_state("panel-sizes", cx, |_, _| ResizableState::default())
|
||||
.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(
|
||||
Resizable::new((id.clone(), "split"), sizes)
|
||||
|
||||
@@ -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.
|
||||
fn reset_pane(&mut self, ix: usize, pane_count: usize, cx: &mut Context<Self>) {
|
||||
let split = self.equal_split(pane_count);
|
||||
|
||||
Reference in New Issue
Block a user