layout: replace dock with simple titlebar and panel row
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
//! The panel row: the window's main content, island-style on the muted
|
||||
//! background. It can split once into two half-width panels with a drag
|
||||
//! divider between them; dragging the seam resizes the panels and a
|
||||
//! double-click restores the half split.
|
||||
|
||||
use gpui::{
|
||||
AnyElement, AnyView, App, Axis, Div, ElementId, IntoElement, ParentElement as _, RenderOnce,
|
||||
StyleRefinement, Styled as _, Window, div,
|
||||
};
|
||||
use gpui_native_theme::ActiveTheme as _;
|
||||
|
||||
use crate::resizable::{Resizable, ResizableState};
|
||||
|
||||
/// The layout the cached panel content lays out with.
|
||||
fn content_style() -> StyleRefinement {
|
||||
StyleRefinement::default().size_full()
|
||||
}
|
||||
|
||||
/// The island chrome every panel paints.
|
||||
fn island(panel: Div, cx: &App) -> Div {
|
||||
let theme = cx.theme();
|
||||
let colors = theme.colors;
|
||||
|
||||
panel
|
||||
.size_full()
|
||||
.bg(colors.background)
|
||||
.p_2()
|
||||
.border_1()
|
||||
.border_color(colors.border)
|
||||
.rounded(theme.radius.overlay)
|
||||
}
|
||||
|
||||
/// The panel row drawn under the titlebar.
|
||||
#[derive(IntoElement)]
|
||||
#[must_use]
|
||||
pub struct Panel {
|
||||
id: ElementId,
|
||||
main: Option<AnyElement>,
|
||||
split: Option<AnyElement>,
|
||||
}
|
||||
|
||||
impl Panel {
|
||||
/// Creates the panel row.
|
||||
pub fn new<I>(id: I) -> Self
|
||||
where
|
||||
I: Into<ElementId>,
|
||||
{
|
||||
Self {
|
||||
id: id.into(),
|
||||
main: None,
|
||||
split: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the main panel's content.
|
||||
pub fn main(mut self, main: AnyView) -> Self {
|
||||
self.main = Some(main.cached(content_style()).into_any_element());
|
||||
self
|
||||
}
|
||||
|
||||
/// Splits the row into two half-width panels,
|
||||
pub fn split(mut self, panel: AnyView) -> Self {
|
||||
self.split = Some(panel.cached(content_style()).into_any_element());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl RenderOnce for Panel {
|
||||
fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let app_background = theme.colors.muted;
|
||||
let id = self.id.clone();
|
||||
|
||||
let main = island(
|
||||
div()
|
||||
.size_full()
|
||||
.child(self.main.unwrap_or_else(|| div().into_any_element())),
|
||||
cx,
|
||||
);
|
||||
|
||||
let row = match self.split {
|
||||
Some(split) => {
|
||||
let sizes = window.with_element_namespace(id.clone(), |window| {
|
||||
window
|
||||
.use_keyed_state("panel-sizes", cx, |_, _| ResizableState::default())
|
||||
.clone()
|
||||
});
|
||||
|
||||
div().w_full().h_full().child(
|
||||
Resizable::new((id.clone(), "split"), sizes)
|
||||
.axis(Axis::Horizontal)
|
||||
.pane(main)
|
||||
.pane(island(div().size_full().child(split), cx))
|
||||
.h_full(),
|
||||
)
|
||||
}
|
||||
None => div().w_full().h_full().child(main),
|
||||
};
|
||||
|
||||
div()
|
||||
.flex_1()
|
||||
.min_w_0()
|
||||
.h_full()
|
||||
.p_2()
|
||||
.bg(app_background)
|
||||
.child(row)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user