Refine naming of element-related types and traits

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Nathan Sobo 2023-04-21 13:04:03 -06:00
parent 03619dfa55
commit fe492eacbf
93 changed files with 661 additions and 656 deletions

View file

@ -68,11 +68,11 @@ impl View for CollabTitlebarItem {
"CollabTitlebarItem"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let workspace = if let Some(workspace) = self.workspace.upgrade(cx) {
workspace
} else {
return Empty::new().into_element();
return Empty::new().into_any();
};
let project = workspace.read(cx).project().read(cx);
@ -129,7 +129,7 @@ impl View for CollabTitlebarItem {
Stack::new()
.with_child(left_container)
.with_child(right_container.aligned().right())
.into_element()
.into_any()
}
}
@ -299,7 +299,7 @@ impl CollabTitlebarItem {
))
.contained()
.with_style(item_style.container)
.into_element()
.into_any()
})),
ContextMenuItem::item("Sign out", SignOut),
ContextMenuItem::item("Send Feedback", feedback::feedback_editor::GiveFeedback),
@ -325,7 +325,7 @@ impl CollabTitlebarItem {
&self,
theme: &Theme,
cx: &mut ViewContext<Self>,
) -> Element<Self> {
) -> AnyElement<Self> {
let titlebar = &theme.workspace.titlebar;
let badge = if self
@ -379,7 +379,7 @@ impl CollabTitlebarItem {
)
.with_children(badge)
.with_children(self.render_contacts_popover_host(titlebar, cx))
.into_element()
.into_any()
}
fn render_toggle_screen_sharing_button(
@ -387,7 +387,7 @@ impl CollabTitlebarItem {
theme: &Theme,
room: &ModelHandle<Room>,
cx: &mut ViewContext<Self>,
) -> Element<Self> {
) -> AnyElement<Self> {
let icon;
let tooltip;
if room.read(cx).is_screen_sharing() {
@ -424,7 +424,7 @@ impl CollabTitlebarItem {
cx,
)
.aligned()
.into_element()
.into_any()
}
fn render_in_call_share_unshare_button(
@ -432,7 +432,7 @@ impl CollabTitlebarItem {
workspace: &ViewHandle<Workspace>,
theme: &Theme,
cx: &mut ViewContext<Self>,
) -> Option<Element<Self>> {
) -> Option<AnyElement<Self>> {
let project = workspace.read(cx).project();
if project.read(cx).is_remote() {
return None;
@ -478,11 +478,15 @@ impl CollabTitlebarItem {
.aligned()
.contained()
.with_margin_left(theme.workspace.titlebar.item_spacing)
.into_element(),
.into_any(),
)
}
fn render_user_menu_button(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render_user_menu_button(
&self,
theme: &Theme,
cx: &mut ViewContext<Self>,
) -> AnyElement<Self> {
let titlebar = &theme.workspace.titlebar;
Stack::new()
@ -520,10 +524,10 @@ impl CollabTitlebarItem {
.bottom()
.right(),
)
.into_element()
.into_any()
}
fn render_sign_in_button(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render_sign_in_button(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let titlebar = &theme.workspace.titlebar;
MouseEventHandler::<SignIn, Self>::new(0, cx, |state, _| {
let style = titlebar.sign_in_prompt.style_for(state, false);
@ -535,14 +539,14 @@ impl CollabTitlebarItem {
.on_click(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(SignIn);
})
.into_element()
.into_any()
}
fn render_contacts_popover_host<'a>(
&'a self,
_theme: &'a theme::Titlebar,
cx: &'a ViewContext<Self>,
) -> Option<Element<Self>> {
) -> Option<AnyElement<Self>> {
self.contacts_popover.as_ref().map(|popover| {
Overlay::new(ChildView::new(popover, cx))
.with_fit_mode(OverlayFitMode::SwitchAnchor)
@ -551,7 +555,7 @@ impl CollabTitlebarItem {
.aligned()
.bottom()
.right()
.into_element()
.into_any()
})
}
@ -602,7 +606,7 @@ impl CollabTitlebarItem {
user: &Arc<User>,
peer_id: PeerId,
cx: &mut ViewContext<Self>,
) -> Element<Self> {
) -> AnyElement<Self> {
let replica_id = workspace.read(cx).project().read(cx).replica_id();
Container::new(self.render_face_pile(
user,
@ -614,7 +618,7 @@ impl CollabTitlebarItem {
cx,
))
.with_margin_right(theme.workspace.titlebar.item_spacing)
.into_element()
.into_any()
}
fn render_face_pile(
@ -626,7 +630,7 @@ impl CollabTitlebarItem {
workspace: &ViewHandle<Workspace>,
theme: &Theme,
cx: &mut ViewContext<Self>,
) -> Element<Self> {
) -> AnyElement<Self> {
let project_id = workspace.read(cx).project().read(cx).remote_id();
let room = ActiveCall::global(cx).read(cx).room();
let is_being_followed = workspace.read(cx).is_being_followed(peer_id);
@ -732,7 +736,7 @@ impl CollabTitlebarItem {
.bottom(),
)
})())
.into_element();
.into_any();
if let Some(location) = location {
if let Some(replica_id) = replica_id {
@ -756,7 +760,7 @@ impl CollabTitlebarItem {
theme.tooltip.clone(),
cx,
)
.into_element();
.into_any();
} else if let ParticipantLocation::SharedProject { project_id } = location {
let user_id = user.id;
content = MouseEventHandler::<JoinProject, Self>::new(
@ -778,7 +782,7 @@ impl CollabTitlebarItem {
theme.tooltip.clone(),
cx,
)
.into_element();
.into_any();
}
}
content
@ -807,7 +811,7 @@ impl CollabTitlebarItem {
avatar: Arc<ImageData>,
avatar_style: AvatarStyle,
background_color: Color,
) -> Element<V> {
) -> AnyElement<V> {
Image::from_data(avatar)
.with_style(avatar_style.image)
.aligned()
@ -818,14 +822,14 @@ impl CollabTitlebarItem {
.with_width(avatar_style.outer_width)
.with_height(avatar_style.outer_width)
.aligned()
.into_element()
.into_any()
}
fn render_connection_status(
&self,
status: &client::Status,
cx: &mut ViewContext<Self>,
) -> Option<Element<Self>> {
) -> Option<AnyElement<Self>> {
enum ConnectionStatusButton {}
let theme = &cx.global::<Settings>().theme.clone();
@ -842,7 +846,7 @@ impl CollabTitlebarItem {
.aligned()
.contained()
.with_style(theme.workspace.titlebar.offline_icon.container)
.into_element(),
.into_any(),
),
client::Status::UpgradeRequired => Some(
MouseEventHandler::<ConnectionStatusButton, Self>::new(0, cx, |_, _| {
@ -858,7 +862,7 @@ impl CollabTitlebarItem {
.on_click(MouseButton::Left, |_, _, cx| {
cx.dispatch_action(auto_update::Check);
})
.into_element(),
.into_any(),
),
_ => None,
}
@ -875,7 +879,7 @@ impl AvatarRibbon {
}
}
impl Drawable<CollabTitlebarItem> for AvatarRibbon {
impl Element<CollabTitlebarItem> for AvatarRibbon {
type LayoutState = ();
type PaintState = ();

View file

@ -30,7 +30,7 @@ impl View for CollaboratorListPopover {
"CollaboratorListPopover"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = cx.global::<Settings>().theme.clone();
MouseEventHandler::<Self, Self>::new(0, cx, |_, _| {
@ -44,7 +44,7 @@ impl View for CollaboratorListPopover {
.on_down_out(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(ToggleCollaboratorList);
})
.into_element()
.into_any()
}
fn focus_out(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
@ -116,7 +116,7 @@ fn render_collaborator_list_entry<UA: Action + Clone, IA: Action + Clone>(
icon_action: IA,
icon_tooltip: String,
cx: &mut ViewContext<CollaboratorListPopover>,
) -> Element<CollaboratorListPopover> {
) -> AnyElement<CollaboratorListPopover> {
enum Username {}
enum UsernameTooltip {}
enum Icon {}
@ -146,9 +146,9 @@ fn render_collaborator_list_entry<UA: Action + Clone, IA: Action + Clone>(
tooltip_theme.clone(),
cx,
)
.into_element()
.into_any()
} else {
username.into_element()
username.into_any()
})
.with_child(
MouseEventHandler::<Icon, CollaboratorListPopover>::new(index, cx, |_, _| icon)
@ -157,5 +157,5 @@ fn render_collaborator_list_entry<UA: Action + Clone, IA: Action + Clone>(
})
.with_tooltip::<IconTooltip>(index, icon_tooltip, None, tooltip_theme, cx),
)
.into_element()
.into_any()
}

View file

@ -96,7 +96,7 @@ impl PickerDelegate for ContactFinderDelegate {
mouse_state: &mut MouseState,
selected: bool,
cx: &gpui::AppContext,
) -> Element<Picker<Self>> {
) -> AnyElement<Picker<Self>> {
let theme = &cx.global::<Settings>().theme;
let user = &self.potential_contacts[ix];
let request_status = self.user_store.read(cx).contact_request_status(user);
@ -150,6 +150,6 @@ impl PickerDelegate for ContactFinderDelegate {
.with_style(style.container)
.constrained()
.with_height(theme.contact_finder.row_height)
.into_element()
.into_any()
}
}

View file

@ -748,7 +748,7 @@ impl ContactList {
is_pending: bool,
is_selected: bool,
theme: &theme::ContactList,
) -> Element<Self> {
) -> AnyElement<Self> {
Flex::row()
.with_children(user.avatar.clone().map(|avatar| {
Image::from_data(avatar)
@ -785,7 +785,7 @@ impl ContactList {
.contact_row
.style_for(&mut Default::default(), is_selected),
)
.into_element()
.into_any()
}
fn render_participant_project(
@ -797,7 +797,7 @@ impl ContactList {
is_selected: bool,
theme: &theme::ContactList,
cx: &mut ViewContext<Self>,
) -> Element<Self> {
) -> AnyElement<Self> {
let font_cache = cx.font_cache();
let host_avatar_height = theme
.contact_avatar
@ -881,7 +881,7 @@ impl ContactList {
});
}
})
.into_element()
.into_any()
}
fn render_participant_screen(
@ -890,7 +890,7 @@ impl ContactList {
is_selected: bool,
theme: &theme::ContactList,
cx: &mut ViewContext<Self>,
) -> Element<Self> {
) -> AnyElement<Self> {
let font_cache = cx.font_cache();
let host_avatar_height = theme
.contact_avatar
@ -974,7 +974,7 @@ impl ContactList {
.on_click(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(OpenSharedScreen { peer_id });
})
.into_element()
.into_any()
}
fn render_header(
@ -983,7 +983,7 @@ impl ContactList {
is_selected: bool,
is_collapsed: bool,
cx: &mut ViewContext<Self>,
) -> Element<Self> {
) -> AnyElement<Self> {
enum Header {}
enum LeaveCallContactList {}
@ -1046,7 +1046,7 @@ impl ContactList {
.on_click(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(ToggleExpanded(section))
})
.into_element()
.into_any()
}
fn render_contact(
@ -1056,7 +1056,7 @@ impl ContactList {
theme: &theme::ContactList,
is_selected: bool,
cx: &mut ViewContext<Self>,
) -> Element<Self> {
) -> AnyElement<Self> {
let online = contact.online;
let busy = contact.busy || calling;
let user_id = contact.user.id;
@ -1155,7 +1155,7 @@ impl ContactList {
event_handler = event_handler.with_cursor_style(CursorStyle::PointingHand);
}
event_handler.into_element()
event_handler.into_any()
}
fn render_contact_request(
@ -1165,7 +1165,7 @@ impl ContactList {
is_incoming: bool,
is_selected: bool,
cx: &mut ViewContext<Self>,
) -> Element<Self> {
) -> AnyElement<Self> {
enum Decline {}
enum Accept {}
enum Cancel {}
@ -1266,7 +1266,7 @@ impl ContactList {
.contact_row
.style_for(&mut Default::default(), is_selected),
)
.into_element()
.into_any()
}
fn call(&mut self, action: &Call, cx: &mut ViewContext<Self>) {
@ -1295,7 +1295,7 @@ impl View for ContactList {
cx
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
enum AddContact {}
let theme = cx.global::<Settings>().theme.clone();
@ -1331,7 +1331,7 @@ impl View for ContactList {
.with_height(theme.contact_list.user_query_editor_height),
)
.with_child(List::new(self.list_state.clone()).flex(1., false))
.into_element()
.into_any()
}
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {
@ -1347,7 +1347,7 @@ impl View for ContactList {
}
}
fn render_icon_button(style: &IconButton, svg_path: &'static str) -> impl Drawable<ContactList> {
fn render_icon_button(style: &IconButton, svg_path: &'static str) -> impl Element<ContactList> {
Svg::new(svg_path)
.with_color(style.color)
.constrained()

View file

@ -42,7 +42,7 @@ impl View for ContactNotification {
"ContactNotification"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
match self.kind {
ContactEventKind::Requested => render_user_notification(
self.user.clone(),

View file

@ -96,7 +96,7 @@ impl View for ContactsPopover {
"ContactsPopover"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = cx.global::<Settings>().theme.clone();
let child = match &self.child {
Child::ContactList(child) => ChildView::new(child, cx),
@ -115,7 +115,7 @@ impl View for ContactsPopover {
.on_down_out(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(ToggleContactsMenu);
})
.into_element()
.into_any()
}
fn focus_in(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) {

View file

@ -7,14 +7,14 @@ use gpui::{
},
json::ToJson,
serde_json::{self, json},
Axis, Drawable, Element, SceneBuilder, ViewContext,
AnyElement, Axis, Element, SceneBuilder, ViewContext,
};
use crate::CollabTitlebarItem;
pub(crate) struct FacePile {
overlap: f32,
faces: Vec<Element<CollabTitlebarItem>>,
faces: Vec<AnyElement<CollabTitlebarItem>>,
}
impl FacePile {
@ -26,7 +26,7 @@ impl FacePile {
}
}
impl Drawable<CollabTitlebarItem> for FacePile {
impl Element<CollabTitlebarItem> for FacePile {
type LayoutState = ();
type PaintState = ();
@ -101,8 +101,8 @@ impl Drawable<CollabTitlebarItem> for FacePile {
}
}
impl Extend<Element<CollabTitlebarItem>> for FacePile {
fn extend<T: IntoIterator<Item = Element<CollabTitlebarItem>>>(&mut self, children: T) {
impl Extend<AnyElement<CollabTitlebarItem>> for FacePile {
fn extend<T: IntoIterator<Item = AnyElement<CollabTitlebarItem>>>(&mut self, children: T) {
self.faces.extend(children);
}
}

View file

@ -6,7 +6,7 @@ use gpui::{
geometry::{rect::RectF, vector::vec2f},
impl_internal_actions,
platform::{CursorStyle, MouseButton, WindowBounds, WindowKind, WindowOptions},
AppContext, Element, Entity, View, ViewContext,
AnyElement, AppContext, Entity, View, ViewContext,
};
use settings::Settings;
use util::ResultExt;
@ -99,7 +99,7 @@ impl IncomingCallNotification {
}
}
fn render_caller(&self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render_caller(&self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = &cx.global::<Settings>().theme.incoming_call_notification;
let default_project = proto::ParticipantProject::default();
let initial_project = self
@ -157,10 +157,10 @@ impl IncomingCallNotification {
.contained()
.with_style(theme.caller_container)
.flex(1., true)
.into_element()
.into_any()
}
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
enum Accept {}
enum Decline {}
@ -200,7 +200,7 @@ impl IncomingCallNotification {
.incoming_call_notification
.button_width,
)
.into_element()
.into_any()
}
}
@ -213,7 +213,7 @@ impl View for IncomingCallNotification {
"IncomingCallNotification"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let background = cx
.global::<Settings>()
.theme
@ -226,6 +226,6 @@ impl View for IncomingCallNotification {
.contained()
.with_background_color(background)
.expanded()
.into_element()
.into_any()
}
}

View file

@ -2,7 +2,7 @@ use client::User;
use gpui::{
elements::*,
platform::{CursorStyle, MouseButton},
Action, Drawable, Element, View, ViewContext,
Action, AnyElement, Element, View, ViewContext,
};
use settings::Settings;
use std::sync::Arc;
@ -17,7 +17,7 @@ pub fn render_user_notification<V: View, A: Action + Clone>(
dismiss_action: A,
buttons: Vec<(&'static str, Box<dyn Action>)>,
cx: &mut ViewContext<V>,
) -> Element<V> {
) -> AnyElement<V> {
let theme = cx.global::<Settings>().theme.clone();
let theme = &theme.contact_notification;
@ -77,7 +77,7 @@ pub fn render_user_notification<V: View, A: Action + Clone>(
.top()
.flex_float(),
)
.into_named_element("contact notification header"),
.into_any_named("contact notification header"),
)
.with_children(body.map(|body| {
Label::new(body, theme.body_message.text.clone())
@ -108,5 +108,5 @@ pub fn render_user_notification<V: View, A: Action + Clone>(
)
})
.contained()
.into_element()
.into_any()
}

View file

@ -102,7 +102,7 @@ impl ProjectSharedNotification {
cx.remove_window();
}
fn render_owner(&self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render_owner(&self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = &cx.global::<Settings>().theme.project_shared_notification;
Flex::row()
.with_children(self.owner.avatar.clone().map(|avatar| {
@ -154,10 +154,10 @@ impl ProjectSharedNotification {
.contained()
.with_style(theme.owner_container)
.flex(1., true)
.into_element()
.into_any()
}
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render_buttons(&self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
enum Open {}
enum Dismiss {}
@ -203,7 +203,7 @@ impl ProjectSharedNotification {
.project_shared_notification
.button_width,
)
.into_element()
.into_any()
}
}
@ -216,7 +216,7 @@ impl View for ProjectSharedNotification {
"ProjectSharedNotification"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> gpui::Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> gpui::AnyElement<Self> {
let background = cx
.global::<Settings>()
.theme
@ -228,6 +228,6 @@ impl View for ProjectSharedNotification {
.contained()
.with_background_color(background)
.expanded()
.into_element()
.into_any()
}
}

View file

@ -3,7 +3,7 @@ use gpui::{
color::Color,
elements::{MouseEventHandler, Svg},
platform::{Appearance, MouseButton},
AppContext, Drawable, Element, Entity, View, ViewContext,
AnyElement, AppContext, Element, Entity, View, ViewContext,
};
use settings::Settings;
@ -40,7 +40,7 @@ impl View for SharingStatusIndicator {
"SharingStatusIndicator"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let color = match cx.window_appearance() {
Appearance::Light | Appearance::VibrantLight => Color::black(),
Appearance::Dark | Appearance::VibrantDark => Color::white(),
@ -56,6 +56,6 @@ impl View for SharingStatusIndicator {
.on_click(MouseButton::Left, |_, _, cx| {
cx.dispatch_action(ToggleScreenSharing);
})
.into_element()
.into_any()
}
}