Rename Drawable::boxed to into_element and make containers generic

Multi-element are now generic over any drawable child, which can be converted
into an element.

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Antonio Scandurra 2023-04-21 18:36:21 +02:00 committed by Nathan Sobo
parent 4d433663bd
commit 03619dfa55
80 changed files with 1132 additions and 1434 deletions

View file

@ -72,7 +72,7 @@ impl View for CollabTitlebarItem {
let workspace = if let Some(workspace) = self.workspace.upgrade(cx) {
workspace
} else {
return Empty::new().boxed();
return Empty::new().into_element();
};
let project = workspace.read(cx).project().read(cx);
@ -97,8 +97,7 @@ impl View for CollabTitlebarItem {
.contained()
.with_margin_right(theme.workspace.titlebar.item_spacing)
.aligned()
.left()
.boxed(),
.left(),
);
let user = workspace.read(cx).user_store().read(cx).current_user();
@ -128,9 +127,9 @@ impl View for CollabTitlebarItem {
}
Stack::new()
.with_child(left_container.boxed())
.with_child(right_container.aligned().right().boxed())
.boxed()
.with_child(left_container)
.with_child(right_container.aligned().right())
.into_element()
}
}
@ -294,13 +293,13 @@ impl CollabTitlebarItem {
Color::transparent_black(),
)
}))
.with_child(
Label::new(user.github_login.clone(), item_style.label.clone())
.boxed(),
)
.with_child(Label::new(
user.github_login.clone(),
item_style.label.clone(),
))
.contained()
.with_style(item_style.container)
.boxed()
.into_element()
})),
ContextMenuItem::item("Sign out", SignOut),
ContextMenuItem::item("Send Feedback", feedback::feedback_editor::GiveFeedback),
@ -345,8 +344,7 @@ impl CollabTitlebarItem {
.contained()
.with_margin_left(titlebar.toggle_contacts_button.default.icon_width)
.with_margin_top(titlebar.toggle_contacts_button.default.icon_width)
.aligned()
.boxed(),
.aligned(),
)
};
@ -366,7 +364,6 @@ impl CollabTitlebarItem {
.with_height(style.button_width)
.contained()
.with_style(style.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
@ -378,12 +375,11 @@ impl CollabTitlebarItem {
Some(Box::new(ToggleContactsMenu)),
theme.tooltip.clone(),
cx,
)
.boxed(),
),
)
.with_children(badge)
.with_children(self.render_contacts_popover_host(titlebar, cx))
.boxed()
.into_element()
}
fn render_toggle_screen_sharing_button(
@ -415,7 +411,6 @@ impl CollabTitlebarItem {
.with_height(style.button_width)
.contained()
.with_style(style.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
@ -429,7 +424,7 @@ impl CollabTitlebarItem {
cx,
)
.aligned()
.boxed()
.into_element()
}
fn render_in_call_share_unshare_button(
@ -463,7 +458,6 @@ impl CollabTitlebarItem {
Label::new(label, style.text.clone())
.contained()
.with_style(style.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
@ -479,13 +473,12 @@ impl CollabTitlebarItem {
None,
theme.tooltip.clone(),
cx,
)
.boxed(),
),
)
.aligned()
.contained()
.with_margin_left(theme.workspace.titlebar.item_spacing)
.boxed(),
.into_element(),
)
}
@ -506,7 +499,6 @@ impl CollabTitlebarItem {
.with_height(style.button_width)
.contained()
.with_style(style.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
@ -520,17 +512,15 @@ impl CollabTitlebarItem {
cx,
)
.contained()
.with_margin_left(theme.workspace.titlebar.item_spacing)
.boxed(),
.with_margin_left(theme.workspace.titlebar.item_spacing),
)
.with_child(
ChildView::new(&self.user_menu, cx)
.aligned()
.bottom()
.right()
.boxed(),
.right(),
)
.boxed()
.into_element()
}
fn render_sign_in_button(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> Element<Self> {
@ -540,13 +530,12 @@ impl CollabTitlebarItem {
Label::new("Sign In", style.text.clone())
.contained()
.with_style(style.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(SignIn);
})
.boxed()
.into_element()
}
fn render_contacts_popover_host<'a>(
@ -555,14 +544,14 @@ impl CollabTitlebarItem {
cx: &'a ViewContext<Self>,
) -> Option<Element<Self>> {
self.contacts_popover.as_ref().map(|popover| {
Overlay::new(ChildView::new(popover, cx).boxed())
Overlay::new(ChildView::new(popover, cx))
.with_fit_mode(OverlayFitMode::SwitchAnchor)
.with_anchor_corner(AnchorCorner::TopRight)
.with_z_index(999)
.aligned()
.bottom()
.right()
.boxed()
.into_element()
})
}
@ -572,7 +561,7 @@ impl CollabTitlebarItem {
theme: &Theme,
room: &ModelHandle<Room>,
cx: &mut ViewContext<Self>,
) -> Vec<Element<Self>> {
) -> Vec<Container<Self>> {
let mut participants = room
.read(cx)
.remote_participants()
@ -600,8 +589,7 @@ impl CollabTitlebarItem {
theme,
cx,
))
.with_margin_right(theme.workspace.titlebar.face_pile_spacing)
.boxed(),
.with_margin_right(theme.workspace.titlebar.face_pile_spacing),
)
})
.collect()
@ -626,7 +614,7 @@ impl CollabTitlebarItem {
cx,
))
.with_margin_right(theme.workspace.titlebar.item_spacing)
.boxed()
.into_element()
}
fn render_face_pile(
@ -730,7 +718,7 @@ impl CollabTitlebarItem {
}
}
container.boxed()
container
}))
.with_children((|| {
let replica_id = replica_id?;
@ -741,11 +729,10 @@ impl CollabTitlebarItem {
.with_width(theme.workspace.titlebar.avatar_ribbon.width)
.with_height(theme.workspace.titlebar.avatar_ribbon.height)
.aligned()
.bottom()
.boxed(),
.bottom(),
)
})())
.boxed();
.into_element();
if let Some(location) = location {
if let Some(replica_id) = replica_id {
@ -769,7 +756,7 @@ impl CollabTitlebarItem {
theme.tooltip.clone(),
cx,
)
.boxed();
.into_element();
} else if let ParticipantLocation::SharedProject { project_id } = location {
let user_id = user.id;
content = MouseEventHandler::<JoinProject, Self>::new(
@ -791,7 +778,7 @@ impl CollabTitlebarItem {
theme.tooltip.clone(),
cx,
)
.boxed();
.into_element();
}
}
content
@ -831,7 +818,7 @@ impl CollabTitlebarItem {
.with_width(avatar_style.outer_width)
.with_height(avatar_style.outer_width)
.aligned()
.boxed()
.into_element()
}
fn render_connection_status(
@ -848,20 +835,14 @@ impl CollabTitlebarItem {
| client::Status::Reauthenticating { .. }
| client::Status::Reconnecting { .. }
| client::Status::ReconnectionError { .. } => Some(
Container::new(
Align::new(
ConstrainedBox::new(
Svg::new("icons/cloud_slash_12.svg")
.with_color(theme.workspace.titlebar.offline_icon.color)
.boxed(),
)
.with_width(theme.workspace.titlebar.offline_icon.width)
.boxed(),
)
.boxed(),
)
.with_style(theme.workspace.titlebar.offline_icon.container)
.boxed(),
Svg::new("icons/cloud_slash_12.svg")
.with_color(theme.workspace.titlebar.offline_icon.color)
.constrained()
.with_width(theme.workspace.titlebar.offline_icon.width)
.aligned()
.contained()
.with_style(theme.workspace.titlebar.offline_icon.container)
.into_element(),
),
client::Status::UpgradeRequired => Some(
MouseEventHandler::<ConnectionStatusButton, Self>::new(0, cx, |_, _| {
@ -872,13 +853,12 @@ impl CollabTitlebarItem {
.contained()
.with_style(theme.workspace.titlebar.outdated_warning.container)
.aligned()
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, |_, _, cx| {
cx.dispatch_action(auto_update::Check);
})
.boxed(),
.into_element(),
),
_ => None,
}

View file

@ -40,12 +40,11 @@ impl View for CollaboratorListPopover {
.constrained()
.with_width(theme.contacts_popover.width)
.with_height(theme.contacts_popover.height)
.boxed()
})
.on_down_out(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(ToggleCollaboratorList);
})
.boxed()
.into_element()
}
fn focus_out(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
@ -129,7 +128,7 @@ fn render_collaborator_list_entry<UA: Action + Clone, IA: Action + Clone>(
let username =
MouseEventHandler::<Username, CollaboratorListPopover>::new(index, cx, |_, _| {
Label::new(username.to_owned(), username_theme.clone()).boxed()
Label::new(username.to_owned(), username_theme.clone())
})
.on_click(MouseButton::Left, move |_, _, cx| {
if let Some(username_action) = username_action.clone() {
@ -147,17 +146,16 @@ fn render_collaborator_list_entry<UA: Action + Clone, IA: Action + Clone>(
tooltip_theme.clone(),
cx,
)
.boxed()
.into_element()
} else {
username.boxed()
username.into_element()
})
.with_child(
MouseEventHandler::<Icon, CollaboratorListPopover>::new(index, cx, |_, _| icon.boxed())
MouseEventHandler::<Icon, CollaboratorListPopover>::new(index, cx, |_, _| icon)
.on_click(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(icon_action.clone())
})
.with_tooltip::<IconTooltip>(index, icon_tooltip, None, tooltip_theme, cx)
.boxed(),
.with_tooltip::<IconTooltip>(index, icon_tooltip, None, tooltip_theme, cx),
)
.boxed()
.into_element()
}

View file

@ -124,15 +124,13 @@ impl PickerDelegate for ContactFinderDelegate {
.with_style(theme.contact_finder.contact_avatar)
.aligned()
.left()
.boxed()
}))
.with_child(
Label::new(user.github_login.clone(), style.label.clone())
.contained()
.with_style(theme.contact_finder.contact_username)
.aligned()
.left()
.boxed(),
.left(),
)
.with_children(icon_path.map(|icon_path| {
Svg::new(icon_path)
@ -147,12 +145,11 @@ impl PickerDelegate for ContactFinderDelegate {
.with_height(button_style.button_width)
.aligned()
.flex_float()
.boxed()
}))
.contained()
.with_style(style.container)
.constrained()
.with_height(theme.contact_finder.row_height)
.boxed()
.into_element()
}
}

