Fix dropdown selected icon.

This commit is contained in:
Jason Lee 2024-06-30 19:17:52 +08:00
parent 6503e00b69
commit 29dc803014
2 changed files with 17 additions and 20 deletions

View file

@ -85,36 +85,32 @@ impl ParentElement for ListItem {
impl RenderOnce for ListItem { impl RenderOnce for ListItem {
fn render(self, cx: &mut WindowContext) -> impl IntoElement { fn render(self, cx: &mut WindowContext) -> impl IntoElement {
div() h_flex()
.id("item-group") .id("list-item")
.w_full()
.relative() .relative()
.gap_x_2() .gap_x_2()
.items_center()
.justify_between()
.text_base() .text_base()
.text_color(cx.theme().foreground) .text_color(cx.theme().foreground)
.when_some(self.on_click, |this, on_click| { .when_some(self.on_click, |this, on_click| {
this.cursor_pointer().on_click(on_click) this.cursor_pointer().on_click(on_click)
}) })
.when(self.selected, |this| this.bg(cx.theme().accent))
.when(!self.selected, |this| {
this.hover(|this| this.bg(cx.theme().accent))
})
// Right click // Right click
.when_some(self.on_secondary_mouse_down, |this, on_mouse_down| { .when_some(self.on_secondary_mouse_down, |this, on_mouse_down| {
this.on_mouse_down(MouseButton::Right, move |ev, cx| (on_mouse_down)(ev, cx)) this.on_mouse_down(MouseButton::Right, move |ev, cx| (on_mouse_down)(ev, cx))
}) })
.when(self.selected, |this| this.bg(cx.theme().accent)) .child(self.base.w_full())
.child( .when(self.selected, |this| {
self.base if let Some(icon) = self.check_icon {
.when(!self.selected, |this| { this.child(icon.text_color(cx.theme().muted_foreground).mr_2())
this.hover(|this| this.bg(cx.theme().accent)) } else {
}) this
.w_full() }
.items_center() })
.justify_between()
.when(self.selected, |this| {
if let Some(icon) = self.check_icon {
this.child(icon.text_color(cx.theme().muted))
} else {
this
}
}),
)
} }
} }

View file

@ -508,6 +508,7 @@ impl<D: PickerDelegate> Render for Picker<D> {
el.child( el.child(
v_flex() v_flex()
.flex_grow() .flex_grow()
.min_h(px(100.))
.when_some(self.max_height, |div, max_h| div.max_h(max_h)) .when_some(self.max_height, |div, max_h| div.max_h(max_h))
.overflow_hidden() .overflow_hidden()
.child(self.render_element_container(cx)), .child(self.render_element_container(cx)),