Re-vendor the native UI kit at 278430d
- Upstream merged core, data, editor, and utils into a single `components` crate: `ui::button`, `ui::tabs`, `ui::code`, `ui::tree`, `ui::sidebar` are flat, and `h_flex`/`v_flex`/`StyledExt` live in `ui::common` and `ui::layout`. - Adopts the new wrapper-less component module tree, the merged theme/icon updates, and the relocated editor grammars. - Titlebar repo tabs use the new `TabsVariant::Titlebar` capsule sizing. - Doc examples now import from `ui::`, so all 44 doctests compile; the clipboard sample no longer names the kit crate. - docs/ui-gaps.md records that `ui` has no dock/view-registry API instead of the deleted `DockState`.
This commit is contained in:
@@ -1,8 +1,32 @@
|
||||
//! The floating menu panel shared by menus, dropdowns, and context menus.
|
||||
//! Renders floating menus of [`MenuItem`] rows for [`Menu`], dropdowns, and
|
||||
//! context menus.
|
||||
//!
|
||||
//! # Examples
|
||||
//!
|
||||
//! ```no_run
|
||||
//! use gpui::{IntoElement as _, ParentElement as _, SharedString, div};
|
||||
//! use ui::menu::{Menu, MenuItem};
|
||||
//!
|
||||
//! let menu = Menu::new("file-menu")
|
||||
//! .trigger(|_window, _cx| {
|
||||
//! div().child(SharedString::from("File")).into_any_element()
|
||||
//! })
|
||||
//! .items(|_window, _cx| {
|
||||
//! vec![
|
||||
//! MenuItem::new("New File").handler(|_window, _cx| println!("new")),
|
||||
//! MenuItem::separator(),
|
||||
//! MenuItem::new("Open Recent").submenu(vec![MenuItem::new("Project One")]),
|
||||
//! ]
|
||||
//! });
|
||||
//! ```
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::components::common::{OVERLAY_LAYER, StyledExt as _, focus_handle, v_flex};
|
||||
use crate::components::scroll_area::{ScrollArea, ScrollAxes};
|
||||
use crate::icons::{Icon, IconRole, icon as icon_glyph};
|
||||
use crate::theme::{ActiveTheme as _, BORDER_WIDTH, MENU_MIN_WIDTH, POPUP_MAX_HEIGHT};
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
Animation, AnimationExt as _, AnyElement, App, Bounds, BoxShadow, DefiniteLength,
|
||||
@@ -12,12 +36,6 @@ use gpui::{
|
||||
Window, anchored, canvas, deferred, div, ease_out_quint, point, px, relative,
|
||||
};
|
||||
|
||||
use crate::components::common::{OVERLAY_LAYER, StyledExt as _, v_flex};
|
||||
use crate::components::scroll_area::{ScrollArea, ScrollAxes};
|
||||
use crate::icons::{Icon, IconRole, icon as icon_glyph};
|
||||
use crate::theme::{ActiveTheme as _, BORDER_WIDTH, MENU_MIN_WIDTH, POPUP_MAX_HEIGHT};
|
||||
use crate::utils::focus_handle;
|
||||
|
||||
/// Runs the item's action. The menu closes itself before the handler runs.
|
||||
pub type ItemHandler = Rc<dyn Fn(&mut Window, &mut App)>;
|
||||
|
||||
@@ -27,7 +45,9 @@ pub(crate) type ChangeHandler = Rc<dyn Fn(bool, &mut Window, &mut App)>;
|
||||
type FlyoutSetter = Rc<dyn Fn(Option<usize>, bool, &mut App)>;
|
||||
/// Bounds captured during the last paint, shared with the dismissal listener.
|
||||
pub(crate) type TriggerBoundsCell = Rc<RefCell<Option<Bounds<Pixels>>>>;
|
||||
/// The element the panel anchors below, built during render.
|
||||
type TriggerFn = Box<dyn Fn(&mut Window, &mut App) -> AnyElement>;
|
||||
/// The menu's rows, rebuilt on each render while open.
|
||||
type ItemsFn = Box<dyn Fn(&mut Window, &mut App) -> Vec<MenuItem>>;
|
||||
|
||||
/// One row of a [`Menu`]: an action, a checkable action, a submenu, or a separator.
|
||||
@@ -53,7 +73,7 @@ enum MenuItemKind {
|
||||
}
|
||||
|
||||
impl MenuItem {
|
||||
/// An action row with this label.
|
||||
/// Creates an action row with this label.
|
||||
pub fn new<L>(label: L) -> Self
|
||||
where
|
||||
L: Into<SharedString>,
|
||||
@@ -71,7 +91,7 @@ impl MenuItem {
|
||||
}
|
||||
}
|
||||
|
||||
/// A divider between groups of actions.
|
||||
/// Creates a divider between groups of actions.
|
||||
pub fn separator() -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
@@ -188,7 +208,7 @@ pub(crate) struct MenuChrome {
|
||||
shadow: Vec<BoxShadow>,
|
||||
}
|
||||
|
||||
/// A floating menu of actions anchored below its trigger.
|
||||
/// A floating menu of [`MenuItem`] rows anchored below its trigger.
|
||||
#[derive(IntoElement)]
|
||||
#[must_use]
|
||||
pub struct Menu {
|
||||
@@ -255,7 +275,7 @@ impl Menu {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the row keyboard-highlighted when the menu opens.
|
||||
/// Sets the row that starts keyboard-selected when the menu opens.
|
||||
pub fn initial_selection(mut self, index: usize) -> Self {
|
||||
self.initial_selection = Some(index);
|
||||
self
|
||||
|
||||
Reference in New Issue
Block a user