feat: redesign login panel
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-21 13:43:21 +07:00
parent bfe2badb38
commit 13ebb24861
14 changed files with 247 additions and 53 deletions
+60 -22
View File
@@ -1,19 +1,20 @@
//! The panel row: the window's main content, island-style over the app
//! 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.
//! background. It can split once into two panels with a drag divider
//! between them; the divider opens at half the row or at a set width
//! ([`PanelRow::split_at`]), and dragging it can be disabled
//! ([`PanelRow::resizable`]). A double-click restores the half split.
use std::sync::Arc;
use gpui::{
AnyElement, AnyView, App, Axis, Div, ElementId, Entity, IntoElement, ParentElement as _,
Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div,
Pixels, Render, RenderOnce, SharedString, StyleRefinement, Styled as _, Window, div,
};
use crate::components::tabs::Tab;
use crate::layout::StyledExt as _;
use crate::layout::resizable::{Resizable, ResizableState};
use crate::theme::{ActiveTheme as _, RESIZE_HANDLE_WIDTH};
use crate::theme::{ActiveTheme as _, PANE_MIN_SIZE, RESIZE_HANDLE_WIDTH};
/// A user-defined panel the row can show.
#[allow(unused_variables)]
@@ -141,6 +142,9 @@ pub struct PanelRow {
id: ElementId,
main: Option<AnyElement>,
split: Option<AnyElement>,
/// The main pane's width when split; `None` splits the row in half.
split_width: Option<Pixels>,
resizable: bool,
style: StyleRefinement,
}
@@ -154,6 +158,8 @@ impl PanelRow {
id: id.into(),
main: None,
split: None,
split_width: None,
resizable: true,
style: StyleRefinement::default(),
}
}
@@ -175,6 +181,22 @@ impl PanelRow {
self.split = Some(panel.view().cached(content_style()).into_any_element());
self
}
/// Splits the row with the main pane at `width`, the split pane beside it.
pub fn split_at<P>(mut self, panel: P, width: Pixels) -> Self
where
P: PanelView,
{
self.split_width = Some(width);
self.split = Some(panel.view().cached(content_style()).into_any_element());
self
}
/// Whether the divider can be dragged to resize the panels. Defaults to true.
pub fn resizable(mut self, resizable: bool) -> Self {
self.resizable = resizable;
self
}
}
impl gpui::Styled for PanelRow {
@@ -197,26 +219,42 @@ impl RenderOnce for PanelRow {
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()
});
let split = island(div().size_full().child(split), cx);
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)
});
}
let main_width = self
.split_width
.unwrap_or((extent - gutter) / 2.0)
.max(PANE_MIN_SIZE);
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(),
)
if !self.resizable {
div()
.w_full()
.h_full()
.flex()
.flex_row()
.child(div().flex_none().w(main_width).h_full().child(main))
.child(div().flex_none().w(gutter))
.child(div().flex_1().min_w_0().h_full().child(split))
} else {
let sizes = window.with_element_namespace(id.clone(), |window| {
window
.use_keyed_state("panel-sizes", cx, |_, _| ResizableState::default())
.clone()
});
if sizes.read(cx).sizes().is_empty() {
sizes.update(cx, |state, cx| state.set_pane_width(0, main_width, cx));
}
div().w_full().h_full().child(
Resizable::new((id.clone(), "split"), sizes)
.axis(Axis::Horizontal)
.pane(main)
.pane(split)
.h_full(),
)
}
}
None => div().w_full().h_full().child(main),
};
+82 -7
View File
@@ -4,8 +4,8 @@
use gpui::{
AnyElement, App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement as _,
Render, SharedString, Styled as _, TestAppContext, VisualTestContext, Window, div, point, px,
size,
Pixels, Render, SharedString, Styled as _, TestAppContext, VisualTestContext, Window, div,
point, px, size,
};
use ui::common::v_flex;
use ui::layout::panel::{Panel, PanelRow, PanelView};
@@ -45,23 +45,36 @@ impl Panel for TagView {
struct PanelHarness {
split: bool,
split_width: Option<Pixels>,
resizable: bool,
main: Entity<TagView>,
split_view: Entity<TagView>,
}
impl Render for PanelHarness {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
let panel = PanelRow::new("panel-harness").main(self.main.clone());
let panel = if self.split {
panel.split(self.split_view.clone())
} else {
panel
let panel = PanelRow::new("panel-harness")
.main(self.main.clone())
.resizable(self.resizable);
let panel = match self.split_width {
Some(width) => panel.split_at(self.split_view.clone(), width),
None if self.split => panel.split(self.split_view.clone()),
None => panel,
};
div().size_full().child(panel)
}
}
fn panel_window(cx: &mut TestAppContext, split: bool) -> VisualTestContext {
split_window(cx, split, None, true)
}
fn split_window(
cx: &mut TestAppContext,
split: bool,
split_width: Option<Pixels>,
resizable: bool,
) -> VisualTestContext {
let (main, split_view) = cx.update(|cx| {
Theme::init(cx);
let main = cx.new(|_| TagView::new("panel-test-main"));
@@ -72,6 +85,8 @@ fn panel_window(cx: &mut TestAppContext, split: bool) -> VisualTestContext {
let window = cx.open_window(size(px(WINDOW_WIDTH), px(WINDOW_HEIGHT)), |_, _| {
PanelHarness {
split,
split_width,
resizable,
main,
split_view,
}
@@ -120,6 +135,66 @@ fn split_makes_two_half_width_panels(cx: &mut TestAppContext) {
assert!(main.size.height >= px(WINDOW_HEIGHT - 40.0));
}
/// A split opened at a width lays the main pane out at exactly that width.
#[gpui::test]
fn split_at_opens_the_main_pane_at_the_width(cx: &mut TestAppContext) {
let mut cx = split_window(cx, true, Some(px(300.0)), 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");
// The marker fills the island's content box, which extends under the
// overlay border to the full pane width.
assert_eq!(main.size.width, px(300.0));
assert!(main.right() <= split.left());
assert!(split.size.width > px(300.0));
assert!(split.right() <= px(WINDOW_WIDTH));
}
/// With resizing disabled there is no divider and drags over the seam do nothing.
#[gpui::test]
fn a_static_split_ignores_drags(cx: &mut TestAppContext) {
let mut cx = split_window(cx, true, Some(px(300.0)), false);
let before = cx
.debug_bounds("panel-test-main")
.expect("main panel laid out");
assert_eq!(before.size.width, px(300.0));
assert!(
cx.debug_bounds("resize-handle").is_none(),
"a static split has no divider"
);
cx.simulate_event(MouseDownEvent {
position: point(px(320.0), px(400.0)),
button: MouseButton::Left,
modifiers: Modifiers::default(),
click_count: 1,
first_mouse: false,
});
cx.simulate_event(MouseMoveEvent {
position: point(px(420.0), px(400.0)),
pressed_button: Some(MouseButton::Left),
modifiers: Modifiers::default(),
});
cx.simulate_event(MouseUpEvent {
position: point(px(420.0), px(400.0)),
button: MouseButton::Left,
modifiers: Modifiers::default(),
click_count: 1,
});
cx.run_until_parked();
let after = cx
.debug_bounds("panel-test-main")
.expect("main panel laid out after the drag");
assert_eq!(after, before);
}
#[gpui::test]
fn dragging_the_divider_resizes_the_panels(cx: &mut TestAppContext) {
let mut cx = panel_window(cx, true);