Fix ListItem check icon.
This commit is contained in:
parent
cb8067d89b
commit
daf4e713d1
4 changed files with 33 additions and 22 deletions
|
|
@ -10,6 +10,7 @@ use crate::{
|
||||||
selectable::{Selectable, Selection},
|
selectable::{Selectable, Selection},
|
||||||
stock::{h_flex, v_flex},
|
stock::{h_flex, v_flex},
|
||||||
theme::{ActiveTheme, Colorize as _},
|
theme::{ActiveTheme, Colorize as _},
|
||||||
|
IconName,
|
||||||
};
|
};
|
||||||
|
|
||||||
type OnClick = Box<dyn Fn(&Selection, &mut WindowContext) + 'static>;
|
type OnClick = Box<dyn Fn(&Selection, &mut WindowContext) + 'static>;
|
||||||
|
|
@ -114,8 +115,8 @@ impl RenderOnce for Checkbox {
|
||||||
.size_3()
|
.size_3()
|
||||||
.text_color(icon_color)
|
.text_color(icon_color)
|
||||||
.map(|this| match self.checked {
|
.map(|this| match self.checked {
|
||||||
Selection::Selected => this.path("icons/check.svg"),
|
Selection::Selected => this.path(IconName::Check.path()),
|
||||||
Selection::Indeterminate => this.path("icons/minus.svg"),
|
Selection::Indeterminate => this.path(IconName::Minus.path()),
|
||||||
_ => this,
|
_ => this,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -184,10 +184,11 @@ where
|
||||||
}))
|
}))
|
||||||
.child(
|
.child(
|
||||||
h_flex()
|
h_flex()
|
||||||
|
.w_full()
|
||||||
.items_center()
|
.items_center()
|
||||||
.justify_between()
|
.justify_between()
|
||||||
.child(title)
|
.child(div().flex_1().child(title))
|
||||||
.child(IconName::ChevronDown),
|
.child(div().w_4().h_4().child(IconName::ChevronDown)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.when(self.open, |this| {
|
.when(self.open, |this| {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
use gpui::{svg, IntoElement, RenderOnce, SharedString, Styled as _, Svg, WindowContext};
|
use gpui::{svg, IntoElement, RenderOnce, SharedString, Styled, Svg, WindowContext};
|
||||||
|
|
||||||
|
use crate::theme::ActiveTheme;
|
||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub enum IconName {
|
pub enum IconName {
|
||||||
|
|
@ -38,10 +40,16 @@ pub struct Icon {
|
||||||
path: SharedString,
|
path: SharedString,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Styled for Icon {
|
||||||
|
fn style(&mut self) -> &mut gpui::StyleRefinement {
|
||||||
|
self.base.style()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Icon {
|
impl Icon {
|
||||||
pub fn new(name: IconName) -> Self {
|
pub fn new(name: IconName) -> Self {
|
||||||
Self {
|
Self {
|
||||||
base: svg().flex_none().size_full(),
|
base: svg().flex_none().size_4(),
|
||||||
path: name.path(),
|
path: name.path(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -56,7 +64,7 @@ impl Icon {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderOnce for Icon {
|
impl RenderOnce for Icon {
|
||||||
fn render(self, _cx: &mut WindowContext) -> impl IntoElement {
|
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||||
self.base.path(self.path)
|
self.base.text_color(cx.theme().foreground).path(self.path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use gpui::{
|
use gpui::{
|
||||||
div, prelude::FluentBuilder as _, ClickEvent, Div, ElementId, InteractiveElement, IntoElement,
|
div, prelude::FluentBuilder as _, AnyElement, ClickEvent, Div, ElementId, InteractiveElement,
|
||||||
MouseButton, MouseDownEvent, ParentElement, RenderOnce, SharedString, Stateful,
|
IntoElement, MouseButton, MouseDownEvent, ParentElement, RenderOnce, SharedString, Stateful,
|
||||||
StatefulInteractiveElement as _, Style, Styled, WindowContext,
|
StatefulInteractiveElement as _, Style, Styled, WindowContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -11,7 +11,7 @@ pub struct ListItem {
|
||||||
base: Stateful<Div>,
|
base: Stateful<Div>,
|
||||||
disabled: bool,
|
disabled: bool,
|
||||||
selected: bool,
|
selected: bool,
|
||||||
check_icon: Option<IconName>,
|
check_icon: Option<Icon>,
|
||||||
on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||||
on_secondary_mouse_down: Option<Box<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
on_secondary_mouse_down: Option<Box<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
||||||
}
|
}
|
||||||
|
|
@ -29,7 +29,7 @@ impl ListItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_icon(mut self, icon: IconName) -> Self {
|
pub fn check_icon(mut self, icon: IconName) -> Self {
|
||||||
self.check_icon = Some(icon);
|
self.check_icon = Some(Icon::new(icon));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,9 +87,7 @@ impl RenderOnce for ListItem {
|
||||||
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
fn render(self, cx: &mut WindowContext) -> impl IntoElement {
|
||||||
h_flex()
|
h_flex()
|
||||||
.id("item-group")
|
.id("item-group")
|
||||||
.items_center()
|
.flex_none()
|
||||||
.gap_2()
|
|
||||||
.w_full()
|
|
||||||
.relative()
|
.relative()
|
||||||
.gap_x_2()
|
.gap_x_2()
|
||||||
.text_base()
|
.text_base()
|
||||||
|
|
@ -105,12 +103,15 @@ impl RenderOnce for ListItem {
|
||||||
this.hover(|this| this.bg(cx.theme().accent))
|
this.hover(|this| this.bg(cx.theme().accent))
|
||||||
})
|
})
|
||||||
.when(self.selected, |this| this.bg(cx.theme().accent))
|
.when(self.selected, |this| this.bg(cx.theme().accent))
|
||||||
.child(self.base.when(self.selected, |this| {
|
.child(self.base.w_full().items_center().justify_between().when(
|
||||||
if let Some(icon) = self.check_icon {
|
self.selected,
|
||||||
this.child(icon)
|
|this| {
|
||||||
} else {
|
if let Some(icon) = self.check_icon {
|
||||||
this
|
this.child(icon.text_color(cx.theme().muted))
|
||||||
}
|
} else {
|
||||||
}))
|
this
|
||||||
|
}
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue