refactor: replace signed out view with explore banner
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
pub mod helpers;
|
pub mod helpers;
|
||||||
mod placeholder;
|
mod placeholder;
|
||||||
mod sign_in;
|
|
||||||
|
|
||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyView, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
App, AppContext as _, Context, Entity, InteractiveElement as _, IntoElement,
|
||||||
ParentElement as _, Render, Styled as _, Subscription, Window, div, px,
|
ParentElement as _, Render, Styled as _, Subscription, WeakEntity, Window, div,
|
||||||
};
|
};
|
||||||
use helpers::apply_appearance_mode;
|
use helpers::apply_appearance_mode;
|
||||||
use settings::SettingsStore;
|
use settings::SettingsStore;
|
||||||
@@ -18,7 +17,6 @@ use ui::layout::titlebar::Titlebar;
|
|||||||
use ui::toast::Toast;
|
use ui::toast::Toast;
|
||||||
|
|
||||||
use crate::app::placeholder::PlaceholderView;
|
use crate::app::placeholder::PlaceholderView;
|
||||||
use crate::app::sign_in::SignedOutView;
|
|
||||||
use crate::explore::ExploreView;
|
use crate::explore::ExploreView;
|
||||||
use crate::identity::passphrase::PassphraseDialog;
|
use crate::identity::passphrase::PassphraseDialog;
|
||||||
use crate::shared::log_dropped;
|
use crate::shared::log_dropped;
|
||||||
@@ -30,9 +28,6 @@ use crate::titlebar::{
|
|||||||
pub struct AppRoot {
|
pub struct AppRoot {
|
||||||
panels: Entity<PanelStack>,
|
panels: Entity<PanelStack>,
|
||||||
titlebar: Entity<TitlebarView>,
|
titlebar: Entity<TitlebarView>,
|
||||||
sign_in: Entity<SignedOutView>,
|
|
||||||
explore: Entity<ExploreView>,
|
|
||||||
empty: Entity<PlaceholderView>,
|
|
||||||
passphrase: Option<Entity<PassphraseDialog>>,
|
passphrase: Option<Entity<PassphraseDialog>>,
|
||||||
_subscriptions: Vec<Subscription>,
|
_subscriptions: Vec<Subscription>,
|
||||||
}
|
}
|
||||||
@@ -44,19 +39,17 @@ impl AppRoot {
|
|||||||
let app = cx.entity().downgrade();
|
let app = cx.entity().downgrade();
|
||||||
let panels = cx.new(|cx| PanelStack::new("signed-panel", cx));
|
let panels = cx.new(|cx| PanelStack::new("signed-panel", cx));
|
||||||
let titlebar = cx.new(|cx| TitlebarView::new(app.clone(), window, cx));
|
let titlebar = cx.new(|cx| TitlebarView::new(app.clone(), window, cx));
|
||||||
let sign_in = cx.new(|_| SignedOutView::new());
|
|
||||||
let explore = cx.new(|cx| ExploreView::new(app.clone(), cx));
|
|
||||||
let empty = cx.new(|_| PlaceholderView::new("Select a repository"));
|
let empty = cx.new(|_| PlaceholderView::new("Select a repository"));
|
||||||
|
panels.update(cx, |panels, cx| panels.set_empty(empty, None, cx));
|
||||||
|
|
||||||
let backend = Backend::global(cx);
|
let backend = Backend::global(cx);
|
||||||
let signed_in = backend.read(cx).current_user().is_some();
|
|
||||||
let settings = SettingsStore::global(cx);
|
let settings = SettingsStore::global(cx);
|
||||||
let mut subscriptions = Vec::new();
|
let mut subscriptions = Vec::new();
|
||||||
|
|
||||||
subscriptions.push(cx.subscribe_in(
|
subscriptions.push(cx.subscribe_in(
|
||||||
&backend,
|
&backend,
|
||||||
window,
|
window,
|
||||||
|this, backend, event, window, cx| match event {
|
|this, _backend, event, window, cx| match event {
|
||||||
BackendEvent::PassphraseRequired => {
|
BackendEvent::PassphraseRequired => {
|
||||||
this.open_passphrase(cx);
|
this.open_passphrase(cx);
|
||||||
}
|
}
|
||||||
@@ -65,18 +58,8 @@ impl AppRoot {
|
|||||||
}
|
}
|
||||||
BackendEvent::SignerChanged => {
|
BackendEvent::SignerChanged => {
|
||||||
let app = cx.entity().downgrade();
|
let app = cx.entity().downgrade();
|
||||||
let backend = backend.clone();
|
|
||||||
|
|
||||||
window.defer(cx, move |window, cx| {
|
window.defer(cx, move |window, cx| {
|
||||||
let signed_in = backend.read(cx).current_user().is_some();
|
Self::reset_to_explore(&app, window, cx)
|
||||||
|
|
||||||
log_dropped(app.update(cx, |this, cx| {
|
|
||||||
this.sync_session(signed_in, cx);
|
|
||||||
}));
|
|
||||||
|
|
||||||
if signed_in {
|
|
||||||
ExploreView::open(&app, window, cx);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -88,19 +71,16 @@ impl AppRoot {
|
|||||||
apply_appearance_mode(settings.appearance, cx);
|
apply_appearance_mode(settings.appearance, cx);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
cx.defer_in(window, move |this, _window, cx| {
|
window.defer(cx, move |window, cx| {
|
||||||
if backend.read(cx).passphrase_required() {
|
if backend.read(cx).passphrase_required() {
|
||||||
log_dropped(app.update(cx, |this, cx| this.open_passphrase(cx)));
|
log_dropped(app.update(cx, |this, cx| this.open_passphrase(cx)));
|
||||||
}
|
}
|
||||||
this.sync_session(signed_in, cx);
|
Self::reset_to_explore(&app, window, cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
panels,
|
panels,
|
||||||
titlebar,
|
titlebar,
|
||||||
sign_in,
|
|
||||||
explore,
|
|
||||||
empty,
|
|
||||||
passphrase: None,
|
passphrase: None,
|
||||||
_subscriptions: subscriptions,
|
_subscriptions: subscriptions,
|
||||||
}
|
}
|
||||||
@@ -120,20 +100,13 @@ impl AppRoot {
|
|||||||
&self.panels
|
&self.panels
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Empties the stack and sets what it shows until a panel opens.
|
/// Empties the stack and opens it on the explore panel, where every session starts.
|
||||||
fn sync_session(&mut self, signed_in: bool, cx: &mut Context<Self>) {
|
fn reset_to_explore(app: &WeakEntity<Self>, window: &mut Window, cx: &mut App) {
|
||||||
let main: AnyView = if signed_in {
|
let result = app.update(cx, |this, cx| {
|
||||||
self.empty.clone().into()
|
this.panels.update(cx, |panels, cx| panels.clear(cx))
|
||||||
} else {
|
|
||||||
self.sign_in.clone().into()
|
|
||||||
};
|
|
||||||
|
|
||||||
let split = (!signed_in).then(|| (self.explore.clone().into(), px(300.)));
|
|
||||||
|
|
||||||
self.panels.update(cx, |panels, cx| {
|
|
||||||
panels.clear(cx);
|
|
||||||
panels.set_empty(main, split, cx);
|
|
||||||
});
|
});
|
||||||
|
log_dropped(result);
|
||||||
|
ExploreView::open(app, window, cx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
|
||||||
|
|
||||||
use gpui::prelude::FluentBuilder as _;
|
|
||||||
use gpui::{
|
|
||||||
Context, Entity, IntoElement, ObjectFit, ParentElement as _, Render, SharedString, Styled as _,
|
|
||||||
StyledImage as _, Window, div, img,
|
|
||||||
};
|
|
||||||
use ui::button::{Button, ButtonVariant};
|
|
||||||
use ui::common::v_flex;
|
|
||||||
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>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SignedOutView {
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self {
|
|
||||||
banner: pick_banner(),
|
|
||||||
onboarding: None,
|
|
||||||
import: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn open_onboarding(&mut self, cx: &mut Context<Self>) {
|
|
||||||
self.onboarding = Some(OnboardingDialog::new(cx));
|
|
||||||
cx.notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn open_import(&mut self, cx: &mut Context<Self>) {
|
|
||||||
self.import = Some(ImportDialog::new(cx));
|
|
||||||
cx.notify();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
.child(
|
|
||||||
v_flex()
|
|
||||||
.size_full()
|
|
||||||
.relative()
|
|
||||||
.bg(colors.background)
|
|
||||||
.rounded(theme.radius.overlay)
|
|
||||||
.overflow_hidden()
|
|
||||||
.child(
|
|
||||||
div().absolute().inset_0().child(
|
|
||||||
img(self.banner.clone())
|
|
||||||
.size_full()
|
|
||||||
.object_fit(ObjectFit::Cover)
|
|
||||||
.rounded(theme.radius.overlay),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.child(
|
|
||||||
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))
|
|
||||||
.when_some(self.import.clone(), |el, view| el.child(view))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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()
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
use std::sync::LazyLock;
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use gpui::prelude::FluentBuilder as _;
|
use gpui::prelude::FluentBuilder as _;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, Entity, InteractiveElement as _, IntoElement, ParentElement as _, SharedString,
|
AnyElement, Entity, InteractiveElement as _, IntoElement, ParentElement as _, SharedString,
|
||||||
@@ -18,6 +21,18 @@ use crate::repo::helpers::{announcement_display_name, upstream_display_name};
|
|||||||
|
|
||||||
const RECENT_COUNT: usize = 10;
|
const RECENT_COUNT: usize = 10;
|
||||||
|
|
||||||
|
/// One of the three banner photos, picked per process launch.
|
||||||
|
pub fn pick_banner() -> SharedString {
|
||||||
|
static BANNER: LazyLock<SharedString> = LazyLock::new(|| {
|
||||||
|
let nanos = SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.map(|now| now.subsec_nanos())
|
||||||
|
.unwrap_or(0);
|
||||||
|
SharedString::from(format!("backgrounds/banner{}.jpg", nanos % 3 + 1))
|
||||||
|
});
|
||||||
|
BANNER.clone()
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||||
pub(super) enum RepoFilter {
|
pub(super) enum RepoFilter {
|
||||||
#[default]
|
#[default]
|
||||||
|
|||||||
@@ -1,26 +1,33 @@
|
|||||||
mod helpers;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ListAlignment, ListState,
|
AnyElement, App, AppContext as _, Context, Entity, IntoElement, ListAlignment, ListState,
|
||||||
ParentElement as _, Render, SharedString, Styled as _, Subscription, WeakEntity, Window, div,
|
ObjectFit, ParentElement as _, Pixels, Render, SharedString, Styled as _, StyledImage as _,
|
||||||
list, px,
|
Subscription, WeakEntity, Window, div, img, list, px,
|
||||||
};
|
};
|
||||||
use helpers::{RepoFilter, render_card};
|
use helpers::{RepoFilter, render_card};
|
||||||
use metadata::ProfileDirectory;
|
use metadata::ProfileDirectory;
|
||||||
use nostr::prelude::PublicKey;
|
use nostr::prelude::PublicKey;
|
||||||
use signed_state::RepoListStore;
|
use signed_state::{Backend, RepoListStore};
|
||||||
|
use ui::button::{Button, ButtonVariant};
|
||||||
use ui::common::{h_flex, v_flex};
|
use ui::common::{h_flex, v_flex};
|
||||||
use ui::empty_state::EmptyState;
|
use ui::empty_state::EmptyState;
|
||||||
use ui::icons::{Icon, IconRole};
|
use ui::icons::{Icon, IconRole};
|
||||||
use ui::input::{Input, InputState, InputStateEvent};
|
use ui::input::{Input, InputState, InputStateEvent};
|
||||||
use ui::layout::panel::Panel;
|
use ui::layout::panel::{Panel, PanelSlot, SplitSide};
|
||||||
|
use ui::layout::root::RootContext as _;
|
||||||
use ui::scrollbar::Scrollbar;
|
use ui::scrollbar::Scrollbar;
|
||||||
use ui::segmented::{Segmented, SegmentedOption};
|
use ui::segmented::{Segmented, SegmentedOption};
|
||||||
use ui::theme::ActiveTheme as _;
|
use ui::theme::ActiveTheme as _;
|
||||||
|
|
||||||
use crate::app::AppRoot;
|
use crate::app::AppRoot;
|
||||||
|
use crate::explore::helpers::pick_banner;
|
||||||
|
use crate::identity::import::ImportDialog;
|
||||||
|
use crate::identity::onboarding::OnboardingDialog;
|
||||||
use crate::shared::panels;
|
use crate::shared::panels;
|
||||||
|
|
||||||
|
mod helpers;
|
||||||
|
|
||||||
const COLUMNS: usize = 2;
|
const COLUMNS: usize = 2;
|
||||||
// Name row, avatar strip, meta row, and their borders and gaps, in px.
|
// Name row, avatar strip, meta row, and their borders and gaps, in px.
|
||||||
const CARD_HEIGHT: f32 = 40. + 64. + 48. + 2. + 6.;
|
const CARD_HEIGHT: f32 = 40. + 64. + 48. + 2. + 6.;
|
||||||
@@ -37,6 +44,8 @@ pub struct ExploreView {
|
|||||||
directory: Entity<ProfileDirectory>,
|
directory: Entity<ProfileDirectory>,
|
||||||
_search_subscription: Subscription,
|
_search_subscription: Subscription,
|
||||||
_store_subscription: Subscription,
|
_store_subscription: Subscription,
|
||||||
|
/// Observes the panel stack for the onboarding sidebar, set once this view is in it.
|
||||||
|
_stack_subscription: Option<Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExploreView {
|
impl ExploreView {
|
||||||
@@ -74,9 +83,13 @@ impl ExploreView {
|
|||||||
this.rebuild_rows(cx);
|
this.rebuild_rows(cx);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The root and the stack are still being updated while this view is built.
|
||||||
cx.defer(move |cx| {
|
cx.defer(move |cx| {
|
||||||
if let Err(error) = weak.update(cx, |this, cx| this.rebuild_rows(cx)) {
|
if let Err(error) = weak.update(cx, |this, cx| {
|
||||||
log::warn!("failed to load explore rows: {error}");
|
this.rebuild_rows(cx);
|
||||||
|
this.watch_stack(cx);
|
||||||
|
}) {
|
||||||
|
log::warn!("failed to set up the explore panel: {error}");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -90,6 +103,7 @@ impl ExploreView {
|
|||||||
directory,
|
directory,
|
||||||
_search_subscription: search_subscription,
|
_search_subscription: search_subscription,
|
||||||
_store_subscription: store_subscription,
|
_store_subscription: store_subscription,
|
||||||
|
_stack_subscription: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,6 +138,50 @@ impl ExploreView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Observes the panel stack so the onboarding sidebar follows the shown panel.
|
||||||
|
fn watch_stack(&mut self, cx: &mut Context<Self>) {
|
||||||
|
let Ok(stack) = self
|
||||||
|
.workspace
|
||||||
|
.read_with(cx, |workspace, _| workspace.panels().clone())
|
||||||
|
else {
|
||||||
|
log::warn!("failed to watch the panel stack: the app root is gone");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
self._stack_subscription =
|
||||||
|
Some(cx.observe(&stack, |this, _stack, cx| this.sync_sidebar(cx)));
|
||||||
|
self.sync_sidebar(cx);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shows the onboarding sidebar while signed out and an explore panel is shown, and closes it otherwise.
|
||||||
|
fn sync_sidebar(&mut self, cx: &mut Context<Self>) {
|
||||||
|
let signed_out = Backend::global(cx).read(cx).current_user().is_none();
|
||||||
|
let explore = SharedString::from(Self::PANEL_ID);
|
||||||
|
let sidebar = SharedString::from(OnboardingSidebar::PANEL_ID);
|
||||||
|
|
||||||
|
let result = self.workspace.update(cx, |workspace, cx| {
|
||||||
|
workspace.panels().clone().update(cx, |stack, cx| {
|
||||||
|
let shown = signed_out && stack.is_active(PanelSlot::Main, &explore);
|
||||||
|
|
||||||
|
if shown && !stack.is_open(PanelSlot::Split, &sidebar) {
|
||||||
|
let view = Arc::new(cx.new(|_| OnboardingSidebar));
|
||||||
|
stack.insert_split_at(
|
||||||
|
sidebar.clone(),
|
||||||
|
OnboardingSidebar::WIDTH,
|
||||||
|
SplitSide::Leading,
|
||||||
|
view,
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
} else if !shown {
|
||||||
|
stack.close(PanelSlot::Split, &sidebar, cx);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Err(error) = result {
|
||||||
|
log::warn!("failed to update the onboarding sidebar: {error}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn render_header(
|
fn render_header(
|
||||||
search: Entity<InputState>,
|
search: Entity<InputState>,
|
||||||
filter: RepoFilter,
|
filter: RepoFilter,
|
||||||
@@ -260,3 +318,72 @@ impl Render for ExploreView {
|
|||||||
.child(Scrollbar::vertical("explore-scroll", scroll_handle))
|
.child(Scrollbar::vertical("explore-scroll", scroll_handle))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The onboarding sidebar shown beside the explore panel while signed out.
|
||||||
|
struct OnboardingSidebar;
|
||||||
|
|
||||||
|
impl OnboardingSidebar {
|
||||||
|
/// The identifier of the sidebar in the panel stack; shown as its tab label.
|
||||||
|
const PANEL_ID: &'static str = "Onboarding";
|
||||||
|
/// The width the sidebar opens at.
|
||||||
|
const WIDTH: Pixels = px(300.);
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Panel for OnboardingSidebar {
|
||||||
|
fn title(&self, _cx: &App) -> SharedString {
|
||||||
|
SharedString::from(Self::PANEL_ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Render for OnboardingSidebar {
|
||||||
|
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()
|
||||||
|
.relative()
|
||||||
|
.bg(colors.background)
|
||||||
|
.rounded(theme.radius.overlay)
|
||||||
|
.overflow_hidden()
|
||||||
|
.child(
|
||||||
|
div().absolute().inset_0().child(
|
||||||
|
img(pick_banner())
|
||||||
|
.size_full()
|
||||||
|
.object_fit(ObjectFit::Cover)
|
||||||
|
.rounded(theme.radius.overlay),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
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| {
|
||||||
|
let dialog = OnboardingDialog::new(cx);
|
||||||
|
cx.open_dialog(dialog)
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.child(
|
||||||
|
Button::new("import")
|
||||||
|
.label("Import identity")
|
||||||
|
.variant(ButtonVariant::Secondary)
|
||||||
|
.on_click(|_, _, cx| {
|
||||||
|
let dialog = ImportDialog::new(cx);
|
||||||
|
cx.open_dialog(dialog)
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+139
-55
@@ -2,9 +2,10 @@
|
|||||||
//! background. It owns every panel it shows: a main stack, tabbed in the
|
//! background. It owns every panel it shows: a main stack, tabbed in the
|
||||||
//! titlebar through [`PanelStack::main_tabs`], and a split stack that opens a
|
//! titlebar through [`PanelStack::main_tabs`], and a split stack that opens a
|
||||||
//! second pane beside the main panel while it holds a panel, at half the
|
//! second pane beside the main panel while it holds a panel, at half the
|
||||||
//! width, with a drag divider between the panes; a double-click restores half.
|
//! width or at a set width on either side of it
|
||||||
//! While no main panel is open the stack shows the empty state its owner set
|
//! ([`PanelStack::insert_split_at`]), with a drag divider between the panes; a
|
||||||
//! ([`PanelStack::set_empty`]).
|
//! double-click restores half. While no main panel is open the stack shows the
|
||||||
|
//! empty state its owner set ([`PanelStack::set_empty`]).
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@@ -128,6 +129,15 @@ pub enum PanelSlot {
|
|||||||
Split,
|
Split,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The side of the main panel a split pane opens on.
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum SplitSide {
|
||||||
|
/// Before the main panel.
|
||||||
|
Leading,
|
||||||
|
/// After the main panel.
|
||||||
|
Trailing,
|
||||||
|
}
|
||||||
|
|
||||||
/// An ordered stack of panels with one of them shown.
|
/// An ordered stack of panels with one of them shown.
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Stack {
|
struct Stack {
|
||||||
@@ -216,6 +226,12 @@ pub struct PanelStack {
|
|||||||
split: Stack,
|
split: Stack,
|
||||||
empty: Option<EmptyContent>,
|
empty: Option<EmptyContent>,
|
||||||
resizable: bool,
|
resizable: bool,
|
||||||
|
/// The width the on-screen split pane opened at; `None` splits the row in half.
|
||||||
|
split_width: Option<Pixels>,
|
||||||
|
/// The side of the main panel the on-screen split pane opened on.
|
||||||
|
split_side: SplitSide,
|
||||||
|
/// The main pane width the divider was last seeded at, to tell a drag from a window resize.
|
||||||
|
opened_at: Option<Pixels>,
|
||||||
/// The divider position, kept only while a split is on screen.
|
/// The divider position, kept only while a split is on screen.
|
||||||
sizes: Entity<ResizableState>,
|
sizes: Entity<ResizableState>,
|
||||||
}
|
}
|
||||||
@@ -251,6 +267,9 @@ impl PanelStack {
|
|||||||
split: Stack::default(),
|
split: Stack::default(),
|
||||||
empty: None,
|
empty: None,
|
||||||
resizable: true,
|
resizable: true,
|
||||||
|
split_width: None,
|
||||||
|
split_side: SplitSide::Trailing,
|
||||||
|
opened_at: None,
|
||||||
sizes: ResizableState::new(cx),
|
sizes: ResizableState::new(cx),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -311,6 +330,34 @@ impl PanelStack {
|
|||||||
self.insert(slot, id, view, cx);
|
self.insert(slot, id, view, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the panel under `id` is open in `slot`.
|
||||||
|
pub fn is_open(&self, slot: PanelSlot, id: &SharedString) -> bool {
|
||||||
|
self.stack(slot).position(id).is_some()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the panel under `id` is the one shown in `slot`.
|
||||||
|
pub fn is_active(&self, slot: PanelSlot, id: &SharedString) -> bool {
|
||||||
|
self.stack(slot).active.as_ref() == Some(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shows `view` in the split stack under `id`; a split pane not on screen yet opens at `width` on `side`.
|
||||||
|
pub fn insert_split_at<T>(
|
||||||
|
&mut self,
|
||||||
|
id: T,
|
||||||
|
width: Pixels,
|
||||||
|
side: SplitSide,
|
||||||
|
view: Arc<dyn PanelView>,
|
||||||
|
cx: &mut Context<Self>,
|
||||||
|
) where
|
||||||
|
T: Into<SharedString>,
|
||||||
|
{
|
||||||
|
if !self.is_split_shown() {
|
||||||
|
self.split_width = Some(width);
|
||||||
|
self.split_side = side;
|
||||||
|
}
|
||||||
|
self.insert(PanelSlot::Split, id, view, cx);
|
||||||
|
}
|
||||||
|
|
||||||
/// Closes the panel under `id`.
|
/// Closes the panel under `id`.
|
||||||
pub fn close(&mut self, slot: PanelSlot, id: &SharedString, cx: &mut Context<Self>) {
|
pub fn close(&mut self, slot: PanelSlot, id: &SharedString, cx: &mut Context<Self>) {
|
||||||
if let Some(index) = self.stack(slot).position(id) {
|
if let Some(index) = self.stack(slot).position(id) {
|
||||||
@@ -431,12 +478,19 @@ impl PanelStack {
|
|||||||
.is_some_and(|empty| empty.split.is_some())
|
.is_some_and(|empty| empty.split.is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Drops the divider position while no split is on screen, so the next one opens at its start width.
|
/// Drops the divider position, width, and side while no split is on screen, so the next split opens at its start width.
|
||||||
fn forget_divider(&mut self, cx: &mut Context<Self>) {
|
fn forget_divider(&mut self, cx: &mut Context<Self>) {
|
||||||
if self.is_split_shown() || self.sizes.read(cx).sizes().is_empty() {
|
if self.is_split_shown() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.sizes.update(cx, |state, cx| state.set_sizes([], cx));
|
|
||||||
|
self.split_width = None;
|
||||||
|
self.split_side = SplitSide::Trailing;
|
||||||
|
self.opened_at = None;
|
||||||
|
|
||||||
|
if !self.sizes.read(cx).sizes().is_empty() {
|
||||||
|
self.sizes.update(cx, |state, cx| state.set_sizes([], cx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The split pane's content: the split stack's tabs over its shown panel.
|
/// The split pane's content: the split stack's tabs over its shown panel.
|
||||||
@@ -489,63 +543,93 @@ impl PanelStack {
|
|||||||
impl Render for PanelStack {
|
impl Render for PanelStack {
|
||||||
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
|
||||||
let gutter = RESIZE_HANDLE_WIDTH;
|
let gutter = RESIZE_HANDLE_WIDTH;
|
||||||
|
let extent = window.viewport_size().width - gutter * 2.0;
|
||||||
let cached = |view: AnyView| view.cached(content_style()).into_any_element();
|
let cached = |view: AnyView| view.cached(content_style()).into_any_element();
|
||||||
|
|
||||||
// The main pane's content, the split pane's when one is on screen, and the width the main pane opens at.
|
// The main pane's content, the split pane's when one is on screen, and how the first pane opens.
|
||||||
let (main, split, width): (AnyElement, Option<AnyElement>, Option<Pixels>) =
|
let (main, split, width, leading) = match self.main.active() {
|
||||||
match self.main.active() {
|
Some(panel) => {
|
||||||
Some(panel) => (
|
let leading = self.split_side == SplitSide::Leading;
|
||||||
|
// The pane opened at a width is the sized one; the other fills what is left.
|
||||||
|
let width = if leading {
|
||||||
|
self.split_width
|
||||||
|
} else {
|
||||||
|
self.split_width
|
||||||
|
.map(|split_width| extent - gutter - split_width)
|
||||||
|
};
|
||||||
|
(
|
||||||
cached(panel.view()),
|
cached(panel.view()),
|
||||||
(!self.split.is_empty()).then(|| self.split_pane(cx)),
|
(!self.split.is_empty()).then(|| self.split_pane(cx)),
|
||||||
None,
|
width,
|
||||||
),
|
leading,
|
||||||
None => match &self.empty {
|
)
|
||||||
Some(empty) => {
|
}
|
||||||
let (split, width) = match &empty.split {
|
None => match &self.empty {
|
||||||
Some((view, width)) => (Some(cached(view.clone())), Some(*width)),
|
Some(empty) => {
|
||||||
None => (None, None),
|
let (split, width) = match &empty.split {
|
||||||
};
|
Some((view, width)) => (Some(cached(view.clone())), Some(*width)),
|
||||||
(cached(empty.main.clone()), split, width)
|
None => (None, None),
|
||||||
|
};
|
||||||
|
(cached(empty.main.clone()), split, width, false)
|
||||||
|
}
|
||||||
|
None => (div().into_any_element(), None, None, false),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
div().flex_1().min_w_0().h_full().p_2().pt_1().map(|this| {
|
||||||
|
match split {
|
||||||
|
Some(split) => {
|
||||||
|
let main = island(div().size_full().child(main), cx);
|
||||||
|
let split = island(div().size_full().child(split), cx);
|
||||||
|
let (first, last) = if leading {
|
||||||
|
(split, main)
|
||||||
|
} else {
|
||||||
|
(main, split)
|
||||||
|
};
|
||||||
|
let first_width = width.unwrap_or((extent - gutter) / 2.0).max(PANE_MIN_SIZE);
|
||||||
|
|
||||||
|
if !self.resizable {
|
||||||
|
this.child(
|
||||||
|
div()
|
||||||
|
.w_full()
|
||||||
|
.h_full()
|
||||||
|
.flex()
|
||||||
|
.flex_row()
|
||||||
|
.child(div().flex_none().w(first_width).h_full().child(first))
|
||||||
|
.child(div().flex_none().w(gutter))
|
||||||
|
.child(div().flex_1().min_w_0().h_full().child(last)),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// A split opened at a width keeps it across window resizes until the divider is dragged.
|
||||||
|
let current = self.sizes.read(cx).sizes().first().copied();
|
||||||
|
let keeps_width = self.split_width.is_some() && current == self.opened_at;
|
||||||
|
|
||||||
|
if current.is_none() || (keeps_width && self.opened_at != Some(first_width))
|
||||||
|
{
|
||||||
|
self.sizes.update(cx, |state, cx| {
|
||||||
|
state.set_pane_width(0, first_width, cx);
|
||||||
|
});
|
||||||
|
self.opened_at = Some(first_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.child(
|
||||||
|
div().w_full().h_full().child(
|
||||||
|
Resizable::new((self.id.clone(), "split"), self.sizes.clone())
|
||||||
|
.axis(Axis::Horizontal)
|
||||||
|
.pane(first)
|
||||||
|
.pane(last)
|
||||||
|
.h_full(),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
None => (div().into_any_element(), None, None),
|
}
|
||||||
},
|
None => this.child(
|
||||||
};
|
|
||||||
|
|
||||||
let main = island(div().size_full().child(main), cx);
|
|
||||||
|
|
||||||
let row = match split {
|
|
||||||
Some(split) => {
|
|
||||||
let split = island(div().size_full().child(split), cx);
|
|
||||||
let extent = window.viewport_size().width - gutter * 2.0;
|
|
||||||
let main_width = width.unwrap_or((extent - gutter) / 2.0).max(PANE_MIN_SIZE);
|
|
||||||
|
|
||||||
if !self.resizable {
|
|
||||||
div()
|
div()
|
||||||
.w_full()
|
.w_full()
|
||||||
.h_full()
|
.h_full()
|
||||||
.flex()
|
.child(island(div().size_full().child(main), cx)),
|
||||||
.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 {
|
|
||||||
if self.sizes.read(cx).sizes().is_empty() {
|
|
||||||
self.sizes
|
|
||||||
.update(cx, |state, cx| state.set_pane_width(0, main_width, cx));
|
|
||||||
}
|
|
||||||
|
|
||||||
div().w_full().h_full().child(
|
|
||||||
Resizable::new((self.id.clone(), "split"), self.sizes.clone())
|
|
||||||
.axis(Axis::Horizontal)
|
|
||||||
.pane(main)
|
|
||||||
.pane(split)
|
|
||||||
.h_full(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => div().w_full().h_full().child(main),
|
})
|
||||||
};
|
|
||||||
|
|
||||||
div().flex_1().min_w_0().h_full().p_2().pt_1().child(row)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,9 +111,11 @@ impl ResizableState {
|
|||||||
pub fn set_pane_width(&mut self, ix: usize, width: Pixels, cx: &mut Context<Self>) {
|
pub fn set_pane_width(&mut self, ix: usize, width: Pixels, cx: &mut Context<Self>) {
|
||||||
// Persisted layouts can carry negative sizes.
|
// Persisted layouts can carry negative sizes.
|
||||||
let width = width.max(PANE_MIN_SIZE);
|
let width = width.max(PANE_MIN_SIZE);
|
||||||
|
|
||||||
while self.sizes.len() <= ix {
|
while self.sizes.len() <= ix {
|
||||||
self.sizes.push(width);
|
self.sizes.push(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.sizes[ix] != width {
|
if self.sizes[ix] != width {
|
||||||
self.sizes[ix] = width;
|
self.sizes[ix] = width;
|
||||||
cx.notify();
|
cx.notify();
|
||||||
@@ -305,7 +307,9 @@ impl RenderOnce for Resizable {
|
|||||||
Axis::Vertical => bounds.size.height,
|
Axis::Vertical => bounds.size.height,
|
||||||
Axis::Horizontal => bounds.size.width,
|
Axis::Horizontal => bounds.size.width,
|
||||||
};
|
};
|
||||||
state.update(cx, |state, cx| state.set_measured(extent, cx));
|
state.update(cx, |state, cx| {
|
||||||
|
state.set_measured(extent, cx);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|_, _, _, _| {},
|
|_, _, _, _| {},
|
||||||
@@ -316,30 +320,3 @@ impl RenderOnce for Resizable {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
use gpui::TestAppContext;
|
|
||||||
|
|
||||||
#[gpui::test]
|
|
||||||
fn resize_never_stores_sub_floor_size(cx: &mut TestAppContext) {
|
|
||||||
let state = cx.new(|_| ResizableState::default());
|
|
||||||
state.update(cx, |state, cx| {
|
|
||||||
// The measured extent is smaller than the other pane's floor.
|
|
||||||
state.set_measured(px(100.), cx);
|
|
||||||
state.resize(0, px(500.), &[px(48.), px(150.)], cx);
|
|
||||||
assert_eq!(state.sizes[0], px(48.));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[gpui::test]
|
|
||||||
fn set_pane_width_clamps_negative_values(cx: &mut TestAppContext) {
|
|
||||||
let state = cx.new(|_| ResizableState::default());
|
|
||||||
state.update(cx, |state, cx| {
|
|
||||||
// Persisted layouts can carry negative sizes.
|
|
||||||
state.set_pane_width(0, px(-20.), cx);
|
|
||||||
assert_eq!(state.pane_size(0, 1), PANE_MIN_SIZE);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
+241
-1
@@ -10,7 +10,7 @@ use gpui::{
|
|||||||
size,
|
size,
|
||||||
};
|
};
|
||||||
use ui::common::v_flex;
|
use ui::common::v_flex;
|
||||||
use ui::layout::panel::{Panel, PanelSlot, PanelStack, PanelView};
|
use ui::layout::panel::{Panel, PanelSlot, PanelStack, PanelView, SplitSide};
|
||||||
use ui::tabs::Tabs;
|
use ui::tabs::Tabs;
|
||||||
use ui::theme::Theme;
|
use ui::theme::Theme;
|
||||||
|
|
||||||
@@ -580,3 +580,243 @@ fn main_tabs_switch_and_close_the_main_stack(cx: &mut TestAppContext) {
|
|||||||
"the shown panel stays"
|
"the shown panel stays"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A split inserted at a width opens with it.
|
||||||
|
#[gpui::test]
|
||||||
|
fn a_split_inserted_at_a_width_opens_there(cx: &mut TestAppContext) {
|
||||||
|
let (mut cx, stack) = stack_window(cx, main_only);
|
||||||
|
cx.update(|_, cx| {
|
||||||
|
stack.update(cx, |stack, cx| {
|
||||||
|
stack.insert_split_at(
|
||||||
|
"side",
|
||||||
|
px(300.),
|
||||||
|
SplitSide::Trailing,
|
||||||
|
Arc::new(tag(cx, "panel-test-split")),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
let split = cx
|
||||||
|
.debug_bounds("panel-test-split")
|
||||||
|
.expect("split panel laid out");
|
||||||
|
assert!((split.size.width - px(300.0)).abs() <= px(2.0));
|
||||||
|
cx.update(|_, cx| {
|
||||||
|
let stack = stack.read(cx);
|
||||||
|
let side = SharedString::from("side");
|
||||||
|
assert!(stack.is_open(PanelSlot::Split, &side));
|
||||||
|
assert!(stack.is_active(PanelSlot::Split, &side));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A split already on screen keeps its divider and side when another opens at a width.
|
||||||
|
#[gpui::test]
|
||||||
|
fn a_width_and_side_apply_to_a_split_new_to_the_screen_only(cx: &mut TestAppContext) {
|
||||||
|
let (mut cx, stack) = stack_window(cx, main_and_split);
|
||||||
|
let before = cx
|
||||||
|
.debug_bounds("panel-test-main")
|
||||||
|
.expect("main panel laid out");
|
||||||
|
|
||||||
|
cx.update(|_, cx| {
|
||||||
|
stack.update(cx, |stack, cx| {
|
||||||
|
stack.insert_split_at(
|
||||||
|
"side",
|
||||||
|
px(300.),
|
||||||
|
SplitSide::Leading,
|
||||||
|
Arc::new(tag(cx, "panel-test-side")),
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
});
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
let after = cx
|
||||||
|
.debug_bounds("panel-test-main")
|
||||||
|
.expect("main panel laid out");
|
||||||
|
assert_eq!(after, before);
|
||||||
|
cx.update(|_, cx| {
|
||||||
|
let stack = stack.read(cx);
|
||||||
|
let split = SharedString::from("split");
|
||||||
|
assert!(stack.is_open(PanelSlot::Split, &split));
|
||||||
|
assert!(!stack.is_active(PanelSlot::Split, &split));
|
||||||
|
});
|
||||||
|
let side = cx
|
||||||
|
.debug_bounds("panel-test-side")
|
||||||
|
.expect("the new split panel laid out");
|
||||||
|
assert!(
|
||||||
|
side.left() >= after.right(),
|
||||||
|
"it still opens after the main panel"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A split opened at a width keeps it across window resizes until the divider is dragged.
|
||||||
|
#[gpui::test]
|
||||||
|
fn a_width_split_follows_resizes_until_dragged(cx: &mut TestAppContext) {
|
||||||
|
let (mut cx, _stack) = stack_window(cx, |stack, cx| {
|
||||||
|
main_only(stack, cx);
|
||||||
|
stack.insert_split_at(
|
||||||
|
"side",
|
||||||
|
px(300.),
|
||||||
|
SplitSide::Trailing,
|
||||||
|
Arc::new(tag(cx, "panel-test-split")),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
cx.simulate_resize(size(px(WINDOW_WIDTH + 400.0), px(WINDOW_HEIGHT)));
|
||||||
|
cx.run_until_parked();
|
||||||
|
let split = cx
|
||||||
|
.debug_bounds("panel-test-split")
|
||||||
|
.expect("split panel laid out after the resize");
|
||||||
|
assert!(
|
||||||
|
(split.size.width - px(300.0)).abs() <= px(2.0),
|
||||||
|
"the split keeps its width: {:?}",
|
||||||
|
split.size.width
|
||||||
|
);
|
||||||
|
|
||||||
|
let handle = cx.debug_bounds("resize-handle").expect("divider laid out");
|
||||||
|
let seam = point(handle.center().x, px(400.0));
|
||||||
|
cx.simulate_event(MouseDownEvent {
|
||||||
|
position: seam,
|
||||||
|
button: MouseButton::Left,
|
||||||
|
modifiers: Modifiers::default(),
|
||||||
|
click_count: 1,
|
||||||
|
first_mouse: false,
|
||||||
|
});
|
||||||
|
cx.simulate_event(MouseMoveEvent {
|
||||||
|
position: point(seam.x + px(100.0), seam.y),
|
||||||
|
pressed_button: Some(MouseButton::Left),
|
||||||
|
modifiers: Modifiers::default(),
|
||||||
|
});
|
||||||
|
cx.simulate_event(MouseUpEvent {
|
||||||
|
position: point(seam.x + px(100.0), seam.y),
|
||||||
|
button: MouseButton::Left,
|
||||||
|
modifiers: Modifiers::default(),
|
||||||
|
click_count: 1,
|
||||||
|
});
|
||||||
|
cx.run_until_parked();
|
||||||
|
let dragged = cx
|
||||||
|
.debug_bounds("panel-test-main")
|
||||||
|
.expect("main panel laid out after the drag")
|
||||||
|
.size
|
||||||
|
.width;
|
||||||
|
|
||||||
|
cx.simulate_resize(size(px(WINDOW_WIDTH), px(WINDOW_HEIGHT)));
|
||||||
|
cx.run_until_parked();
|
||||||
|
let resized = cx
|
||||||
|
.debug_bounds("panel-test-main")
|
||||||
|
.expect("main panel laid out after the resize")
|
||||||
|
.size
|
||||||
|
.width;
|
||||||
|
assert_eq!(resized, dragged, "a dragged divider keeps its pane's width");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A leading split opens before the main panel and keeps its width, dragged or not, across window resizes.
|
||||||
|
#[gpui::test]
|
||||||
|
fn a_leading_split_opens_before_the_main_panel_at_its_width(cx: &mut TestAppContext) {
|
||||||
|
let (mut cx, _stack) = stack_window(cx, |stack, cx| {
|
||||||
|
main_only(stack, cx);
|
||||||
|
stack.insert_split_at(
|
||||||
|
"side",
|
||||||
|
px(300.),
|
||||||
|
SplitSide::Leading,
|
||||||
|
Arc::new(tag(cx, "panel-test-split")),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
let split = cx
|
||||||
|
.debug_bounds("panel-test-split")
|
||||||
|
.expect("split panel laid out");
|
||||||
|
let main = cx
|
||||||
|
.debug_bounds("panel-test-main")
|
||||||
|
.expect("main panel laid out");
|
||||||
|
assert!(split.right() <= main.left(), "the split comes first");
|
||||||
|
assert!((split.size.width - px(300.0)).abs() <= px(2.0));
|
||||||
|
|
||||||
|
cx.simulate_resize(size(px(WINDOW_WIDTH + 400.0), px(WINDOW_HEIGHT)));
|
||||||
|
cx.run_until_parked();
|
||||||
|
let split = cx
|
||||||
|
.debug_bounds("panel-test-split")
|
||||||
|
.expect("split panel laid out after the resize");
|
||||||
|
assert!(
|
||||||
|
(split.size.width - px(300.0)).abs() <= px(2.0),
|
||||||
|
"the split keeps its width: {:?}",
|
||||||
|
split.size.width
|
||||||
|
);
|
||||||
|
|
||||||
|
// Drag the divider 100px right, then put the window back: the split keeps the dragged width.
|
||||||
|
let handle = cx.debug_bounds("resize-handle").expect("divider laid out");
|
||||||
|
let seam = point(handle.center().x, px(400.0));
|
||||||
|
cx.simulate_event(MouseDownEvent {
|
||||||
|
position: seam,
|
||||||
|
button: MouseButton::Left,
|
||||||
|
modifiers: Modifiers::default(),
|
||||||
|
click_count: 1,
|
||||||
|
first_mouse: false,
|
||||||
|
});
|
||||||
|
cx.simulate_event(MouseMoveEvent {
|
||||||
|
position: point(seam.x + px(100.0), seam.y),
|
||||||
|
pressed_button: Some(MouseButton::Left),
|
||||||
|
modifiers: Modifiers::default(),
|
||||||
|
});
|
||||||
|
cx.simulate_event(MouseUpEvent {
|
||||||
|
position: point(seam.x + px(100.0), seam.y),
|
||||||
|
button: MouseButton::Left,
|
||||||
|
modifiers: Modifiers::default(),
|
||||||
|
click_count: 1,
|
||||||
|
});
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
cx.simulate_resize(size(px(WINDOW_WIDTH), px(WINDOW_HEIGHT)));
|
||||||
|
cx.run_until_parked();
|
||||||
|
let split = cx
|
||||||
|
.debug_bounds("panel-test-split")
|
||||||
|
.expect("split panel laid out after the resize");
|
||||||
|
assert!(
|
||||||
|
(split.size.width - px(400.0)).abs() <= px(2.0),
|
||||||
|
"the split keeps its dragged width: {:?}",
|
||||||
|
split.size.width
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Once no split is on screen, the next one opens after the main panel again.
|
||||||
|
#[gpui::test]
|
||||||
|
fn a_split_after_a_leading_one_opens_after_the_main_panel(cx: &mut TestAppContext) {
|
||||||
|
let (mut cx, stack) = stack_window(cx, |stack, cx| {
|
||||||
|
main_only(stack, cx);
|
||||||
|
stack.insert_split_at(
|
||||||
|
"side",
|
||||||
|
px(300.),
|
||||||
|
SplitSide::Leading,
|
||||||
|
Arc::new(tag(cx, "panel-test-side")),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
let side = SharedString::from("side");
|
||||||
|
cx.update(|_, cx| {
|
||||||
|
stack.update(cx, |stack, cx| {
|
||||||
|
stack.close(PanelSlot::Split, &side, cx);
|
||||||
|
stack.insert(
|
||||||
|
PanelSlot::Split,
|
||||||
|
"split",
|
||||||
|
Arc::new(tag(cx, "panel-test-split")),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
cx.run_until_parked();
|
||||||
|
|
||||||
|
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");
|
||||||
|
assert!(
|
||||||
|
main.right() <= split.left(),
|
||||||
|
"the split opens after the main panel again"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Vendored `crates/ui` shortcomings recorded here instead of patched in place.
|
Vendored `crates/ui` shortcomings recorded here instead of patched in place.
|
||||||
|
|
||||||
- `PanelStack` (`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.
|
- `PanelStack` (`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. A split opened at a width is not affected: `insert_split_at` sizes a leading one directly and re-seeds a trailing one while untouched. Seeding from the canvas-measured extent, or re-seeding while no user resize has happened, would fix the half splits.
|
||||||
- `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`.
|
- `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`.
|
||||||
- The popup primitives extracted into `menu.rs` (`trigger_toggle`, `anchored_overlay`, `focus_capture`) cover the trigger-button, anchored-panel, and focus-grab surfaces. They do not cover lists: `ComboboxState` and `CommandPaletteState` keep their own entity-backed virtualized rows outside the `MenuItem` engine because menu rows are built per frame from a `Vec`, while both hold stateful selections the `uniform_list` drives. Any future row engine should absorb those two.
|
- The popup primitives extracted into `menu.rs` (`trigger_toggle`, `anchored_overlay`, `focus_capture`) cover the trigger-button, anchored-panel, and focus-grab surfaces. They do not cover lists: `ComboboxState` and `CommandPaletteState` keep their own entity-backed virtualized rows outside the `MenuItem` engine because menu rows are built per frame from a `Vec`, while both hold stateful selections the `uniform_list` drives. Any future row engine should absorb those two.
|
||||||
- `toast.rs` and `alert.rs` each re-implement the same scaffolding: a store entity with push/dismiss ids, an entry wrapper, a floating stack view with fade-out. Unification was declined for now; if either gains behavior the other lacks, extract the shared store/stack shell first.
|
- `toast.rs` and `alert.rs` each re-implement the same scaffolding: a store entity with push/dismiss ids, an entry wrapper, a floating stack view with fade-out. Unification was declined for now; if either gains behavior the other lacks, extract the shared store/stack shell first.
|
||||||
|
|||||||
Reference in New Issue
Block a user