Use children for ListItems

This commit is contained in:
Marshall Bowers 2023-11-22 12:44:51 -05:00
parent 031fca4105
commit fd5793ddec
2 changed files with 12 additions and 5 deletions

View file

@ -113,7 +113,8 @@ impl Render for ContextMenu {
let callback = callback.clone(); let callback = callback.clone();
let dismiss = cx.listener(|_, _, cx| cx.emit(Manager::Dismiss)); let dismiss = cx.listener(|_, _, cx| cx.emit(Manager::Dismiss));
ListItem::new(entry.clone(), Label::new(entry.clone())) ListItem::new(entry.clone())
.child(Label::new(entry.clone()))
.on_click(move |event, cx| { .on_click(move |event, cx| {
callback(event, cx); callback(event, cx);
dismiss(event, cx) dismiss(event, cx)

View file

@ -245,28 +245,28 @@ pub struct ListItem {
// TODO: Reintroduce this // TODO: Reintroduce this
// disclosure_control_style: DisclosureControlVisibility, // disclosure_control_style: DisclosureControlVisibility,
indent_level: u32, indent_level: u32,
label: Label,
left_slot: Option<GraphicSlot>, left_slot: Option<GraphicSlot>,
overflow: OverflowStyle, overflow: OverflowStyle,
size: ListEntrySize, size: ListEntrySize,
toggle: Toggle, toggle: Toggle,
variant: ListItemVariant, variant: ListItemVariant,
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>, on_click: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
children: SmallVec<[AnyElement; 2]>,
} }
impl ListItem { impl ListItem {
pub fn new(id: impl Into<ElementId>, label: Label) -> Self { pub fn new(id: impl Into<ElementId>) -> Self {
Self { Self {
id: id.into(), id: id.into(),
disabled: false, disabled: false,
indent_level: 0, indent_level: 0,
label,
left_slot: None, left_slot: None,
overflow: OverflowStyle::Hidden, overflow: OverflowStyle::Hidden,
size: ListEntrySize::default(), size: ListEntrySize::default(),
toggle: Toggle::NotToggleable, toggle: Toggle::NotToggleable,
variant: ListItemVariant::default(), variant: ListItemVariant::default(),
on_click: Default::default(), on_click: Default::default(),
children: SmallVec::new(),
} }
} }
@ -377,11 +377,17 @@ impl Component for ListItem {
.relative() .relative()
.child(disclosure_control(self.toggle)) .child(disclosure_control(self.toggle))
.children(left_content) .children(left_content)
.child(self.label), .children(self.children),
) )
} }
} }
impl ParentElement for ListItem {
fn children_mut(&mut self) -> &mut SmallVec<[AnyElement; 2]> {
&mut self.children
}
}
#[derive(RenderOnce, Clone)] #[derive(RenderOnce, Clone)]
pub struct ListSeparator; pub struct ListSeparator;