Merge remote-tracking branch 'origin/main' into feat/chat-settings
@@ -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>) -> imp132
)132
)133
})133
})134
})134
})135
.listbox()135
}136
}136
137
137
pub fn link_dropdown(138
pub fn link_dropdown(@@ -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
26
pub fn menu_icon(name: IconName) -> Icon {27
Icon::new(name)28
}29
26
pub fn symbol(name: &str, size: f32, color: Hsla) -> Icon {30
pub 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
47
pub fn count_badge(count: u32, muted: bool) -> Div {51
#[derive(Clone, Copy)]48
let (background, foreground) = if muted {52
pub 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
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
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)]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_system138
.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
pub fn page_header(title: &str) -> Div {160
pub fn page_header(title: &str) -> Div {@@ -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: visual1520
.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
found1559
}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
found1626
}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 = visual1686
.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> = found1715
.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 = visual1738
.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 = visual1816
.debug_bounds(Box::leak(badge_selector(&text).into_boxed_str()))1817
.expect("badge rendered");1818
let label = visual1819
.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_size1823
} else {1824
COUNT_BADGE.font_size1825
};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> = found1830
.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 gaps1862
if (side - BANNER_INSET).abs() > INSET_TOLERANCE1511
.iter()1863
|| gaps1512
.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
}@@ -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;16
pub use dialog::{SettingsDialog, SettingsDialogEvent};16
pub use dialog::{SettingsDialog, SettingsDialogEvent};17
#[cfg(test)]17
#[cfg(test)]18
pub use nav::{item_selector, label, label_selector};18
pub use nav::{item_selector, label, label_selector};19
pub(crate) use rows::switch;19
pub(crate) use rows::{select_selector, switch};@@ -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
165
pub fn select_selector(id: &str) -> String {166
format!("settings-select/{id}")167
}168
165
pub fn select(169
pub 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
}@@ -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;13
use super::new_meeting_dialog::open_new_meeting;13
use super::new_meeting_dialog::open_new_meeting;14
use super::scroll_edge::with_top_edge;14
use super::scroll_edge::with_top_edge;15
use super::sidebar::SIDEBAR_SCROLL_DIVIDER;15
use super::sidebar::SIDEBAR_SCROLL_DIVIDER;16
use super::widgets::icon;16
use super::widgets::{icon, menu_icon};17
use crate::app_state::AppState;17
use crate::app_state::AppState;18
use crate::call::{18
use 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.;25
const VIEWPORT_MARGIN: f32 = 300.;25
const VIEWPORT_MARGIN: f32 = 300.;26
const TIME_COLUMN_WIDTH: f32 = 96.;26
const TIME_COLUMN_WIDTH: f32 = 96.;27
const AVATAR_SIZE: f32 = 36.;27
const AVATAR_SIZE: f32 = 36.;28
const MENU_ICON_SIZE: f32 = 15.;29
28
30
fn meeting_avatar() -> Div {29
fn 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)@@ -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))@@ -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;10
use crate::theme;10
use crate::theme;11
11
12
const BANNER_HEIGHT: f32 = 40.;12
const BANNER_HEIGHT: f32 = 40.;13
const BANNER_INSET: f32 = ROW_PADDING;14
pub const PIN_BANNER_TAG: &str = "shell/islands/main/pin-banner";13
pub const PIN_BANNER_TAG: &str = "shell/islands/main/pin-banner";15
const BANNER_GAP: f32 = 8.;14
const BANNER_GAP: f32 = 8.;16
const BANNER_PADDING: f32 = 12.;15
const BANNER_PADDING: f32 = 12.;16
pub const BANNER_INSET: f32 = ROW_PADDING - BANNER_PADDING;17
const BUTTON_SIZE: f32 = 28.;17
const BUTTON_SIZE: f32 = 28.;18
const FALLBACK_PREVIEW: &str = "Pinned message";18
const FALLBACK_PREVIEW: &str = "Pinned message";19
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
6
use super::shortcuts::keys_for_label;6
use super::shortcuts::keys_for_label;7
use super::sidebar::{SidebarTab, SidebarView};7
use super::sidebar::{SidebarTab, SidebarView};8
use super::widgets::icon;8
use super::widgets::{RAIL_BADGE, badge_pill, icon};9
use crate::activity::ActivityCenter;9
use crate::activity::ActivityCenter;10
use crate::agents::{AgentRuns, runs_handle};10
use crate::agents::{AgentRuns, runs_handle};11
use crate::app_state::AppState;11
use crate::app_state::AppState;12
use crate::format;13
use crate::sidebar_model::{any_unread_channel, unread_chat_count};12
use crate::sidebar_model::{any_unread_channel, unread_chat_count};14
use crate::theme;13
use crate::theme;15
use app_ui_kit::layout::{RAIL_ITEM_WIDTH, RAIL_WIDTH};14
use 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
@@ -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;21
use super::saved_panel::SavedPanel;21
use super::saved_panel::SavedPanel;22
use super::scroll_edge::with_top_edge;22
use super::scroll_edge::with_top_edge;23
use super::section_dialog::{SectionNameTarget, open_section_name_dialog};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
use crate::agents::AgentsPanel;25
use crate::agents::AgentsPanel;26
use crate::app_state::{AppEvent, AppState, Selection};26
use crate::app_state::{AppEvent, AppState, Selection};27
use crate::channel_menu::{27
use crate::channel_menu::{@@ -67,7 +67,6 @@ const HIDDEN_TEAMS_LABEL: &str = "Hidden teams";67
const TEAM_ROW_HEIGHT: f32 = 40.;67
const TEAM_ROW_HEIGHT: f32 = 40.;68
const REVEAL_ROW_HEIGHT: f32 = 32.;68
const REVEAL_ROW_HEIGHT: f32 = 32.;69
const NEW_CHAT_BUTTON_SIZE: f32 = 32.;69
const NEW_CHAT_BUTTON_SIZE: f32 = 32.;70
const MENU_ICON_SIZE: f32 = 15.;71
const NOTIFICATION_ICON_SIZE: f32 = 13.;70
const NOTIFICATION_ICON_SIZE: f32 = 13.;72
const MENTION_ICON_SIZE: f32 = 15.;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
#[derive(Clone)]100
#[derive(Clone)]98
struct DraggedChat {101
struct 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
138
fn menu_icon(name: IconName) -> gpui_kit::component::Icon {139
icon(name, MENU_ICON_SIZE, theme::text_muted())140
}141
142
fn chat_menu(141
fn 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()@@ -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
@@ -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| {@@ -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
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.);@@ -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 angle171
/// Rotate the icon by the given angle168
///172
///169
/// Replaces any previous transformation or rotation.173
/// Replaces any previous transformation or rotation.@@ -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;44
pub mod dock;44
pub mod dock;45
pub mod elevation;45
pub mod elevation;46
pub mod empty;46
pub mod empty;47
pub mod fluent;47
pub mod form;48
pub mod form;48
pub mod group_box;49
pub mod group_box;49
pub mod highlighter;50
pub mod highlighter;@@ -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
22
use crate::fluent::{TOAST_ICON_GAP, TOAST_ICON_SIZE, TOAST_LINE_HEIGHT};22
use crate::{23
use 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);30
const NOTIFICATION_EXIT_DURATION: Duration = Duration::from_millis(200);31
const NOTIFICATION_EXIT_DURATION: Duration = Duration::from_millis(200);31
const NOTIFICATION_TRANSITION_OFFSET: Pixels = px(96.);32
const NOTIFICATION_TRANSITION_OFFSET: Pixels = px(96.);32
const DEFAULT_NOTIFICATION_WIDTH: Pixels = px(382.);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
const NOTIFICATION_ADVANCE_INTERVAL: Duration = Duration::from_millis(50);36
const NOTIFICATION_ADVANCE_INTERVAL: Duration = Duration::from_millis(50);34
struct DismissRequest;37
struct 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
})@@ -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