View file

@ -755,7 +755,6 @@ impl ContactList {
.with_style(theme.contact_avatar)
.aligned()
.left()
.boxed()
}))
.with_child(
Label::new(
@ -766,16 +765,14 @@ impl ContactList {
.with_style(theme.contact_username.container)
.aligned()
.left()
.flex(1., true)
.boxed(),
.flex(1., true),
)
.with_children(if is_pending {
Some(
Label::new("Calling", theme.calling_indicator.text.clone())
.contained()
.with_style(theme.calling_indicator.container)
.aligned()
.boxed(),
.aligned(),
)
} else {
None
@ -788,7 +785,7 @@ impl ContactList {
.contact_row
.style_for(&mut Default::default(), is_selected),
)
.boxed()
.into_element()
}
fn render_participant_project(
@ -826,41 +823,37 @@ impl ContactList {
Flex::row()
.with_child(
Stack::new()
.with_child(
Canvas::new(move |scene, bounds, _, _, _| {
let start_x = bounds.min_x() + (bounds.width() / 2.)
- (tree_branch.width / 2.);
let end_x = bounds.max_x();
let start_y = bounds.min_y();
let end_y = bounds.min_y() + baseline_offset - (cap_height / 2.);
.with_child(Canvas::new(move |scene, bounds, _, _, _| {
let start_x =
bounds.min_x() + (bounds.width() / 2.) - (tree_branch.width / 2.);
let end_x = bounds.max_x();
let start_y = bounds.min_y();
let end_y = bounds.min_y() + baseline_offset - (cap_height / 2.);
scene.push_quad(gpui::Quad {
bounds: RectF::from_points(
vec2f(start_x, start_y),
vec2f(
start_x + tree_branch.width,
if is_last { end_y } else { bounds.max_y() },
),
scene.push_quad(gpui::Quad {
bounds: RectF::from_points(
vec2f(start_x, start_y),
vec2f(
start_x + tree_branch.width,
if is_last { end_y } else { bounds.max_y() },
),
background: Some(tree_branch.color),
border: gpui::Border::default(),
corner_radius: 0.,
});
scene.push_quad(gpui::Quad {
bounds: RectF::from_points(
vec2f(start_x, end_y),
vec2f(end_x, end_y + tree_branch.width),
),
background: Some(tree_branch.color),
border: gpui::Border::default(),
corner_radius: 0.,
});
})
.boxed(),
)
),
background: Some(tree_branch.color),
border: gpui::Border::default(),
corner_radius: 0.,
});
scene.push_quad(gpui::Quad {
bounds: RectF::from_points(
vec2f(start_x, end_y),
vec2f(end_x, end_y + tree_branch.width),
),
background: Some(tree_branch.color),
border: gpui::Border::default(),
corner_radius: 0.,
});
}))
.constrained()
.with_width(host_avatar_height)
.boxed(),
.with_width(host_avatar_height),
)
.with_child(
Label::new(project_name, row.name.text.clone())
@ -868,14 +861,12 @@ impl ContactList {
.left()
.contained()
.with_style(row.name.container)
.flex(1., false)
.boxed(),
.flex(1., false),
)
.constrained()
.with_height(theme.row_height)
.contained()
.with_style(row.container)
.boxed()
})
.with_cursor_style(if !is_current {
CursorStyle::PointingHand
@ -890,7 +881,7 @@ impl ContactList {
});
}
})
.boxed()
.into_element()
}
fn render_participant_screen(
@ -923,42 +914,37 @@ impl ContactList {
Flex::row()
.with_child(
Stack::new()
.with_child(
Canvas::new(move |scene, bounds, _, _, _| {
let start_x = bounds.min_x() + (bounds.width() / 2.)
- (tree_branch.width / 2.);
let end_x = bounds.max_x();
let start_y = bounds.min_y();
let end_y =
bounds.min_y() + baseline_offset - (cap_height / 2.);
.with_child(Canvas::new(move |scene, bounds, _, _, _| {
let start_x = bounds.min_x() + (bounds.width() / 2.)
- (tree_branch.width / 2.);
let end_x = bounds.max_x();
let start_y = bounds.min_y();
let end_y = bounds.min_y() + baseline_offset - (cap_height / 2.);
scene.push_quad(gpui::Quad {
bounds: RectF::from_points(
vec2f(start_x, start_y),
vec2f(
start_x + tree_branch.width,
if is_last { end_y } else { bounds.max_y() },
),
scene.push_quad(gpui::Quad {
bounds: RectF::from_points(
vec2f(start_x, start_y),
vec2f(
start_x + tree_branch.width,
if is_last { end_y } else { bounds.max_y() },
),
background: Some(tree_branch.color),
border: gpui::Border::default(),
corner_radius: 0.,
});
scene.push_quad(gpui::Quad {
bounds: RectF::from_points(
vec2f(start_x, end_y),
vec2f(end_x, end_y + tree_branch.width),
),
background: Some(tree_branch.color),
border: gpui::Border::default(),
corner_radius: 0.,
});
})
.boxed(),
)
),
background: Some(tree_branch.color),
border: gpui::Border::default(),
corner_radius: 0.,
});
scene.push_quad(gpui::Quad {
bounds: RectF::from_points(
vec2f(start_x, end_y),
vec2f(end_x, end_y + tree_branch.width),
),
background: Some(tree_branch.color),
border: gpui::Border::default(),
corner_radius: 0.,
});
}))
.constrained()
.with_width(host_avatar_height)
.boxed(),
.with_width(host_avatar_height),
)
.with_child(
Svg::new("icons/disable_screen_sharing_12.svg")
@ -968,8 +954,7 @@ impl ContactList {
.aligned()
.left()
.contained()
.with_style(row.icon.container)
.boxed(),
.with_style(row.icon.container),
)
.with_child(
Label::new("Screen", row.name.text.clone())
@ -977,21 +962,19 @@ impl ContactList {
.left()
.contained()
.with_style(row.name.container)
.flex(1., false)
.boxed(),
.flex(1., false),
)
.constrained()
.with_height(theme.row_height)
.contained()
.with_style(row.container)
.boxed()
},
)
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(OpenSharedScreen { peer_id });
})
.boxed()
.into_element()
}
fn render_header(
@ -1020,11 +1003,9 @@ impl ContactList {
Label::new("Leave Call", style.text.clone())
.contained()
.with_style(style.container)
.boxed()
})
.on_click(MouseButton::Left, |_, _, cx| cx.dispatch_action(LeaveCall))
.aligned()
.boxed(),
.aligned(),
)
} else {
None
@ -1045,8 +1026,7 @@ impl ContactList {
.with_max_height(icon_size)
.aligned()
.constrained()
.with_width(icon_size)
.boxed(),
.with_width(icon_size),
)
.with_child(
Label::new(text, header_style.text.clone())
@ -1054,21 +1034,19 @@ impl ContactList {
.left()
.contained()
.with_margin_left(theme.contact_username.container.margin.left)
.flex(1., true)
.boxed(),
.flex(1., true),
)
.with_children(leave_call)
.constrained()
.with_height(theme.row_height)
.contained()
.with_style(header_style.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(ToggleExpanded(section))
})
.boxed()
.into_element()
}
fn render_contact(
@ -1084,7 +1062,7 @@ impl ContactList {
let user_id = contact.user.id;
let github_login = contact.user.github_login.clone();
let initial_project = project.clone();
let mut element =
let mut event_handler =
MouseEventHandler::<Contact, Self>::new(contact.user.id as usize, cx, |_, cx| {
Flex::row()
.with_children(contact.user.avatar.clone().map(|avatar| {
@ -1098,8 +1076,7 @@ impl ContactList {
} else {
theme.contact_status_free
})
.aligned()
.boxed(),
.aligned(),
)
} else {
None
@ -1109,11 +1086,9 @@ impl ContactList {
Image::from_data(avatar)
.with_style(theme.contact_avatar)
.aligned()
.left()
.boxed(),
.left(),
)
.with_children(status_badge)
.boxed()
}))
.with_child(
Label::new(
@ -1124,8 +1099,7 @@ impl ContactList {
.with_style(theme.contact_username.container)
.aligned()
.left()
.flex(1., true)
.boxed(),
.flex(1., true),
)
.with_child(
MouseEventHandler::<Cancel, Self>::new(
@ -1137,7 +1111,6 @@ impl ContactList {
render_icon_button(button_style, "icons/x_mark_8.svg")
.aligned()
.flex_float()
.boxed()
},
)
.with_padding(Padding::uniform(2.))
@ -1148,16 +1121,14 @@ impl ContactList {
github_login: github_login.clone(),
})
})
.flex_float()
.boxed(),
.flex_float(),
)
.with_children(if calling {
Some(
Label::new("Calling", theme.calling_indicator.text.clone())
.contained()
.with_style(theme.calling_indicator.container)
.aligned()
.boxed(),
.aligned(),
)
} else {
None
@ -1170,7 +1141,6 @@ impl ContactList {
.contact_row
.style_for(&mut Default::default(), is_selected),
)
.boxed()
})
.on_click(MouseButton::Left, move |_, _, cx| {
if online && !busy {
@ -1182,10 +1152,10 @@ impl ContactList {
});
if online {
element = element.with_cursor_style(CursorStyle::PointingHand);
event_handler = event_handler.with_cursor_style(CursorStyle::PointingHand);
}
element.boxed()
event_handler.into_element()
}
fn render_contact_request(
@ -1206,7 +1176,6 @@ impl ContactList {
.with_style(theme.contact_avatar)
.aligned()
.left()
.boxed()
}))
.with_child(
Label::new(
@ -1217,8 +1186,7 @@ impl ContactList {
.with_style(theme.contact_username.container)
.aligned()
.left()
.flex(1., true)
.boxed(),
.flex(1., true),
);
let user_id = user.id;
@ -1227,16 +1195,14 @@ impl ContactList {
let button_spacing = theme.contact_button_spacing;
if is_incoming {
row.add_children([
row.add_child(
MouseEventHandler::<Decline, Self>::new(user.id as usize, cx, |mouse_state, _| {
let button_style = if is_contact_request_pending {
&theme.disabled_button
} else {
theme.contact_button.style_for(mouse_state, false)
};
render_icon_button(button_style, "icons/x_mark_8.svg")
.aligned()
.boxed()
render_icon_button(button_style, "icons/x_mark_8.svg").aligned()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
@ -1246,8 +1212,10 @@ impl ContactList {
})
})
.contained()
.with_margin_right(button_spacing)
.boxed(),
.with_margin_right(button_spacing),
);
row.add_child(
MouseEventHandler::<Accept, Self>::new(user.id as usize, cx, |mouse_state, _| {
let button_style = if is_contact_request_pending {
&theme.disabled_button
@ -1257,7 +1225,6 @@ impl ContactList {
render_icon_button(button_style, "icons/check_8.svg")
.aligned()
.flex_float()
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
@ -1265,9 +1232,8 @@ impl ContactList {
user_id,
accept: true,
})
})
.boxed(),
]);
}),
);
} else {
row.add_child(
MouseEventHandler::<Cancel, Self>::new(user.id as usize, cx, |mouse_state, _| {
@ -1279,7 +1245,6 @@ impl ContactList {
render_icon_button(button_style, "icons/x_mark_8.svg")
.aligned()
.flex_float()
.boxed()
})
.with_padding(Padding::uniform(2.))
.with_cursor_style(CursorStyle::PointingHand)
@ -1289,8 +1254,7 @@ impl ContactList {
github_login: github_login.clone(),
})
})
.flex_float()
.boxed(),
.flex_float(),
);
}
@ -1302,7 +1266,7 @@ impl ContactList {
.contact_row
.style_for(&mut Default::default(), is_selected),
)
.boxed()
.into_element()
}
fn call(&mut self, action: &Call, cx: &mut ViewContext<Self>) {
@ -1342,8 +1306,7 @@ impl View for ContactList {
ChildView::new(&self.filter_editor, cx)
.contained()
.with_style(theme.contact_list.user_query_editor.container)
.flex(1., true)
.boxed(),
.flex(1., true),
)
.with_child(
MouseEventHandler::<AddContact, Self>::new(0, cx, |_, _| {
@ -1351,7 +1314,6 @@ impl View for ContactList {
&theme.contact_list.add_contact_button,
"icons/user_plus_16.svg",
)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, |_, _, cx| {
@ -1363,15 +1325,13 @@ impl View for ContactList {
None,
theme.tooltip.clone(),
cx,
)
.boxed(),
),
)
.constrained()
.with_height(theme.contact_list.user_query_editor_height)
.boxed(),
.with_height(theme.contact_list.user_query_editor_height),
)
.with_child(List::new(self.list_state.clone()).flex(1., false).boxed())
.boxed()
.with_child(List::new(self.list_state.clone()).flex(1., false))
.into_element()
}
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {

View file

@ -105,18 +105,17 @@ impl View for ContactsPopover {
MouseEventHandler::<ContactsPopover, Self>::new(0, cx, |_, _| {
Flex::column()
.with_child(child.flex(1., true).boxed())
.with_child(child.flex(1., true))
.contained()
.with_style(theme.contacts_popover.container)
.constrained()
.with_width(theme.contacts_popover.width)
.with_height(theme.contacts_popover.height)
.boxed()
})
.on_down_out(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(ToggleContactsMenu);
})
.boxed()
.into_element()
}
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {

View file

@ -112,7 +112,6 @@ impl IncomingCallNotification {
Image::from_data(avatar)
.with_style(theme.caller_avatar)
.aligned()
.boxed()
}))
.with_child(
Flex::column()
@ -122,8 +121,7 @@ impl IncomingCallNotification {
theme.caller_username.text.clone(),
)
.contained()
.with_style(theme.caller_username.container)
.boxed(),
.with_style(theme.caller_username.container),
)
.with_child(
Label::new(
@ -138,8 +136,7 @@ impl IncomingCallNotification {
theme.caller_message.text.clone(),
)
.contained()
.with_style(theme.caller_message.container)
.boxed(),
.with_style(theme.caller_message.container),
)
.with_children(if initial_project.worktree_root_names.is_empty() {
None
@ -150,19 +147,17 @@ impl IncomingCallNotification {
theme.worktree_roots.text.clone(),
)
.contained()
.with_style(theme.worktree_roots.container)
.boxed(),
.with_style(theme.worktree_roots.container),
)
})
.contained()
.with_style(theme.caller_metadata)
.aligned()
.boxed(),
.aligned(),
)
.contained()
.with_style(theme.caller_container)
.flex(1., true)
.boxed()
.into_element()
}
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> Element<Self> {
@ -177,14 +172,12 @@ impl IncomingCallNotification {
.aligned()
.contained()
.with_style(theme.accept_button.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, |_, _, cx| {
cx.dispatch_action(RespondToCall { accept: true });
})
.flex(1., true)
.boxed(),
.flex(1., true),
)
.with_child(
MouseEventHandler::<Decline, Self>::new(0, cx, |_, cx| {
@ -193,14 +186,12 @@ impl IncomingCallNotification {
.aligned()
.contained()
.with_style(theme.decline_button.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, |_, _, cx| {
cx.dispatch_action(RespondToCall { accept: false });
})
.flex(1., true)
.boxed(),
.flex(1., true),
)
.constrained()
.with_width(
@ -209,7 +200,7 @@ impl IncomingCallNotification {
.incoming_call_notification
.button_width,
)
.boxed()
.into_element()
}
}
@ -235,6 +226,6 @@ impl View for IncomingCallNotification {
.contained()
.with_background_color(background)
.expanded()
.boxed()
.into_element()
}
}

View file

@ -35,7 +35,6 @@ pub fn render_user_notification<V: View, A: Action + Clone>(
)
.aligned()
.top()
.boxed()
}))
.with_child(
Text::new(
@ -47,8 +46,7 @@ pub fn render_user_notification<V: View, A: Action + Clone>(
.aligned()
.top()
.left()
.flex(1., true)
.boxed(),
.flex(1., true),
)
.with_child(
MouseEventHandler::<Dismiss, V>::new(user.id as usize, cx, |state, _| {
@ -63,7 +61,6 @@ pub fn render_user_notification<V: View, A: Action + Clone>(
.constrained()
.with_width(style.button_width)
.with_height(style.button_width)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.with_padding(Padding::uniform(5.))
@ -78,16 +75,14 @@ pub fn render_user_notification<V: View, A: Action + Clone>(
)
.aligned()
.top()
.flex_float()
.boxed(),
.flex_float(),
)
.named("contact notification header"),
.into_named_element("contact notification header"),
)
.with_children(body.map(|body| {
Label::new(body, theme.body_message.text.clone())
.contained()
.with_style(theme.body_message.container)
.boxed()
}))
.with_children(if buttons.is_empty() {
None
@ -101,20 +96,17 @@ pub fn render_user_notification<V: View, A: Action + Clone>(
Label::new(message, button.text.clone())
.contained()
.with_style(button.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
cx.dispatch_any_action(action.boxed_clone())
})
.boxed()
},
))
.aligned()
.right()
.boxed(),
.right(),
)
})
.contained()
.boxed()
.into_element()
}

