Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

ui: Add ability to customize context menu spacing (#65044)

Danilo Leal7bbd162ddfe1
diff --git a/crates/ui/src/components/context_menu.rs b/crates/ui/src/components/context_menu.rs
index 44c60606928..5bfe2c2b8da 100644
--- a/crates/ui/src/components/context_menu.rs
+++ b/crates/ui/src/components/context_menu.rs
@@ -1,6 +1,6 @@
use crate::{
- ButtonCommon, ButtonStyle, IconButtonShape, KeyBinding, List, ListItem, ListSeparator,
- ListSubHeader, Tooltip, prelude::*, utils::WithRemSize,
+ ButtonCommon, ButtonStyle, IconButtonShape, KeyBinding, List, ListItem, ListItemSpacing,
+ ListSeparator, ListSubHeader, Tooltip, prelude::*, utils::WithRemSize,
};
use gpui::{
Action, Anchor, AnyElement, App, Bounds, DismissEvent, Entity, EventEmitter, FocusHandle,
@@ -223,6 +223,7 @@ pub struct ContextMenu {
_on_blur_subscription: Subscription,
keep_open_on_confirm: bool,
fixed_width: Option<DefiniteLength>,
+ spacing: ListItemSpacing,
main_menu: Option<Entity<ContextMenu>>,
main_menu_observed_bounds: Rc<Cell<Option<Bounds<Pixels>>>>,
// Docs aide-related fields
@@ -355,6 +356,7 @@ impl ContextMenu {
_on_blur_subscription,
keep_open_on_confirm: true,
fixed_width: None,
+ spacing: ListItemSpacing::default(),
main_menu: None,
main_menu_observed_bounds: Rc::new(Cell::new(None)),
documentation_aside: None,
@@ -425,6 +427,7 @@ impl ContextMenu {
),
keep_open_on_confirm: false,
fixed_width: None,
+ spacing: self.spacing,
main_menu: None,
main_menu_observed_bounds: Rc::new(Cell::new(None)),
documentation_aside: None,
@@ -442,6 +445,7 @@ impl ContextMenu {
);
self.items = new_menu.items;
+ self.spacing = new_menu.spacing;
cx.notify();
}
@@ -868,6 +872,11 @@ impl ContextMenu {
self
}
+ pub fn spacing(mut self, spacing: ListItemSpacing) -> Self {
+ self.spacing = spacing;
+ self
+ }
+
pub fn end_slot_action(mut self, action: Box<dyn Action>) -> Self {
self.end_slot_action = Some(action);
self
@@ -1262,6 +1271,7 @@ impl ContextMenu {
_on_blur_subscription,
keep_open_on_confirm: false,
fixed_width: None,
+ spacing: ListItemSpacing::default(),
documentation_aside: None,
aside_trigger_bounds: Rc::new(RefCell::new(HashMap::default())),
main_menu: Some(parent_entity),
@@ -1433,6 +1443,7 @@ impl ContextMenu {
}
ContextMenuItem::Label(label) => ListItem::new(ix)
.inset(true)
+ .spacing(self.spacing)
.disabled(true)
.child(Label::new(label.clone()))
.into_any_element(),
@@ -1485,6 +1496,7 @@ impl ContextMenu {
.child(
ListItem::new(ix)
.inset(true)
+ .spacing(self.spacing)
.when(selectable, |item| item.aria_role(Role::MenuItem))
.when(is_active_descendant(selectable), |item| {
item.aria_active_descendant()
@@ -1572,6 +1584,7 @@ impl ContextMenu {
.child(
ListItem::new(ix)
.inset(true)
+ .spacing(self.spacing)
.aria_role(Role::MenuItem)
.when(is_active_descendant, |item| item.aria_active_descendant())
.aria_label(label.clone())
@@ -1907,6 +1920,7 @@ impl ContextMenu {
ListItem::new(ix)
.group_name("label_container")
.inset(true)
+ .spacing(self.spacing)
.disabled(*disabled)
.aria_role(if toggle.is_some() {
Role::MenuItemCheckBox
@@ -2171,6 +2185,7 @@ impl ContextMenu {
_on_blur_subscription,
keep_open_on_confirm: false,
fixed_width: None,
+ spacing: ListItemSpacing::default(),
main_menu: None,
main_menu_observed_bounds: Rc::new(Cell::new(None)),
documentation_aside: None,