BlueGit

ict rusty-teams

Merge remote-tracking branch 'origin/main' into feat/chat-settings

metis Daniel Däschle · pushed by metis

Authored 2026-10-18 · 6 weeks ago

Hash
c4483875e490fc39e5dff35889b4f9a084643a5f
25 files changed +721 −129
crates/app-ui-kit/src/settings_controls.rs +1 −0
@@ -132,6 +132,7 @@ pub fn dropdown(id: &'static str, label: String, entries: Vec<MenuEntry>) -> imp
132 132 )
133 133 })
134 134 })
135 .listbox()
135 136 }
136 137
137 138 pub fn link_dropdown(
@@ -132,6 +132,7 @@ pub fn dropdown(id: &'static str, label: String, entries: Vec<MenuEntry>) -> imp
132 )
132 )
133 })
133 })
134 })
134 })
135 .listbox()
135}
136}
136
137
137pub fn link_dropdown(
138pub fn link_dropdown(
crates/app-ui-kit/src/widgets.rs +103 −13
@@ -23,6 +23,10 @@ pub fn icon(name: IconName, size: f32, color: Hsla) -> Icon {
23 23 Icon::new(name).size(px(size)).text_color(color)
24 24 }
25 25
26 pub fn menu_icon(name: IconName) -> Icon {
27 Icon::new(name)
28 }
29
26 30 pub fn symbol(name: &str, size: f32, color: Hsla) -> Icon {
27 31 Icon::empty()
28 32 .path(format!("symbols/{name}.svg"))
@@ -44,27 +48,113 @@ pub fn corner_badge(corner: Corner, overhang: f32) -> Div {
44 48 }
45 49 }
46 50
47 pub fn count_badge(count: u32, muted: bool) -> Div {
48 let (background, foreground) = if muted {
49 (theme::badge_muted(), theme::text_strong())
50 } else {
51 (theme::accent(), theme::on_accent())
52 };
51 #[derive(Clone, Copy)]
52 pub struct BadgeMetrics {
53 pub height: f32,
54 pub padding_x: f32,
55 pub font_size: f32,
56 }
57
58 pub const COUNT_BADGE: BadgeMetrics = BadgeMetrics {
59 height: 18.,
60 padding_x: 5.,
61 font_size: 11.,
62 };
63
64 pub const RAIL_BADGE: BadgeMetrics = BadgeMetrics {
65 height: 16.,
66 padding_x: 4.,
67 font_size: 10.,
68 };
69
70 pub fn badge_selector(text: &str) -> String {
71 format!("count-badge/{text}")
72 }
73
74 pub fn badge_text_selector(text: &str) -> String {
75 format!("count-badge/{text}/text")
76 }
77
78 pub fn badge_pill(count: u32, metrics: BadgeMetrics, background: Hsla, foreground: Hsla) -> Div {
79 let text = format::badge_text(count);
53 80 div()
54 .min_w(px(18.))
55 .h(px(18.))
56 .px(px(5.))
81 .debug_selector(|| badge_selector(&text))
82 .min_w(px(metrics.height))
83 .h(px(metrics.height))
84 .px(px(metrics.padding_x))
57 85 .flex()
58 86 .flex_none()
59 87 .items_center()
60 88 .justify_center()
61 .rounded(px(9.))
89 .rounded(px(metrics.height / 2.))
62 90 .bg(background)
63 91 .text_color(foreground)
64 .text_size(px(11.))
65 .line_height(px(18.))
92 .text_size(px(metrics.font_size))
93 .line_height(px(metrics.height))
66 94 .font_weight(FontWeight::BOLD)
67 .child(format::badge_text(count))
95 .child(BadgeText {
96 text,
97 font_size: metrics.font_size,
98 line_height: metrics.height,
99 })
100 }
101
102 #[derive(IntoElement)]
103 struct BadgeText {
104 text: String,
105 font_size: f32,
106 line_height: f32,
107 }
108
109 impl RenderOnce for BadgeText {
110 fn render(self, window: &mut Window, _: &mut App) -> impl IntoElement {
111 let (shift_x, shift_y) = badge_ink_offset(window, &self.text, self.font_size);
112 div()
113 .debug_selector(|| badge_text_selector(&self.text))
114 .relative()
115 .left(px(-shift_x))
116 .top(px(-shift_y))
117 .flex_none()
118 .h(px(self.line_height))
119 .child(self.text)
120 }
121 }
122
123 pub fn badge_ink_offset(window: &Window, text: &str, font_size: f32) -> (f32, f32) {
124 let mut font = window.text_style().font();
125 font.weight = FontWeight::BOLD;
126 let text_system = window.text_system();
127 let font_id = text_system.resolve_font(&font);
128 let size = px(font_size);
129 let ascent = f32::from(text_system.ascent(font_id, size));
130 let descent = f32::from(text_system.descent(font_id, size)).abs();
131 let cap_height = f32::from(text_system.cap_height(font_id, size));
132 let shift_y = (ascent - descent - cap_height) / 2.;
133 let mut pen = 0.;
134 let mut ink_left = None;
135 let mut ink_right = 0.;
136 for character in text.chars() {
137 let advance = text_system
138 .advance(font_id, size, character)
139 .map_or(0., |advance| f32::from(advance.width));
140 if let Ok(bounds) = text_system.typographic_bounds(font_id, size, character) {
141 let left = pen + f32::from(bounds.origin.x);
142 ink_left.get_or_insert(left);
143 ink_right = left + f32::from(bounds.size.width);
144 }
145 pen += advance;
146 }
147 let shift_x = ink_left.map_or(0., |left| (left + ink_right) / 2. - pen / 2.);
148 (shift_x, shift_y)
149 }
150
151 pub fn count_badge(count: u32, muted: bool) -> Div {
152 let (background, foreground) = if muted {
153 (theme::badge_muted(), theme::text_strong())
154 } else {
155 (theme::accent(), theme::on_accent())
156 };
157 badge_pill(count, COUNT_BADGE, background, foreground)
68 158 }
69 159
70 160 pub fn page_header(title: &str) -> Div {
@@ -23,6 +23,10 @@ pub fn icon(name: IconName, size: f32, color: Hsla) -> Icon {
23 Icon::new(name).size(px(size)).text_color(color)
23 Icon::new(name).size(px(size)).text_color(color)
24}
24}
25
25
26pub fn menu_icon(name: IconName) -> Icon {
27 Icon::new(name)
28}
29
26pub fn symbol(name: &str, size: f32, color: Hsla) -> Icon {
30pub fn symbol(name: &str, size: f32, color: Hsla) -> Icon {
27 Icon::empty()
31 Icon::empty()
28 .path(format!("symbols/{name}.svg"))
32 .path(format!("symbols/{name}.svg"))
@@ -44,27 +48,113 @@ pub fn corner_badge(corner: Corner, overhang: f32) -> Div {
44 }
48 }
45}
49}
46
50
47pub fn count_badge(count: u32, muted: bool) -> Div {
51#[derive(Clone, Copy)]
48 let (background, foreground) = if muted {
52pub struct BadgeMetrics {
49 (theme::badge_muted(), theme::text_strong())
53 pub height: f32,
50 } else {
54 pub padding_x: f32,
51 (theme::accent(), theme::on_accent())
55 pub font_size: f32,
52 };
56}
57
58pub const COUNT_BADGE: BadgeMetrics = BadgeMetrics {
59 height: 18.,
60 padding_x: 5.,
61 font_size: 11.,
62};
63
64pub const RAIL_BADGE: BadgeMetrics = BadgeMetrics {
65 height: 16.,
66 padding_x: 4.,
67 font_size: 10.,
68};
69
70pub fn badge_selector(text: &str) -> String {
71 format!("count-badge/{text}")
72}
73
74pub fn badge_text_selector(text: &str) -> String {
75 format!("count-badge/{text}/text")
76}
77
78pub fn badge_pill(count: u32, metrics: BadgeMetrics, background: Hsla, foreground: Hsla) -> Div {
79 let text = format::badge_text(count);
53 div()
80 div()
54 .min_w(px(18.))
81 .debug_selector(|| badge_selector(&text))
55 .h(px(18.))
82 .min_w(px(metrics.height))
56 .px(px(5.))
83 .h(px(metrics.height))
84 .px(px(metrics.padding_x))
57 .flex()
85 .flex()
58 .flex_none()
86 .flex_none()
59 .items_center()
87 .items_center()
60 .justify_center()
88 .justify_center()
61 .rounded(px(9.))
89 .rounded(px(metrics.height / 2.))
62 .bg(background)
90 .bg(background)
63 .text_color(foreground)
91 .text_color(foreground)
64 .text_size(px(11.))
92 .text_size(px(metrics.font_size))
65 .line_height(px(18.))
93 .line_height(px(metrics.height))
66 .font_weight(FontWeight::BOLD)
94 .font_weight(FontWeight::BOLD)
67 .child(format::badge_text(count))
95 .child(BadgeText {
96 text,
97 font_size: metrics.font_size,
98 line_height: metrics.height,
99 })
100}
101
102#[derive(IntoElement)]
103struct BadgeText {
104 text: String,
105 font_size: f32,
106 line_height: f32,
107}
108
109impl RenderOnce for BadgeText {
110 fn render(self, window: &mut Window, _: &mut App) -> impl IntoElement {
111 let (shift_x, shift_y) = badge_ink_offset(window, &self.text, self.font_size);
112 div()
113 .debug_selector(|| badge_text_selector(&self.text))
114 .relative()
115 .left(px(-shift_x))
116 .top(px(-shift_y))
117 .flex_none()
118 .h(px(self.line_height))
119 .child(self.text)
120 }
121}
122
123pub fn badge_ink_offset(window: &Window, text: &str, font_size: f32) -> (f32, f32) {
124 let mut font = window.text_style().font();
125 font.weight = FontWeight::BOLD;
126 let text_system = window.text_system();
127 let font_id = text_system.resolve_font(&font);
128 let size = px(font_size);
129 let ascent = f32::from(text_system.ascent(font_id, size));
130 let descent = f32::from(text_system.descent(font_id, size)).abs();
131 let cap_height = f32::from(text_system.cap_height(font_id, size));
132 let shift_y = (ascent - descent - cap_height) / 2.;
133 let mut pen = 0.;
134 let mut ink_left = None;
135 let mut ink_right = 0.;
136 for character in text.chars() {
137 let advance = text_system
138 .advance(font_id, size, character)
139 .map_or(0., |advance| f32::from(advance.width));
140 if let Ok(bounds) = text_system.typographic_bounds(font_id, size, character) {
141 let left = pen + f32::from(bounds.origin.x);
142 ink_left.get_or_insert(left);
143 ink_right = left + f32::from(bounds.size.width);
144 }
145 pen += advance;
146 }
147 let shift_x = ink_left.map_or(0., |left| (left + ink_right) / 2. - pen / 2.);
148 (shift_x, shift_y)
149}
150
151pub fn count_badge(count: u32, muted: bool) -> Div {
152 let (background, foreground) = if muted {
153 (theme::badge_muted(), theme::text_strong())
154 } else {
155 (theme::accent(), theme::on_accent())
156 };
157 badge_pill(count, COUNT_BADGE, background, foreground)
68}
158}
69
159
70pub fn page_header(title: &str) -> Div {
160pub fn page_header(title: &str) -> Div {
crates/app/src/layout_guard.rs +358 −5
@@ -171,6 +171,7 @@ mod frames {
171 171 use crate::app_state::{AppHandle, AppState, Mode, Selection};
172 172 use crate::call::{ActiveCall, CallModel, ConsultCall};
173 173 use crate::demo;
174 use crate::settings::select_selector;
174 175 use crate::settings::{item_selector, label, label_selector, metrics};
175 176 use crate::settings_section::SettingsSection;
176 177 use crate::user_activity::UserInput;
@@ -189,7 +190,7 @@ mod frames {
189 190 FIND_DIVIDER_TAG, FIND_INPUT_TAG, FIND_PANEL_TAG, FIND_RESULTS_TAG,
190 191 };
191 192 use crate::views::message_row::BUBBLE_TAGS;
192 use crate::views::pin_banner::PIN_BANNER_TAG;
193 use crate::views::pin_banner::{BANNER_INSET, PIN_BANNER_TAG};
193 194 use crate::views::proposal_card::{PROPOSAL_BUTTONS, PROPOSAL_CARD, PROPOSAL_THUMBNAILS};
194 195 use crate::views::reaction_proposal_pill::REACTION_PILL;
195 196 use crate::views::recap_tab::RECAP_REGION;
@@ -201,10 +202,24 @@ mod frames {
201 202 OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenSaved,
202 203 };
203 204 use crate::views::sidebar::SIDEBAR_SCROLL_DIVIDER;
205 use crate::views::sidebar::chat_row_selector;
204 206 use crate::views::sidebar::chat_filter_bar::{
205 207 FILTER_EMPTY_TAG, FILTER_INPUT_TAG, FILTER_PILLS_TAG, FILTER_TAG,
206 208 };
207 209 use crate::views::status_menu::{OWN_AVATAR_DISC, TITLE_AVATAR_SIZE};
210 use crate::views::widgets::{
211 COUNT_BADGE, RAIL_BADGE, badge_ink_offset, badge_pill, badge_selector, badge_text_selector,
212 count_badge,
213 };
214 use gpui_kit::MouseButton;
215 use gpui_kit::component::fluent::{
216 DROPDOWN_OFFSET, MENU_ICON_LABEL_GAP, MENU_LIST_PADDING, OPTION_CHECK_GAP,
217 OPTION_CHECK_INSET,
218 };
219 use gpui_kit::component::menu::selectors::{
220 ITEMS_SELECTOR, icon_selector, item_selector as menu_item_selector,
221 label_selector as menu_label_selector,
222 };
208 223
209 224 const GUARDED: &[&str] = &[
210 225 "shell",
@@ -1481,6 +1496,343 @@ mod frames {
1481 1496 }
1482 1497 }
1483 1498
1499 const MENU_ITEMS_SCANNED: usize = 40;
1500 const MENU_CHAT: &str = "demo-chat-release";
1501 const THEME_SELECT: &str = "settings-theme";
1502
1503 struct MenuRow {
1504 index: usize,
1505 item: Bounds<Pixels>,
1506 icon: Option<Bounds<Pixels>>,
1507 label: Option<Bounds<Pixels>>,
1508 }
1509
1510 fn menu_rows(visual: &mut VisualTestContext) -> Vec<MenuRow> {
1511 (0..MENU_ITEMS_SCANNED)
1512 .filter_map(|index| {
1513 let item =
1514 visual.debug_bounds(Box::leak(menu_item_selector(index).into_boxed_str()))?;
1515 Some(MenuRow {
1516 index,
1517 item,
1518 icon: visual.debug_bounds(Box::leak(icon_selector(index).into_boxed_str())),
1519 label: visual
1520 .debug_bounds(Box::leak(menu_label_selector(index).into_boxed_str())),
1521 })
1522 })
1523 .collect()
1524 }
1525
1526 fn menu_row_violations(rows: &[MenuRow], expected_gap: f32) -> Vec<(String, String)> {
1527 let mut found = Vec::new();
1528 for row in rows {
1529 let Some(icon) = row.icon else {
1530 continue;
1531 };
1532 let key = format!("{MENU}/item-{}", row.index);
1533 if let Some(label) = row.label {
1534 let gap = f32::from(label.left() - icon.right());
1535 if (gap - expected_gap).abs() > TOLERANCE {
1536 found.push((
1537 format!("{key}:icon-gap"),
1538 format!(
1539 "icon {} to label {} is {gap} px, expected {expected_gap}",
1540 describe(icon),
1541 describe(label)
1542 ),
1543 ));
1544 }
1545 }
1546 let offset = f32::from(icon.center().y - row.item.center().y);
1547 if offset.abs() > TOLERANCE {
1548 found.push((
1549 format!("{key}:icon-off-centre"),
1550 format!(
1551 "icon {} sits {offset} px off the centre of item {}",
1552 describe(icon),
1553 describe(row.item)
1554 ),
1555 ));
1556 }
1557 }
1558 found
1559 }
1560
1561 fn listbox_violations(
1562 trigger: Bounds<Pixels>,
1563 menu: Bounds<Pixels>,
1564 items: Bounds<Pixels>,
1565 rows: &[MenuRow],
1566 ) -> Vec<(String, String)> {
1567 let mut found = Vec::new();
1568 let near = |value: f32, expected: f32| (value - expected).abs() <= TOLERANCE;
1569 if !near(f32::from(menu.left() - trigger.left()), 0.) {
1570 found.push((
1571 format!("{MENU}:not-aligned-to-trigger"),
1572 format!(
1573 "list {} must start at the trigger's left edge {}",
1574 describe(menu),
1575 describe(trigger)
1576 ),
1577 ));
1578 }
1579 if !near(
1580 f32::from(menu.top() - trigger.bottom()),
1581 f32::from(DROPDOWN_OFFSET),
1582 ) {
1583 found.push((
1584 format!("{MENU}:trigger-offset"),
1585 format!(
1586 "list {} must open {} px below the trigger {}",
1587 describe(menu),
1588 f32::from(DROPDOWN_OFFSET),
1589 describe(trigger)
1590 ),
1591 ));
1592 }
1593 if menu.size.width < trigger.size.width - px(TOLERANCE) {
1594 found.push((
1595 format!("{MENU}:narrower-than-trigger"),
1596 format!(
1597 "list {} is narrower than the trigger {}",
1598 describe(menu),
1599 describe(trigger)
1600 ),
1601 ));
1602 }
1603 if let (Some(first), Some(last)) = (rows.first(), rows.last()) {
1604 let top = f32::from(first.item.top() - items.top());
1605 let bottom = f32::from(items.bottom() - last.item.bottom());
1606 let padding = f32::from(MENU_LIST_PADDING);
1607 if !near(top, padding) || !near(bottom, padding) {
1608 found.push((
1609 format!("{MENU}:uneven-padding"),
1610 format!("list padding top {top} / bottom {bottom}, both must be {padding}"),
1611 ));
1612 }
1613 let expected_inset = f32::from(MENU_LIST_PADDING + OPTION_CHECK_INSET);
1614 match first.icon {
1615 Some(check) if near(f32::from(check.left() - menu.left()), expected_inset) => {}
1616 check => found.push((
1617 format!("{MENU}:check-inset"),
1618 format!(
1619 "check column {check:?} must start {expected_inset} px inside the list {}",
1620 describe(menu)
1621 ),
1622 )),
1623 }
1624 }
1625 found
1626 }
1627
1628 #[test]
1629 fn menu_rules_flag_gaps_offsets_and_misaligned_lists() {
1630 let row =
1631 |index: usize, item_top: f32, icon_left: f32, icon_top: f32, label_left: f32| MenuRow {
1632 index,
1633 item: rectangle(4., item_top, 120., 32.),
1634 icon: Some(rectangle(icon_left, icon_top, 20., 20.)),
1635 label: Some(rectangle(label_left, item_top + 6., 60., 20.)),
1636 };
1637 let rows = [row(0, 4., 10., 10., 36.), row(1, 38., 10., 46., 32.)];
1638 let keys: Vec<String> = menu_row_violations(&rows, f32::from(MENU_ICON_LABEL_GAP))
1639 .into_iter()
1640 .map(|(key, _)| key)
1641 .collect();
1642 assert_eq!(
1643 keys,
1644 [
1645 "popup-menu/item-1:icon-gap",
1646 "popup-menu/item-1:icon-off-centre"
1647 ]
1648 );
1649
1650 let trigger = rectangle(100., 50., 216., 32.);
1651 let option = |index: usize, top: f32| MenuRow {
1652 index,
1653 item: rectangle(104., top, 208., 32.),
1654 icon: Some(rectangle(110., top + 8., 16., 16.)),
1655 label: Some(rectangle(132., top + 6., 80., 20.)),
1656 };
1657 let aligned = [option(0, 88.), option(1, 122.)];
1658 let menu = rectangle(100., 84., 216., 74.);
1659 assert!(listbox_violations(trigger, menu, menu, &aligned).is_empty());
1660 let shifted = rectangle(96., 90., 200., 80.);
1661 let keys: Vec<String> = listbox_violations(trigger, shifted, shifted, &aligned)
1662 .into_iter()
1663 .map(|(key, _)| key)
1664 .collect();
1665 assert_eq!(
1666 keys,
1667 [
1668 "popup-menu:not-aligned-to-trigger",
1669 "popup-menu:trigger-offset",
1670 "popup-menu:narrower-than-trigger",
1671 "popup-menu:uneven-padding",
1672 "popup-menu:check-inset",
1673 ]
1674 );
1675 }
1676
1677 #[gpui_kit::test]
1678 fn menu_items_keep_one_icon_gap_and_centred_icons(cx: &mut TestAppContext) {
1679 let (handle, _) = mount(cx);
1680 let mut visual = VisualTestContext::from_window(handle, cx);
1681 visual.simulate_resize(size(px(1280.), px(800.)));
1682 let chat_row: &'static str = Box::leak(chat_row_selector(MENU_CHAT).into_boxed_str());
1683 collect(&mut visual, Some(chat_row));
1684 let mut found = Vec::new();
1685 let own_status = visual
1686 .debug_bounds(OWN_STATUS)
1687 .expect("own status button rendered");
1688 visual.simulate_click(own_status.center(), Default::default());
1689 collect(&mut visual, Some(MENU));
1690 let status_rows = menu_rows(&mut visual);
1691 assert!(
1692 status_rows.iter().any(|row| row.icon.is_some()),
1693 "status menu shows icons"
1694 );
1695 found.extend(menu_row_violations(
1696 &status_rows,
1697 f32::from(MENU_ICON_LABEL_GAP),
1698 ));
1699 visual.simulate_keystrokes("escape");
1700 collect(&mut visual, None);
1701 let row = visual.debug_bounds(chat_row).expect("chat row rendered");
1702 visual.simulate_mouse_down(row.center(), MouseButton::Right, Default::default());
1703 visual.simulate_mouse_up(row.center(), MouseButton::Right, Default::default());
1704 collect(&mut visual, Some(MENU));
1705 let chat_rows = menu_rows(&mut visual);
1706 assert!(
1707 chat_rows.iter().any(|row| row.icon.is_some()),
1708 "chat menu shows icons"
1709 );
1710 found.extend(menu_row_violations(
1711 &chat_rows,
1712 f32::from(MENU_ICON_LABEL_GAP),
1713 ));
1714 let found: Vec<String> = found
1715 .into_iter()
1716 .map(|(key, message)| format!("{key}: {message}"))
1717 .collect();
1718 assert!(found.is_empty(), "{}", found.join("\n"));
1719 }
1720
1721 #[gpui_kit::test]
1722 fn settings_select_list_lines_up_with_its_trigger(cx: &mut TestAppContext) {
1723 let (handle, state) = mount(cx);
1724 let mut visual = VisualTestContext::from_window(handle, cx);
1725 visual.simulate_resize(size(px(1280.), px(800.)));
1726 visual.update(|_, cx| {
1727 state.update(cx, |state, cx| {
1728 state.open_settings(SettingsSection::Appearance, cx)
1729 })
1730 });
1731 let select: &'static str = Box::leak(select_selector(THEME_SELECT).into_boxed_str());
1732 collect(&mut visual, Some(select));
1733 let trigger = visual.debug_bounds(select).expect("theme select rendered");
1734 visual.simulate_click(trigger.center(), Default::default());
1735 collect(&mut visual, Some(MENU));
1736 let menu = visual.debug_bounds(MENU).expect("list rendered");
1737 let items = visual
1738 .debug_bounds(ITEMS_SELECTOR)
1739 .expect("list items rendered");
1740 let rows = menu_rows(&mut visual);
1741 let found: Vec<String> = listbox_violations(trigger, menu, items, &rows)
1742 .into_iter()
1743 .chain(menu_row_violations(&rows, f32::from(OPTION_CHECK_GAP)))
1744 .map(|(key, message)| format!("{key}: {message}"))
1745 .collect();
1746 assert!(found.is_empty(), "{}", found.join("\n"));
1747 }
1748
1749 const BADGE_SAMPLES: [(u32, bool); 5] =
1750 [(1, false), (42, false), (120, false), (7, true), (15, true)];
1751
1752 struct BadgeSamples;
1753
1754 impl gpui_kit::Render for BadgeSamples {
1755 fn render(
1756 &mut self,
1757 _: &mut gpui_kit::Window,
1758 _: &mut gpui_kit::Context<Self>,
1759 ) -> impl gpui_kit::IntoElement {
1760 use gpui_kit::{ParentElement as _, Styled as _};
1761 gpui_kit::div()
1762 .flex()
1763 .gap(px(12.))
1764 .p(px(12.))
1765 .children(BADGE_SAMPLES.map(|(count, rail)| {
1766 if rail {
1767 badge_pill(
1768 count,
1769 RAIL_BADGE,
1770 crate::theme::accent(),
1771 crate::theme::on_accent(),
1772 )
1773 } else {
1774 count_badge(count, false)
1775 }
1776 }))
1777 }
1778 }
1779
1780 fn badge_violation(
1781 text: &str,
1782 pill: Bounds<Pixels>,
1783 label: Bounds<Pixels>,
1784 ink_offset: (f32, f32),
1785 ) -> Option<(String, String)> {
1786 let ink_x = f32::from(label.center().x) + ink_offset.0;
1787 let ink_y = f32::from(label.center().y) + ink_offset.1;
1788 let off_x = ink_x - f32::from(pill.center().x);
1789 let off_y = ink_y - f32::from(pill.center().y);
1790 (off_x.abs() > TOLERANCE || off_y.abs() > TOLERANCE).then(|| {
1791 (
1792 format!("count-badge/{text}:off-centre"),
1793 format!("text ink of {text:?} sits ({off_x:.2}, {off_y:.2}) px off the centre of its circle {}", describe(pill)),
1794 )
1795 })
1796 }
1797
1798 #[test]
1799 fn badge_rule_flags_off_centre_text() {
1800 let pill = rectangle(0., 0., 18., 18.);
1801 assert!(badge_violation("1", pill, rectangle(6., 0., 6., 18.), (0., 0.)).is_none());
1802 assert!(badge_violation("1", pill, rectangle(6., 0., 6., 18.), (1., 0.)).is_some());
1803 assert!(badge_violation("1", pill, rectangle(6., 0., 6., 18.), (0., -1.)).is_some());
1804 }
1805
1806 #[gpui_kit::test]
1807 fn count_badge_text_sits_in_the_centre_of_its_circle(cx: &mut TestAppContext) {
1808 cx.update(gpui_kit::init);
1809 cx.update(crate::theme::apply);
1810 let (_, visual) = cx.add_window_view(|_, _| BadgeSamples);
1811 collect(visual, None);
1812 let mut found = Vec::new();
1813 for (count, rail) in BADGE_SAMPLES {
1814 let text = crate::format::badge_text(count);
1815 let pill = visual
1816 .debug_bounds(Box::leak(badge_selector(&text).into_boxed_str()))
1817 .expect("badge rendered");
1818 let label = visual
1819 .debug_bounds(Box::leak(badge_text_selector(&text).into_boxed_str()))
1820 .expect("badge text rendered");
1821 let font_size = if rail {
1822 RAIL_BADGE.font_size
1823 } else {
1824 COUNT_BADGE.font_size
1825 };
1826 let offset = visual.update(|window, _| badge_ink_offset(window, &text, font_size));
1827 found.extend(badge_violation(&text, pill, label, offset));
1828 }
1829 let found: Vec<String> = found
1830 .into_iter()
1831 .map(|(key, message)| format!("{key}: {message}"))
1832 .collect();
1833 assert!(found.is_empty(), "{}", found.join("\n"));
1834 }
1835
1484 1836 const PINNED_CHAT: &str = "demo-chat-release";
1485 1837 const PINNED_CHANNEL: &str = "demo-channel-1-1";
1486 1838
@@ -1507,12 +1859,13 @@ mod frames {
1507 1859 ("below divider", f32::from(banner.top() - divider.bottom())),
1508 1860 ];
1509 1861 let side = gaps[1].1;
1510 if gaps
1511 .iter()
1512 .any(|(_, gap)| (gap - side).abs() > INSET_TOLERANCE)
1862 if (side - BANNER_INSET).abs() > INSET_TOLERANCE
1863 || gaps
1864 .iter()
1865 .any(|(_, gap)| (gap - side).abs() > INSET_TOLERANCE)
1513 1866 {
1514 1867 found.push(format!(
1515 "pin banner@{width}x{height}: gaps {gaps:?} must match"
1868 "pin banner@{width}x{height}: gaps {gaps:?} must all be {BANNER_INSET}"
1516 1869 ));
1517 1870 }
1518 1871 }
@@ -171,6 +171,7 @@ mod frames {
171 use crate::app_state::{AppHandle, AppState, Mode, Selection};
171 use crate::app_state::{AppHandle, AppState, Mode, Selection};
172 use crate::call::{ActiveCall, CallModel, ConsultCall};
172 use crate::call::{ActiveCall, CallModel, ConsultCall};
173 use crate::demo;
173 use crate::demo;
174 use crate::settings::select_selector;
174 use crate::settings::{item_selector, label, label_selector, metrics};
175 use crate::settings::{item_selector, label, label_selector, metrics};
175 use crate::settings_section::SettingsSection;
176 use crate::settings_section::SettingsSection;
176 use crate::user_activity::UserInput;
177 use crate::user_activity::UserInput;
@@ -189,7 +190,7 @@ mod frames {
189 FIND_DIVIDER_TAG, FIND_INPUT_TAG, FIND_PANEL_TAG, FIND_RESULTS_TAG,
190 FIND_DIVIDER_TAG, FIND_INPUT_TAG, FIND_PANEL_TAG, FIND_RESULTS_TAG,
190 };
191 };
191 use crate::views::message_row::BUBBLE_TAGS;
192 use crate::views::message_row::BUBBLE_TAGS;
192 use crate::views::pin_banner::PIN_BANNER_TAG;
193 use crate::views::pin_banner::{BANNER_INSET, PIN_BANNER_TAG};
193 use crate::views::proposal_card::{PROPOSAL_BUTTONS, PROPOSAL_CARD, PROPOSAL_THUMBNAILS};
194 use crate::views::proposal_card::{PROPOSAL_BUTTONS, PROPOSAL_CARD, PROPOSAL_THUMBNAILS};
194 use crate::views::reaction_proposal_pill::REACTION_PILL;
195 use crate::views::reaction_proposal_pill::REACTION_PILL;
195 use crate::views::recap_tab::RECAP_REGION;
196 use crate::views::recap_tab::RECAP_REGION;
@@ -201,10 +202,24 @@ mod frames {
201 OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenSaved,
202 OpenChannelsTab, OpenChatFilter, OpenChatsTab, OpenSaved,
202 };
203 };
203 use crate::views::sidebar::SIDEBAR_SCROLL_DIVIDER;
204 use crate::views::sidebar::SIDEBAR_SCROLL_DIVIDER;
205 use crate::views::sidebar::chat_row_selector;
204 use crate::views::sidebar::chat_filter_bar::{
206 use crate::views::sidebar::chat_filter_bar::{
205 FILTER_EMPTY_TAG, FILTER_INPUT_TAG, FILTER_PILLS_TAG, FILTER_TAG,
207 FILTER_EMPTY_TAG, FILTER_INPUT_TAG, FILTER_PILLS_TAG, FILTER_TAG,
206 };
208 };
207 use crate::views::status_menu::{OWN_AVATAR_DISC, TITLE_AVATAR_SIZE};
209 use crate::views::status_menu::{OWN_AVATAR_DISC, TITLE_AVATAR_SIZE};
210 use crate::views::widgets::{
211 COUNT_BADGE, RAIL_BADGE, badge_ink_offset, badge_pill, badge_selector, badge_text_selector,
212 count_badge,
213 };
214 use gpui_kit::MouseButton;
215 use gpui_kit::component::fluent::{
216 DROPDOWN_OFFSET, MENU_ICON_LABEL_GAP, MENU_LIST_PADDING, OPTION_CHECK_GAP,
217 OPTION_CHECK_INSET,
218 };
219 use gpui_kit::component::menu::selectors::{
220 ITEMS_SELECTOR, icon_selector, item_selector as menu_item_selector,
221 label_selector as menu_label_selector,
222 };
208
223
209 const GUARDED: &[&str] = &[
224 const GUARDED: &[&str] = &[
210 "shell",
225 "shell",
@@ -1481,6 +1496,343 @@ mod frames {
1481 }
1496 }
1482 }
1497 }
1483
1498
1499 const MENU_ITEMS_SCANNED: usize = 40;
1500 const MENU_CHAT: &str = "demo-chat-release";
1501 const THEME_SELECT: &str = "settings-theme";
1502
1503 struct MenuRow {
1504 index: usize,
1505 item: Bounds<Pixels>,
1506 icon: Option<Bounds<Pixels>>,
1507 label: Option<Bounds<Pixels>>,
1508 }
1509
1510 fn menu_rows(visual: &mut VisualTestContext) -> Vec<MenuRow> {
1511 (0..MENU_ITEMS_SCANNED)
1512 .filter_map(|index| {
1513 let item =
1514 visual.debug_bounds(Box::leak(menu_item_selector(index).into_boxed_str()))?;
1515 Some(MenuRow {
1516 index,
1517 item,
1518 icon: visual.debug_bounds(Box::leak(icon_selector(index).into_boxed_str())),
1519 label: visual
1520 .debug_bounds(Box::leak(menu_label_selector(index).into_boxed_str())),
1521 })
1522 })
1523 .collect()
1524 }
1525
1526 fn menu_row_violations(rows: &[MenuRow], expected_gap: f32) -> Vec<(String, String)> {
1527 let mut found = Vec::new();
1528 for row in rows {
1529 let Some(icon) = row.icon else {
1530 continue;
1531 };
1532 let key = format!("{MENU}/item-{}", row.index);
1533 if let Some(label) = row.label {
1534 let gap = f32::from(label.left() - icon.right());
1535 if (gap - expected_gap).abs() > TOLERANCE {
1536 found.push((
1537 format!("{key}:icon-gap"),
1538 format!(
1539 "icon {} to label {} is {gap} px, expected {expected_gap}",
1540 describe(icon),
1541 describe(label)
1542 ),
1543 ));
1544 }
1545 }
1546 let offset = f32::from(icon.center().y - row.item.center().y);
1547 if offset.abs() > TOLERANCE {
1548 found.push((
1549 format!("{key}:icon-off-centre"),
1550 format!(
1551 "icon {} sits {offset} px off the centre of item {}",
1552 describe(icon),
1553 describe(row.item)
1554 ),
1555 ));
1556 }
1557 }
1558 found
1559 }
1560
1561 fn listbox_violations(
1562 trigger: Bounds<Pixels>,
1563 menu: Bounds<Pixels>,
1564 items: Bounds<Pixels>,
1565 rows: &[MenuRow],
1566 ) -> Vec<(String, String)> {
1567 let mut found = Vec::new();
1568 let near = |value: f32, expected: f32| (value - expected).abs() <= TOLERANCE;
1569 if !near(f32::from(menu.left() - trigger.left()), 0.) {
1570 found.push((
1571 format!("{MENU}:not-aligned-to-trigger"),
1572 format!(
1573 "list {} must start at the trigger's left edge {}",
1574 describe(menu),
1575 describe(trigger)
1576 ),
1577 ));
1578 }
1579 if !near(
1580 f32::from(menu.top() - trigger.bottom()),
1581 f32::from(DROPDOWN_OFFSET),
1582 ) {
1583 found.push((
1584 format!("{MENU}:trigger-offset"),
1585 format!(
1586 "list {} must open {} px below the trigger {}",
1587 describe(menu),
1588 f32::from(DROPDOWN_OFFSET),
1589 describe(trigger)
1590 ),
1591 ));
1592 }
1593 if menu.size.width < trigger.size.width - px(TOLERANCE) {
1594 found.push((
1595 format!("{MENU}:narrower-than-trigger"),
1596 format!(
1597 "list {} is narrower than the trigger {}",
1598 describe(menu),
1599 describe(trigger)
1600 ),
1601 ));
1602 }
1603 if let (Some(first), Some(last)) = (rows.first(), rows.last()) {
1604 let top = f32::from(first.item.top() - items.top());
1605 let bottom = f32::from(items.bottom() - last.item.bottom());
1606 let padding = f32::from(MENU_LIST_PADDING);
1607 if !near(top, padding) || !near(bottom, padding) {
1608 found.push((
1609 format!("{MENU}:uneven-padding"),
1610 format!("list padding top {top} / bottom {bottom}, both must be {padding}"),
1611 ));
1612 }
1613 let expected_inset = f32::from(MENU_LIST_PADDING + OPTION_CHECK_INSET);
1614 match first.icon {
1615 Some(check) if near(f32::from(check.left() - menu.left()), expected_inset) => {}
1616 check => found.push((
1617 format!("{MENU}:check-inset"),
1618 format!(
1619 "check column {check:?} must start {expected_inset} px inside the list {}",
1620 describe(menu)
1621 ),
1622 )),
1623 }
1624 }
1625 found
1626 }
1627
1628 #[test]
1629 fn menu_rules_flag_gaps_offsets_and_misaligned_lists() {
1630 let row =
1631 |index: usize, item_top: f32, icon_left: f32, icon_top: f32, label_left: f32| MenuRow {
1632 index,
1633 item: rectangle(4., item_top, 120., 32.),
1634 icon: Some(rectangle(icon_left, icon_top, 20., 20.)),
1635 label: Some(rectangle(label_left, item_top + 6., 60., 20.)),
1636 };
1637 let rows = [row(0, 4., 10., 10., 36.), row(1, 38., 10., 46., 32.)];
1638 let keys: Vec<String> = menu_row_violations(&rows, f32::from(MENU_ICON_LABEL_GAP))
1639 .into_iter()
1640 .map(|(key, _)| key)
1641 .collect();
1642 assert_eq!(
1643 keys,
1644 [
1645 "popup-menu/item-1:icon-gap",
1646 "popup-menu/item-1:icon-off-centre"
1647 ]
1648 );
1649
1650 let trigger = rectangle(100., 50., 216., 32.);
1651 let option = |index: usize, top: f32| MenuRow {
1652 index,
1653 item: rectangle(104., top, 208., 32.),
1654 icon: Some(rectangle(110., top + 8., 16., 16.)),
1655 label: Some(rectangle(132., top + 6., 80., 20.)),
1656 };
1657 let aligned = [option(0, 88.), option(1, 122.)];
1658 let menu = rectangle(100., 84., 216., 74.);
1659 assert!(listbox_violations(trigger, menu, menu, &aligned).is_empty());
1660 let shifted = rectangle(96., 90., 200., 80.);
1661 let keys: Vec<String> = listbox_violations(trigger, shifted, shifted, &aligned)
1662 .into_iter()
1663 .map(|(key, _)| key)
1664 .collect();
1665 assert_eq!(
1666 keys,
1667 [
1668 "popup-menu:not-aligned-to-trigger",
1669 "popup-menu:trigger-offset",
1670 "popup-menu:narrower-than-trigger",
1671 "popup-menu:uneven-padding",
1672 "popup-menu:check-inset",
1673 ]
1674 );
1675 }
1676
1677 #[gpui_kit::test]
1678 fn menu_items_keep_one_icon_gap_and_centred_icons(cx: &mut TestAppContext) {
1679 let (handle, _) = mount(cx);
1680 let mut visual = VisualTestContext::from_window(handle, cx);
1681 visual.simulate_resize(size(px(1280.), px(800.)));
1682 let chat_row: &'static str = Box::leak(chat_row_selector(MENU_CHAT).into_boxed_str());
1683 collect(&mut visual, Some(chat_row));
1684 let mut found = Vec::new();
1685 let own_status = visual
1686 .debug_bounds(OWN_STATUS)
1687 .expect("own status button rendered");
1688 visual.simulate_click(own_status.center(), Default::default());
1689 collect(&mut visual, Some(MENU));
1690 let status_rows = menu_rows(&mut visual);
1691 assert!(
1692 status_rows.iter().any(|row| row.icon.is_some()),
1693 "status menu shows icons"
1694 );
1695 found.extend(menu_row_violations(
1696 &status_rows,
1697 f32::from(MENU_ICON_LABEL_GAP),
1698 ));
1699 visual.simulate_keystrokes("escape");
1700 collect(&mut visual, None);
1701 let row = visual.debug_bounds(chat_row).expect("chat row rendered");
1702 visual.simulate_mouse_down(row.center(), MouseButton::Right, Default::default());
1703 visual.simulate_mouse_up(row.center(), MouseButton::Right, Default::default());
1704 collect(&mut visual, Some(MENU));
1705 let chat_rows = menu_rows(&mut visual);
1706 assert!(
1707 chat_rows.iter().any(|row| row.icon.is_some()),
1708 "chat menu shows icons"
1709 );
1710 found.extend(menu_row_violations(
1711 &chat_rows,
1712 f32::from(MENU_ICON_LABEL_GAP),
1713 ));
1714 let found: Vec<String> = found
1715 .into_iter()
1716 .map(|(key, message)| format!("{key}: {message}"))
1717 .collect();
1718 assert!(found.is_empty(), "{}", found.join("\n"));
1719 }
1720
1721 #[gpui_kit::test]
1722 fn settings_select_list_lines_up_with_its_trigger(cx: &mut TestAppContext) {
1723 let (handle, state) = mount(cx);
1724 let mut visual = VisualTestContext::from_window(handle, cx);
1725 visual.simulate_resize(size(px(1280.), px(800.)));
1726 visual.update(|_, cx| {
1727 state.update(cx, |state, cx| {
1728 state.open_settings(SettingsSection::Appearance, cx)
1729 })
1730 });
1731 let select: &'static str = Box::leak(select_selector(THEME_SELECT).into_boxed_str());
1732 collect(&mut visual, Some(select));
1733 let trigger = visual.debug_bounds(select).expect("theme select rendered");
1734 visual.simulate_click(trigger.center(), Default::default());
1735 collect(&mut visual, Some(MENU));
1736 let menu = visual.debug_bounds(MENU).expect("list rendered");
1737 let items = visual
1738 .debug_bounds(ITEMS_SELECTOR)
1739 .expect("list items rendered");
1740 let rows = menu_rows(&mut visual);
1741 let found: Vec<String> = listbox_violations(trigger, menu, items, &rows)
1742 .into_iter()
1743 .chain(menu_row_violations(&rows, f32::from(OPTION_CHECK_GAP)))
1744 .map(|(key, message)| format!("{key}: {message}"))
1745 .collect();
1746 assert!(found.is_empty(), "{}", found.join("\n"));
1747 }
1748
1749 const BADGE_SAMPLES: [(u32, bool); 5] =
1750 [(1, false), (42, false), (120, false), (7, true), (15, true)];
1751
1752 struct BadgeSamples;
1753
1754 impl gpui_kit::Render for BadgeSamples {
1755 fn render(
1756 &mut self,
1757 _: &mut gpui_kit::Window,
1758 _: &mut gpui_kit::Context<Self>,
1759 ) -> impl gpui_kit::IntoElement {
1760 use gpui_kit::{ParentElement as _, Styled as _};
1761 gpui_kit::div()
1762 .flex()
1763 .gap(px(12.))
1764 .p(px(12.))
1765 .children(BADGE_SAMPLES.map(|(count, rail)| {
1766 if rail {
1767 badge_pill(
1768 count,
1769 RAIL_BADGE,
1770 crate::theme::accent(),
1771 crate::theme::on_accent(),
1772 )
1773 } else {
1774 count_badge(count, false)
1775 }
1776 }))
1777 }
1778 }
1779
1780 fn badge_violation(
1781 text: &str,
1782 pill: Bounds<Pixels>,
1783 label: Bounds<Pixels>,
1784 ink_offset: (f32, f32),
1785 ) -> Option<(String, String)> {
1786 let ink_x = f32::from(label.center().x) + ink_offset.0;
1787 let ink_y = f32::from(label.center().y) + ink_offset.1;
1788 let off_x = ink_x - f32::from(pill.center().x);
1789 let off_y = ink_y - f32::from(pill.center().y);
1790 (off_x.abs() > TOLERANCE || off_y.abs() > TOLERANCE).then(|| {
1791 (
1792 format!("count-badge/{text}:off-centre"),
1793 format!("text ink of {text:?} sits ({off_x:.2}, {off_y:.2}) px off the centre of its circle {}", describe(pill)),
1794 )
1795 })
1796 }
1797
1798 #[test]
1799 fn badge_rule_flags_off_centre_text() {
1800 let pill = rectangle(0., 0., 18., 18.);
1801 assert!(badge_violation("1", pill, rectangle(6., 0., 6., 18.), (0., 0.)).is_none());
1802 assert!(badge_violation("1", pill, rectangle(6., 0., 6., 18.), (1., 0.)).is_some());
1803 assert!(badge_violation("1", pill, rectangle(6., 0., 6., 18.), (0., -1.)).is_some());
1804 }
1805
1806 #[gpui_kit::test]
1807 fn count_badge_text_sits_in_the_centre_of_its_circle(cx: &mut TestAppContext) {
1808 cx.update(gpui_kit::init);
1809 cx.update(crate::theme::apply);
1810 let (_, visual) = cx.add_window_view(|_, _| BadgeSamples);
1811 collect(visual, None);
1812 let mut found = Vec::new();
1813 for (count, rail) in BADGE_SAMPLES {
1814 let text = crate::format::badge_text(count);
1815 let pill = visual
1816 .debug_bounds(Box::leak(badge_selector(&text).into_boxed_str()))
1817 .expect("badge rendered");
1818 let label = visual
1819 .debug_bounds(Box::leak(badge_text_selector(&text).into_boxed_str()))
1820 .expect("badge text rendered");
1821 let font_size = if rail {
1822 RAIL_BADGE.font_size
1823 } else {
1824 COUNT_BADGE.font_size
1825 };
1826 let offset = visual.update(|window, _| badge_ink_offset(window, &text, font_size));
1827 found.extend(badge_violation(&text, pill, label, offset));
1828 }
1829 let found: Vec<String> = found
1830 .into_iter()
1831 .map(|(key, message)| format!("{key}: {message}"))
1832 .collect();
1833 assert!(found.is_empty(), "{}", found.join("\n"));
1834 }
1835
1484 const PINNED_CHAT: &str = "demo-chat-release";
1836 const PINNED_CHAT: &str = "demo-chat-release";
1485 const PINNED_CHANNEL: &str = "demo-channel-1-1";
1837 const PINNED_CHANNEL: &str = "demo-channel-1-1";
1486
1838
@@ -1507,12 +1859,13 @@ mod frames {
1507 ("below divider", f32::from(banner.top() - divider.bottom())),
1859 ("below divider", f32::from(banner.top() - divider.bottom())),
1508 ];
1860 ];
1509 let side = gaps[1].1;
1861 let side = gaps[1].1;
1510 if gaps
1862 if (side - BANNER_INSET).abs() > INSET_TOLERANCE
1511 .iter()
1863 || gaps
1512 .any(|(_, gap)| (gap - side).abs() > INSET_TOLERANCE)
1864 .iter()
1865 .any(|(_, gap)| (gap - side).abs() > INSET_TOLERANCE)
1513 {
1866 {
1514 found.push(format!(
1867 found.push(format!(
1515 "pin banner@{width}x{height}: gaps {gaps:?} must match"
1868 "pin banner@{width}x{height}: gaps {gaps:?} must all be {BANNER_INSET}"
1516 ));
1869 ));
1517 }
1870 }
1518 }
1871 }
crates/app/src/settings/mod.rs +1 −1
@@ -16,4 +16,4 @@ pub use dialog::metrics;
16 16 pub use dialog::{SettingsDialog, SettingsDialogEvent};
17 17 #[cfg(test)]
18 18 pub use nav::{item_selector, label, label_selector};
19 pub(crate) use rows::switch;
19 pub(crate) use rows::{select_selector, switch};
@@ -16,4 +16,4 @@ pub use dialog::metrics;
16pub use dialog::{SettingsDialog, SettingsDialogEvent};
16pub use dialog::{SettingsDialog, SettingsDialogEvent};
17#[cfg(test)]
17#[cfg(test)]
18pub use nav::{item_selector, label, label_selector};
18pub use nav::{item_selector, label, label_selector};
19pub(crate) use rows::switch;
19pub(crate) use rows::{select_selector, switch};
crates/app/src/settings/rows.rs +8 −1
@@ -162,6 +162,10 @@ pub fn text_button(id: impl Into<ElementId>, label: impl Into<SharedString>) ->
162 162 .child(label.into())
163 163 }
164 164
165 pub fn select_selector(id: &str) -> String {
166 format!("settings-select/{id}")
167 }
168
165 169 pub fn select(
166 170 id: impl Into<ElementId>,
167 171 label: impl Into<SharedString>,
@@ -179,7 +183,9 @@ pub fn select_with_width(
179 183 choices: Vec<Choice>,
180 184 ) -> impl IntoElement {
181 185 let scrollable = choices.len() > SCROLL_MENU_AFTER;
182 Button::new(id)
186 let id: ElementId = id.into();
187 Button::new(id.clone())
188 .debug_selector(|| select_selector(&id.to_string()))
183 189 .outline()
184 190 .w(px(width))
185 191 .flex_none()
@@ -209,4 +215,5 @@ pub fn select_with_width(
209 215 )
210 216 })
211 217 })
218 .listbox()
212 219 }
@@ -162,6 +162,10 @@ pub fn text_button(id: impl Into<ElementId>, label: impl Into<SharedString>) ->
162 .child(label.into())
162 .child(label.into())
163}
163}
164
164
165pub fn select_selector(id: &str) -> String {
166 format!("settings-select/{id}")
167}
168
165pub fn select(
169pub fn select(
166 id: impl Into<ElementId>,
170 id: impl Into<ElementId>,
167 label: impl Into<SharedString>,
171 label: impl Into<SharedString>,
@@ -179,7 +183,9 @@ pub fn select_with_width(
179 choices: Vec<Choice>,
183 choices: Vec<Choice>,
180) -> impl IntoElement {
184) -> impl IntoElement {
181 let scrollable = choices.len() > SCROLL_MENU_AFTER;
185 let scrollable = choices.len() > SCROLL_MENU_AFTER;
182 Button::new(id)
186 let id: ElementId = id.into();
187 Button::new(id.clone())
188 .debug_selector(|| select_selector(&id.to_string()))
183 .outline()
189 .outline()
184 .w(px(width))
190 .w(px(width))
185 .flex_none()
191 .flex_none()
@@ -209,4 +215,5 @@ pub fn select_with_width(
209 )
215 )
210 })
216 })
211 })
217 })
218 .listbox()
212}
219}
crates/app/src/views/calls_tab.rs +3 −8
@@ -13,7 +13,7 @@ use super::join_dialog::open_join_with_id;
13 13 use super::new_meeting_dialog::open_new_meeting;
14 14 use super::scroll_edge::with_top_edge;
15 15 use super::sidebar::SIDEBAR_SCROLL_DIVIDER;
16 use super::widgets::icon;
16 use super::widgets::{icon, menu_icon};
17 17 use crate::app_state::AppState;
18 18 use crate::call::{
19 19 AGENDA_ROW_HEIGHT, AgendaRow, CALL_ROW_HEIGHT, CallRow, DAY_HEIGHT, EMPTY_HEIGHT, ListEntry,
@@ -25,7 +25,6 @@ const FALLBACK_VIEWPORT: f32 = 900.;
25 25 const VIEWPORT_MARGIN: f32 = 300.;
26 26 const TIME_COLUMN_WIDTH: f32 = 96.;
27 27 const AVATAR_SIZE: f32 = 36.;
28 const MENU_ICON_SIZE: f32 = 15.;
29 28
30 29 fn meeting_avatar() -> Div {
31 30 div()
@@ -122,7 +121,7 @@ fn call_row(
122 121 .when(can_call_back, |popup| {
123 122 popup.item(
124 123 PopupMenuItem::new("Call back")
125 .icon(icon(IconName::Phone, MENU_ICON_SIZE, theme::text_muted()))
124 .icon(menu_icon(IconName::Phone))
126 125 .on_click(move |_, _, cx| {
127 126 call_state.update(cx, |state, cx| {
128 127 state.call_back_from_history(&call_row, cx)
@@ -133,11 +132,7 @@ fn call_row(
133 132 .when(can_open_chat, |popup| {
134 133 popup.item(
135 134 PopupMenuItem::new("Open chat")
136 .icon(icon(
137 IconName::MessageSquare,
138 MENU_ICON_SIZE,
139 theme::text_muted(),
140 ))
135 .icon(menu_icon(IconName::MessageSquare))
141 136 .on_click(move |_, _, cx| {
142 137 chat_state.update(cx, |state, cx| {
143 138 state.open_chat_of_call_row(&chat_row, cx)
@@ -13,7 +13,7 @@ use super::join_dialog::open_join_with_id;
13use super::new_meeting_dialog::open_new_meeting;
13use super::new_meeting_dialog::open_new_meeting;
14use super::scroll_edge::with_top_edge;
14use super::scroll_edge::with_top_edge;
15use super::sidebar::SIDEBAR_SCROLL_DIVIDER;
15use super::sidebar::SIDEBAR_SCROLL_DIVIDER;
16use super::widgets::icon;
16use super::widgets::{icon, menu_icon};
17use crate::app_state::AppState;
17use crate::app_state::AppState;
18use crate::call::{
18use crate::call::{
19 AGENDA_ROW_HEIGHT, AgendaRow, CALL_ROW_HEIGHT, CallRow, DAY_HEIGHT, EMPTY_HEIGHT, ListEntry,
19 AGENDA_ROW_HEIGHT, AgendaRow, CALL_ROW_HEIGHT, CallRow, DAY_HEIGHT, EMPTY_HEIGHT, ListEntry,
@@ -25,7 +25,6 @@ const FALLBACK_VIEWPORT: f32 = 900.;
25const VIEWPORT_MARGIN: f32 = 300.;
25const VIEWPORT_MARGIN: f32 = 300.;
26const TIME_COLUMN_WIDTH: f32 = 96.;
26const TIME_COLUMN_WIDTH: f32 = 96.;
27const AVATAR_SIZE: f32 = 36.;
27const AVATAR_SIZE: f32 = 36.;
28const MENU_ICON_SIZE: f32 = 15.;
29
28
30fn meeting_avatar() -> Div {
29fn meeting_avatar() -> Div {
31 div()
30 div()
@@ -122,7 +121,7 @@ fn call_row(
122 .when(can_call_back, |popup| {
121 .when(can_call_back, |popup| {
123 popup.item(
122 popup.item(
124 PopupMenuItem::new("Call back")
123 PopupMenuItem::new("Call back")
125 .icon(icon(IconName::Phone, MENU_ICON_SIZE, theme::text_muted()))
124 .icon(menu_icon(IconName::Phone))
126 .on_click(move |_, _, cx| {
125 .on_click(move |_, _, cx| {
127 call_state.update(cx, |state, cx| {
126 call_state.update(cx, |state, cx| {
128 state.call_back_from_history(&call_row, cx)
127 state.call_back_from_history(&call_row, cx)
@@ -133,11 +132,7 @@ fn call_row(
133 .when(can_open_chat, |popup| {
132 .when(can_open_chat, |popup| {
134 popup.item(
133 popup.item(
135 PopupMenuItem::new("Open chat")
134 PopupMenuItem::new("Open chat")
136 .icon(icon(
135 .icon(menu_icon(IconName::MessageSquare))
137 IconName::MessageSquare,
138 MENU_ICON_SIZE,
139 theme::text_muted(),
140 ))
141 .on_click(move |_, _, cx| {
136 .on_click(move |_, _, cx| {
142 chat_state.update(cx, |state, cx| {
137 chat_state.update(cx, |state, cx| {
143 state.open_chat_of_call_row(&chat_row, cx)
138 state.open_chat_of_call_row(&chat_row, cx)
crates/app/src/views/image_menu.rs +2 −12
@@ -2,26 +2,16 @@ use std::path::PathBuf;
2 2 use std::rc::Rc;
3 3
4 4 use gpui_kit::assets::IconName;
5 use gpui_kit::component::{
6 Icon,
7 menu::{ContextMenuExt as _, PopupMenuItem},
8 };
5 use gpui_kit::component::menu::{ContextMenuExt as _, PopupMenuItem};
9 6 use gpui_kit::*;
10 7
11 8 use super::image_viewer::{suggested_name, write_image};
12 use super::widgets::icon;
9 use super::widgets::menu_icon;
13 10 use crate::downloads;
14 11 use crate::image_clipboard::ClipboardImage;
15 use crate::theme;
16
17 const MENU_ICON_SIZE: f32 = 16.;
18 12
19 13 pub type ImageShare = Rc<dyn Fn(&mut App)>;
20 14
21 fn menu_icon(glyph: IconName) -> Icon {
22 icon(glyph, MENU_ICON_SIZE, theme::text_muted())
23 }
24
25 15 pub fn copy_image_file(path: PathBuf, cx: &mut App) {
26 16 cx.spawn(async move |cx| {
27 17 let image = cx
@@ -2,26 +2,16 @@ use std::path::PathBuf;
2use std::rc::Rc;
2use std::rc::Rc;
3
3
4use gpui_kit::assets::IconName;
4use gpui_kit::assets::IconName;
5use gpui_kit::component::{
5use gpui_kit::component::menu::{ContextMenuExt as _, PopupMenuItem};
6 Icon,
7 menu::{ContextMenuExt as _, PopupMenuItem},
8};
9use gpui_kit::*;
6use gpui_kit::*;
10
7
11use super::image_viewer::{suggested_name, write_image};
8use super::image_viewer::{suggested_name, write_image};
12use super::widgets::icon;
9use super::widgets::menu_icon;
13use crate::downloads;
10use crate::downloads;
14use crate::image_clipboard::ClipboardImage;
11use crate::image_clipboard::ClipboardImage;
15use crate::theme;
16
17const MENU_ICON_SIZE: f32 = 16.;
18
12
19pub type ImageShare = Rc<dyn Fn(&mut App)>;
13pub type ImageShare = Rc<dyn Fn(&mut App)>;
20
14
21fn menu_icon(glyph: IconName) -> Icon {
22 icon(glyph, MENU_ICON_SIZE, theme::text_muted())
23}
24
25pub fn copy_image_file(path: PathBuf, cx: &mut App) {
15pub fn copy_image_file(path: PathBuf, cx: &mut App) {
26 cx.spawn(async move |cx| {
16 cx.spawn(async move |cx| {
27 let image = cx
17 let image = cx
crates/app/src/views/new_meeting_dialog.rs +2 −1
@@ -176,7 +176,8 @@ impl Render for MeetingForm {
176 176 }),
177 177 )
178 178 })
179 });
179 })
180 .listbox();
180 181 v_flex()
181 182 .debug_selector(|| "new-meeting".into())
182 183 .gap(px(FIELD_GAP))
@@ -176,7 +176,8 @@ impl Render for MeetingForm {
176 }),
176 }),
177 )
177 )
178 })
178 })
179 });
179 })
180 .listbox();
180 v_flex()
181 v_flex()
181 .debug_selector(|| "new-meeting".into())
182 .debug_selector(|| "new-meeting".into())
182 .gap(px(FIELD_GAP))
183 .gap(px(FIELD_GAP))
crates/app/src/views/pin_banner.rs +1 −1
@@ -10,10 +10,10 @@ use super::widgets::icon;
10 10 use crate::theme;
11 11
12 12 const BANNER_HEIGHT: f32 = 40.;
13 const BANNER_INSET: f32 = ROW_PADDING;
14 13 pub const PIN_BANNER_TAG: &str = "shell/islands/main/pin-banner";
15 14 const BANNER_GAP: f32 = 8.;
16 15 const BANNER_PADDING: f32 = 12.;
16 pub const BANNER_INSET: f32 = ROW_PADDING - BANNER_PADDING;
17 17 const BUTTON_SIZE: f32 = 28.;
18 18 const FALLBACK_PREVIEW: &str = "Pinned message";
19 19
@@ -10,10 +10,10 @@ use super::widgets::icon;
10use crate::theme;
10use crate::theme;
11
11
12const BANNER_HEIGHT: f32 = 40.;
12const BANNER_HEIGHT: f32 = 40.;
13const BANNER_INSET: f32 = ROW_PADDING;
14pub const PIN_BANNER_TAG: &str = "shell/islands/main/pin-banner";
13pub const PIN_BANNER_TAG: &str = "shell/islands/main/pin-banner";
15const BANNER_GAP: f32 = 8.;
14const BANNER_GAP: f32 = 8.;
16const BANNER_PADDING: f32 = 12.;
15const BANNER_PADDING: f32 = 12.;
16pub const BANNER_INSET: f32 = ROW_PADDING - BANNER_PADDING;
17const BUTTON_SIZE: f32 = 28.;
17const BUTTON_SIZE: f32 = 28.;
18const FALLBACK_PREVIEW: &str = "Pinned message";
18const FALLBACK_PREVIEW: &str = "Pinned message";
19
19
crates/app/src/views/rail.rs +7 −19
@@ -5,11 +5,10 @@ use gpui_kit::*;
5 5
6 6 use super::shortcuts::keys_for_label;
7 7 use super::sidebar::{SidebarTab, SidebarView};
8 use super::widgets::icon;
8 use super::widgets::{RAIL_BADGE, badge_pill, icon};
9 9 use crate::activity::ActivityCenter;
10 10 use crate::agents::{AgentRuns, runs_handle};
11 11 use crate::app_state::AppState;
12 use crate::format;
13 12 use crate::sidebar_model::{any_unread_channel, unread_chat_count};
14 13 use crate::theme;
15 14 use app_ui_kit::layout::{RAIL_ITEM_WIDTH, RAIL_WIDTH};
@@ -208,23 +207,12 @@ fn badge(badge: RailBadge) -> Option<Div> {
208 207 .size(px(7.))
209 208 .rounded_full()
210 209 .bg(theme::accent()),
211 RailBadge::Count(count) => div()
212 .absolute()
213 .top(px(5.))
214 .left(px(28.))
215 .min_w(px(16.))
216 .h(px(16.))
217 .px(px(4.))
218 .flex()
219 .items_center()
220 .justify_center()
221 .rounded(px(8.))
222 .bg(theme::accent())
223 .text_color(theme::on_accent())
224 .text_size(px(10.))
225 .line_height(px(16.))
226 .font_weight(FontWeight::BOLD)
227 .child(format::badge_text(count)),
210 RailBadge::Count(count) => {
211 badge_pill(count, RAIL_BADGE, theme::accent(), theme::on_accent())
212 .absolute()
213 .top(px(5.))
214 .left(px(28.))
215 }
228 216 })
229 217 }
230 218
@@ -5,11 +5,10 @@ use gpui_kit::*;
5
5
6use super::shortcuts::keys_for_label;
6use super::shortcuts::keys_for_label;
7use super::sidebar::{SidebarTab, SidebarView};
7use super::sidebar::{SidebarTab, SidebarView};
8use super::widgets::icon;
8use super::widgets::{RAIL_BADGE, badge_pill, icon};
9use crate::activity::ActivityCenter;
9use crate::activity::ActivityCenter;
10use crate::agents::{AgentRuns, runs_handle};
10use crate::agents::{AgentRuns, runs_handle};
11use crate::app_state::AppState;
11use crate::app_state::AppState;
12use crate::format;
13use crate::sidebar_model::{any_unread_channel, unread_chat_count};
12use crate::sidebar_model::{any_unread_channel, unread_chat_count};
14use crate::theme;
13use crate::theme;
15use app_ui_kit::layout::{RAIL_ITEM_WIDTH, RAIL_WIDTH};
14use app_ui_kit::layout::{RAIL_ITEM_WIDTH, RAIL_WIDTH};
@@ -208,23 +207,12 @@ fn badge(badge: RailBadge) -> Option<Div> {
208 .size(px(7.))
207 .size(px(7.))
209 .rounded_full()
208 .rounded_full()
210 .bg(theme::accent()),
209 .bg(theme::accent()),
211 RailBadge::Count(count) => div()
210 RailBadge::Count(count) => {
212 .absolute()
211 badge_pill(count, RAIL_BADGE, theme::accent(), theme::on_accent())
213 .top(px(5.))
212 .absolute()
214 .left(px(28.))
213 .top(px(5.))
215 .min_w(px(16.))
214 .left(px(28.))
216 .h(px(16.))
215 }
217 .px(px(4.))
218 .flex()
219 .items_center()
220 .justify_center()
221 .rounded(px(8.))
222 .bg(theme::accent())
223 .text_color(theme::on_accent())
224 .text_size(px(10.))
225 .line_height(px(16.))
226 .font_weight(FontWeight::BOLD)
227 .child(format::badge_text(count)),
228 })
216 })
229}
217}
230
218
crates/app/src/views/shared_tab.rs +1 −6
@@ -14,7 +14,7 @@ use gpui_kit::*;
14 14 use teams_core::{DriveEntry, FileKind};
15 15
16 16 use super::attachments::file_badge;
17 use super::widgets::icon;
17 use super::widgets::{icon, menu_icon};
18 18 use crate::channel_files::{
19 19 LibraryPath, MessageFilter, SharedContent, SharedItem, grouped_items, size_label,
20 20 };
@@ -30,7 +30,6 @@ const MODIFIED_BY_WIDTH: f32 = 160.;
30 30 const SIZE_WIDTH: f32 = 90.;
31 31 const SKELETON_ROWS: usize = 6;
32 32 const NEW_FOLDER_WIDTH: f32 = 220.;
33 const MENU_ICON_SIZE: f32 = 14.;
34 33
35 34 pub const EMPTY_LIBRARY: &str = "No files yet. Upload or drop files here.";
36 35 pub const EMPTY_MESSAGES: &str = "No files or links shared in this channel yet.";
@@ -254,10 +253,6 @@ fn modified_text(entry: &DriveEntry) -> String {
254 253 })
255 254 }
256 255
257 fn menu_icon(glyph: IconName) -> gpui_kit::component::Icon {
258 icon(glyph, MENU_ICON_SIZE, theme::text_muted())
259 }
260
261 256 fn entry_row(
262 257 index: usize,
263 258 entry: &DriveEntry,
@@ -14,7 +14,7 @@ use gpui_kit::*;
14use teams_core::{DriveEntry, FileKind};
14use teams_core::{DriveEntry, FileKind};
15
15
16use super::attachments::file_badge;
16use super::attachments::file_badge;
17use super::widgets::icon;
17use super::widgets::{icon, menu_icon};
18use crate::channel_files::{
18use crate::channel_files::{
19 LibraryPath, MessageFilter, SharedContent, SharedItem, grouped_items, size_label,
19 LibraryPath, MessageFilter, SharedContent, SharedItem, grouped_items, size_label,
20};
20};
@@ -30,7 +30,6 @@ const MODIFIED_BY_WIDTH: f32 = 160.;
30const SIZE_WIDTH: f32 = 90.;
30const SIZE_WIDTH: f32 = 90.;
31const SKELETON_ROWS: usize = 6;
31const SKELETON_ROWS: usize = 6;
32const NEW_FOLDER_WIDTH: f32 = 220.;
32const NEW_FOLDER_WIDTH: f32 = 220.;
33const MENU_ICON_SIZE: f32 = 14.;
34
33
35pub const EMPTY_LIBRARY: &str = "No files yet. Upload or drop files here.";
34pub const EMPTY_LIBRARY: &str = "No files yet. Upload or drop files here.";
36pub const EMPTY_MESSAGES: &str = "No files or links shared in this channel yet.";
35pub const EMPTY_MESSAGES: &str = "No files or links shared in this channel yet.";
@@ -254,10 +253,6 @@ fn modified_text(entry: &DriveEntry) -> String {
254 })
253 })
255}
254}
256
255
257fn menu_icon(glyph: IconName) -> gpui_kit::component::Icon {
258 icon(glyph, MENU_ICON_SIZE, theme::text_muted())
259}
260
261fn entry_row(
256fn entry_row(
262 index: usize,
257 index: usize,
263 entry: &DriveEntry,
258 entry: &DriveEntry,
crates/app/src/views/sidebar.rs +8 −8
@@ -21,7 +21,7 @@ use super::calls_tab::calls_body;
21 21 use super::saved_panel::SavedPanel;
22 22 use super::scroll_edge::with_top_edge;
23 23 use super::section_dialog::{SectionNameTarget, open_section_name_dialog};
24 use super::widgets::{count_badge, icon, page_header, unread_marker};
24 use super::widgets::{count_badge, icon, menu_icon, page_header, unread_marker};
25 25 use crate::agents::AgentsPanel;
26 26 use crate::app_state::{AppEvent, AppState, Selection};
27 27 use crate::channel_menu::{
@@ -67,7 +67,6 @@ const HIDDEN_TEAMS_LABEL: &str = "Hidden teams";
67 67 const TEAM_ROW_HEIGHT: f32 = 40.;
68 68 const REVEAL_ROW_HEIGHT: f32 = 32.;
69 69 const NEW_CHAT_BUTTON_SIZE: f32 = 32.;
70 const MENU_ICON_SIZE: f32 = 15.;
71 70 const NOTIFICATION_ICON_SIZE: f32 = 13.;
72 71 const MENTION_ICON_SIZE: f32 = 15.;
73 72
@@ -94,6 +93,10 @@ impl SidebarTab {
94 93 }
95 94 }
96 95
96 pub fn chat_row_selector(chat_id: &str) -> String {
97 format!("chat-row/{chat_id}")
98 }
99
97 100 #[derive(Clone)]
98 101 struct DraggedChat {
99 102 id: String,
@@ -135,10 +138,6 @@ struct MenuContext {
135 138 folders: Vec<(String, String)>,
136 139 }
137 140
138 fn menu_icon(name: IconName) -> gpui_kit::component::Icon {
139 icon(name, MENU_ICON_SIZE, theme::text_muted())
140 }
141
142 141 fn chat_menu(
143 142 popup: PopupMenu,
144 143 window: &mut Window,
@@ -259,7 +258,7 @@ fn chat_menu(
259 258 PopupMenuItem::element(|_, _| {
260 259 div().text_color(theme::red_soft()).child("Leave chat...")
261 260 })
262 .icon(icon(IconName::LogOut, MENU_ICON_SIZE, theme::red_soft()))
261 .icon(menu_icon(IconName::LogOut).text_color(theme::red_soft()))
263 262 .on_click(move |_, window, cx| {
264 263 confirm_leave(&leave_state, &leave_id, &title, member_count, window, cx);
265 264 }),
@@ -480,7 +479,7 @@ fn section_menu(
480 479 PopupMenuItem::element(|_, _| {
481 480 div().text_color(theme::red_soft()).child("Delete section")
482 481 })
483 .icon(icon(IconName::Trash, MENU_ICON_SIZE, theme::red_soft()))
482 .icon(menu_icon(IconName::Trash).text_color(theme::red_soft()))
484 483 .disabled(target.read_only)
485 484 .on_click(move |_, window, cx| {
486 485 confirm_delete_section(&delete_state, &folder_id, &name, window, cx);
@@ -1193,6 +1192,7 @@ impl SidebarView {
1193 1192 };
1194 1193 h_flex()
1195 1194 .id(SharedString::from(format!("chat-{}", item.id)))
1195 .debug_selector(|| chat_row_selector(&item.id))
1196 1196 .mx(px(6.))
1197 1197 .h(px(ROW_HEIGHT))
1198 1198 .flex_none()
@@ -21,7 +21,7 @@ use super::calls_tab::calls_body;
21use super::saved_panel::SavedPanel;
21use super::saved_panel::SavedPanel;
22use super::scroll_edge::with_top_edge;
22use super::scroll_edge::with_top_edge;
23use super::section_dialog::{SectionNameTarget, open_section_name_dialog};
23use super::section_dialog::{SectionNameTarget, open_section_name_dialog};
24use super::widgets::{count_badge, icon, page_header, unread_marker};
24use super::widgets::{count_badge, icon, menu_icon, page_header, unread_marker};
25use crate::agents::AgentsPanel;
25use crate::agents::AgentsPanel;
26use crate::app_state::{AppEvent, AppState, Selection};
26use crate::app_state::{AppEvent, AppState, Selection};
27use crate::channel_menu::{
27use crate::channel_menu::{
@@ -67,7 +67,6 @@ const HIDDEN_TEAMS_LABEL: &str = "Hidden teams";
67const TEAM_ROW_HEIGHT: f32 = 40.;
67const TEAM_ROW_HEIGHT: f32 = 40.;
68const REVEAL_ROW_HEIGHT: f32 = 32.;
68const REVEAL_ROW_HEIGHT: f32 = 32.;
69const NEW_CHAT_BUTTON_SIZE: f32 = 32.;
69const NEW_CHAT_BUTTON_SIZE: f32 = 32.;
70const MENU_ICON_SIZE: f32 = 15.;
71const NOTIFICATION_ICON_SIZE: f32 = 13.;
70const NOTIFICATION_ICON_SIZE: f32 = 13.;
72const MENTION_ICON_SIZE: f32 = 15.;
71const MENTION_ICON_SIZE: f32 = 15.;
73
72
@@ -94,6 +93,10 @@ impl SidebarTab {
94 }
93 }
95}
94}
96
95
96pub fn chat_row_selector(chat_id: &str) -> String {
97 format!("chat-row/{chat_id}")
98}
99
97#[derive(Clone)]
100#[derive(Clone)]
98struct DraggedChat {
101struct DraggedChat {
99 id: String,
102 id: String,
@@ -135,10 +138,6 @@ struct MenuContext {
135 folders: Vec<(String, String)>,
138 folders: Vec<(String, String)>,
136}
139}
137
140
138fn menu_icon(name: IconName) -> gpui_kit::component::Icon {
139 icon(name, MENU_ICON_SIZE, theme::text_muted())
140}
141
142fn chat_menu(
141fn chat_menu(
143 popup: PopupMenu,
142 popup: PopupMenu,
144 window: &mut Window,
143 window: &mut Window,
@@ -259,7 +258,7 @@ fn chat_menu(
259 PopupMenuItem::element(|_, _| {
258 PopupMenuItem::element(|_, _| {
260 div().text_color(theme::red_soft()).child("Leave chat...")
259 div().text_color(theme::red_soft()).child("Leave chat...")
261 })
260 })
262 .icon(icon(IconName::LogOut, MENU_ICON_SIZE, theme::red_soft()))
261 .icon(menu_icon(IconName::LogOut).text_color(theme::red_soft()))
263 .on_click(move |_, window, cx| {
262 .on_click(move |_, window, cx| {
264 confirm_leave(&leave_state, &leave_id, &title, member_count, window, cx);
263 confirm_leave(&leave_state, &leave_id, &title, member_count, window, cx);
265 }),
264 }),
@@ -480,7 +479,7 @@ fn section_menu(
480 PopupMenuItem::element(|_, _| {
479 PopupMenuItem::element(|_, _| {
481 div().text_color(theme::red_soft()).child("Delete section")
480 div().text_color(theme::red_soft()).child("Delete section")
482 })
481 })
483 .icon(icon(IconName::Trash, MENU_ICON_SIZE, theme::red_soft()))
482 .icon(menu_icon(IconName::Trash).text_color(theme::red_soft()))
484 .disabled(target.read_only)
483 .disabled(target.read_only)
485 .on_click(move |_, window, cx| {
484 .on_click(move |_, window, cx| {
486 confirm_delete_section(&delete_state, &folder_id, &name, window, cx);
485 confirm_delete_section(&delete_state, &folder_id, &name, window, cx);
@@ -1193,6 +1192,7 @@ impl SidebarView {
1193 };
1192 };
1194 h_flex()
1193 h_flex()
1195 .id(SharedString::from(format!("chat-{}", item.id)))
1194 .id(SharedString::from(format!("chat-{}", item.id)))
1195 .debug_selector(|| chat_row_selector(&item.id))
1196 .mx(px(6.))
1196 .mx(px(6.))
1197 .h(px(ROW_HEIGHT))
1197 .h(px(ROW_HEIGHT))
1198 .flex_none()
1198 .flex_none()
crates/app/src/views/status_menu.rs +3 −7
@@ -11,7 +11,7 @@ use gpui_kit::*;
11 11 use teams_core::{ForcedAvailability, ForcedKind, PresenceStatus, WorkLocationKind};
12 12
13 13 use super::avatar::{person_avatar, with_presence, with_presence_badge};
14 use super::widgets::{icon, symbol};
14 use super::widgets::{menu_icon, symbol};
15 15 use crate::app_state::AppState;
16 16 use crate::data::{Person, PresenceKind};
17 17 use crate::own_status::{
@@ -30,7 +30,7 @@ const PRESENCE_OVERHANG: f32 = 2.;
30 30 const TITLE_BUTTON_INSET: f32 = 2.;
31 31 const OWN_STATUS_BUTTON_SIZE: f32 =
32 32 TITLE_AVATAR_SIZE + 2. * (PRESENCE_OVERHANG + TITLE_BUTTON_INSET);
33 const MENU_ICON_SIZE: f32 = 14.;
33 const PRESENCE_ICON_SIZE: f32 = 14.;
34 34 const ICON_COLUMN: f32 = 16.;
35 35 const HEADER_INSET: f32 = 24.;
36 36
@@ -118,11 +118,7 @@ fn status_icon(kind: PresenceKind) -> gpui_kit::component::Icon {
118 118 PresenceKind::Offline => ("status_ring", theme::text_muted()),
119 119 PresenceKind::Unknown => ("status_ring", theme::text_faint()),
120 120 };
121 symbol(name, MENU_ICON_SIZE, color)
122 }
123
124 fn menu_icon(name: IconName) -> gpui_kit::component::Icon {
125 icon(name, MENU_ICON_SIZE, theme::text_muted())
121 symbol(name, PRESENCE_ICON_SIZE, color)
126 122 }
127 123
128 124 fn header(context: &MenuContext, cx: &App) -> Div {
@@ -11,7 +11,7 @@ use gpui_kit::*;
11use teams_core::{ForcedAvailability, ForcedKind, PresenceStatus, WorkLocationKind};
11use teams_core::{ForcedAvailability, ForcedKind, PresenceStatus, WorkLocationKind};
12
12
13use super::avatar::{person_avatar, with_presence, with_presence_badge};
13use super::avatar::{person_avatar, with_presence, with_presence_badge};
14use super::widgets::{icon, symbol};
14use super::widgets::{menu_icon, symbol};
15use crate::app_state::AppState;
15use crate::app_state::AppState;
16use crate::data::{Person, PresenceKind};
16use crate::data::{Person, PresenceKind};
17use crate::own_status::{
17use crate::own_status::{
@@ -30,7 +30,7 @@ const PRESENCE_OVERHANG: f32 = 2.;
30const TITLE_BUTTON_INSET: f32 = 2.;
30const TITLE_BUTTON_INSET: f32 = 2.;
31const OWN_STATUS_BUTTON_SIZE: f32 =
31const OWN_STATUS_BUTTON_SIZE: f32 =
32 TITLE_AVATAR_SIZE + 2. * (PRESENCE_OVERHANG + TITLE_BUTTON_INSET);
32 TITLE_AVATAR_SIZE + 2. * (PRESENCE_OVERHANG + TITLE_BUTTON_INSET);
33const MENU_ICON_SIZE: f32 = 14.;
33const PRESENCE_ICON_SIZE: f32 = 14.;
34const ICON_COLUMN: f32 = 16.;
34const ICON_COLUMN: f32 = 16.;
35const HEADER_INSET: f32 = 24.;
35const HEADER_INSET: f32 = 24.;
36
36
@@ -118,11 +118,7 @@ fn status_icon(kind: PresenceKind) -> gpui_kit::component::Icon {
118 PresenceKind::Offline => ("status_ring", theme::text_muted()),
118 PresenceKind::Offline => ("status_ring", theme::text_muted()),
119 PresenceKind::Unknown => ("status_ring", theme::text_faint()),
119 PresenceKind::Unknown => ("status_ring", theme::text_faint()),
120 };
120 };
121 symbol(name, MENU_ICON_SIZE, color)
121 symbol(name, PRESENCE_ICON_SIZE, color)
122}
123
124fn menu_icon(name: IconName) -> gpui_kit::component::Icon {
125 icon(name, MENU_ICON_SIZE, theme::text_muted())
126}
122}
127
123
128fn header(context: &MenuContext, cx: &App) -> Div {
124fn header(context: &MenuContext, cx: &App) -> Div {
crates/app/src/views/status_message_dialog.rs +2 −1
@@ -206,7 +206,8 @@ impl StatusMessageDialog {
206 206 }),
207 207 )
208 208 })
209 }),
209 })
210 .listbox(),
210 211 )
211 212 }
212 213
@@ -206,7 +206,8 @@ impl StatusMessageDialog {
206 }),
206 }),
207 )
207 )
208 })
208 })
209 }),
209 })
210 .listbox(),
210 )
211 )
211 }
212 }
212
213
vendor/gpui-component/src/button/button.rs +2 −3
@@ -745,9 +745,8 @@ impl RenderOnce for Button {
745 745 .justify_center()
746 746 .button_text_size(self.size)
747 747 .map(|this| match self.size {
748 Size::XSmall => this.gap_1(),
749 Size::Small => this.gap_1(),
750 _ => this.gap_2(),
748 Size::XSmall | Size::Small => this.gap(crate::fluent::BUTTON_ICON_GAP_SMALL),
749 _ => this.gap(crate::fluent::BUTTON_ICON_GAP),
751 750 })
752 751 .refine_style(&self.content_style)
753 752 .when_some(self.icon, |this, icon| {
@@ -745,9 +745,8 @@ impl RenderOnce for Button {
745 .justify_center()
745 .justify_center()
746 .button_text_size(self.size)
746 .button_text_size(self.size)
747 .map(|this| match self.size {
747 .map(|this| match self.size {
748 Size::XSmall => this.gap_1(),
748 Size::XSmall | Size::Small => this.gap(crate::fluent::BUTTON_ICON_GAP_SMALL),
749 Size::Small => this.gap_1(),
749 _ => this.gap(crate::fluent::BUTTON_ICON_GAP),
750 _ => this.gap_2(),
751 })
750 })
752 .refine_style(&self.content_style)
751 .refine_style(&self.content_style)
753 .when_some(self.icon, |this, icon| {
752 .when_some(self.icon, |this, icon| {
vendor/gpui-component/src/fluent.rs added +29 −0
@@ -0,0 +1,29 @@
1 //! Fluent UI v9 metrics as shipped in the Teams web bundle.
2
3 use gpui::{Pixels, px};
4
5 pub const MENU_ITEM_HEIGHT: Pixels = px(32.);
6 pub const MENU_ITEM_PADDING_X: Pixels = px(6.);
7 pub const MENU_ICON_SLOT: Pixels = px(20.);
8 // A Lucide glyph at 18 px covers what a Fluent 20 px regular icon covers.
9 pub const MENU_ICON_GLYPH: Pixels = px(18.);
10 pub const MENU_ICON_GAP: Pixels = px(4.);
11 pub const MENU_LABEL_INSET: Pixels = px(2.);
12 pub const MENU_ICON_LABEL_GAP: Pixels = px(6.);
13 pub const MENU_LIST_PADDING: Pixels = px(4.);
14 pub const MENU_ITEM_GAP: Pixels = px(2.);
15 pub const MENU_DIVIDER_MARGIN_Y: Pixels = px(4.);
16
17 pub const OPTION_CHECK_INSET: Pixels = px(6.);
18 pub const OPTION_PADDING_RIGHT: Pixels = px(8.);
19 pub const OPTION_CHECK_SIZE: Pixels = px(16.);
20 pub const OPTION_CHECK_GAP: Pixels = px(6.);
21 pub const LISTBOX_MIN_WIDTH: Pixels = px(160.);
22 pub const DROPDOWN_OFFSET: Pixels = px(2.);
23
24 pub const BUTTON_ICON_GAP: Pixels = px(6.);
25 pub const BUTTON_ICON_GAP_SMALL: Pixels = px(4.);
26
27 pub const TOAST_ICON_SIZE: Pixels = px(16.);
28 pub const TOAST_ICON_GAP: Pixels = px(8.);
29 pub const TOAST_LINE_HEIGHT: Pixels = px(20.);
@@ -0,0 +1,29 @@
1//! Fluent UI v9 metrics as shipped in the Teams web bundle.
2
3use gpui::{Pixels, px};
4
5pub const MENU_ITEM_HEIGHT: Pixels = px(32.);
6pub const MENU_ITEM_PADDING_X: Pixels = px(6.);
7pub const MENU_ICON_SLOT: Pixels = px(20.);
8// A Lucide glyph at 18 px covers what a Fluent 20 px regular icon covers.
9pub const MENU_ICON_GLYPH: Pixels = px(18.);
10pub const MENU_ICON_GAP: Pixels = px(4.);
11pub const MENU_LABEL_INSET: Pixels = px(2.);
12pub const MENU_ICON_LABEL_GAP: Pixels = px(6.);
13pub const MENU_LIST_PADDING: Pixels = px(4.);
14pub const MENU_ITEM_GAP: Pixels = px(2.);
15pub const MENU_DIVIDER_MARGIN_Y: Pixels = px(4.);
16
17pub const OPTION_CHECK_INSET: Pixels = px(6.);
18pub const OPTION_PADDING_RIGHT: Pixels = px(8.);
19pub const OPTION_CHECK_SIZE: Pixels = px(16.);
20pub const OPTION_CHECK_GAP: Pixels = px(6.);
21pub const LISTBOX_MIN_WIDTH: Pixels = px(160.);
22pub const DROPDOWN_OFFSET: Pixels = px(2.);
23
24pub const BUTTON_ICON_GAP: Pixels = px(6.);
25pub const BUTTON_ICON_GAP_SMALL: Pixels = px(4.);
26
27pub const TOAST_ICON_SIZE: Pixels = px(16.);
28pub const TOAST_ICON_GAP: Pixels = px(8.);
29pub const TOAST_LINE_HEIGHT: Pixels = px(20.);
vendor/gpui-component/src/icon.rs +4 −0
@@ -164,6 +164,10 @@ impl Icon {
164 164 Self::default()
165 165 }
166 166
167 pub(crate) fn has_explicit_size(&self) -> bool {
168 self.size.is_some() || self.style.size.width.is_some() || self.style.size.height.is_some()
169 }
170
167 171 /// Rotate the icon by the given angle
168 172 ///
169 173 /// Replaces any previous transformation or rotation.
@@ -164,6 +164,10 @@ impl Icon {
164 Self::default()
164 Self::default()
165 }
165 }
166
166
167 pub(crate) fn has_explicit_size(&self) -> bool {
168 self.size.is_some() || self.style.size.width.is_some() || self.style.size.height.is_some()
169 }
170
167 /// Rotate the icon by the given angle
171 /// Rotate the icon by the given angle
168 ///
172 ///
169 /// Replaces any previous transformation or rotation.
173 /// Replaces any previous transformation or rotation.
vendor/gpui-component/src/lib.rs +1 −0
@@ -44,6 +44,7 @@ pub mod dialog;
44 44 pub mod dock;
45 45 pub mod elevation;
46 46 pub mod empty;
47 pub mod fluent;
47 48 pub mod form;
48 49 pub mod group_box;
49 50 pub mod highlighter;
@@ -44,6 +44,7 @@ pub mod dialog;
44pub mod dock;
44pub mod dock;
45pub mod elevation;
45pub mod elevation;
46pub mod empty;
46pub mod empty;
47pub mod fluent;
47pub mod form;
48pub mod form;
48pub mod group_box;
49pub mod group_box;
49pub mod highlighter;
50pub mod highlighter;
vendor/gpui-component/src/menu/dropdown_menu.rs +42 −8
@@ -1,12 +1,15 @@
1 use std::cell::Cell;
1 2 use std::rc::Rc;
2 3
3 4 use gpui::{
4 5 Anchor, AnyElement, App, Context, DismissEvent, Element, ElementId, Entity, FocusHandle,
5 6 Focusable, GlobalElementId, InspectorElementId, InteractiveElement, IntoElement, LayoutId,
6 RenderOnce, SharedString, Styled, Window, prelude::FluentBuilder,
7 Pixels, RenderOnce, SharedString, Styled, Window, prelude::FluentBuilder,
7 8 };
8 9
9 use crate::{Selectable, button::Button, menu::PopupMenu, popover::Popover};
10 use crate::{
11 Selectable, button::Button, fluent::DROPDOWN_OFFSET, menu::PopupMenu, popover::Popover,
12 };
10 13
11 14 /// A dropdown menu trait for buttons and other interactive elements
12 15 pub trait DropdownMenu: Styled + Selectable + InteractiveElement + IntoElement + 'static {
@@ -40,6 +43,7 @@ pub struct DropdownMenuPopover<T: Selectable + IntoElement + 'static> {
40 43 builder: Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>,
41 44 on_open_change: Option<Rc<dyn Fn(&bool, &mut Window, &mut App)>>,
42 45 open: Option<bool>,
46 listbox: bool,
43 47 }
44 48
45 49 impl<T> DropdownMenuPopover<T>
@@ -59,6 +63,7 @@ where
59 63 builder: Rc::new(builder),
60 64 on_open_change: None,
61 65 open: None,
66 listbox: false,
62 67 }
63 68 }
64 69
@@ -68,6 +73,13 @@ where
68 73 self
69 74 }
70 75
76 /// Open the menu as a Fluent `Listbox`: left aligned under the trigger,
77 /// 2 px below it and at least as wide, with a check column.
78 pub fn listbox(mut self) -> Self {
79 self.listbox = true;
80 self
81 }
82
71 83 /// Set the anchor corner for the dropdown menu popover.
72 84 pub fn anchor(mut self, anchor: impl Into<Anchor>) -> Self {
73 85 self.anchor = anchor.into();
@@ -91,15 +103,28 @@ struct DropdownMenuState {
91 103 menu: Option<Entity<PopupMenu>>,
92 104 }
93 105
106 #[derive(Default)]
107 struct TriggerWidth(Rc<Cell<Pixels>>);
108
94 109 impl<T> RenderOnce for DropdownMenuPopover<T>
95 110 where
96 111 T: Selectable + IntoElement + 'static,
97 112 {
98 fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
99 TriggerFocus::new(self.id.clone(), move |trigger_focus, window, cx| {
100 self.render_popover(trigger_focus, window, cx)
101 .into_any_element()
102 })
113 fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
114 let width_key = SharedString::from(format!("{}:trigger-width", self.id));
115 let trigger_width = window
116 .use_keyed_state(width_key, cx, |_, _| TriggerWidth::default())
117 .read(cx)
118 .0
119 .clone();
120 TriggerFocus::new(
121 self.id.clone(),
122 trigger_width.clone(),
123 move |trigger_focus, window, cx| {
124 self.render_popover(trigger_focus, trigger_width, window, cx)
125 .into_any_element()
126 },
127 )
103 128 }
104 129 }
105 130
@@ -110,10 +135,12 @@ where
110 135 fn render_popover(
111 136 self,
112 137 trigger_focus: FocusHandle,
138 trigger_width: Rc<Cell<Pixels>>,
113 139 window: &mut Window,
114 140 cx: &mut App,
115 141 ) -> Popover {
116 142 let builder = self.builder.clone();
143 let listbox = self.listbox;
117 144 let menu_state =
118 145 window.use_keyed_state(self.id.clone(), cx, |_, _| DropdownMenuState::default());
119 146
@@ -122,6 +149,7 @@ where
122 149 .overlay_closable(false)
123 150 .trigger(self.trigger)
124 151 .anchor(self.anchor)
152 .when(listbox, |this| this.offset(DROPDOWN_OFFSET))
125 153 .when_some(self.open, |this, open| this.open(open))
126 154 .when_some(self.on_open_change, |this, callback| {
127 155 this.on_open_change(move |open, window, cx| callback(open, window, cx))
@@ -137,7 +165,9 @@ where
137 165 Some(menu) => menu,
138 166 None => {
139 167 let builder = builder.clone();
168 let width = trigger_width.get();
140 169 let menu = PopupMenu::build(window, cx, move |menu, window, cx| {
170 let menu = if listbox { menu.listbox(width) } else { menu };
141 171 builder(menu, window, cx)
142 172 });
143 173 menu.update(cx, |menu, cx| {
@@ -191,6 +221,7 @@ type TriggerFocusBuild = Box<dyn FnOnce(FocusHandle, &mut Window, &mut App) -> A
191 221 /// the menu was not yet.
192 222 struct TriggerFocus {
193 223 id: ElementId,
224 width: Rc<Cell<Pixels>>,
194 225 build: Option<TriggerFocusBuild>,
195 226 }
196 227
@@ -207,10 +238,12 @@ struct TriggerFocusFrame {
207 238 impl TriggerFocus {
208 239 fn new(
209 240 id: ElementId,
241 width: Rc<Cell<Pixels>>,
210 242 build: impl FnOnce(FocusHandle, &mut Window, &mut App) -> AnyElement + 'static,
211 243 ) -> Self {
212 244 Self {
213 245 id,
246 width,
214 247 build: Some(Box::new(build)),
215 248 }
216 249 }
@@ -269,11 +302,12 @@ impl Element for TriggerFocus {
269 302 &mut self,
270 303 _: Option<&GlobalElementId>,
271 304 _: Option<&InspectorElementId>,
272 _: gpui::Bounds<gpui::Pixels>,
305 bounds: gpui::Bounds<gpui::Pixels>,
273 306 frame: &mut Self::RequestLayoutState,
274 307 window: &mut Window,
275 308 cx: &mut App,
276 309 ) {
310 self.width.set(bounds.size.width);
277 311 window.set_focus_handle(&frame.focus_handle, cx);
278 312 frame.child.prepaint(window, cx);
279 313 }
@@ -1,12 +1,15 @@
1use std::cell::Cell;
1use std::rc::Rc;
2use std::rc::Rc;
2
3
3use gpui::{
4use gpui::{
4 Anchor, AnyElement, App, Context, DismissEvent, Element, ElementId, Entity, FocusHandle,
5 Anchor, AnyElement, App, Context, DismissEvent, Element, ElementId, Entity, FocusHandle,
5 Focusable, GlobalElementId, InspectorElementId, InteractiveElement, IntoElement, LayoutId,
6 Focusable, GlobalElementId, InspectorElementId, InteractiveElement, IntoElement, LayoutId,
6 RenderOnce, SharedString, Styled, Window, prelude::FluentBuilder,
7 Pixels, RenderOnce, SharedString, Styled, Window, prelude::FluentBuilder,
7};
8};
8
9
9use crate::{Selectable, button::Button, menu::PopupMenu, popover::Popover};
10use crate::{
11 Selectable, button::Button, fluent::DROPDOWN_OFFSET, menu::PopupMenu, popover::Popover,
12};
10
13
11/// A dropdown menu trait for buttons and other interactive elements
14/// A dropdown menu trait for buttons and other interactive elements
12pub trait DropdownMenu: Styled + Selectable + InteractiveElement + IntoElement + 'static {
15pub trait DropdownMenu: Styled + Selectable + InteractiveElement + IntoElement + 'static {
@@ -40,6 +43,7 @@ pub struct DropdownMenuPopover<T: Selectable + IntoElement + 'static> {
40 builder: Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>,
43 builder: Rc<dyn Fn(PopupMenu, &mut Window, &mut Context<PopupMenu>) -> PopupMenu>,
41 on_open_change: Option<Rc<dyn Fn(&bool, &mut Window, &mut App)>>,
44 on_open_change: Option<Rc<dyn Fn(&bool, &mut Window, &mut App)>>,
42 open: Option<bool>,
45 open: Option<bool>,
46 listbox: bool,
43}
47}
44
48
45impl<T> DropdownMenuPopover<T>
49impl<T> DropdownMenuPopover<T>
@@ -59,6 +63,7 @@ where
59 builder: Rc::new(builder),
63 builder: Rc::new(builder),
60 on_open_change: None,
64 on_open_change: None,
61 open: None,
65 open: None,
66 listbox: false,
62 }
67 }
63 }
68 }
64
69
@@ -68,6 +73,13 @@ where
68 self
73 self
69 }
74 }
70
75
76 /// Open the menu as a Fluent `Listbox`: left aligned under the trigger,
77 /// 2 px below it and at least as wide, with a check column.
78 pub fn listbox(mut self) -> Self {
79 self.listbox = true;
80 self
81 }
82
71 /// Set the anchor corner for the dropdown menu popover.
83 /// Set the anchor corner for the dropdown menu popover.
72 pub fn anchor(mut self, anchor: impl Into<Anchor>) -> Self {
84 pub fn anchor(mut self, anchor: impl Into<Anchor>) -> Self {
73 self.anchor = anchor.into();
85 self.anchor = anchor.into();
@@ -91,15 +103,28 @@ struct DropdownMenuState {
91 menu: Option<Entity<PopupMenu>>,
103 menu: Option<Entity<PopupMenu>>,
92}
104}
93
105
106#[derive(Default)]
107struct TriggerWidth(Rc<Cell<Pixels>>);
108
94impl<T> RenderOnce for DropdownMenuPopover<T>
109impl<T> RenderOnce for DropdownMenuPopover<T>
95where
110where
96 T: Selectable + IntoElement + 'static,
111 T: Selectable + IntoElement + 'static,
97{
112{
98 fn render(self, _: &mut Window, _: &mut App) -> impl IntoElement {
113 fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
99 TriggerFocus::new(self.id.clone(), move |trigger_focus, window, cx| {
114 let width_key = SharedString::from(format!("{}:trigger-width", self.id));
100 self.render_popover(trigger_focus, window, cx)
115 let trigger_width = window
101 .into_any_element()
116 .use_keyed_state(width_key, cx, |_, _| TriggerWidth::default())
102 })
117 .read(cx)
118 .0
119 .clone();
120 TriggerFocus::new(
121 self.id.clone(),
122 trigger_width.clone(),
123 move |trigger_focus, window, cx| {
124 self.render_popover(trigger_focus, trigger_width, window, cx)
125 .into_any_element()
126 },
127 )
103 }
128 }
104}
129}
105
130
@@ -110,10 +135,12 @@ where
110 fn render_popover(
135 fn render_popover(
111 self,
136 self,
112 trigger_focus: FocusHandle,
137 trigger_focus: FocusHandle,
138 trigger_width: Rc<Cell<Pixels>>,
113 window: &mut Window,
139 window: &mut Window,
114 cx: &mut App,
140 cx: &mut App,
115 ) -> Popover {
141 ) -> Popover {
116 let builder = self.builder.clone();
142 let builder = self.builder.clone();
143 let listbox = self.listbox;
117 let menu_state =
144 let menu_state =
118 window.use_keyed_state(self.id.clone(), cx, |_, _| DropdownMenuState::default());
145 window.use_keyed_state(self.id.clone(), cx, |_, _| DropdownMenuState::default());
119
146
@@ -122,6 +149,7 @@ where
122 .overlay_closable(false)
149 .overlay_closable(false)
123 .trigger(self.trigger)
150 .trigger(self.trigger)
124 .anchor(self.anchor)
151 .anchor(self.anchor)
152 .when(listbox, |this| this.offset(DROPDOWN_OFFSET))
125 .when_some(self.open, |this, open| this.open(open))
153 .when_some(self.open, |this, open| this.open(open))
126 .when_some(self.on_open_change, |this, callback| {
154 .when_some(self.on_open_change, |this, callback| {
127 this.on_open_change(move |open, window, cx| callback(open, window, cx))
155 this.on_open_change(move |open, window, cx| callback(open, window, cx))
@@ -137,7 +165,9 @@ where
137 Some(menu) => menu,
165 Some(menu) => menu,
138 None => {
166 None => {
139 let builder = builder.clone();
167 let builder = builder.clone();
168 let width = trigger_width.get();
140 let menu = PopupMenu::build(window, cx, move |menu, window, cx| {
169 let menu = PopupMenu::build(window, cx, move |menu, window, cx| {
170 let menu = if listbox { menu.listbox(width) } else { menu };
141 builder(menu, window, cx)
171 builder(menu, window, cx)
142 });
172 });
143 menu.update(cx, |menu, cx| {
173 menu.update(cx, |menu, cx| {
@@ -191,6 +221,7 @@ type TriggerFocusBuild = Box<dyn FnOnce(FocusHandle, &mut Window, &mut App) -> A
191/// the menu was not yet.
221/// the menu was not yet.
192struct TriggerFocus {
222struct TriggerFocus {
193 id: ElementId,
223 id: ElementId,
224 width: Rc<Cell<Pixels>>,
194 build: Option<TriggerFocusBuild>,
225 build: Option<TriggerFocusBuild>,
195}
226}
196
227
@@ -207,10 +238,12 @@ struct TriggerFocusFrame {
207impl TriggerFocus {
238impl TriggerFocus {
208 fn new(
239 fn new(
209 id: ElementId,
240 id: ElementId,
241 width: Rc<Cell<Pixels>>,
210 build: impl FnOnce(FocusHandle, &mut Window, &mut App) -> AnyElement + 'static,
242 build: impl FnOnce(FocusHandle, &mut Window, &mut App) -> AnyElement + 'static,
211 ) -> Self {
243 ) -> Self {
212 Self {
244 Self {
213 id,
245 id,
246 width,
214 build: Some(Box::new(build)),
247 build: Some(Box::new(build)),
215 }
248 }
216 }
249 }
@@ -269,11 +302,12 @@ impl Element for TriggerFocus {
269 &mut self,
302 &mut self,
270 _: Option<&GlobalElementId>,
303 _: Option<&GlobalElementId>,
271 _: Option<&InspectorElementId>,
304 _: Option<&InspectorElementId>,
272 _: gpui::Bounds<gpui::Pixels>,
305 bounds: gpui::Bounds<gpui::Pixels>,
273 frame: &mut Self::RequestLayoutState,
306 frame: &mut Self::RequestLayoutState,
274 window: &mut Window,
307 window: &mut Window,
275 cx: &mut App,
308 cx: &mut App,
276 ) {
309 ) {
310 self.width.set(bounds.size.width);
277 window.set_focus_handle(&frame.focus_handle, cx);
311 window.set_focus_handle(&frame.focus_handle, cx);
278 frame.child.prepaint(window, cx);
312 frame.child.prepaint(window, cx);
279 }
313 }
vendor/gpui-component/src/menu/menu_item.rs +10 −0
@@ -11,6 +11,7 @@ use smallvec::SmallVec;
11 11 pub(crate) struct MenuItemElement {
12 12 id: ElementId,
13 13 aria_label: Option<SharedString>,
14 debug_selector: Option<Box<dyn FnOnce() -> String>>,
14 15 style: StyleRefinement,
15 16 disabled: bool,
16 17 selected: bool,
@@ -26,6 +27,7 @@ impl MenuItemElement {
26 27 Self {
27 28 id: id.clone(),
28 29 aria_label: None,
30 debug_selector: None,
29 31 style: StyleRefinement::default(),
30 32 disabled: false,
31 33 selected: false,
@@ -47,6 +49,11 @@ impl MenuItemElement {
47 49 self
48 50 }
49 51
52 pub(crate) fn debug_selector(mut self, selector: impl FnOnce() -> String + 'static) -> Self {
53 self.debug_selector = Some(Box::new(selector));
54 self
55 }
56
50 57 /// Set the disabled state of the MenuItem.
51 58 pub(crate) fn disabled(mut self, disabled: bool) -> Self {
52 59 self.disabled = disabled;
@@ -97,6 +104,9 @@ impl RenderOnce for MenuItemElement {
97 104 .test_support()
98 105 .role(Role::MenuItem)
99 106 .when_some(self.aria_label, |this, label| this.aria_label(label))
107 .when_some(self.debug_selector, |this, selector| {
108 this.debug_selector(selector)
109 })
100 110 .aria_selected(self.selected)
101 111 .gap_x_1()
102 112 .py_1()
@@ -11,6 +11,7 @@ use smallvec::SmallVec;
11pub(crate) struct MenuItemElement {
11pub(crate) struct MenuItemElement {
12 id: ElementId,
12 id: ElementId,
13 aria_label: Option<SharedString>,
13 aria_label: Option<SharedString>,
14 debug_selector: Option<Box<dyn FnOnce() -> String>>,
14 style: StyleRefinement,
15 style: StyleRefinement,
15 disabled: bool,
16 disabled: bool,
16 selected: bool,
17 selected: bool,
@@ -26,6 +27,7 @@ impl MenuItemElement {
26 Self {
27 Self {
27 id: id.clone(),
28 id: id.clone(),
28 aria_label: None,
29 aria_label: None,
30 debug_selector: None,
29 style: StyleRefinement::default(),
31 style: StyleRefinement::default(),
30 disabled: false,
32 disabled: false,
31 selected: false,
33 selected: false,
@@ -47,6 +49,11 @@ impl MenuItemElement {
47 self
49 self
48 }
50 }
49
51
52 pub(crate) fn debug_selector(mut self, selector: impl FnOnce() -> String + 'static) -> Self {
53 self.debug_selector = Some(Box::new(selector));
54 self
55 }
56
50 /// Set the disabled state of the MenuItem.
57 /// Set the disabled state of the MenuItem.
51 pub(crate) fn disabled(mut self, disabled: bool) -> Self {
58 pub(crate) fn disabled(mut self, disabled: bool) -> Self {
52 self.disabled = disabled;
59 self.disabled = disabled;
@@ -97,6 +104,9 @@ impl RenderOnce for MenuItemElement {
97 .test_support()
104 .test_support()
98 .role(Role::MenuItem)
105 .role(Role::MenuItem)
99 .when_some(self.aria_label, |this, label| this.aria_label(label))
106 .when_some(self.aria_label, |this, label| this.aria_label(label))
107 .when_some(self.debug_selector, |this, selector| {
108 this.debug_selector(selector)
109 })
100 .aria_selected(self.selected)
110 .aria_selected(self.selected)
101 .gap_x_1()
111 .gap_x_1()
102 .py_1()
112 .py_1()
vendor/gpui-component/src/menu/mod.rs +1 −0
@@ -5,6 +5,7 @@ mod context_menu;
5 5 mod dropdown_menu;
6 6 mod menu_item;
7 7 mod popup_menu;
8 pub mod selectors;
8 9
9 10 pub use app_menu_bar::AppMenuBar;
10 11 pub use context_menu::{ContextMenu, ContextMenuExt, ContextMenuState};
@@ -5,6 +5,7 @@ mod context_menu;
5mod dropdown_menu;
5mod dropdown_menu;
6mod menu_item;
6mod menu_item;
7mod popup_menu;
7mod popup_menu;
8pub mod selectors;
8
9
9pub use app_menu_bar::AppMenuBar;
10pub use app_menu_bar::AppMenuBar;
10pub use context_menu::{ContextMenu, ContextMenuExt, ContextMenuState};
11pub use context_menu::{ContextMenu, ContextMenuExt, ContextMenuState};
vendor/gpui-component/src/menu/popup_menu.rs +101 −30
@@ -1,7 +1,13 @@
1 1 use crate::ThemeStyled as _;
2 2 use crate::actions::{Cancel, Confirm, SelectDown, SelectUp};
3 3 use crate::actions::{SelectLeft, SelectRight};
4 use crate::fluent::{
5 LISTBOX_MIN_WIDTH, MENU_DIVIDER_MARGIN_Y, MENU_ICON_GAP, MENU_ICON_GLYPH, MENU_ICON_SLOT,
6 MENU_ITEM_GAP, MENU_ITEM_HEIGHT, MENU_ITEM_PADDING_X, MENU_LABEL_INSET, MENU_LIST_PADDING,
7 OPTION_CHECK_GAP, OPTION_CHECK_INSET, OPTION_CHECK_SIZE, OPTION_PADDING_RIGHT,
8 };
4 9 use crate::menu::menu_item::MenuItemElement;
10 use crate::menu::selectors::{ITEMS_SELECTOR, icon_selector, item_selector, label_selector};
5 11 use crate::scroll::ScrollableElement;
6 12 use crate::{ActiveTheme, ElementExt, Icon, IconName, Sizable as _, h_flex, v_flex};
7 13 use crate::{Side, Size, kbd::Kbd};
@@ -300,6 +306,7 @@ pub struct PopupMenu {
300 306 bounds: Bounds<Pixels>,
301 307 size: Size,
302 308 check_side: Side,
309 listbox: bool,
303 310
304 311 /// The parent menu of this menu, if this is a submenu
305 312 parent_menu: Option<WeakEntity<Self>>,
@@ -344,6 +351,7 @@ impl PopupMenu {
344 351 max_width: None,
345 352 max_height: None,
346 353 check_side: Side::Left,
354 listbox: false,
347 355 bounds: Bounds::default(),
348 356 scrollable: false,
349 357 scroll_handle: ScrollHandle::default(),
@@ -449,6 +457,15 @@ impl PopupMenu {
449 457 self
450 458 }
451 459
460 /// Lay the menu out as a Fluent `Listbox` under a select trigger: a check
461 /// column on every row and at least the trigger's width.
462 pub fn listbox(mut self, trigger_width: Pixels) -> Self {
463 self.listbox = true;
464 self.check_side = Side::Left;
465 self.min_width = Some(trigger_width.max(LISTBOX_MIN_WIDTH));
466 self
467 }
468
452 469 /// Set the side to show check icon, default is `Side::Left`.
453 470 pub fn check_side(mut self, side: Side) -> Self {
454 471 self.check_side = side;
@@ -1151,25 +1168,37 @@ impl PopupMenu {
1151 1168 }
1152 1169
1153 1170 fn render_icon(
1171 index: usize,
1154 1172 has_icon: bool,
1155 1173 checked: bool,
1156 1174 icon: Option<Icon>,
1157 _: &mut Window,
1158 _: &mut Context<Self>,
1175 listbox: bool,
1159 1176 ) -> Option<impl IntoElement> {
1160 1177 if !has_icon {
1161 1178 return None;
1162 1179 }
1163 1180
1164 let icon = if let Some(icon) = icon {
1165 icon.clone()
1166 } else if checked {
1167 Icon::new(IconName::Check)
1181 let (slot, glyph) = if listbox {
1182 (OPTION_CHECK_SIZE, OPTION_CHECK_SIZE)
1168 1183 } else {
1169 Icon::empty()
1184 (MENU_ICON_SLOT, MENU_ICON_GLYPH)
1185 };
1186 let icon = match icon {
1187 Some(icon) if icon.has_explicit_size() => icon,
1188 Some(icon) => icon.with_size(glyph),
1189 None if checked => Icon::new(IconName::Check).with_size(glyph),
1190 None => Icon::empty().with_size(glyph),
1170 1191 };
1171 1192
1172 Some(icon.xsmall())
1193 Some(
1194 h_flex()
1195 .debug_selector(|| icon_selector(index))
1196 .size(slot)
1197 .flex_none()
1198 .items_center()
1199 .justify_center()
1200 .child(icon),
1201 )
1173 1202 }
1174 1203
1175 1204 #[inline]
@@ -1203,7 +1232,7 @@ impl PopupMenu {
1203 1232 window: &mut Window,
1204 1233 cx: &mut Context<Self>,
1205 1234 ) -> MenuItemElement {
1206 let has_left_icon = options.has_left_icon;
1235 let has_left_icon = options.has_left_icon || self.listbox;
1207 1236 let is_left_check = options.check_side.is_left() && item.is_checked();
1208 1237 let right_check_icon = if options.check_side.is_right() && item.is_checked() {
1209 1238 Some(Icon::new(IconName::Check).xsmall())
@@ -1213,20 +1242,37 @@ impl PopupMenu {
1213 1242
1214 1243 let selected = self.selected_index == Some(ix);
1215 1244 const EDGE_PADDING: Pixels = px(4.);
1216 const INNER_PADDING: Pixels = px(8.);
1245 let listbox = self.listbox;
1246 let (padding_left, padding_right, icon_gap, label_inset) = if listbox {
1247 (
1248 OPTION_CHECK_INSET,
1249 OPTION_PADDING_RIGHT,
1250 OPTION_CHECK_GAP,
1251 px(0.),
1252 )
1253 } else {
1254 (
1255 MENU_ITEM_PADDING_X,
1256 MENU_ITEM_PADDING_X,
1257 MENU_ICON_GAP,
1258 MENU_LABEL_INSET,
1259 )
1260 };
1217 1261
1218 1262 let is_submenu = matches!(item, PopupMenuItem::Submenu { .. });
1219 1263
1220 1264 let (item_height, radius) = match self.size {
1221 1265 Size::Small => (px(20.), options.radius.half()),
1222 _ => (px(26.), options.radius),
1266 _ => (MENU_ITEM_HEIGHT, options.radius),
1223 1267 };
1224 1268
1225 1269 let this = MenuItemElement::new(ix)
1270 .debug_selector(move || item_selector(ix))
1226 1271 .relative()
1227 1272 .text_sm()
1228 1273 .py_0()
1229 .px(INNER_PADDING)
1274 .pl(padding_left)
1275 .pr(padding_right)
1230 1276 .rounded(radius)
1231 1277 .items_center()
1232 1278 .selected(selected)
@@ -1251,7 +1297,7 @@ impl PopupMenu {
1251 1297 PopupMenuItem::Separator => this
1252 1298 .h_auto()
1253 1299 .p_0()
1254 .my_0p5()
1300 .my(MENU_DIVIDER_MARGIN_Y)
1255 1301 .mx_neg_1()
1256 1302 .border_b(px(1.))
1257 1303 .border_color(cx.theme().tokens.sidebar_accent)
@@ -1260,9 +1306,15 @@ impl PopupMenu {
1260 1306 h_flex()
1261 1307 .cursor_default()
1262 1308 .items_center()
1263 .gap_x_1()
1264 .children(Self::render_icon(has_left_icon, false, None, window, cx))
1265 .child(div().flex_1().child(label.clone())),
1309 .gap(icon_gap)
1310 .children(Self::render_icon(ix, has_left_icon, false, None, listbox))
1311 .child(
1312 div().flex_1().px(label_inset).child(
1313 div()
1314 .debug_selector(|| label_selector(ix))
1315 .child(label.clone()),
1316 ),
1317 ),
1266 1318 ),
1267 1319 PopupMenuItem::ElementItem {
1268 1320 render,
@@ -1281,15 +1333,21 @@ impl PopupMenu {
1281 1333 .flex_1()
1282 1334 .min_h(item_height)
1283 1335 .items_center()
1284 .gap_x_1()
1336 .gap(icon_gap)
1285 1337 .children(Self::render_icon(
1338 ix,
1286 1339 has_left_icon,
1287 1340 is_left_check,
1288 1341 icon.clone(),
1289 window,
1290 cx,
1342 listbox,
1291 1343 ))
1292 .child((render)(window, cx))
1344 .child(
1345 div().flex_1().min_w_0().px(label_inset).child(
1346 div()
1347 .debug_selector(|| label_selector(ix))
1348 .child((render)(window, cx)),
1349 ),
1350 )
1293 1351 .children(right_check_icon.map(|icon| icon.ml_3())),
1294 1352 ),
1295 1353 PopupMenuItem::Item {
@@ -1311,21 +1369,28 @@ impl PopupMenu {
1311 1369 })
1312 1370 .disabled(*disabled)
1313 1371 .h(item_height)
1314 .gap_x_1()
1372 .gap(icon_gap)
1315 1373 .children(Self::render_icon(
1374 ix,
1316 1375 has_left_icon,
1317 1376 is_left_check,
1318 1377 icon.clone(),
1319 window,
1320 cx,
1378 listbox,
1321 1379 ))
1322 1380 .child(
1323 1381 h_flex()
1324 1382 .w_full()
1383 .px(label_inset)
1325 1384 .gap_3()
1326 1385 .items_center()
1327 1386 .justify_between()
1328 .when(!show_link_icon, |this| this.child(label.clone()))
1387 .when(!show_link_icon, |this| {
1388 this.child(
1389 div()
1390 .debug_selector(|| label_selector(ix))
1391 .child(label.clone()),
1392 )
1393 })
1329 1394 .children(right_check_icon)
1330 1395 .when(show_link_icon, |this| {
1331 1396 this.child(
@@ -1358,21 +1423,26 @@ impl PopupMenu {
1358 1423 .min_h(item_height)
1359 1424 .size_full()
1360 1425 .items_center()
1361 .gap_x_1()
1426 .gap(icon_gap)
1362 1427 .children(Self::render_icon(
1428 ix,
1363 1429 has_left_icon,
1364 1430 false,
1365 1431 icon.clone(),
1366 window,
1367 cx,
1432 listbox,
1368 1433 ))
1369 1434 .child(
1370 1435 h_flex()
1371 1436 .flex_1()
1437 .px(label_inset)
1372 1438 .gap_2()
1373 1439 .items_center()
1374 1440 .justify_between()
1375 .child(label.clone())
1441 .child(
1442 div()
1443 .debug_selector(|| label_selector(ix))
1444 .child(label.clone()),
1445 )
1376 1446 .child(
1377 1447 Icon::new(IconName::ChevronRight)
1378 1448 .xsmall()
@@ -1485,8 +1555,9 @@ impl Render for PopupMenu {
1485 1555 .child(
1486 1556 v_flex()
1487 1557 .id("items")
1488 .p_1()
1489 .gap_y_0p5()
1558 .debug_selector(|| ITEMS_SELECTOR.into())
1559 .p(MENU_LIST_PADDING)
1560 .gap_y(MENU_ITEM_GAP)
1490 1561 .min_w(rems(8.))
1491 1562 .when_some(self.min_width, |this, min_width| this.min_w(min_width))
1492 1563 .max_w(max_width)
@@ -1,7 +1,13 @@
1use crate::ThemeStyled as _;
1use crate::ThemeStyled as _;
2use crate::actions::{Cancel, Confirm, SelectDown, SelectUp};
2use crate::actions::{Cancel, Confirm, SelectDown, SelectUp};
3use crate::actions::{SelectLeft, SelectRight};
3use crate::actions::{SelectLeft, SelectRight};
4use crate::fluent::{
5 LISTBOX_MIN_WIDTH, MENU_DIVIDER_MARGIN_Y, MENU_ICON_GAP, MENU_ICON_GLYPH, MENU_ICON_SLOT,
6 MENU_ITEM_GAP, MENU_ITEM_HEIGHT, MENU_ITEM_PADDING_X, MENU_LABEL_INSET, MENU_LIST_PADDING,
7 OPTION_CHECK_GAP, OPTION_CHECK_INSET, OPTION_CHECK_SIZE, OPTION_PADDING_RIGHT,
8};
4use crate::menu::menu_item::MenuItemElement;
9use crate::menu::menu_item::MenuItemElement;
10use crate::menu::selectors::{ITEMS_SELECTOR, icon_selector, item_selector, label_selector};
5use crate::scroll::ScrollableElement;
11use crate::scroll::ScrollableElement;
6use crate::{ActiveTheme, ElementExt, Icon, IconName, Sizable as _, h_flex, v_flex};
12use crate::{ActiveTheme, ElementExt, Icon, IconName, Sizable as _, h_flex, v_flex};
7use crate::{Side, Size, kbd::Kbd};
13use crate::{Side, Size, kbd::Kbd};
@@ -300,6 +306,7 @@ pub struct PopupMenu {
300 bounds: Bounds<Pixels>,
306 bounds: Bounds<Pixels>,
301 size: Size,
307 size: Size,
302 check_side: Side,
308 check_side: Side,
309 listbox: bool,
303
310
304 /// The parent menu of this menu, if this is a submenu
311 /// The parent menu of this menu, if this is a submenu
305 parent_menu: Option<WeakEntity<Self>>,
312 parent_menu: Option<WeakEntity<Self>>,
@@ -344,6 +351,7 @@ impl PopupMenu {
344 max_width: None,
351 max_width: None,
345 max_height: None,
352 max_height: None,
346 check_side: Side::Left,
353 check_side: Side::Left,
354 listbox: false,
347 bounds: Bounds::default(),
355 bounds: Bounds::default(),
348 scrollable: false,
356 scrollable: false,
349 scroll_handle: ScrollHandle::default(),
357 scroll_handle: ScrollHandle::default(),
@@ -449,6 +457,15 @@ impl PopupMenu {
449 self
457 self
450 }
458 }
451
459
460 /// Lay the menu out as a Fluent `Listbox` under a select trigger: a check
461 /// column on every row and at least the trigger's width.
462 pub fn listbox(mut self, trigger_width: Pixels) -> Self {
463 self.listbox = true;
464 self.check_side = Side::Left;
465 self.min_width = Some(trigger_width.max(LISTBOX_MIN_WIDTH));
466 self
467 }
468
452 /// Set the side to show check icon, default is `Side::Left`.
469 /// Set the side to show check icon, default is `Side::Left`.
453 pub fn check_side(mut self, side: Side) -> Self {
470 pub fn check_side(mut self, side: Side) -> Self {
454 self.check_side = side;
471 self.check_side = side;
@@ -1151,25 +1168,37 @@ impl PopupMenu {
1151 }
1168 }
1152
1169
1153 fn render_icon(
1170 fn render_icon(
1171 index: usize,
1154 has_icon: bool,
1172 has_icon: bool,
1155 checked: bool,
1173 checked: bool,
1156 icon: Option<Icon>,
1174 icon: Option<Icon>,
1157 _: &mut Window,
1175 listbox: bool,
1158 _: &mut Context<Self>,
1159 ) -> Option<impl IntoElement> {
1176 ) -> Option<impl IntoElement> {
1160 if !has_icon {
1177 if !has_icon {
1161 return None;
1178 return None;
1162 }
1179 }
1163
1180
1164 let icon = if let Some(icon) = icon {
1181 let (slot, glyph) = if listbox {
1165 icon.clone()
1182 (OPTION_CHECK_SIZE, OPTION_CHECK_SIZE)
1166 } else if checked {
1167 Icon::new(IconName::Check)
1168 } else {
1183 } else {
1169 Icon::empty()
1184 (MENU_ICON_SLOT, MENU_ICON_GLYPH)
1185 };
1186 let icon = match icon {
1187 Some(icon) if icon.has_explicit_size() => icon,
1188 Some(icon) => icon.with_size(glyph),
1189 None if checked => Icon::new(IconName::Check).with_size(glyph),
1190 None => Icon::empty().with_size(glyph),
1170 };
1191 };
1171
1192
1172 Some(icon.xsmall())
1193 Some(
1194 h_flex()
1195 .debug_selector(|| icon_selector(index))
1196 .size(slot)
1197 .flex_none()
1198 .items_center()
1199 .justify_center()
1200 .child(icon),
1201 )
1173 }
1202 }
1174
1203
1175 #[inline]
1204 #[inline]
@@ -1203,7 +1232,7 @@ impl PopupMenu {
1203 window: &mut Window,
1232 window: &mut Window,
1204 cx: &mut Context<Self>,
1233 cx: &mut Context<Self>,
1205 ) -> MenuItemElement {
1234 ) -> MenuItemElement {
1206 let has_left_icon = options.has_left_icon;
1235 let has_left_icon = options.has_left_icon || self.listbox;
1207 let is_left_check = options.check_side.is_left() && item.is_checked();
1236 let is_left_check = options.check_side.is_left() && item.is_checked();
1208 let right_check_icon = if options.check_side.is_right() && item.is_checked() {
1237 let right_check_icon = if options.check_side.is_right() && item.is_checked() {
1209 Some(Icon::new(IconName::Check).xsmall())
1238 Some(Icon::new(IconName::Check).xsmall())
@@ -1213,20 +1242,37 @@ impl PopupMenu {
1213
1242
1214 let selected = self.selected_index == Some(ix);
1243 let selected = self.selected_index == Some(ix);
1215 const EDGE_PADDING: Pixels = px(4.);
1244 const EDGE_PADDING: Pixels = px(4.);
1216 const INNER_PADDING: Pixels = px(8.);
1245 let listbox = self.listbox;
1246 let (padding_left, padding_right, icon_gap, label_inset) = if listbox {
1247 (
1248 OPTION_CHECK_INSET,
1249 OPTION_PADDING_RIGHT,
1250 OPTION_CHECK_GAP,
1251 px(0.),
1252 )
1253 } else {
1254 (
1255 MENU_ITEM_PADDING_X,
1256 MENU_ITEM_PADDING_X,
1257 MENU_ICON_GAP,
1258 MENU_LABEL_INSET,
1259 )
1260 };
1217
1261
1218 let is_submenu = matches!(item, PopupMenuItem::Submenu { .. });
1262 let is_submenu = matches!(item, PopupMenuItem::Submenu { .. });
1219
1263
1220 let (item_height, radius) = match self.size {
1264 let (item_height, radius) = match self.size {
1221 Size::Small => (px(20.), options.radius.half()),
1265 Size::Small => (px(20.), options.radius.half()),
1222 _ => (px(26.), options.radius),
1266 _ => (MENU_ITEM_HEIGHT, options.radius),
1223 };
1267 };
1224
1268
1225 let this = MenuItemElement::new(ix)
1269 let this = MenuItemElement::new(ix)
1270 .debug_selector(move || item_selector(ix))
1226 .relative()
1271 .relative()
1227 .text_sm()
1272 .text_sm()
1228 .py_0()
1273 .py_0()
1229 .px(INNER_PADDING)
1274 .pl(padding_left)
1275 .pr(padding_right)
1230 .rounded(radius)
1276 .rounded(radius)
1231 .items_center()
1277 .items_center()
1232 .selected(selected)
1278 .selected(selected)
@@ -1251,7 +1297,7 @@ impl PopupMenu {
1251 PopupMenuItem::Separator => this
1297 PopupMenuItem::Separator => this
1252 .h_auto()
1298 .h_auto()
1253 .p_0()
1299 .p_0()
1254 .my_0p5()
1300 .my(MENU_DIVIDER_MARGIN_Y)
1255 .mx_neg_1()
1301 .mx_neg_1()
1256 .border_b(px(1.))
1302 .border_b(px(1.))
1257 .border_color(cx.theme().tokens.sidebar_accent)
1303 .border_color(cx.theme().tokens.sidebar_accent)
@@ -1260,9 +1306,15 @@ impl PopupMenu {
1260 h_flex()
1306 h_flex()
1261 .cursor_default()
1307 .cursor_default()
1262 .items_center()
1308 .items_center()
1263 .gap_x_1()
1309 .gap(icon_gap)
1264 .children(Self::render_icon(has_left_icon, false, None, window, cx))
1310 .children(Self::render_icon(ix, has_left_icon, false, None, listbox))
1265 .child(div().flex_1().child(label.clone())),
1311 .child(
1312 div().flex_1().px(label_inset).child(
1313 div()
1314 .debug_selector(|| label_selector(ix))
1315 .child(label.clone()),
1316 ),
1317 ),
1266 ),
1318 ),
1267 PopupMenuItem::ElementItem {
1319 PopupMenuItem::ElementItem {
1268 render,
1320 render,
@@ -1281,15 +1333,21 @@ impl PopupMenu {
1281 .flex_1()
1333 .flex_1()
1282 .min_h(item_height)
1334 .min_h(item_height)
1283 .items_center()
1335 .items_center()
1284 .gap_x_1()
1336 .gap(icon_gap)
1285 .children(Self::render_icon(
1337 .children(Self::render_icon(
1338 ix,
1286 has_left_icon,
1339 has_left_icon,
1287 is_left_check,
1340 is_left_check,
1288 icon.clone(),
1341 icon.clone(),
1289 window,
1342 listbox,
1290 cx,
1291 ))
1343 ))
1292 .child((render)(window, cx))
1344 .child(
1345 div().flex_1().min_w_0().px(label_inset).child(
1346 div()
1347 .debug_selector(|| label_selector(ix))
1348 .child((render)(window, cx)),
1349 ),
1350 )
1293 .children(right_check_icon.map(|icon| icon.ml_3())),
1351 .children(right_check_icon.map(|icon| icon.ml_3())),
1294 ),
1352 ),
1295 PopupMenuItem::Item {
1353 PopupMenuItem::Item {
@@ -1311,21 +1369,28 @@ impl PopupMenu {
1311 })
1369 })
1312 .disabled(*disabled)
1370 .disabled(*disabled)
1313 .h(item_height)
1371 .h(item_height)
1314 .gap_x_1()
1372 .gap(icon_gap)
1315 .children(Self::render_icon(
1373 .children(Self::render_icon(
1374 ix,
1316 has_left_icon,
1375 has_left_icon,
1317 is_left_check,
1376 is_left_check,
1318 icon.clone(),
1377 icon.clone(),
1319 window,
1378 listbox,
1320 cx,
1321 ))
1379 ))
1322 .child(
1380 .child(
1323 h_flex()
1381 h_flex()
1324 .w_full()
1382 .w_full()
1383 .px(label_inset)
1325 .gap_3()
1384 .gap_3()
1326 .items_center()
1385 .items_center()
1327 .justify_between()
1386 .justify_between()
1328 .when(!show_link_icon, |this| this.child(label.clone()))
1387 .when(!show_link_icon, |this| {
1388 this.child(
1389 div()
1390 .debug_selector(|| label_selector(ix))
1391 .child(label.clone()),
1392 )
1393 })
1329 .children(right_check_icon)
1394 .children(right_check_icon)
1330 .when(show_link_icon, |this| {
1395 .when(show_link_icon, |this| {
1331 this.child(
1396 this.child(
@@ -1358,21 +1423,26 @@ impl PopupMenu {
1358 .min_h(item_height)
1423 .min_h(item_height)
1359 .size_full()
1424 .size_full()
1360 .items_center()
1425 .items_center()
1361 .gap_x_1()
1426 .gap(icon_gap)
1362 .children(Self::render_icon(
1427 .children(Self::render_icon(
1428 ix,
1363 has_left_icon,
1429 has_left_icon,
1364 false,
1430 false,
1365 icon.clone(),
1431 icon.clone(),
1366 window,
1432 listbox,
1367 cx,
1368 ))
1433 ))
1369 .child(
1434 .child(
1370 h_flex()
1435 h_flex()
1371 .flex_1()
1436 .flex_1()
1437 .px(label_inset)
1372 .gap_2()
1438 .gap_2()
1373 .items_center()
1439 .items_center()
1374 .justify_between()
1440 .justify_between()
1375 .child(label.clone())
1441 .child(
1442 div()
1443 .debug_selector(|| label_selector(ix))
1444 .child(label.clone()),
1445 )
1376 .child(
1446 .child(
1377 Icon::new(IconName::ChevronRight)
1447 Icon::new(IconName::ChevronRight)
1378 .xsmall()
1448 .xsmall()
@@ -1485,8 +1555,9 @@ impl Render for PopupMenu {
1485 .child(
1555 .child(
1486 v_flex()
1556 v_flex()
1487 .id("items")
1557 .id("items")
1488 .p_1()
1558 .debug_selector(|| ITEMS_SELECTOR.into())
1489 .gap_y_0p5()
1559 .p(MENU_LIST_PADDING)
1560 .gap_y(MENU_ITEM_GAP)
1490 .min_w(rems(8.))
1561 .min_w(rems(8.))
1491 .when_some(self.min_width, |this, min_width| this.min_w(min_width))
1562 .when_some(self.min_width, |this, min_width| this.min_w(min_width))
1492 .max_w(max_width)
1563 .max_w(max_width)
vendor/gpui-component/src/menu/selectors.rs added +13 −0
@@ -0,0 +1,13 @@
1 pub const ITEMS_SELECTOR: &str = "popup-menu/items";
2
3 pub fn item_selector(index: usize) -> String {
4 format!("popup-menu/item-{index}")
5 }
6
7 pub fn icon_selector(index: usize) -> String {
8 format!("popup-menu/item-{index}/icon")
9 }
10
11 pub fn label_selector(index: usize) -> String {
12 format!("popup-menu/item-{index}/label")
13 }
@@ -0,0 +1,13 @@
1pub const ITEMS_SELECTOR: &str = "popup-menu/items";
2
3pub fn item_selector(index: usize) -> String {
4 format!("popup-menu/item-{index}")
5}
6
7pub fn icon_selector(index: usize) -> String {
8 format!("popup-menu/item-{index}/icon")
9}
10
11pub fn label_selector(index: usize) -> String {
12 format!("popup-menu/item-{index}/label")
13}
vendor/gpui-component/src/notification.rs +17 −4
@@ -19,6 +19,7 @@ use gpui_base::{
19 19 ToastTransitionStatus,
20 20 };
21 21
22 use crate::fluent::{TOAST_ICON_GAP, TOAST_ICON_SIZE, TOAST_LINE_HEIGHT};
22 23 use crate::{
23 24 ActiveTheme as _, Edges, Icon, IconName, Sizable as _, StyledExt, TITLE_BAR_HEIGHT,
24 25 animation::cubic_bezier,
@@ -30,6 +31,8 @@ const NOTIFICATION_TRANSITION_DURATION: Duration = Duration::from_millis(400);
30 31 const NOTIFICATION_EXIT_DURATION: Duration = Duration::from_millis(200);
31 32 const NOTIFICATION_TRANSITION_OFFSET: Pixels = px(96.);
32 33 const DEFAULT_NOTIFICATION_WIDTH: Pixels = px(382.);
34 const TOAST_PADDING_X: Pixels = px(16.);
35 const TOAST_PADDING_Y: Pixels = px(14.);
33 36 const NOTIFICATION_ADVANCE_INTERVAL: Duration = Duration::from_millis(50);
34 37 struct DismissRequest;
35 38
@@ -432,18 +435,28 @@ impl Render for Notification {
432 435 .bg(toast_elevation.fill)
433 436 .rounded(cx.theme().radius_lg)
434 437 .shadow(resting_shadow)
435 .py_3p5()
436 .px_4()
438 .py(TOAST_PADDING_Y)
439 .px(TOAST_PADDING_X)
437 440 .gap_3()
438 441 .refine_style(&self.style)
439 442 .when_some(icon, |this, icon| {
440 this.child(div().absolute().top(px(18.)).left_4().child(icon))
443 this.child(
444 div()
445 .absolute()
446 .top(TOAST_PADDING_Y)
447 .left(TOAST_PADDING_X)
448 .h(TOAST_LINE_HEIGHT)
449 .flex()
450 .items_center()
451 .child(icon.with_size(TOAST_ICON_SIZE)),
452 )
441 453 })
442 454 .child(
443 455 v_flex()
444 456 .flex_1()
445 457 .overflow_hidden()
446 .when(has_icon, |this| this.pl_6())
458 .line_height(TOAST_LINE_HEIGHT)
459 .when(has_icon, |this| this.pl(TOAST_ICON_SIZE + TOAST_ICON_GAP))
447 460 .when_some(self.title.clone(), |this, title| {
448 461 this.child(div().text_sm().font_semibold().child(title))
449 462 })
@@ -19,6 +19,7 @@ use gpui_base::{
19 ToastTransitionStatus,
19 ToastTransitionStatus,
20};
20};
21
21
22use crate::fluent::{TOAST_ICON_GAP, TOAST_ICON_SIZE, TOAST_LINE_HEIGHT};
22use crate::{
23use crate::{
23 ActiveTheme as _, Edges, Icon, IconName, Sizable as _, StyledExt, TITLE_BAR_HEIGHT,
24 ActiveTheme as _, Edges, Icon, IconName, Sizable as _, StyledExt, TITLE_BAR_HEIGHT,
24 animation::cubic_bezier,
25 animation::cubic_bezier,
@@ -30,6 +31,8 @@ const NOTIFICATION_TRANSITION_DURATION: Duration = Duration::from_millis(400);
30const NOTIFICATION_EXIT_DURATION: Duration = Duration::from_millis(200);
31const NOTIFICATION_EXIT_DURATION: Duration = Duration::from_millis(200);
31const NOTIFICATION_TRANSITION_OFFSET: Pixels = px(96.);
32const NOTIFICATION_TRANSITION_OFFSET: Pixels = px(96.);
32const DEFAULT_NOTIFICATION_WIDTH: Pixels = px(382.);
33const DEFAULT_NOTIFICATION_WIDTH: Pixels = px(382.);
34const TOAST_PADDING_X: Pixels = px(16.);
35const TOAST_PADDING_Y: Pixels = px(14.);
33const NOTIFICATION_ADVANCE_INTERVAL: Duration = Duration::from_millis(50);
36const NOTIFICATION_ADVANCE_INTERVAL: Duration = Duration::from_millis(50);
34struct DismissRequest;
37struct DismissRequest;
35
38
@@ -432,18 +435,28 @@ impl Render for Notification {
432 .bg(toast_elevation.fill)
435 .bg(toast_elevation.fill)
433 .rounded(cx.theme().radius_lg)
436 .rounded(cx.theme().radius_lg)
434 .shadow(resting_shadow)
437 .shadow(resting_shadow)
435 .py_3p5()
438 .py(TOAST_PADDING_Y)
436 .px_4()
439 .px(TOAST_PADDING_X)
437 .gap_3()
440 .gap_3()
438 .refine_style(&self.style)
441 .refine_style(&self.style)
439 .when_some(icon, |this, icon| {
442 .when_some(icon, |this, icon| {
440 this.child(div().absolute().top(px(18.)).left_4().child(icon))
443 this.child(
444 div()
445 .absolute()
446 .top(TOAST_PADDING_Y)
447 .left(TOAST_PADDING_X)
448 .h(TOAST_LINE_HEIGHT)
449 .flex()
450 .items_center()
451 .child(icon.with_size(TOAST_ICON_SIZE)),
452 )
441 })
453 })
442 .child(
454 .child(
443 v_flex()
455 v_flex()
444 .flex_1()
456 .flex_1()
445 .overflow_hidden()
457 .overflow_hidden()
446 .when(has_icon, |this| this.pl_6())
458 .line_height(TOAST_LINE_HEIGHT)
459 .when(has_icon, |this| this.pl(TOAST_ICON_SIZE + TOAST_ICON_GAP))
447 .when_some(self.title.clone(), |this, title| {
460 .when_some(self.title.clone(), |this, title| {
448 this.child(div().text_sm().font_semibold().child(title))
461 this.child(div().text_sm().font_semibold().child(title))
449 })
462 })
vendor/gpui-component/src/popover.rs +1 −1
@@ -36,7 +36,7 @@ fn dropdown_positioner(bounds: Bounds<Pixels>) -> gpui_base::Positioner {
36 36 gpui_base::Positioner::side(bounds)
37 37 .placement(gpui_base::Placement::Bottom)
38 38 .align(gpui_base::Align::Start)
39 .offset(px(6.))
39 .offset(crate::fluent::DROPDOWN_OFFSET)
40 40 .margin(px(8.))
41 41 }
42 42
@@ -36,7 +36,7 @@ fn dropdown_positioner(bounds: Bounds<Pixels>) -> gpui_base::Positioner {
36 gpui_base::Positioner::side(bounds)
36 gpui_base::Positioner::side(bounds)
37 .placement(gpui_base::Placement::Bottom)
37 .placement(gpui_base::Placement::Bottom)
38 .align(gpui_base::Align::Start)
38 .align(gpui_base::Align::Start)
39 .offset(px(6.))
39 .offset(crate::fluent::DROPDOWN_OFFSET)
40 .margin(px(8.))
40 .margin(px(8.))
41}
41}
42
42