Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: fit GPUI menus and library content within windows

Richie McIlroy462619fa1b08
diff --git a/apps/desktop-gpui/src/main_window.rs b/apps/desktop-gpui/src/main_window.rs
index a152d16be..c63a19dec 100644
--- a/apps/desktop-gpui/src/main_window.rs
+++ b/apps/desktop-gpui/src/main_window.rs
@@ -3562,25 +3562,35 @@ impl MainWindow {
)
.child(
div()
- .id("panel-body")
.flex()
.flex_col()
.flex_1()
.min_h_0()
.pt(px(16.))
- .px(px(8.))
- .gap(px(8.))
- .overflow_y_scroll()
- .child(match panel {
- Panel::Device(menu) => self.render_device_list(menu, cx).into_any_element(),
- Panel::Target(target) => {
- self.render_target_grid(target, cx).into_any_element()
- }
- Panel::ModeInfo => self.render_mode_info(cx).into_any_element(),
- Panel::Library(kind) => {
- self.render_library_grid(kind, cx).into_any_element()
- }
- }),
+ .overflow_hidden()
+ .child(
+ div()
+ .id("panel-body")
+ .flex()
+ .flex_col()
+ .flex_1()
+ .min_h_0()
+ .px(px(8.))
+ .gap(px(8.))
+ .overflow_y_scroll()
+ .child(match panel {
+ Panel::Device(menu) => {
+ self.render_device_list(menu, cx).into_any_element()
+ }
+ Panel::Target(target) => {
+ self.render_target_grid(target, cx).into_any_element()
+ }
+ Panel::ModeInfo => self.render_mode_info(cx).into_any_element(),
+ Panel::Library(kind) => {
+ self.render_library_grid(kind, cx).into_any_element()
+ }
+ }),
+ ),
)
}
diff --git a/apps/desktop-gpui/src/settings_window.rs b/apps/desktop-gpui/src/settings_window.rs
index 3b801c2dc..3f6a072c1 100644
--- a/apps/desktop-gpui/src/settings_window.rs
+++ b/apps/desktop-gpui/src/settings_window.rs
@@ -2287,7 +2287,7 @@ impl SettingsWindow {
div()
.w_full()
.truncate()
- .text_size(px(16.))
+ .text_size(px(14.))
.child(item.pretty_name.clone()),
);
@@ -2587,14 +2587,10 @@ impl SettingsWindow {
.gap(px(8.))
.min_w_0()
.child(
- // A bare `<span>`: no text class, so the 16px document
- // default. Truncated rather than allowed to push the
- // buttons off a window that cannot be widened past its
- // own content.
div()
.w_full()
.truncate()
- .text_size(px(16.))
+ .text_size(px(14.))
.child(item.pretty_name.clone()),
)
.child(self.render_recording_badges(item)),
diff --git a/apps/desktop-gpui/src/ui/menu.rs b/apps/desktop-gpui/src/ui/menu.rs
index 9423283e4..c18c7552d 100644
--- a/apps/desktop-gpui/src/ui/menu.rs
+++ b/apps/desktop-gpui/src/ui/menu.rs
@@ -160,6 +160,8 @@ impl Menu {
items: Vec<MenuItem>,
state: &MenuState,
) -> Self {
+ let mut bg = theme.settings_card_bg();
+ bg.a = 1.;
Self {
id: id.into(),
items,
@@ -167,7 +169,7 @@ impl Menu {
highlighted: state.visible_highlight(),
min_width: px(180.),
max_height: px(320.),
- bg: theme.settings_card_bg(),
+ bg,
border: theme.settings_border(),
hover: theme.settings_hover(),
text: theme.settings_text(),
@@ -213,7 +215,7 @@ impl Menu {
}
impl RenderOnce for Menu {
- fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
+ fn render(self, window: &mut Window, _cx: &mut App) -> impl IntoElement {
let Menu {
id,
items,
@@ -234,6 +236,9 @@ impl RenderOnce for Menu {
other => SharedString::from(format!("{other:?}")),
};
let handler: Option<std::rc::Rc<SelectHandler>> = on_select.map(std::rc::Rc::new);
+ let viewport = window.viewport_size();
+ let max_width = (viewport.width - px(24.)).max(px(0.));
+ let max_height = max_height.min((viewport.height - px(24.)).max(px(0.)));
div()
.absolute()
@@ -253,47 +258,56 @@ impl RenderOnce for Menu {
}),
)
.child(
- div()
- .id(id)
- .absolute()
- .left(origin.x)
- .top(origin.y)
- .flex()
- .flex_col()
- .min_w(min_width)
- .max_h(max_height)
- .overflow_y_scroll()
- .p(px(4.))
- .rounded(px(8.))
- .border_1()
- .border_color(border)
- .bg(bg)
- .text_color(text)
- .text_size(px(12.))
- .children(items.into_iter().enumerate().map(|(index, item)| {
- let handler = handler.clone();
+ gpui::anchored()
+ .position(origin)
+ .snap_to_window_with_margin(px(12.))
+ .child(
div()
- .id(SharedString::from(format!("{prefix}-item-{index}")))
+ .id(id)
+ .occlude()
.flex()
- .flex_row()
- .items_center()
- .gap(px(6.))
- .h(px(24.))
- .px(px(6.))
- .rounded(px(4.))
- // The keyboard highlight paints the same fill the
- // pointer does -- `data-highlighted:bg-gray-3` is
- // one rule in Kobalte, driven by either input.
- .when(highlighted == Some(index), |this| this.bg(hover))
- .hover(move |style| style.bg(hover))
- .child(div().w(px(12.)).flex_shrink_0().children(item.checked.then(
- || svg().path("icons/check.svg").size(px(12.)).text_color(text),
- )))
- .child(div().flex_1().min_w_0().truncate().child(item.label))
- .when_some(handler, |this, handler| {
- this.on_click(move |_, window, cx| handler(&index, window, cx))
- })
- })),
+ .flex_col()
+ .min_w(min_width.min(max_width))
+ .max_w(max_width)
+ .max_h(max_height)
+ .overflow_y_scroll()
+ .p(px(4.))
+ .rounded(px(8.))
+ .border_1()
+ .border_color(border)
+ .bg(bg)
+ .text_color(text)
+ .text_size(px(12.))
+ .children(items.into_iter().enumerate().map(|(index, item)| {
+ let handler = handler.clone();
+ div()
+ .id(SharedString::from(format!("{prefix}-item-{index}")))
+ .flex()
+ .flex_row()
+ .flex_shrink_0()
+ .items_center()
+ .gap(px(6.))
+ .h(px(24.))
+ .px(px(6.))
+ .rounded(px(4.))
+ .when(highlighted == Some(index), |this| this.bg(hover))
+ .hover(move |style| style.bg(hover))
+ .child(div().w(px(12.)).flex_shrink_0().children(
+ item.checked.then(|| {
+ svg()
+ .path("icons/check.svg")
+ .size(px(12.))
+ .text_color(text)
+ }),
+ ))
+ .child(div().flex_1().min_w_0().truncate().child(item.label))
+ .when_some(handler, |this, handler| {
+ this.on_click(move |_, window, cx| {
+ handler(&index, window, cx)
+ })
+ })
+ })),
+ ),
)
}
}