Compare commits

1 Commits
Author SHA1 Message Date
reya b75968ee0f switch gpui family to gpui-pre 0.3.10 and re-export editor crate 2026-11-09 21:17:50 +07:00
7 changed files with 701 additions and 775 deletions
-1
View File
@@ -1,6 +1,5 @@
# Coding guidelines # Coding guidelines
- Prefer existing components (e.g. build a close affordance out of `Button`) over custom elements; build a custom element only when no existing component fits.
- Prioritize code correctness and clarity. Speed and efficiency are secondary priorities unless otherwise specified. - Prioritize code correctness and clarity. Speed and efficiency are secondary priorities unless otherwise specified.
- Do not write organizational or comments that summarize the code. Comments should only be written to explain "why" the code is written in some way in the case there is a reason that is tricky / non-obvious. - Do not write organizational or comments that summarize the code. Comments should only be written to explain "why" the code is written in some way in the case there is a reason that is tricky / non-obvious.
- Keep doc comments and comments simple, one line, straightforward, and unbloated. - Keep doc comments and comments simple, one line, straightforward, and unbloated.
Generated
+688 -709
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -24,9 +24,9 @@ gpui-native-icons = { path = "crates/icons" }
gpui-native-theme = { path = "crates/theme" } gpui-native-theme = { path = "crates/theme" }
[workspace.dependencies] [workspace.dependencies]
gpui = { git = "https://github.com/zed-industries/zed" } gpui = { package = "gpui-pre", version = "0.3.10" }
gpui_platform = { git = "https://github.com/zed-industries/zed", features = ["font-kit"] } gpui_platform = { package = "gpui-pre-platform", version = "0.3.10", features = ["font-kit"] }
reqwest_client = { git = "https://github.com/zed-industries/zed" } reqwest_client = { package = "gpui-pre-reqwest-client", version = "0.3.10" }
gpui-native-core = { path = "crates/core", default-features = false } gpui-native-core = { path = "crates/core", default-features = false }
gpui-native-data = { path = "crates/data", default-features = false } gpui-native-data = { path = "crates/data", default-features = false }
+1 -1
View File
@@ -76,7 +76,7 @@ tooltip = []
menu = ["scroll_area"] menu = ["scroll_area"]
dropdown_menu = ["menu", "button"] dropdown_menu = ["menu", "button"]
select = ["menu"] select = ["menu"]
dialog = ["button"] dialog = []
empty_state = [] empty_state = []
alert = [] alert = []
toast = [] toast = []
+6 -38
View File
@@ -6,17 +6,14 @@ use gpui::{
IntoElement, KeyDownEvent, MouseButton, ParentElement as _, RenderOnce, Role, SharedString, IntoElement, KeyDownEvent, MouseButton, ParentElement as _, RenderOnce, Role, SharedString,
StatefulInteractiveElement as _, Styled as _, Window, canvas, div, ease_out_quint, relative, StatefulInteractiveElement as _, Styled as _, Window, canvas, div, ease_out_quint, relative,
}; };
use gpui_native_icons::IconRole;
use gpui_native_theme::ActiveTheme as _; use gpui_native_theme::ActiveTheme as _;
use crate::button::{Button, ButtonVariant}; use crate::common::v_flex;
use crate::common::{Sizable, v_flex};
/// Requests the dialog's close: `false` closes. /// Requests the dialog's close: `false` closes.
pub type ChangeHandler = Rc<dyn Fn(bool, &mut Window, &mut App)>; pub type ChangeHandler = Rc<dyn Fn(bool, &mut Window, &mut App)>;
type ContentFn = Box<dyn Fn(&mut Window, &mut App) -> AnyElement>; type ContentFn = Box<dyn Fn(&mut Window, &mut App) -> AnyElement>;
type ActionsFn = Box<dyn Fn(&mut Window, &mut App) -> Vec<AnyElement>>; type ActionsFn = Box<dyn Fn(&mut Window, &mut App) -> Vec<AnyElement>>;
/// A centred panel over a dim scrim: the platform's modal. /// A centred panel over a dim scrim: the platform's modal.
#[derive(IntoElement)] #[derive(IntoElement)]
pub struct Dialog { pub struct Dialog {
@@ -60,7 +57,7 @@ impl Dialog {
self self
} }
/// Requests close through `on_change` on escape, scrim clicks, and the close button. /// Requests close through `on_change` on escape and scrim clicks.
pub fn on_change<F>(mut self, handler: F) -> Self pub fn on_change<F>(mut self, handler: F) -> Self
where where
F: Fn(bool, &mut Window, &mut App) + 'static, F: Fn(bool, &mut Window, &mut App) + 'static,
@@ -157,7 +154,6 @@ impl RenderOnce for Dialog {
let on_change = self.on_change.clone(); let on_change = self.on_change.clone();
let alert = self.alert; let alert = self.alert;
let show_close = !alert && on_change.is_some();
// Keyboard focus rides the panel across frames. // Keyboard focus rides the panel across frames.
let focus = gpui_native_utils::focus_handle(&self.id, window, cx); let focus = gpui_native_utils::focus_handle(&self.id, window, cx);
@@ -194,40 +190,12 @@ impl RenderOnce for Dialog {
cx.stop_propagation(); cx.stop_propagation();
} }
}) })
.when(self.title.is_some() || show_close, |panel| { .when_some(self.title, |panel, title| {
panel.child( panel.child(
div() div()
.flex() .text_size(title_size)
.items_center() .font_weight(FontWeight::SEMIBOLD)
.justify_end() .child(title),
.gap_2()
.when_some(self.title.clone(), |row, title| {
row.child(
div()
.flex_1()
.text_size(title_size)
.font_weight(FontWeight::SEMIBOLD)
.child(title),
)
})
.when(show_close, |row| {
row.child(
Button::new("dialog-close")
.icon(IconRole::Close)
.variant(ButtonVariant::Ghost)
.small()
.debug_selector(|| "dialog-close".to_string())
.accessibility_label("Close")
.on_click({
let on_change = on_change.clone();
move |_, window, cx| {
if let Some(on_change) = &on_change {
on_change(false, window, cx);
}
}
}),
)
}),
) )
}) })
.when_some(content, |panel, content| { .when_some(content, |panel, content| {
-23
View File
@@ -158,26 +158,3 @@ fn clicking_the_panel_does_not_dismiss() {
click(&mut visual, point(px(960.), px(540.))); click(&mut visual, point(px(960.), px(540.)));
assert!(changes.borrow().is_empty()); assert!(changes.borrow().is_empty());
} }
/// Clicking the close button reports close like escape and the scrim; the
/// panel then unmounts the button with the rest of the dialog.
#[test]
fn the_close_button_reports_close_and_disappears() {
let (_cx, mut visual, changes) = dialog_window(true, false);
let bounds = visual
.debug_bounds("dialog-close")
.expect("the close button rendered");
click(&mut visual, bounds.center());
assert_eq!(*changes.borrow(), vec![false]);
draw(&mut visual);
assert!(visual.debug_bounds("dialog-close").is_none());
}
/// An alert answers only through its actions, so it renders no close button.
#[test]
fn an_alert_hides_the_close_button() {
let (_cx, mut visual, _changes) = dialog_window(true, true);
assert!(visual.debug_bounds("dialog-close").is_none());
}
+3
View File
@@ -13,6 +13,9 @@ pub use gpui_native_data as data;
#[cfg(feature = "layout")] #[cfg(feature = "layout")]
pub use gpui_native_layout as layout; pub use gpui_native_layout as layout;
#[cfg(feature = "editor")]
pub use gpui_native_editor as editor;
use gpui::App; use gpui::App;
/// Initializes the framework. /// Initializes the framework.