debugger: Tidy up dropdown menus (#30679)

Before
![CleanShot 2025-05-14 at 13 22
44@2x](https://github.com/user-attachments/assets/c6c06c5c-571d-4913-a691-161f44bba27c)

After
![CleanShot 2025-05-14 at 13 22
17@2x](https://github.com/user-attachments/assets/0a25a053-81a3-4b96-8963-4b770b1e5b45)

Release Notes:

- N/A
This commit is contained in:
Nate Butler 2025-05-14 13:32:51 +02:00 committed by GitHub
parent 4280bff10a
commit dce6e96c16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 329 additions and 169 deletions

View file

@ -1,7 +1,14 @@
use gpui::{ClickEvent, Corner, CursorStyle, Entity, MouseButton};
use gpui::{ClickEvent, Corner, CursorStyle, Entity, Hsla, MouseButton};
use crate::{ContextMenu, PopoverMenu, prelude::*};
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
pub enum DropdownStyle {
#[default]
Solid,
Ghost,
}
enum LabelKind {
Text(SharedString),
Element(AnyElement),
@ -11,6 +18,7 @@ enum LabelKind {
pub struct DropdownMenu {
id: ElementId,
label: LabelKind,
style: DropdownStyle,
menu: Entity<ContextMenu>,
full_width: bool,
disabled: bool,
@ -25,6 +33,7 @@ impl DropdownMenu {
Self {
id: id.into(),
label: LabelKind::Text(label.into()),
style: DropdownStyle::default(),
menu,
full_width: false,
disabled: false,
@ -39,12 +48,18 @@ impl DropdownMenu {
Self {
id: id.into(),
label: LabelKind::Element(label),
style: DropdownStyle::default(),
menu,
full_width: false,
disabled: false,
}
}
pub fn style(mut self, style: DropdownStyle) -> Self {
self.style = style;
self
}
pub fn full_width(mut self, full_width: bool) -> Self {
self.full_width = full_width;
self
@ -66,7 +81,8 @@ impl RenderOnce for DropdownMenu {
.trigger(
DropdownMenuTrigger::new(self.label)
.full_width(self.full_width)
.disabled(self.disabled),
.disabled(self.disabled)
.style(self.style),
)
.attach(Corner::BottomLeft)
}
@ -135,12 +151,35 @@ impl Component for DropdownMenu {
}
}
#[derive(Debug, Clone, Copy)]
pub struct DropdownTriggerStyle {
pub bg: Hsla,
}
impl DropdownTriggerStyle {
pub fn for_style(style: DropdownStyle, cx: &App) -> Self {
let colors = cx.theme().colors();
if style == DropdownStyle::Solid {
Self {
// why is this editor_background?
bg: colors.editor_background,
}
} else {
Self {
bg: colors.ghost_element_background,
}
}
}
}
#[derive(IntoElement)]
struct DropdownMenuTrigger {
label: LabelKind,
full_width: bool,
selected: bool,
disabled: bool,
style: DropdownStyle,
cursor_style: CursorStyle,
on_click: Option<Box<dyn Fn(&ClickEvent, &mut Window, &mut App) + 'static>>,
}
@ -152,6 +191,7 @@ impl DropdownMenuTrigger {
full_width: false,
selected: false,
disabled: false,
style: DropdownStyle::default(),
cursor_style: CursorStyle::default(),
on_click: None,
}
@ -161,6 +201,11 @@ impl DropdownMenuTrigger {
self.full_width = full_width;
self
}
pub fn style(mut self, style: DropdownStyle) -> Self {
self.style = style;
self
}
}
impl Disableable for DropdownMenuTrigger {
@ -193,11 +238,13 @@ impl RenderOnce for DropdownMenuTrigger {
fn render(self, _window: &mut Window, cx: &mut App) -> impl IntoElement {
let disabled = self.disabled;
let style = DropdownTriggerStyle::for_style(self.style, cx);
h_flex()
.id("dropdown-menu-trigger")
.justify_between()
.rounded_sm()
.bg(cx.theme().colors().editor_background)
.bg(style.bg)
.pl_2()
.pr_1p5()
.py_0p5()