View file

@ -109,7 +109,6 @@ impl ProjectSharedNotification {
Image::from_data(avatar)
.with_style(theme.owner_avatar)
.aligned()
.boxed()
}))
.with_child(
Flex::column()
@ -119,8 +118,7 @@ impl ProjectSharedNotification {
theme.owner_username.text.clone(),
)
.contained()
.with_style(theme.owner_username.container)
.boxed(),
.with_style(theme.owner_username.container),
)
.with_child(
Label::new(
@ -135,8 +133,7 @@ impl ProjectSharedNotification {
theme.message.text.clone(),
)
.contained()
.with_style(theme.message.container)
.boxed(),
.with_style(theme.message.container),
)
.with_children(if self.worktree_root_names.is_empty() {
None
@ -147,19 +144,17 @@ impl ProjectSharedNotification {
theme.worktree_roots.text.clone(),
)
.contained()
.with_style(theme.worktree_roots.container)
.boxed(),
.with_style(theme.worktree_roots.container),
)
})
.contained()
.with_style(theme.owner_metadata)
.aligned()
.boxed(),
.aligned(),
)
.contained()
.with_style(theme.owner_container)
.flex(1., true)
.boxed()
.into_element()
}
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> Element<Self> {
@ -177,7 +172,6 @@ impl ProjectSharedNotification {
.aligned()
.contained()
.with_style(theme.open_button.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, move |_, _, cx| {
@ -186,8 +180,7 @@ impl ProjectSharedNotification {
follow_user_id: owner_user_id,
});
})
.flex(1., true)
.boxed(),
.flex(1., true),
)
.with_child(
MouseEventHandler::<Dismiss, Self>::new(0, cx, |_, cx| {
@ -196,14 +189,12 @@ impl ProjectSharedNotification {
.aligned()
.contained()
.with_style(theme.dismiss_button.container)
.boxed()
})
.with_cursor_style(CursorStyle::PointingHand)
.on_click(MouseButton::Left, |_, _, cx| {
cx.dispatch_action(DismissProject);
})
.flex(1., true)
.boxed(),
.flex(1., true),
)
.constrained()
.with_width(
@ -212,7 +203,7 @@ impl ProjectSharedNotification {
.project_shared_notification
.button_width,
)
.boxed()
.into_element()
}
}
@ -237,6 +228,6 @@ impl View for ProjectSharedNotification {
.contained()
.with_background_color(background)
.expanded()
.boxed()
.into_element()
}
}

View file

@ -52,11 +52,10 @@ impl View for SharingStatusIndicator {
.constrained()
.with_width(18.)
.aligned()
.boxed()
})
.on_click(MouseButton::Left, |_, _, cx| {
cx.dispatch_action(ToggleScreenSharing);
})
.boxed()
.into_element()
}
}