Use Box instead of Rc for List event handlers
This commit is contained in:
parent
149e90c3d9
commit
a208229a2c
3 changed files with 13 additions and 25 deletions
|
@ -1,14 +1,10 @@
|
||||||
use std::rc::Rc;
|
use crate::{prelude::*, Color, Icon, IconButton, IconSize};
|
||||||
|
|
||||||
use gpui::ClickEvent;
|
use gpui::ClickEvent;
|
||||||
|
|
||||||
use crate::prelude::*;
|
|
||||||
use crate::{Color, Icon, IconButton, IconSize};
|
|
||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct Disclosure {
|
pub struct Disclosure {
|
||||||
is_open: bool,
|
is_open: bool,
|
||||||
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
on_toggle: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Disclosure {
|
impl Disclosure {
|
||||||
|
@ -21,7 +17,7 @@ impl Disclosure {
|
||||||
|
|
||||||
pub fn on_toggle(
|
pub fn on_toggle(
|
||||||
mut self,
|
mut self,
|
||||||
handler: impl Into<Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>>,
|
handler: impl Into<Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.on_toggle = handler.into();
|
self.on_toggle = handler.into();
|
||||||
self
|
self
|
||||||
|
|
|
@ -1,18 +1,14 @@
|
||||||
use std::rc::Rc;
|
use crate::{h_stack, prelude::*, Disclosure, Icon, IconElement, IconSize, Label};
|
||||||
|
|
||||||
use gpui::{AnyElement, ClickEvent, Div};
|
use gpui::{AnyElement, ClickEvent, Div};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use crate::prelude::*;
|
|
||||||
use crate::{h_stack, Disclosure, Icon, IconElement, IconSize, Label};
|
|
||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct ListHeader {
|
pub struct ListHeader {
|
||||||
label: SharedString,
|
label: SharedString,
|
||||||
left_icon: Option<Icon>,
|
left_icon: Option<Icon>,
|
||||||
meta: SmallVec<[AnyElement; 2]>,
|
meta: SmallVec<[AnyElement; 2]>,
|
||||||
toggle: Option<bool>,
|
toggle: Option<bool>,
|
||||||
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
on_toggle: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||||
inset: bool,
|
inset: bool,
|
||||||
selected: bool,
|
selected: bool,
|
||||||
}
|
}
|
||||||
|
@ -39,7 +35,7 @@ impl ListHeader {
|
||||||
mut self,
|
mut self,
|
||||||
on_toggle: impl Fn(&ClickEvent, &mut WindowContext) + 'static,
|
on_toggle: impl Fn(&ClickEvent, &mut WindowContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.on_toggle = Some(Rc::new(on_toggle));
|
self.on_toggle = Some(Box::new(on_toggle));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
use std::rc::Rc;
|
use crate::{prelude::*, Avatar, Disclosure, Icon, IconElement, IconSize};
|
||||||
|
|
||||||
use gpui::{
|
use gpui::{
|
||||||
px, AnyElement, AnyView, ClickEvent, Div, ImageSource, MouseButton, MouseDownEvent, Pixels,
|
px, AnyElement, AnyView, ClickEvent, Div, ImageSource, MouseButton, MouseDownEvent, Pixels,
|
||||||
Stateful,
|
Stateful,
|
||||||
};
|
};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use crate::prelude::*;
|
|
||||||
use crate::{Avatar, Disclosure, Icon, IconElement, IconSize};
|
|
||||||
|
|
||||||
#[derive(IntoElement)]
|
#[derive(IntoElement)]
|
||||||
pub struct ListItem {
|
pub struct ListItem {
|
||||||
id: ElementId,
|
id: ElementId,
|
||||||
|
@ -20,10 +16,10 @@ pub struct ListItem {
|
||||||
left_slot: Option<AnyElement>,
|
left_slot: Option<AnyElement>,
|
||||||
toggle: Option<bool>,
|
toggle: Option<bool>,
|
||||||
inset: bool,
|
inset: bool,
|
||||||
on_click: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
on_click: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||||
on_toggle: Option<Rc<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
on_toggle: Option<Box<dyn Fn(&ClickEvent, &mut WindowContext) + 'static>>,
|
||||||
tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView + 'static>>,
|
tooltip: Option<Box<dyn Fn(&mut WindowContext) -> AnyView + 'static>>,
|
||||||
on_secondary_mouse_down: Option<Rc<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
on_secondary_mouse_down: Option<Box<dyn Fn(&MouseDownEvent, &mut WindowContext) + 'static>>,
|
||||||
children: SmallVec<[AnyElement; 2]>,
|
children: SmallVec<[AnyElement; 2]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,7 +42,7 @@ impl ListItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_click(mut self, handler: impl Fn(&ClickEvent, &mut WindowContext) + 'static) -> Self {
|
pub fn on_click(mut self, handler: impl Fn(&ClickEvent, &mut WindowContext) + 'static) -> Self {
|
||||||
self.on_click = Some(Rc::new(handler));
|
self.on_click = Some(Box::new(handler));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +50,7 @@ impl ListItem {
|
||||||
mut self,
|
mut self,
|
||||||
handler: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
|
handler: impl Fn(&MouseDownEvent, &mut WindowContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.on_secondary_mouse_down = Some(Rc::new(handler));
|
self.on_secondary_mouse_down = Some(Box::new(handler));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +83,7 @@ impl ListItem {
|
||||||
mut self,
|
mut self,
|
||||||
on_toggle: impl Fn(&ClickEvent, &mut WindowContext) + 'static,
|
on_toggle: impl Fn(&ClickEvent, &mut WindowContext) + 'static,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
self.on_toggle = Some(Rc::new(on_toggle));
|
self.on_toggle = Some(Box::new(on_toggle));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue