Vendor the native UI kit as crates/ui
- crates/ui holds the theme, icons, components, data widgets, editor surfaces, layout, and utilities; cargo feature gates are gone. - One merged icon set of 154 SVGs where the app file wins every duplicate name, served by a single rust-embed Assets source. - IconRole grows the 25 app glyphs, so assets::CustomIconName and crates/assets are deleted. - ui::init owns the theme and key bindings that desktop used to bind in three calls. - docs/gpui-native-kit-gaps.md becomes docs/ui-gaps.md; the icon gap is closed.
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
//! The panel row: the main island fills the window; splitting makes two
|
||||
//! half-width islands with a drag divider that resizes them.
|
||||
|
||||
use gpui::{
|
||||
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,
|
||||
};
|
||||
use ui::layout::panel::{Panel, PanelRow};
|
||||
use ui::theme::Theme;
|
||||
|
||||
const WINDOW_WIDTH: f32 = 1024.0;
|
||||
const WINDOW_HEIGHT: f32 = 768.0;
|
||||
|
||||
/// A full-size marker the tests measure through its debug selector.
|
||||
struct TagView {
|
||||
selector: SharedString,
|
||||
}
|
||||
|
||||
impl TagView {
|
||||
fn new(selector: &'static str) -> Self {
|
||||
Self {
|
||||
selector: SharedString::from(selector),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Render for TagView {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let selector = self.selector.clone();
|
||||
div()
|
||||
.debug_selector(move || selector.to_string())
|
||||
.size_full()
|
||||
}
|
||||
}
|
||||
|
||||
impl Panel for TagView {}
|
||||
|
||||
struct PanelHarness {
|
||||
split: 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
|
||||
};
|
||||
div().size_full().child(panel)
|
||||
}
|
||||
}
|
||||
|
||||
fn panel_window(cx: &mut TestAppContext, split: bool) -> VisualTestContext {
|
||||
let (main, split_view) = cx.update(|cx| {
|
||||
Theme::init(cx);
|
||||
let main = cx.new(|_| TagView::new("panel-test-main"));
|
||||
let split = cx.new(|_| TagView::new("panel-test-split"));
|
||||
(main, split)
|
||||
});
|
||||
|
||||
let window = cx.open_window(size(px(WINDOW_WIDTH), px(WINDOW_HEIGHT)), |_, _| {
|
||||
PanelHarness {
|
||||
split,
|
||||
main,
|
||||
split_view,
|
||||
}
|
||||
});
|
||||
let cx = VisualTestContext::from_window(window.into(), cx);
|
||||
cx.run_until_parked();
|
||||
cx
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn main_fills_the_row_without_a_split(cx: &mut TestAppContext) {
|
||||
let mut cx = panel_window(cx, false);
|
||||
|
||||
let main = cx
|
||||
.debug_bounds("panel-test-main")
|
||||
.expect("main panel laid out");
|
||||
|
||||
// The row's padding and the island's inset are all main gives up.
|
||||
assert!(main.size.width >= px(WINDOW_WIDTH - 40.0));
|
||||
assert!(main.size.height >= px(WINDOW_HEIGHT - 40.0));
|
||||
assert!(main.origin.x >= px(0.0));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn split_makes_two_half_width_panels(cx: &mut TestAppContext) {
|
||||
let mut cx = panel_window(cx, 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");
|
||||
|
||||
// Both islands share the row at half width, main first, and neither
|
||||
// leaves the viewport. The divider's width lands on the remainder pane.
|
||||
assert!(
|
||||
(main.size.width - split.size.width).abs() <= px(10.0),
|
||||
"main={:?} split={:?}",
|
||||
main.size.width,
|
||||
split.size.width
|
||||
);
|
||||
assert!(main.size.width < px(WINDOW_WIDTH / 2.0));
|
||||
assert!(main.right() <= split.left());
|
||||
assert!(split.right() <= px(WINDOW_WIDTH));
|
||||
assert!(main.size.height >= px(WINDOW_HEIGHT - 40.0));
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn dragging_the_divider_resizes_the_panels(cx: &mut TestAppContext) {
|
||||
let mut cx = panel_window(cx, true);
|
||||
|
||||
let before = cx
|
||||
.debug_bounds("panel-test-main")
|
||||
.expect("main panel laid out");
|
||||
|
||||
// Press the divider between the islands and drag it 100px to the right.
|
||||
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();
|
||||
|
||||
// The main panel grew by the drag; the split panel gave up the space.
|
||||
let after = cx
|
||||
.debug_bounds("panel-test-main")
|
||||
.expect("main panel laid out after the drag");
|
||||
assert_eq!(after.size.width, before.size.width + px(100.0));
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
use gpui::{
|
||||
Context, IntoElement, ParentElement as _, Render, Styled as _, TestAppContext,
|
||||
VisualTestContext, Window, div, px, size,
|
||||
};
|
||||
use ui::button::Button;
|
||||
use ui::common::Sizable as _;
|
||||
use ui::dropdown_menu::DropdownMenu;
|
||||
use ui::icons::IconRole;
|
||||
use ui::menu::MenuItem;
|
||||
use ui::theme::Theme;
|
||||
|
||||
struct Harness;
|
||||
|
||||
impl Render for Harness {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
div()
|
||||
.size_full()
|
||||
.flex()
|
||||
.flex_col()
|
||||
.gap_2()
|
||||
.child(
|
||||
Button::new("height-probe")
|
||||
.label("Probe")
|
||||
.debug_selector(|| "height-probe".to_string()),
|
||||
)
|
||||
.child(
|
||||
Button::new("xsmall-height-probe")
|
||||
.label("Probe")
|
||||
.xsmall()
|
||||
.debug_selector(|| "xsmall-height-probe".to_string()),
|
||||
)
|
||||
.child(
|
||||
DropdownMenu::new("icon-only-dropdown")
|
||||
.icon(IconRole::More)
|
||||
.accessibility_label("More actions")
|
||||
.items(|_, _| vec![MenuItem::new("One")]),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn buttons_render_at_their_token_heights(cx: &mut TestAppContext) {
|
||||
cx.update(Theme::init);
|
||||
let window = cx.open_window(size(px(400.), px(400.)), |_, _| Harness);
|
||||
let mut cx = VisualTestContext::from_window(window.into(), cx);
|
||||
cx.run_until_parked();
|
||||
|
||||
let medium = cx.debug_bounds("height-probe").expect("button laid out");
|
||||
let xsmall = cx
|
||||
.debug_bounds("xsmall-height-probe")
|
||||
.expect("xsmall button laid out");
|
||||
let icon_only = cx
|
||||
.debug_bounds("icon-only-dropdown-trigger")
|
||||
.expect("icon-only dropdown laid out");
|
||||
|
||||
assert_eq!(medium.size.height, px(32.0));
|
||||
assert_eq!(xsmall.size.height, px(20.0));
|
||||
assert_eq!(icon_only.size, size(px(32.0), px(32.0)));
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
//! Grouped tabs: same-kind tabs collapse into one chip that opens a popover
|
||||
//! listing the members; picking one selects it by its original index. Tabs
|
||||
//! also drag onto each other to reorder, and pinned tabs wear the active
|
||||
//! treatment at all times.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use gpui::{
|
||||
Context, IntoElement, Modifiers, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
|
||||
ParentElement as _, Render, Styled as _, TestAppContext, VisualTestContext, Window, div, point,
|
||||
px, size,
|
||||
};
|
||||
use ui::data::tabs::{Tab, Tabs, TabsVariant};
|
||||
use ui::theme::Theme;
|
||||
|
||||
struct StripHarness {
|
||||
changed: Rc<RefCell<Vec<usize>>>,
|
||||
reordered: Rc<RefCell<Vec<(usize, usize)>>>,
|
||||
pinned: bool,
|
||||
}
|
||||
|
||||
impl Render for StripHarness {
|
||||
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
|
||||
let changed = self.changed.clone();
|
||||
let reordered = self.reordered.clone();
|
||||
div().size_full().child(
|
||||
Tabs::new("strip")
|
||||
.variant(TabsVariant::Pill)
|
||||
.draggable(true)
|
||||
.tabs({
|
||||
let pinned = self.pinned;
|
||||
move |_, _| {
|
||||
vec![
|
||||
Tab::new("a", "Alpha").kind("Kind"),
|
||||
Tab::new("b", "Beta").kind("Kind"),
|
||||
Tab::new("c", "Gamma"),
|
||||
Tab::new("d", "Delta").kind("Lone").pinned(pinned),
|
||||
]
|
||||
}
|
||||
})
|
||||
.on_change(move |index, _, _| changed.borrow_mut().push(index))
|
||||
.on_reorder(move |from, to, _, _| reordered.borrow_mut().push((from, to))),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn strip_window(
|
||||
cx: &mut TestAppContext,
|
||||
changed: Rc<RefCell<Vec<usize>>>,
|
||||
reordered: Rc<RefCell<Vec<(usize, usize)>>>,
|
||||
pinned: bool,
|
||||
) -> VisualTestContext {
|
||||
cx.update(Theme::init);
|
||||
let window = cx.open_window(size(px(800.), px(600.)), |_, _| StripHarness {
|
||||
changed,
|
||||
reordered,
|
||||
pinned,
|
||||
});
|
||||
let cx = VisualTestContext::from_window(window.into(), cx);
|
||||
cx.run_until_parked();
|
||||
cx
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn same_kind_tabs_collapse_into_one_group(cx: &mut TestAppContext) {
|
||||
let mut cx = strip_window(
|
||||
cx,
|
||||
Rc::new(RefCell::new(Vec::new())),
|
||||
Rc::new(RefCell::new(Vec::new())),
|
||||
false,
|
||||
);
|
||||
|
||||
assert!(
|
||||
cx.debug_bounds("strip-group-Kind").is_some(),
|
||||
"two same-kind tabs draw one group chip"
|
||||
);
|
||||
assert!(
|
||||
cx.debug_bounds("strip-tab-Alpha").is_none(),
|
||||
"grouped members do not draw inline"
|
||||
);
|
||||
assert!(cx.debug_bounds("strip-tab-Beta").is_none());
|
||||
|
||||
// A tab outside any two-member kind group draws itself, kinded or not.
|
||||
assert!(cx.debug_bounds("strip-tab-Gamma").is_some());
|
||||
assert!(cx.debug_bounds("strip-tab-Delta").is_some());
|
||||
assert!(
|
||||
cx.debug_bounds("strip-group-Lone").is_none(),
|
||||
"a lone kinded tab is not grouped"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn picking_a_group_member_selects_it(cx: &mut TestAppContext) {
|
||||
let changed = Rc::new(RefCell::new(Vec::new()));
|
||||
let mut cx = strip_window(
|
||||
cx,
|
||||
changed.clone(),
|
||||
Rc::new(RefCell::new(Vec::new())),
|
||||
false,
|
||||
);
|
||||
|
||||
let chip = cx
|
||||
.debug_bounds("strip-group-Kind")
|
||||
.expect("group chip drawn");
|
||||
cx.simulate_click(chip.center(), Modifiers::none());
|
||||
cx.run_until_parked();
|
||||
|
||||
let beta = cx
|
||||
.debug_bounds("strip-tab-Beta")
|
||||
.expect("the popover lists the members");
|
||||
cx.simulate_click(beta.center(), Modifiers::none());
|
||||
cx.run_until_parked();
|
||||
|
||||
assert_eq!(
|
||||
changed.borrow().as_slice(),
|
||||
&[1],
|
||||
"picking a member reports its original index"
|
||||
);
|
||||
assert!(
|
||||
cx.debug_bounds("strip-tab-Beta").is_none(),
|
||||
"a selection dismisses the popover"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn dragging_a_tab_onto_another_reorders_it(cx: &mut TestAppContext) {
|
||||
let reordered = Rc::new(RefCell::new(Vec::new()));
|
||||
let mut cx = strip_window(
|
||||
cx,
|
||||
Rc::new(RefCell::new(Vec::new())),
|
||||
reordered.clone(),
|
||||
false,
|
||||
);
|
||||
|
||||
// The strip's group chip hides Alpha and Beta; Gamma draws inline, so the
|
||||
// drag runs from Gamma onto Delta: moving Gamma before Delta is a no-op
|
||||
// shift — use Delta onto Gamma instead, reporting (3, 2).
|
||||
let gamma = cx.debug_bounds("strip-tab-Gamma").expect("gamma drawn");
|
||||
let delta = cx.debug_bounds("strip-tab-Delta").expect("delta drawn");
|
||||
|
||||
cx.simulate_event(MouseDownEvent {
|
||||
position: delta.center(),
|
||||
button: MouseButton::Left,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
first_mouse: false,
|
||||
});
|
||||
cx.simulate_event(MouseMoveEvent {
|
||||
position: gamma.center(),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
cx.simulate_event(MouseUpEvent {
|
||||
position: gamma.center(),
|
||||
button: MouseButton::Left,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
assert_eq!(
|
||||
reordered.borrow().as_slice(),
|
||||
&[(3, 2)],
|
||||
"dropping Delta before Gamma reports the move"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn dropping_a_tab_back_on_itself_reorders_nothing(cx: &mut TestAppContext) {
|
||||
let reordered = Rc::new(RefCell::new(Vec::new()));
|
||||
let mut cx = strip_window(
|
||||
cx,
|
||||
Rc::new(RefCell::new(Vec::new())),
|
||||
reordered.clone(),
|
||||
false,
|
||||
);
|
||||
|
||||
let gamma = cx.debug_bounds("strip-tab-Gamma").expect("gamma drawn");
|
||||
cx.simulate_event(MouseDownEvent {
|
||||
position: gamma.center(),
|
||||
button: MouseButton::Left,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
first_mouse: false,
|
||||
});
|
||||
cx.simulate_event(MouseMoveEvent {
|
||||
position: gamma.center() + point(px(2.0), px(0.0)),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
cx.simulate_event(MouseUpEvent {
|
||||
position: gamma.center(),
|
||||
button: MouseButton::Left,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
assert!(
|
||||
reordered.borrow().is_empty(),
|
||||
"a self-drop is a no-op, not a reorder"
|
||||
);
|
||||
}
|
||||
|
||||
#[gpui::test]
|
||||
fn a_vertical_drag_cancels_the_reorder(cx: &mut TestAppContext) {
|
||||
let reordered = Rc::new(RefCell::new(Vec::new()));
|
||||
let mut cx = strip_window(
|
||||
cx,
|
||||
Rc::new(RefCell::new(Vec::new())),
|
||||
reordered.clone(),
|
||||
false,
|
||||
);
|
||||
|
||||
// Drag Delta straight down past the axis lock, then back onto Gamma:
|
||||
// the gesture locked vertical, so the drop must not reorder.
|
||||
let delta = cx.debug_bounds("strip-tab-Delta").expect("delta drawn");
|
||||
let gamma = cx.debug_bounds("strip-tab-Gamma").expect("gamma drawn");
|
||||
let start = delta.center();
|
||||
|
||||
cx.simulate_event(MouseDownEvent {
|
||||
position: start,
|
||||
button: MouseButton::Left,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
first_mouse: false,
|
||||
});
|
||||
// The drag engages a few pixels down; land the origin there.
|
||||
cx.simulate_event(MouseMoveEvent {
|
||||
position: start + point(px(0.0), px(3.0)),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
// Past the axis lock, vertically: dy 30 vs dx 0.
|
||||
cx.simulate_event(MouseMoveEvent {
|
||||
position: start + point(px(0.0), px(30.0)),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
// Back over Gamma — still canceled.
|
||||
cx.simulate_event(MouseMoveEvent {
|
||||
position: gamma.center(),
|
||||
pressed_button: Some(MouseButton::Left),
|
||||
modifiers: Modifiers::default(),
|
||||
});
|
||||
cx.simulate_event(MouseUpEvent {
|
||||
position: gamma.center(),
|
||||
button: MouseButton::Left,
|
||||
modifiers: Modifiers::default(),
|
||||
click_count: 1,
|
||||
});
|
||||
cx.run_until_parked();
|
||||
|
||||
assert!(
|
||||
reordered.borrow().is_empty(),
|
||||
"a vertical drag never reorders, even dropped on another tab"
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user