Add components example
Re-arrange generics on mouse event handler Add TypeTag struct for dynamically tagged components
This commit is contained in:
parent
5ce7ccac32
commit
e5eed29c72
49 changed files with 585 additions and 155 deletions
|
@ -497,9 +497,8 @@ impl View for PanelButtons {
|
|||
};
|
||||
Stack::new()
|
||||
.with_child(
|
||||
MouseEventHandler::<Self, _>::new(panel_ix, cx, |state, cx| {
|
||||
MouseEventHandler::new::<Self, _>(panel_ix, cx, |state, cx| {
|
||||
let style = button_style.in_state(is_active);
|
||||
|
||||
let style = style.style_for(state);
|
||||
Flex::row()
|
||||
.with_child(
|
||||
|
|
|
@ -290,7 +290,7 @@ pub mod simple_message_notification {
|
|||
.flex(1., true),
|
||||
)
|
||||
.with_child(
|
||||
MouseEventHandler::<Cancel, _>::new(0, cx, |state, _| {
|
||||
MouseEventHandler::new::<Cancel, _>(0, cx, |state, _| {
|
||||
let style = theme.dismiss_button.style_for(state);
|
||||
Svg::new("icons/x_mark_8.svg")
|
||||
.with_color(style.color)
|
||||
|
@ -319,7 +319,7 @@ pub mod simple_message_notification {
|
|||
.with_children({
|
||||
click_message
|
||||
.map(|click_message| {
|
||||
MouseEventHandler::<MessageNotificationTag, _>::new(
|
||||
MouseEventHandler::new::<MessageNotificationTag, _>(
|
||||
0,
|
||||
cx,
|
||||
|state, _| {
|
||||
|
|
|
@ -1211,7 +1211,7 @@ impl Pane {
|
|||
|
||||
enum Tab {}
|
||||
let mouse_event_handler =
|
||||
MouseEventHandler::<Tab, Pane>::new(ix, cx, |_, cx| {
|
||||
MouseEventHandler::new::<Tab, _>(ix, cx, |_, cx| {
|
||||
Self::render_tab(
|
||||
&item,
|
||||
pane.clone(),
|
||||
|
@ -1420,7 +1420,7 @@ impl Pane {
|
|||
let item_id = item.id();
|
||||
enum TabCloseButton {}
|
||||
let icon = Svg::new("icons/x_mark_8.svg");
|
||||
MouseEventHandler::<TabCloseButton, _>::new(item_id, cx, |mouse_state, _| {
|
||||
MouseEventHandler::new::<TabCloseButton, _>(item_id, cx, |mouse_state, _| {
|
||||
if mouse_state.hovered() {
|
||||
icon.with_color(tab_style.icon_close_active)
|
||||
} else {
|
||||
|
@ -1485,7 +1485,7 @@ impl Pane {
|
|||
) -> AnyElement<Pane> {
|
||||
enum TabBarButton {}
|
||||
|
||||
let mut button = MouseEventHandler::<TabBarButton, _>::new(index, cx, |mouse_state, cx| {
|
||||
let mut button = MouseEventHandler::new::<TabBarButton, _>(index, cx, |mouse_state, cx| {
|
||||
let theme = &settings::get::<ThemeSettings>(cx).theme.workspace.tab_bar;
|
||||
let style = theme.pane_button.in_state(is_active).style_for(mouse_state);
|
||||
Svg::new(icon)
|
||||
|
@ -1547,7 +1547,7 @@ impl View for Pane {
|
|||
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
|
||||
enum MouseNavigationHandler {}
|
||||
|
||||
MouseEventHandler::<MouseNavigationHandler, _>::new(0, cx, |_, cx| {
|
||||
MouseEventHandler::new::<MouseNavigationHandler, _>(0, cx, |_, cx| {
|
||||
let active_item_index = self.active_item_index;
|
||||
|
||||
if let Some(active_item) = self.active_item() {
|
||||
|
@ -1559,7 +1559,7 @@ impl View for Pane {
|
|||
|
||||
enum TabBarEventHandler {}
|
||||
stack.add_child(
|
||||
MouseEventHandler::<TabBarEventHandler, _>::new(0, cx, |_, _| {
|
||||
MouseEventHandler::new::<TabBarEventHandler, _>(0, cx, |_, _| {
|
||||
Empty::new()
|
||||
.contained()
|
||||
.with_style(theme.workspace.tab_bar.container)
|
||||
|
|
|
@ -19,7 +19,7 @@ pub fn dragged_item_receiver<Tag, D, F>(
|
|||
split_margin: Option<f32>,
|
||||
cx: &mut ViewContext<Pane>,
|
||||
render_child: F,
|
||||
) -> MouseEventHandler<Tag, Pane>
|
||||
) -> MouseEventHandler<Pane>
|
||||
where
|
||||
Tag: 'static,
|
||||
D: Element<Pane>,
|
||||
|
@ -39,7 +39,7 @@ where
|
|||
None
|
||||
};
|
||||
|
||||
let mut handler = MouseEventHandler::<Tag, _>::above(region_id, cx, |state, cx| {
|
||||
let mut handler = MouseEventHandler::above::<Tag, _>(region_id, cx, |state, cx| {
|
||||
// Observing hovered will cause a render when the mouse enters regardless
|
||||
// of if mouse position was accessed before
|
||||
let drag_position = if state.hovered() { drag_position } else { None };
|
||||
|
|
|
@ -212,7 +212,7 @@ impl Member {
|
|||
let leader_user_id = leader.user.id;
|
||||
let app_state = Arc::downgrade(app_state);
|
||||
Some(
|
||||
MouseEventHandler::<FollowIntoExternalProject, _>::new(
|
||||
MouseEventHandler::new::<FollowIntoExternalProject, _>(
|
||||
pane.id(),
|
||||
cx,
|
||||
|_, _| {
|
||||
|
|
|
@ -72,7 +72,7 @@ impl View for SharedScreen {
|
|||
enum Focus {}
|
||||
|
||||
let frame = self.frame.clone();
|
||||
MouseEventHandler::<Focus, _>::new(0, cx, |_, cx| {
|
||||
MouseEventHandler::new::<Focus, _>(0, cx, |_, cx| {
|
||||
Canvas::new(move |scene, bounds, _, _, _| {
|
||||
if let Some(frame) = frame.clone() {
|
||||
let size = constrain_size_preserving_aspect_ratio(
|
||||
|
|
|
@ -223,7 +223,7 @@ fn nav_button<A: Action, F: 'static + Fn(&mut Toolbar, &mut ViewContext<Toolbar>
|
|||
action_name: &'static str,
|
||||
cx: &mut ViewContext<Toolbar>,
|
||||
) -> AnyElement<Toolbar> {
|
||||
MouseEventHandler::<A, _>::new(0, cx, |state, _| {
|
||||
MouseEventHandler::new::<A, _>(0, cx, |state, _| {
|
||||
let style = if enabled {
|
||||
style.style_for(state)
|
||||
} else {
|
||||
|
|
|
@ -2560,7 +2560,7 @@ impl Workspace {
|
|||
};
|
||||
|
||||
enum TitleBar {}
|
||||
MouseEventHandler::<TitleBar, _>::new(0, cx, |_, cx| {
|
||||
MouseEventHandler::new::<TitleBar, _>(0, cx, |_, cx| {
|
||||
Stack::new()
|
||||
.with_children(
|
||||
self.titlebar_item
|
||||
|
@ -2649,7 +2649,7 @@ impl Workspace {
|
|||
if self.project.read(cx).is_read_only() {
|
||||
enum DisconnectedOverlay {}
|
||||
Some(
|
||||
MouseEventHandler::<DisconnectedOverlay, _>::new(0, cx, |_, cx| {
|
||||
MouseEventHandler::new::<DisconnectedOverlay, _>(0, cx, |_, cx| {
|
||||
let theme = &theme::current(cx);
|
||||
Label::new(
|
||||
"Your connection to the remote project has been lost.",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue