feat: redesign login panel
This commit is contained in:
Generated
+1
@@ -7111,6 +7111,7 @@ dependencies = [
|
||||
"metadata",
|
||||
"paths",
|
||||
"reqwest_client",
|
||||
"rust-embed",
|
||||
"settings",
|
||||
"signed_app",
|
||||
"signed_state",
|
||||
|
||||
@@ -5,7 +5,7 @@ mod sign_in;
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
AppContext as _, Context, Entity, InteractiveElement as _, IntoElement, ParentElement as _,
|
||||
Render, Styled as _, Subscription, Window, div,
|
||||
Render, Styled as _, Subscription, Window, div, px,
|
||||
};
|
||||
use helpers::apply_appearance;
|
||||
use settings::SettingsStore;
|
||||
@@ -34,6 +34,7 @@ pub struct AppRoot {
|
||||
titlebar: Entity<TitlebarView>,
|
||||
toasts: Entity<Toasts>,
|
||||
sign_in: Entity<SignedOutView>,
|
||||
explore: Entity<ExploreView>,
|
||||
empty: Entity<PlaceholderView>,
|
||||
passphrase: Option<Entity<PassphraseDialog>>,
|
||||
_subscriptions: Vec<Subscription>,
|
||||
@@ -48,6 +49,7 @@ impl AppRoot {
|
||||
|
||||
let toasts = cx.new(|_| Toasts::default());
|
||||
let sign_in = cx.new(|_| SignedOutView::new());
|
||||
let explore = cx.new(|cx| ExploreView::new(workspace.downgrade(), cx));
|
||||
let empty = cx.new(|_| PlaceholderView::new("Select a repository"));
|
||||
|
||||
let backend = Backend::global(cx);
|
||||
@@ -95,6 +97,7 @@ impl AppRoot {
|
||||
titlebar,
|
||||
toasts,
|
||||
sign_in,
|
||||
explore,
|
||||
empty,
|
||||
passphrase: None,
|
||||
_subscriptions: subscriptions,
|
||||
@@ -166,6 +169,7 @@ impl Render for AppRoot {
|
||||
})
|
||||
.when(!main.is_some() && !signed_in, |row| {
|
||||
row.main(self.sign_in.clone())
|
||||
.split_at(self.explore.clone(), px(300.))
|
||||
}),
|
||||
)
|
||||
.toasts(self.toasts.clone()),
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
use gpui::prelude::FluentBuilder as _;
|
||||
use gpui::{
|
||||
App, Context, Entity, IntoElement, ParentElement as _, Render, SharedString, Styled as _,
|
||||
Window, div,
|
||||
App, Context, Entity, IntoElement, ObjectFit, ParentElement as _, Render, SharedString,
|
||||
Styled as _, StyledImage as _, Window, div, img,
|
||||
};
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
use ui::common::{StyledExt as _, v_flex};
|
||||
use ui::common::v_flex;
|
||||
use ui::layout::panel::Panel;
|
||||
use ui::theme::ActiveTheme as _;
|
||||
|
||||
use crate::identity::import::ImportDialog;
|
||||
use crate::identity::onboarding::OnboardingDialog;
|
||||
|
||||
pub struct SignedOutView {
|
||||
banner: SharedString,
|
||||
onboarding: Option<Entity<OnboardingDialog>>,
|
||||
import: Option<Entity<ImportDialog>>,
|
||||
}
|
||||
@@ -18,6 +22,7 @@ pub struct SignedOutView {
|
||||
impl SignedOutView {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
banner: pick_banner(),
|
||||
onboarding: None,
|
||||
import: None,
|
||||
}
|
||||
@@ -40,28 +45,65 @@ impl Panel for SignedOutView {
|
||||
}
|
||||
}
|
||||
|
||||
/// One of the three banner photos, picked per process launch.
|
||||
fn pick_banner() -> SharedString {
|
||||
let nanos = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.map(|now| now.subsec_nanos())
|
||||
.unwrap_or(0);
|
||||
format!("backgrounds/banner{}.jpg", nanos % 3 + 1).into()
|
||||
}
|
||||
|
||||
impl Render for SignedOutView {
|
||||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let theme = cx.theme();
|
||||
let colors = theme.colors;
|
||||
|
||||
v_flex()
|
||||
.size_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.gap_4()
|
||||
.child(div().text_2xl().font_semibold().child("Signed"))
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_1()
|
||||
.w_48()
|
||||
.size_full()
|
||||
.relative()
|
||||
.bg(colors.background)
|
||||
.rounded(theme.radius.overlay)
|
||||
.overflow_hidden()
|
||||
.child(
|
||||
Button::new("onboarding")
|
||||
.label("Join now")
|
||||
.on_click(cx.listener(|this, _, _, cx| this.open_onboarding(cx))),
|
||||
div().absolute().inset_0().child(
|
||||
img(self.banner.clone())
|
||||
.size_full()
|
||||
.object_fit(ObjectFit::Cover)
|
||||
.rounded(theme.radius.overlay),
|
||||
),
|
||||
)
|
||||
.child(
|
||||
Button::new("import")
|
||||
.label("Import identity")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click(cx.listener(|this, _, _, cx| this.open_import(cx))),
|
||||
v_flex()
|
||||
.size_full()
|
||||
.justify_end()
|
||||
.p_4()
|
||||
.gap_6()
|
||||
.child(img("backgrounds/headline.png").max_w_48())
|
||||
.child(
|
||||
v_flex()
|
||||
.gap_2()
|
||||
.w_full()
|
||||
.child(
|
||||
Button::new("join")
|
||||
.label("Join now")
|
||||
.variant(ButtonVariant::Primary)
|
||||
.on_click(cx.listener(|this, _, _, cx| {
|
||||
this.open_onboarding(cx)
|
||||
})),
|
||||
)
|
||||
.child(
|
||||
Button::new("import")
|
||||
.label("Import identity")
|
||||
.variant(ButtonVariant::Secondary)
|
||||
.on_click(
|
||||
cx.listener(|this, _, _, cx| this.open_import(cx)),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
.when_some(self.onboarding.clone(), |el, view| el.child(view))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use gpui::{
|
||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ParentElement as _, Render,
|
||||
Styled as _, Window, div,
|
||||
Styled as _, Window, div, px,
|
||||
};
|
||||
use signed_state::Backend;
|
||||
use ui::button::{Button, ButtonVariant};
|
||||
@@ -22,20 +22,22 @@ impl ExitDialog {
|
||||
|
||||
impl Render for ExitDialog {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
const WARNING: &str = "You will be signed out on this device and will need to sign in again on the next session.";
|
||||
|
||||
let cancel_close = self.handle.clone();
|
||||
let confirm_close = self.handle.clone();
|
||||
|
||||
Dialog::new("exit-dialog")
|
||||
.handle(self.handle.clone())
|
||||
.width(px(420.))
|
||||
.title("Exit Signed?")
|
||||
.content(|_, cx| {
|
||||
v_flex()
|
||||
.child(
|
||||
div().text_base()
|
||||
div()
|
||||
.text_sm()
|
||||
.text_color(cx.theme().colors.muted_foreground)
|
||||
.child(
|
||||
"You will be signed out on this device and will need to sign in again on the next session.",
|
||||
),
|
||||
.child(WARNING),
|
||||
)
|
||||
.into_any_element()
|
||||
})
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -37,6 +37,7 @@ gpui.workspace = true
|
||||
gpui_platform.workspace = true
|
||||
ui = { path = "../crates/ui" }
|
||||
reqwest_client.workspace = true
|
||||
rust-embed.workspace = true
|
||||
tracing.workspace = true
|
||||
tracing-subscriber.workspace = true
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 421 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 598 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 639 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
+27
-2
@@ -3,16 +3,41 @@ use std::sync::Arc;
|
||||
use gpui::*;
|
||||
use gpui_platform::application;
|
||||
use settings::SettingsStore;
|
||||
use ui::Assets;
|
||||
use ui::theme::{ActiveTheme as _, Theme};
|
||||
|
||||
actions!(signed, [Quit]);
|
||||
|
||||
#[derive(rust_embed::RustEmbed)]
|
||||
#[folder = "assets"]
|
||||
#[exclude = "*.DS_Store"]
|
||||
struct BackgroundAssets;
|
||||
|
||||
/// Serves app artwork plus the ui crate's icon set.
|
||||
struct AppAssets;
|
||||
|
||||
impl AssetSource for AppAssets {
|
||||
fn load(&self, path: &str) -> gpui::Result<Option<std::borrow::Cow<'static, [u8]>>> {
|
||||
if path.starts_with("backgrounds/") {
|
||||
return Ok(BackgroundAssets::get(path).map(|file| file.data));
|
||||
}
|
||||
ui::Assets.load(path)
|
||||
}
|
||||
|
||||
fn list(&self, path: &str) -> gpui::Result<Vec<SharedString>> {
|
||||
let mut files: Vec<SharedString> = BackgroundAssets::iter()
|
||||
.filter(|file| file.starts_with(path))
|
||||
.map(SharedString::from)
|
||||
.collect();
|
||||
files.extend(ui::Assets.list(path)?);
|
||||
Ok(files)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
application()
|
||||
.with_assets(Assets)
|
||||
.with_assets(AppAssets)
|
||||
.with_http_client(Arc::new(reqwest_client::ReqwestClient::new()))
|
||||
.run(move |cx| {
|
||||
ui::init(cx);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
# gpui-native-kit gaps
|
||||
|
||||
Vendored `crates/ui` shortcomings recorded here instead of patched in place.
|
||||
|
||||
- `PanelRow` (`src/layout/panel.rs`) seeds its split panes from `window.viewport_size()` during the first render frame. On some launches that size is not yet the window's final bounds, so the divider freezes at a wrong position (observed ~24% instead of the intended 50%) until a drag or a double-click reset. Seeding from the canvas-measured extent, or re-seeding while no user resize has happened, would fix it.
|
||||
- `island()` (`src/layout/panel.rs`) rounds and paints `overflow_hidden`, but gpui's `ContentMask` is rectangular only: children are never clipped to the rounded corners. Full-bleed panel content (photos, backgrounds) paints square over the island chrome and must apply the matching `theme.radius.overlay` itself — see the signed-out banner in `signed_app`.
|
||||
Reference in New Issue
Block a user