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

@ -315,7 +315,7 @@ impl View for ActivityIndicator {
"ActivityIndicator" "ActivityIndicator"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let Content { let Content {
icon, icon,
message, message,
@ -343,7 +343,7 @@ impl View for ActivityIndicator {
.contained() .contained()
.with_margin_right(style.icon_spacing) .with_margin_right(style.icon_spacing)
.aligned() .aligned()
.into_named_element("activity-icon") .into_any_named("activity-icon")
})) }))
.with_child( .with_child(
Text::new(message, style.message.clone()) Text::new(message, style.message.clone())
@ -365,7 +365,7 @@ impl View for ActivityIndicator {
}); });
} }
element.into_element() element.into_any()
} }
} }

View File

@ -2,7 +2,7 @@ use crate::ViewReleaseNotes;
use gpui::{ use gpui::{
elements::{Flex, MouseEventHandler, Padding, ParentElement, Svg, Text}, elements::{Flex, MouseEventHandler, Padding, ParentElement, Svg, Text},
platform::{AppVersion, CursorStyle, MouseButton}, platform::{AppVersion, CursorStyle, MouseButton},
Drawable, Entity, View, ViewContext, Element, Entity, View, ViewContext,
}; };
use menu::Cancel; use menu::Cancel;
use settings::Settings; use settings::Settings;
@ -26,7 +26,7 @@ impl View for UpdateNotification {
"UpdateNotification" "UpdateNotification"
} }
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> gpui::Element<Self> { fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> gpui::AnyElement<Self> {
let theme = cx.global::<Settings>().theme.clone(); let theme = cx.global::<Settings>().theme.clone();
let theme = &theme.update_notification; let theme = &theme.update_notification;
@ -86,7 +86,7 @@ impl View for UpdateNotification {
.on_click(MouseButton::Left, |_, _, cx| { .on_click(MouseButton::Left, |_, _, cx| {
cx.dispatch_action(ViewReleaseNotes) cx.dispatch_action(ViewReleaseNotes)
}) })
.into_named_element("update notification") .into_any_named("update notification")
} }
} }

View File

@ -41,10 +41,10 @@ impl View for Breadcrumbs {
"Breadcrumbs" "Breadcrumbs"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let active_item = match &self.active_item { let active_item = match &self.active_item {
Some(active_item) => active_item, Some(active_item) => active_item,
None => return Empty::new().into_element(), None => return Empty::new().into_any(),
}; };
let not_editor = active_item.downcast::<editor::Editor>().is_none(); let not_editor = active_item.downcast::<editor::Editor>().is_none();
@ -53,7 +53,7 @@ impl View for Breadcrumbs {
let breadcrumbs = match active_item.breadcrumbs(&theme, cx) { let breadcrumbs = match active_item.breadcrumbs(&theme, cx) {
Some(breadcrumbs) => breadcrumbs, Some(breadcrumbs) => breadcrumbs,
None => return Empty::new().into_element(), None => return Empty::new().into_any(),
} }
.into_iter() .into_iter()
.map(|breadcrumb| { .map(|breadcrumb| {
@ -62,12 +62,12 @@ impl View for Breadcrumbs {
theme.workspace.breadcrumbs.default.text.clone(), theme.workspace.breadcrumbs.default.text.clone(),
) )
.with_highlights(breadcrumb.highlights.unwrap_or_default()) .with_highlights(breadcrumb.highlights.unwrap_or_default())
.into_element() .into_any()
}); });
let crumbs = Flex::row() let crumbs = Flex::row()
.with_children(Itertools::intersperse_with(breadcrumbs, || { .with_children(Itertools::intersperse_with(breadcrumbs, || {
Label::new("", style.default.text.clone()).into_element() Label::new("", style.default.text.clone()).into_any()
})) }))
.constrained() .constrained()
.with_height(theme.workspace.breadcrumb_height) .with_height(theme.workspace.breadcrumb_height)
@ -78,7 +78,7 @@ impl View for Breadcrumbs {
.with_style(style.default.container) .with_style(style.default.container)
.aligned() .aligned()
.left() .left()
.into_element(); .into_any();
} }
MouseEventHandler::<Breadcrumbs, Breadcrumbs>::new(0, cx, |state, _| { MouseEventHandler::<Breadcrumbs, Breadcrumbs>::new(0, cx, |state, _| {
@ -97,7 +97,7 @@ impl View for Breadcrumbs {
) )
.aligned() .aligned()
.left() .left()
.into_element() .into_any()
} }
} }

View File

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

View File

@ -30,7 +30,7 @@ impl View for CollaboratorListPopover {
"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(); let theme = cx.global::<Settings>().theme.clone();
MouseEventHandler::<Self, Self>::new(0, cx, |_, _| { MouseEventHandler::<Self, Self>::new(0, cx, |_, _| {
@ -44,7 +44,7 @@ impl View for CollaboratorListPopover {
.on_down_out(MouseButton::Left, move |_, _, cx| { .on_down_out(MouseButton::Left, move |_, _, cx| {
cx.dispatch_action(ToggleCollaboratorList); cx.dispatch_action(ToggleCollaboratorList);
}) })
.into_element() .into_any()
} }
fn focus_out(&mut self, _: gpui::AnyViewHandle, cx: &mut ViewContext<Self>) { 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_action: IA,
icon_tooltip: String, icon_tooltip: String,
cx: &mut ViewContext<CollaboratorListPopover>, cx: &mut ViewContext<CollaboratorListPopover>,
) -> Element<CollaboratorListPopover> { ) -> AnyElement<CollaboratorListPopover> {
enum Username {} enum Username {}
enum UsernameTooltip {} enum UsernameTooltip {}
enum Icon {} enum Icon {}
@ -146,9 +146,9 @@ fn render_collaborator_list_entry<UA: Action + Clone, IA: Action + Clone>(
tooltip_theme.clone(), tooltip_theme.clone(),
cx, cx,
) )
.into_element() .into_any()
} else { } else {
username.into_element() username.into_any()
}) })
.with_child( .with_child(
MouseEventHandler::<Icon, CollaboratorListPopover>::new(index, cx, |_, _| icon) 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), .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, mouse_state: &mut MouseState,
selected: bool, selected: bool,
cx: &gpui::AppContext, cx: &gpui::AppContext,
) -> Element<Picker<Self>> { ) -> AnyElement<Picker<Self>> {
let theme = &cx.global::<Settings>().theme; let theme = &cx.global::<Settings>().theme;
let user = &self.potential_contacts[ix]; let user = &self.potential_contacts[ix];
let request_status = self.user_store.read(cx).contact_request_status(user); let request_status = self.user_store.read(cx).contact_request_status(user);
@ -150,6 +150,6 @@ impl PickerDelegate for ContactFinderDelegate {
.with_style(style.container) .with_style(style.container)
.constrained() .constrained()
.with_height(theme.contact_finder.row_height) .with_height(theme.contact_finder.row_height)
.into_element() .into_any()
} }
} }

View File

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

View File

@ -42,7 +42,7 @@ impl View for ContactNotification {
"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 { match self.kind {
ContactEventKind::Requested => render_user_notification( ContactEventKind::Requested => render_user_notification(
self.user.clone(), self.user.clone(),

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
use collections::CommandPaletteFilter; use collections::CommandPaletteFilter;
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, elements::*, keymap_matcher::Keystroke, Action, AppContext, Drawable, MouseState, actions, elements::*, keymap_matcher::Keystroke, Action, AppContext, Element, MouseState,
ViewContext, ViewContext,
}; };
use picker::{Picker, PickerDelegate, PickerEvent}; use picker::{Picker, PickerDelegate, PickerEvent};
@ -176,7 +176,7 @@ impl PickerDelegate for CommandPaletteDelegate {
mouse_state: &mut MouseState, mouse_state: &mut MouseState,
selected: bool, selected: bool,
cx: &gpui::AppContext, cx: &gpui::AppContext,
) -> Element<Picker<Self>> { ) -> AnyElement<Picker<Self>> {
let mat = &self.matches[ix]; let mat = &self.matches[ix];
let command = &self.actions[mat.candidate_id]; let command = &self.actions[mat.candidate_id];
let settings = cx.global::<Settings>(); let settings = cx.global::<Settings>();
@ -223,7 +223,7 @@ impl PickerDelegate for CommandPaletteDelegate {
})) }))
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.into_element() .into_any()
} }
} }

View File

@ -26,10 +26,10 @@ pub fn init(cx: &mut AppContext) {
cx.add_action(ContextMenu::cancel); cx.add_action(ContextMenu::cancel);
} }
pub type StaticItem = Box<dyn Fn(&mut AppContext) -> Element<ContextMenu>>; pub type StaticItem = Box<dyn Fn(&mut AppContext) -> AnyElement<ContextMenu>>;
type ContextMenuItemBuilder = type ContextMenuItemBuilder =
Box<dyn Fn(&mut MouseState, &theme::ContextMenuItem) -> Element<ContextMenu>>; Box<dyn Fn(&mut MouseState, &theme::ContextMenuItem) -> AnyElement<ContextMenu>>;
pub enum ContextMenuItemLabel { pub enum ContextMenuItemLabel {
String(Cow<'static, str>), String(Cow<'static, str>),
@ -142,9 +142,9 @@ impl View for ContextMenu {
cx cx
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if !self.visible { if !self.visible {
return Empty::new().into_element(); return Empty::new().into_any();
} }
// Render the menu once at minimum width. // Render the menu once at minimum width.
@ -165,7 +165,7 @@ impl View for ContextMenu {
.with_anchor_position(self.anchor_position) .with_anchor_position(self.anchor_position)
.with_anchor_corner(self.anchor_corner) .with_anchor_corner(self.anchor_corner)
.with_position_mode(self.position_mode) .with_position_mode(self.position_mode)
.into_element() .into_any()
} }
fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_out(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
@ -327,10 +327,7 @@ impl ContextMenu {
self.position_mode = mode; self.position_mode = mode;
} }
fn render_menu_for_measurement( fn render_menu_for_measurement(&self, cx: &mut ViewContext<Self>) -> impl Element<ContextMenu> {
&self,
cx: &mut ViewContext<Self>,
) -> impl Drawable<ContextMenu> {
let style = cx.global::<Settings>().theme.context_menu.clone(); let style = cx.global::<Settings>().theme.context_menu.clone();
Flex::row() Flex::row()
.with_child( .with_child(
@ -347,7 +344,7 @@ impl ContextMenu {
Label::new(label.to_string(), style.label.clone()) Label::new(label.to_string(), style.label.clone())
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.into_element() .into_any()
} }
ContextMenuItemLabel::Element(element) => { ContextMenuItemLabel::Element(element) => {
element(&mut Default::default(), style) element(&mut Default::default(), style)
@ -363,7 +360,7 @@ impl ContextMenu {
.with_style(style.separator) .with_style(style.separator)
.constrained() .constrained()
.with_height(1.) .with_height(1.)
.into_element(), .into_any(),
} }
})), })),
) )
@ -391,10 +388,10 @@ impl ContextMenu {
style.keystroke.container, style.keystroke.container,
style.keystroke.text.clone(), style.keystroke.text.clone(),
) )
.into_element() .into_any()
} }
ContextMenuItem::Static(_) => Empty::new().into_element(), ContextMenuItem::Static(_) => Empty::new().into_any(),
ContextMenuItem::Separator => Empty::new() ContextMenuItem::Separator => Empty::new()
.collapsed() .collapsed()
@ -402,7 +399,7 @@ impl ContextMenu {
.with_height(1.) .with_height(1.)
.contained() .contained()
.with_style(style.separator) .with_style(style.separator)
.into_element(), .into_any(),
} }
})) }))
.contained() .contained()
@ -412,7 +409,7 @@ impl ContextMenu {
.with_style(style.container) .with_style(style.container)
} }
fn render_menu(&self, cx: &mut ViewContext<Self>) -> impl Drawable<ContextMenu> { fn render_menu(&self, cx: &mut ViewContext<Self>) -> impl Element<ContextMenu> {
enum Menu {} enum Menu {}
enum MenuItem {} enum MenuItem {}
@ -441,7 +438,7 @@ impl ContextMenu {
ContextMenuItemLabel::String(label) => { ContextMenuItemLabel::String(label) => {
Label::new(label.clone(), style.label.clone()) Label::new(label.clone(), style.label.clone())
.contained() .contained()
.into_element() .into_any()
} }
ContextMenuItemLabel::Element(element) => { ContextMenuItemLabel::Element(element) => {
element(state, style) element(state, style)
@ -468,7 +465,7 @@ impl ContextMenu {
cx.dispatch_any_action_at(window_id, view_id, action.boxed_clone()); cx.dispatch_any_action_at(window_id, view_id, action.boxed_clone());
}) })
.on_drag(MouseButton::Left, |_, _, _| {}) .on_drag(MouseButton::Left, |_, _, _| {})
.into_element() .into_any()
} }
ContextMenuItem::Static(f) => f(cx), ContextMenuItem::Static(f) => f(cx),
@ -478,7 +475,7 @@ impl ContextMenu {
.with_height(1.) .with_height(1.)
.contained() .contained()
.with_style(style.separator) .with_style(style.separator)
.into_element(), .into_any(),
} }
})) }))
.contained() .contained()

View File

@ -4,7 +4,7 @@ use gpui::{
geometry::rect::RectF, geometry::rect::RectF,
impl_internal_actions, impl_internal_actions,
platform::{WindowBounds, WindowKind, WindowOptions}, platform::{WindowBounds, WindowKind, WindowOptions},
AnyViewHandle, AppContext, ClipboardItem, Drawable, Element, Entity, View, ViewContext, AnyElement, AnyViewHandle, AppContext, ClipboardItem, Element, Entity, View, ViewContext,
ViewHandle, ViewHandle,
}; };
use settings::Settings; use settings::Settings;
@ -119,7 +119,7 @@ impl CopilotCodeVerification {
data: &PromptUserDeviceFlow, data: &PromptUserDeviceFlow,
style: &theme::Copilot, style: &theme::Copilot,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> impl Drawable<Self> { ) -> impl Element<Self> {
let copied = cx let copied = cx
.read_from_clipboard() .read_from_clipboard()
.map(|item| item.text() == &data.user_code) .map(|item| item.text() == &data.user_code)
@ -167,7 +167,7 @@ impl CopilotCodeVerification {
data: &PromptUserDeviceFlow, data: &PromptUserDeviceFlow,
style: &theme::Copilot, style: &theme::Copilot,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Element<Self> { ) -> AnyElement<Self> {
enum ConnectButton {} enum ConnectButton {}
Flex::column() Flex::column()
@ -226,10 +226,13 @@ impl CopilotCodeVerification {
}, },
)) ))
.align_children_center() .align_children_center()
.into_element() .into_any()
} }
fn render_enabled_modal(style: &theme::Copilot, cx: &mut ViewContext<Self>) -> Element<Self> { fn render_enabled_modal(
style: &theme::Copilot,
cx: &mut ViewContext<Self>,
) -> AnyElement<Self> {
enum DoneButton {} enum DoneButton {}
let enabled_style = &style.auth.authorized; let enabled_style = &style.auth.authorized;
@ -267,13 +270,13 @@ impl CopilotCodeVerification {
|_, _, cx| cx.remove_window(), |_, _, cx| cx.remove_window(),
)) ))
.align_children_center() .align_children_center()
.into_element() .into_any()
} }
fn render_unauthorized_modal( fn render_unauthorized_modal(
style: &theme::Copilot, style: &theme::Copilot,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Element<Self> { ) -> AnyElement<Self> {
let unauthorized_style = &style.auth.not_authorized; let unauthorized_style = &style.auth.not_authorized;
Flex::column() Flex::column()
@ -324,7 +327,7 @@ impl CopilotCodeVerification {
}, },
)) ))
.align_children_center() .align_children_center()
.into_element() .into_any()
} }
} }
@ -345,7 +348,7 @@ impl View for CopilotCodeVerification {
cx.notify() cx.notify()
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
enum ConnectModal {} enum ConnectModal {}
let style = cx.global::<Settings>().theme.clone(); let style = cx.global::<Settings>().theme.clone();
@ -357,7 +360,7 @@ impl View for CopilotCodeVerification {
|cx| { |cx| {
Flex::column() Flex::column()
.with_children([ .with_children([
theme::ui::icon(&style.copilot.auth.header).into_element(), theme::ui::icon(&style.copilot.auth.header).into_any(),
match &self.status { match &self.status {
Status::SigningIn { Status::SigningIn {
prompt: Some(prompt), prompt: Some(prompt),
@ -375,12 +378,12 @@ impl View for CopilotCodeVerification {
self.connect_clicked = false; self.connect_clicked = false;
Self::render_enabled_modal(&style.copilot, cx) Self::render_enabled_modal(&style.copilot, cx)
} }
_ => Empty::new().into_element(), _ => Empty::new().into_any(),
}, },
]) ])
.align_children_center() .align_children_center()
}, },
) )
.into_element() .into_any()
} }
} }

View File

@ -6,7 +6,8 @@ use gpui::{
elements::*, elements::*,
impl_internal_actions, impl_internal_actions,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
AppContext, Drawable, Element, Entity, MouseState, Subscription, View, ViewContext, ViewHandle, AnyElement, AppContext, Element, Entity, MouseState, Subscription, View, ViewContext,
ViewHandle,
}; };
use settings::{settings_file::SettingsFile, Settings}; use settings::{settings_file::SettingsFile, Settings};
use workspace::{ use workspace::{
@ -155,17 +156,17 @@ impl View for CopilotButton {
"CopilotButton" "CopilotButton"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let settings = cx.global::<Settings>(); let settings = cx.global::<Settings>();
if !settings.features.copilot { if !settings.features.copilot {
return Empty::new().into_element(); return Empty::new().into_any();
} }
let theme = settings.theme.clone(); let theme = settings.theme.clone();
let active = self.popup_menu.read(cx).visible(); let active = self.popup_menu.read(cx).visible();
let Some(copilot) = Copilot::global(cx) else { let Some(copilot) = Copilot::global(cx) else {
return Empty::new().into_element(); return Empty::new().into_any();
}; };
let status = copilot.read(cx).status(); let status = copilot.read(cx).status();
@ -205,7 +206,7 @@ impl View for CopilotButton {
.constrained() .constrained()
.with_width(style.icon_size) .with_width(style.icon_size)
.aligned() .aligned()
.into_named_element("copilot-icon"), .into_any_named("copilot-icon"),
) )
.constrained() .constrained()
.with_height(style.icon_size) .with_height(style.icon_size)
@ -236,7 +237,7 @@ impl View for CopilotButton {
), ),
) )
.with_child(ChildView::new(&self.popup_menu, cx).aligned().top().right()) .with_child(ChildView::new(&self.popup_menu, cx).aligned().top().right())
.into_element() .into_any()
} }
} }
@ -323,7 +324,7 @@ impl CopilotButton {
.with_child(Label::new("Copilot Settings", style.label.clone())) .with_child(Label::new("Copilot Settings", style.label.clone()))
.with_child(theme::ui::icon(icon_style.style_for(state, false))) .with_child(theme::ui::icon(icon_style.style_for(state, false)))
.align_children_center() .align_children_center()
.into_element() .into_any()
}, },
), ),
OsOpen::new(COPILOT_SETTINGS_URL), OsOpen::new(COPILOT_SETTINGS_URL),

View File

@ -89,16 +89,16 @@ impl View for ProjectDiagnosticsEditor {
"ProjectDiagnosticsEditor" "ProjectDiagnosticsEditor"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if self.path_states.is_empty() { if self.path_states.is_empty() {
let theme = &cx.global::<Settings>().theme.project_diagnostics; let theme = &cx.global::<Settings>().theme.project_diagnostics;
Label::new("No problems in workspace", theme.empty_message.clone()) Label::new("No problems in workspace", theme.empty_message.clone())
.aligned() .aligned()
.contained() .contained()
.with_style(theme.container) .with_style(theme.container)
.into_element() .into_any()
} else { } else {
ChildView::new(&self.editor, cx).into_element() ChildView::new(&self.editor, cx).into_any()
} }
} }
@ -535,7 +535,7 @@ impl Item for ProjectDiagnosticsEditor {
_detail: Option<usize>, _detail: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
cx: &AppContext, cx: &AppContext,
) -> Element<T> { ) -> AnyElement<T> {
render_summary( render_summary(
&self.summary, &self.summary,
&style.label.text, &style.label.text,
@ -718,7 +718,7 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
.with_padding_left(cx.gutter_padding) .with_padding_left(cx.gutter_padding)
.with_padding_right(cx.gutter_padding) .with_padding_right(cx.gutter_padding)
.expanded() .expanded()
.into_named_element("diagnostic header") .into_any_named("diagnostic header")
}) })
} }
@ -726,9 +726,9 @@ pub(crate) fn render_summary<T: View>(
summary: &DiagnosticSummary, summary: &DiagnosticSummary,
text_style: &TextStyle, text_style: &TextStyle,
theme: &theme::ProjectDiagnostics, theme: &theme::ProjectDiagnostics,
) -> Element<T> { ) -> AnyElement<T> {
if summary.error_count == 0 && summary.warning_count == 0 { if summary.error_count == 0 && summary.warning_count == 0 {
Label::new("No problems", text_style.clone()).into_element() Label::new("No problems", text_style.clone()).into_any()
} else { } else {
let icon_width = theme.tab_icon_width; let icon_width = theme.tab_icon_width;
let icon_spacing = theme.tab_icon_spacing; let icon_spacing = theme.tab_icon_spacing;
@ -773,7 +773,7 @@ pub(crate) fn render_summary<T: View>(
) )
.aligned(), .aligned(),
) )
.into_element() .into_any()
} }
} }

View File

@ -85,7 +85,7 @@ impl View for DiagnosticIndicator {
"DiagnosticIndicator" "DiagnosticIndicator"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
enum Summary {} enum Summary {}
enum Message {} enum Message {}
@ -146,7 +146,7 @@ impl View for DiagnosticIndicator {
.constrained() .constrained()
.with_width(style.icon_width) .with_width(style.icon_width)
.aligned() .aligned()
.into_named_element("ok-icon"), .into_any_named("ok-icon"),
); );
} }
@ -174,7 +174,7 @@ impl View for DiagnosticIndicator {
cx, cx,
) )
.aligned() .aligned()
.into_element(), .into_any(),
); );
let style = &cx.global::<Settings>().theme.workspace.status_bar; let style = &cx.global::<Settings>().theme.workspace.status_bar;
@ -206,7 +206,7 @@ impl View for DiagnosticIndicator {
); );
} }
element.into_named_element("diagnostic indicator") element.into_any_named("diagnostic indicator")
} }
fn debug_json(&self, _: &gpui::AppContext) -> serde_json::Value { fn debug_json(&self, _: &gpui::AppContext) -> serde_json::Value {

View File

@ -6,7 +6,7 @@ use gpui::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
scene::{MouseDown, MouseDrag}, scene::{MouseDown, MouseDrag},
Drawable, Element, View, ViewContext, WeakViewHandle, WindowContext, AnyElement, Element, View, ViewContext, WeakViewHandle, WindowContext,
}; };
const DEAD_ZONE: f32 = 4.; const DEAD_ZONE: f32 = 4.;
@ -26,7 +26,7 @@ enum State<V: View> {
region_offset: Vector2F, region_offset: Vector2F,
region: RectF, region: RectF,
payload: Rc<dyn Any + 'static>, payload: Rc<dyn Any + 'static>,
render: Rc<dyn Fn(Rc<dyn Any>, &mut ViewContext<V>) -> Element<V>>, render: Rc<dyn Fn(Rc<dyn Any>, &mut ViewContext<V>) -> AnyElement<V>>,
}, },
Canceled, Canceled,
} }
@ -124,7 +124,7 @@ impl<V: View> DragAndDrop<V> {
event: MouseDrag, event: MouseDrag,
payload: Rc<T>, payload: Rc<T>,
cx: &mut WindowContext, cx: &mut WindowContext,
render: Rc<impl 'static + Fn(&T, &mut ViewContext<V>) -> Element<V>>, render: Rc<impl 'static + Fn(&T, &mut ViewContext<V>) -> AnyElement<V>>,
) { ) {
let window_id = cx.window_id(); let window_id = cx.window_id();
cx.update_global(|this: &mut Self, cx| { cx.update_global(|this: &mut Self, cx| {
@ -178,7 +178,7 @@ impl<V: View> DragAndDrop<V> {
}); });
} }
pub fn render(cx: &mut ViewContext<V>) -> Option<Element<V>> { pub fn render(cx: &mut ViewContext<V>) -> Option<AnyElement<V>> {
enum DraggedElementHandler {} enum DraggedElementHandler {}
cx.global::<Self>() cx.global::<Self>()
.currently_dragged .currently_dragged
@ -230,7 +230,7 @@ impl<V: View> DragAndDrop<V> {
.with_height(region.height()), .with_height(region.height()),
) )
.with_anchor_position(position) .with_anchor_position(position)
.into_element(), .into_any(),
) )
} }
@ -252,7 +252,7 @@ impl<V: View> DragAndDrop<V> {
}); });
}); });
}) })
.into_element(), .into_any(),
), ),
} }
}) })
@ -295,7 +295,7 @@ pub trait Draggable<V: View> {
fn as_draggable<D: View, P: Any>( fn as_draggable<D: View, P: Any>(
self, self,
payload: P, payload: P,
render: impl 'static + Fn(&P, &mut ViewContext<D>) -> Element<D>, render: impl 'static + Fn(&P, &mut ViewContext<D>) -> AnyElement<D>,
) -> Self ) -> Self
where where
Self: Sized; Self: Sized;
@ -305,7 +305,7 @@ impl<Tag, V: View> Draggable<V> for MouseEventHandler<Tag, V> {
fn as_draggable<D: View, P: Any>( fn as_draggable<D: View, P: Any>(
self, self,
payload: P, payload: P,
render: impl 'static + Fn(&P, &mut ViewContext<D>) -> Element<D>, render: impl 'static + Fn(&P, &mut ViewContext<D>) -> AnyElement<D>,
) -> Self ) -> Self
where where
Self: Sized, Self: Sized,

View File

@ -973,7 +973,7 @@ pub mod tests {
position, position,
height, height,
disposition, disposition,
render: Arc::new(|_| Empty::new().into_element()), render: Arc::new(|_| Empty::new().into_any()),
} }
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View File

@ -4,7 +4,7 @@ use super::{
}; };
use crate::{Anchor, Editor, ExcerptId, ExcerptRange, ToPoint as _}; use crate::{Anchor, Editor, ExcerptId, ExcerptRange, ToPoint as _};
use collections::{Bound, HashMap, HashSet}; use collections::{Bound, HashMap, HashSet};
use gpui::{fonts::HighlightStyle, Element, ViewContext}; use gpui::{fonts::HighlightStyle, AnyElement, ViewContext};
use language::{BufferSnapshot, Chunk, Patch, Point}; use language::{BufferSnapshot, Chunk, Patch, Point};
use parking_lot::Mutex; use parking_lot::Mutex;
use std::{ use std::{
@ -50,7 +50,7 @@ struct BlockRow(u32);
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)] #[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
struct WrapRow(u32); struct WrapRow(u32);
pub type RenderBlock = Arc<dyn Fn(&mut BlockContext) -> Element<Editor>>; pub type RenderBlock = Arc<dyn Fn(&mut BlockContext) -> AnyElement<Editor>>;
pub struct Block { pub struct Block {
id: BlockId, id: BlockId,
@ -69,7 +69,7 @@ where
pub position: P, pub position: P,
pub height: u8, pub height: u8,
pub style: BlockStyle, pub style: BlockStyle,
pub render: Arc<dyn Fn(&mut BlockContext) -> Element<Editor>>, pub render: Arc<dyn Fn(&mut BlockContext) -> AnyElement<Editor>>,
pub disposition: BlockDisposition, pub disposition: BlockDisposition,
} }
@ -947,7 +947,7 @@ impl DerefMut for BlockContext<'_, '_, '_, '_> {
} }
impl Block { impl Block {
pub fn render(&self, cx: &mut BlockContext) -> Element<Editor> { pub fn render(&self, cx: &mut BlockContext) -> AnyElement<Editor> {
self.render.lock()(cx) self.render.lock()(cx)
} }
@ -994,7 +994,7 @@ mod tests {
use crate::display_map::suggestion_map::SuggestionMap; use crate::display_map::suggestion_map::SuggestionMap;
use crate::display_map::{fold_map::FoldMap, tab_map::TabMap, wrap_map::WrapMap}; use crate::display_map::{fold_map::FoldMap, tab_map::TabMap, wrap_map::WrapMap};
use crate::multi_buffer::MultiBuffer; use crate::multi_buffer::MultiBuffer;
use gpui::{elements::Empty, Drawable}; use gpui::{elements::Empty, Element};
use rand::prelude::*; use rand::prelude::*;
use settings::Settings; use settings::Settings;
use std::env; use std::env;
@ -1045,21 +1045,21 @@ mod tests {
position: buffer_snapshot.anchor_after(Point::new(1, 0)), position: buffer_snapshot.anchor_after(Point::new(1, 0)),
height: 1, height: 1,
disposition: BlockDisposition::Above, disposition: BlockDisposition::Above,
render: Arc::new(|_| Empty::new().into_named_element("block 1")), render: Arc::new(|_| Empty::new().into_any_named("block 1")),
}, },
BlockProperties { BlockProperties {
style: BlockStyle::Fixed, style: BlockStyle::Fixed,
position: buffer_snapshot.anchor_after(Point::new(1, 2)), position: buffer_snapshot.anchor_after(Point::new(1, 2)),
height: 2, height: 2,
disposition: BlockDisposition::Above, disposition: BlockDisposition::Above,
render: Arc::new(|_| Empty::new().into_named_element("block 2")), render: Arc::new(|_| Empty::new().into_any_named("block 2")),
}, },
BlockProperties { BlockProperties {
style: BlockStyle::Fixed, style: BlockStyle::Fixed,
position: buffer_snapshot.anchor_after(Point::new(3, 3)), position: buffer_snapshot.anchor_after(Point::new(3, 3)),
height: 3, height: 3,
disposition: BlockDisposition::Below, disposition: BlockDisposition::Below,
render: Arc::new(|_| Empty::new().into_named_element("block 3")), render: Arc::new(|_| Empty::new().into_any_named("block 3")),
}, },
]); ]);
@ -1219,14 +1219,14 @@ mod tests {
style: BlockStyle::Fixed, style: BlockStyle::Fixed,
position: buffer_snapshot.anchor_after(Point::new(1, 12)), position: buffer_snapshot.anchor_after(Point::new(1, 12)),
disposition: BlockDisposition::Above, disposition: BlockDisposition::Above,
render: Arc::new(|_| Empty::new().into_named_element("block 1")), render: Arc::new(|_| Empty::new().into_any_named("block 1")),
height: 1, height: 1,
}, },
BlockProperties { BlockProperties {
style: BlockStyle::Fixed, style: BlockStyle::Fixed,
position: buffer_snapshot.anchor_after(Point::new(1, 1)), position: buffer_snapshot.anchor_after(Point::new(1, 1)),
disposition: BlockDisposition::Below, disposition: BlockDisposition::Below,
render: Arc::new(|_| Empty::new().into_named_element("block 2")), render: Arc::new(|_| Empty::new().into_any_named("block 2")),
height: 1, height: 1,
}, },
]); ]);
@ -1329,7 +1329,7 @@ mod tests {
position, position,
height, height,
disposition, disposition,
render: Arc::new(|_| Empty::new().into_element()), render: Arc::new(|_| Empty::new().into_any()),
} }
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();

View File

@ -41,7 +41,7 @@ use gpui::{
keymap_matcher::KeymapContext, keymap_matcher::KeymapContext,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
serde_json::{self, json}, serde_json::{self, json},
AnyViewHandle, AppContext, AsyncAppContext, ClipboardItem, Drawable, Element, Entity, AnyElement, AnyViewHandle, AppContext, AsyncAppContext, ClipboardItem, Element, Entity,
ModelHandle, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext, ModelHandle, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
}; };
use highlight_matching_bracket::refresh_matching_bracket_highlights; use highlight_matching_bracket::refresh_matching_bracket_highlights;
@ -725,7 +725,7 @@ impl ContextMenu {
cursor_position: DisplayPoint, cursor_position: DisplayPoint,
style: EditorStyle, style: EditorStyle,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> (DisplayPoint, Element<Editor>) { ) -> (DisplayPoint, AnyElement<Editor>) {
match self { match self {
ContextMenu::Completions(menu) => (cursor_position, menu.render(style, cx)), ContextMenu::Completions(menu) => (cursor_position, menu.render(style, cx)),
ContextMenu::CodeActions(menu) => menu.render(cursor_position, style, cx), ContextMenu::CodeActions(menu) => menu.render(cursor_position, style, cx),
@ -777,7 +777,7 @@ impl CompletionsMenu {
!self.matches.is_empty() !self.matches.is_empty()
} }
fn render(&self, style: EditorStyle, cx: &mut ViewContext<Editor>) -> Element<Editor> { fn render(&self, style: EditorStyle, cx: &mut ViewContext<Editor>) -> AnyElement<Editor> {
enum CompletionTag {} enum CompletionTag {}
let completions = self.completions.clone(); let completions = self.completions.clone();
@ -827,7 +827,7 @@ impl CompletionsMenu {
item_ix: Some(item_ix), item_ix: Some(item_ix),
}); });
}) })
.into_element(), .into_any(),
); );
} }
}, },
@ -847,7 +847,7 @@ impl CompletionsMenu {
) )
.contained() .contained()
.with_style(container_style) .with_style(container_style)
.into_element() .into_any()
} }
pub async fn filter(&mut self, query: Option<&str>, executor: Arc<executor::Background>) { pub async fn filter(&mut self, query: Option<&str>, executor: Arc<executor::Background>) {
@ -953,7 +953,7 @@ impl CodeActionsMenu {
mut cursor_position: DisplayPoint, mut cursor_position: DisplayPoint,
style: EditorStyle, style: EditorStyle,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> (DisplayPoint, Element<Editor>) { ) -> (DisplayPoint, AnyElement<Editor>) {
enum ActionTag {} enum ActionTag {}
let container_style = style.autocomplete.container; let container_style = style.autocomplete.container;
@ -988,7 +988,7 @@ impl CodeActionsMenu {
item_ix: Some(item_ix), item_ix: Some(item_ix),
}); });
}) })
.into_element(), .into_any(),
); );
} }
}, },
@ -1002,7 +1002,7 @@ impl CodeActionsMenu {
) )
.contained() .contained()
.with_style(container_style) .with_style(container_style)
.into_element(); .into_any();
if self.deployed_from_indicator { if self.deployed_from_indicator {
*cursor_position.column_mut() = 0; *cursor_position.column_mut() = 0;
@ -3129,7 +3129,7 @@ impl Editor {
style: &EditorStyle, style: &EditorStyle,
active: bool, active: bool,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Option<Element<Self>> { ) -> Option<AnyElement<Self>> {
if self.available_code_actions.is_some() { if self.available_code_actions.is_some() {
enum CodeActions {} enum CodeActions {}
Some( Some(
@ -3144,7 +3144,7 @@ impl Editor {
deployed_from_indicator: true, deployed_from_indicator: true,
}); });
}) })
.into_element(), .into_any(),
) )
} else { } else {
None None
@ -3159,7 +3159,7 @@ impl Editor {
line_height: f32, line_height: f32,
gutter_margin: f32, gutter_margin: f32,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Vec<Option<Element<Self>>> { ) -> Vec<Option<AnyElement<Self>>> {
enum FoldIndicators {} enum FoldIndicators {}
let style = style.folds.clone(); let style = style.folds.clone();
@ -3207,7 +3207,7 @@ impl Editor {
}); });
} }
}) })
.into_element() .into_any()
}) })
}) })
.flatten() .flatten()
@ -3226,7 +3226,7 @@ impl Editor {
cursor_position: DisplayPoint, cursor_position: DisplayPoint,
style: EditorStyle, style: EditorStyle,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> Option<(DisplayPoint, Element<Editor>)> { ) -> Option<(DisplayPoint, AnyElement<Editor>)> {
self.context_menu self.context_menu
.as_ref() .as_ref()
.map(|menu| menu.render(cursor_position, style, cx)) .map(|menu| menu.render(cursor_position, style, cx))
@ -5889,7 +5889,7 @@ impl Editor {
ChildView::new(&editor, cx) ChildView::new(&editor, cx)
.contained() .contained()
.with_padding_left(cx.anchor_x) .with_padding_left(cx.anchor_x)
.into_element() .into_any()
} }
}), }),
disposition: BlockDisposition::Below, disposition: BlockDisposition::Below,
@ -7003,7 +7003,7 @@ impl Entity for Editor {
} }
impl View for Editor { impl View for Editor {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let style = self.style(cx); let style = self.style(cx);
let font_changed = self.display_map.update(cx, |map, cx| { let font_changed = self.display_map.update(cx, |map, cx| {
map.set_fold_ellipses_color(style.folds.ellipses.text_color); map.set_fold_ellipses_color(style.folds.ellipses.text_color);
@ -7020,7 +7020,7 @@ impl View for Editor {
Stack::new() Stack::new()
.with_child(EditorElement::new(style.clone())) .with_child(EditorElement::new(style.clone()))
.with_child(ChildView::new(&self.mouse_context_menu, cx)) .with_child(ChildView::new(&self.mouse_context_menu, cx))
.into_element() .into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
@ -7496,7 +7496,7 @@ pub fn diagnostic_block_renderer(diagnostic: Diagnostic, is_valid: bool) -> Rend
})) }))
.aligned() .aligned()
.left() .left()
.into_element() .into_any()
}) })
} }

View File

@ -2299,7 +2299,7 @@ fn test_move_line_up_down_with_blocks(cx: &mut TestAppContext) {
position: snapshot.anchor_after(Point::new(2, 0)), position: snapshot.anchor_after(Point::new(2, 0)),
disposition: BlockDisposition::Below, disposition: BlockDisposition::Below,
height: 1, height: 1,
render: Arc::new(|_| Empty::new().into_element()), render: Arc::new(|_| Empty::new().into_any()),
}], }],
cx, cx,
); );

View File

@ -31,7 +31,7 @@ use gpui::{
json::{self, ToJson}, json::{self, ToJson},
platform::{CursorStyle, Modifiers, MouseButton, MouseButtonEvent, MouseMovedEvent}, platform::{CursorStyle, Modifiers, MouseButton, MouseButtonEvent, MouseMovedEvent},
text_layout::{self, Line, RunStyle, TextLayoutCache}, text_layout::{self, Line, RunStyle, TextLayoutCache},
Axis, Border, CursorRegion, Drawable, Element, EventContext, MouseRegion, Quad, SceneBuilder, AnyElement, Axis, Border, CursorRegion, Element, EventContext, MouseRegion, Quad, SceneBuilder,
SizeConstraint, ViewContext, WindowContext, SizeConstraint, ViewContext, WindowContext,
}; };
use itertools::Itertools; use itertools::Itertools;
@ -1500,7 +1500,7 @@ impl EditorElement {
.with_padding_left(gutter_padding) .with_padding_left(gutter_padding)
.with_padding_right(gutter_padding) .with_padding_right(gutter_padding)
.expanded() .expanded()
.into_named_element("path header block") .into_any_named("path header block")
} else { } else {
let text_style = self.style.text.clone(); let text_style = self.style.text.clone();
Flex::row() Flex::row()
@ -1510,7 +1510,7 @@ impl EditorElement {
.with_padding_left(gutter_padding) .with_padding_left(gutter_padding)
.with_padding_right(gutter_padding) .with_padding_right(gutter_padding)
.expanded() .expanded()
.into_named_element("collapsed context") .into_any_named("collapsed context")
} }
} }
}; };
@ -1563,7 +1563,7 @@ impl EditorElement {
} }
} }
impl Drawable<Editor> for EditorElement { impl Element<Editor> for EditorElement {
type LayoutState = LayoutState; type LayoutState = LayoutState;
type PaintState = (); type PaintState = ();
@ -2106,10 +2106,10 @@ pub struct LayoutState {
scrollbar_row_range: Range<f32>, scrollbar_row_range: Range<f32>,
show_scrollbars: bool, show_scrollbars: bool,
max_row: u32, max_row: u32,
context_menu: Option<(DisplayPoint, Element<Editor>)>, context_menu: Option<(DisplayPoint, AnyElement<Editor>)>,
code_actions_indicator: Option<(u32, Element<Editor>)>, code_actions_indicator: Option<(u32, AnyElement<Editor>)>,
hover_popovers: Option<(DisplayPoint, Vec<Element<Editor>>)>, hover_popovers: Option<(DisplayPoint, Vec<AnyElement<Editor>>)>,
fold_indicators: Vec<Option<Element<Editor>>>, fold_indicators: Vec<Option<AnyElement<Editor>>>,
} }
pub struct PositionMap { pub struct PositionMap {
@ -2160,7 +2160,7 @@ impl PositionMap {
struct BlockLayout { struct BlockLayout {
row: u32, row: u32,
element: Element<Editor>, element: AnyElement<Editor>,
style: BlockStyle, style: BlockStyle,
} }
@ -2531,7 +2531,7 @@ mod tests {
disposition: BlockDisposition::Above, disposition: BlockDisposition::Above,
height: 3, height: 3,
position: Anchor::min(), position: Anchor::min(),
render: Arc::new(|_| Empty::new().into_element()), render: Arc::new(|_| Empty::new().into_any()),
}], }],
cx, cx,
); );

View File

@ -4,7 +4,7 @@ use gpui::{
elements::{Flex, MouseEventHandler, Padding, Text}, elements::{Flex, MouseEventHandler, Padding, Text},
impl_internal_actions, impl_internal_actions,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
AppContext, Axis, Drawable, Element, ModelHandle, Task, ViewContext, AnyElement, AppContext, Axis, Element, ModelHandle, Task, ViewContext,
}; };
use language::{Bias, DiagnosticEntry, DiagnosticSeverity}; use language::{Bias, DiagnosticEntry, DiagnosticSeverity};
use project::{HoverBlock, Project}; use project::{HoverBlock, Project};
@ -283,7 +283,7 @@ impl HoverState {
style: &EditorStyle, style: &EditorStyle,
visible_rows: Range<u32>, visible_rows: Range<u32>,
cx: &mut ViewContext<Editor>, cx: &mut ViewContext<Editor>,
) -> Option<(DisplayPoint, Vec<Element<Editor>>)> { ) -> Option<(DisplayPoint, Vec<AnyElement<Editor>>)> {
// If there is a diagnostic, position the popovers based on that. // If there is a diagnostic, position the popovers based on that.
// Otherwise use the start of the hover range // Otherwise use the start of the hover range
let anchor = self let anchor = self
@ -323,7 +323,7 @@ pub struct InfoPopover {
} }
impl InfoPopover { impl InfoPopover {
pub fn render(&self, style: &EditorStyle, cx: &mut ViewContext<Editor>) -> Element<Editor> { pub fn render(&self, style: &EditorStyle, cx: &mut ViewContext<Editor>) -> AnyElement<Editor> {
MouseEventHandler::<InfoPopover, _>::new(0, cx, |_, cx| { MouseEventHandler::<InfoPopover, _>::new(0, cx, |_, cx| {
let mut flex = Flex::new(Axis::Vertical).scrollable::<HoverBlock>(1, None, cx); let mut flex = Flex::new(Axis::Vertical).scrollable::<HoverBlock>(1, None, cx);
flex.extend(self.contents.iter().map(|content| { flex.extend(self.contents.iter().map(|content| {
@ -344,7 +344,7 @@ impl InfoPopover {
}) })
.collect(), .collect(),
) )
.into_element() .into_any()
} else { } else {
let mut text_style = style.hover_popover.prose.clone(); let mut text_style = style.hover_popover.prose.clone();
text_style.font_size = style.text.font_size; text_style.font_size = style.text.font_size;
@ -353,7 +353,7 @@ impl InfoPopover {
.with_soft_wrap(true) .with_soft_wrap(true)
.contained() .contained()
.with_style(style.hover_popover.block_style) .with_style(style.hover_popover.block_style)
.into_element() .into_any()
} }
})); }));
flex.contained().with_style(style.hover_popover.container) flex.contained().with_style(style.hover_popover.container)
@ -365,7 +365,7 @@ impl InfoPopover {
top: HOVER_POPOVER_GAP, top: HOVER_POPOVER_GAP,
..Default::default() ..Default::default()
}) })
.into_element() .into_any()
} }
} }
@ -376,7 +376,7 @@ pub struct DiagnosticPopover {
} }
impl DiagnosticPopover { impl DiagnosticPopover {
pub fn render(&self, style: &EditorStyle, cx: &mut ViewContext<Editor>) -> Element<Editor> { pub fn render(&self, style: &EditorStyle, cx: &mut ViewContext<Editor>) -> AnyElement<Editor> {
enum PrimaryDiagnostic {} enum PrimaryDiagnostic {}
let mut text_style = style.hover_popover.prose.clone(); let mut text_style = style.hover_popover.prose.clone();
@ -415,7 +415,7 @@ impl DiagnosticPopover {
tooltip_style, tooltip_style,
cx, cx,
) )
.into_element() .into_any()
} }
pub fn activation_info(&self) -> (usize, Anchor) { pub fn activation_info(&self) -> (usize, Anchor) {

View File

@ -563,7 +563,7 @@ impl Item for Editor {
detail: Option<usize>, detail: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
cx: &AppContext, cx: &AppContext,
) -> Element<T> { ) -> AnyElement<T> {
Flex::row() Flex::row()
.with_child(Label::new(self.title(cx).to_string(), style.label.clone()).aligned()) .with_child(Label::new(self.title(cx).to_string(), style.label.clone()).aligned())
.with_children(detail.and_then(|detail| { .with_children(detail.and_then(|detail| {
@ -579,7 +579,7 @@ impl Item for Editor {
.aligned(), .aligned(),
) )
})) }))
.into_element() .into_any()
} }
fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) { fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) {
@ -1108,16 +1108,16 @@ impl View for CursorPosition {
"CursorPosition" "CursorPosition"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if let Some(position) = self.position { if let Some(position) = self.position {
let theme = &cx.global::<Settings>().theme.workspace.status_bar; let theme = &cx.global::<Settings>().theme.workspace.status_bar;
let mut text = format!("{},{}", position.row + 1, position.column + 1); let mut text = format!("{},{}", position.row + 1, position.column + 1);
if self.selected_count > 0 { if self.selected_count > 0 {
write!(text, " ({} selected)", self.selected_count).unwrap(); write!(text, " ({} selected)", self.selected_count).unwrap();
} }
Label::new(text, theme.cursor_position.clone()).into_element() Label::new(text, theme.cursor_position.clone()).into_any()
} else { } else {
Empty::new().into_element() Empty::new().into_any()
} }
} }
} }

View File

@ -27,7 +27,7 @@ impl View for DeployFeedbackButton {
"DeployFeedbackButton" "DeployFeedbackButton"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let active = self.active; let active = self.active;
let theme = cx.global::<Settings>().theme.clone(); let theme = cx.global::<Settings>().theme.clone();
Stack::new() Stack::new()
@ -65,7 +65,7 @@ impl View for DeployFeedbackButton {
cx, cx,
), ),
) )
.into_element() .into_any()
} }
} }

View File

@ -13,7 +13,7 @@ use gpui::{
actions, actions,
elements::{ChildView, Flex, Label, ParentElement, Svg}, elements::{ChildView, Flex, Label, ParentElement, Svg},
platform::PromptLevel, platform::PromptLevel,
serde_json, AnyViewHandle, AppContext, Drawable, Element, Entity, ModelHandle, Task, View, serde_json, AnyElement, AnyViewHandle, AppContext, Element, Entity, ModelHandle, Task, View,
ViewContext, ViewHandle, ViewContext, ViewHandle,
}; };
use isahc::Request; use isahc::Request;
@ -230,8 +230,8 @@ impl View for FeedbackEditor {
"FeedbackEditor" "FeedbackEditor"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
ChildView::new(&self.editor, cx).into_element() ChildView::new(&self.editor, cx).into_any()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
@ -255,7 +255,7 @@ impl Item for FeedbackEditor {
_: Option<usize>, _: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
_: &AppContext, _: &AppContext,
) -> Element<T> { ) -> AnyElement<T> {
Flex::row() Flex::row()
.with_child( .with_child(
Svg::new("icons/feedback_16.svg") Svg::new("icons/feedback_16.svg")
@ -271,7 +271,7 @@ impl Item for FeedbackEditor {
.aligned() .aligned()
.contained(), .contained(),
) )
.into_element() .into_any()
} }
fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) { fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) {

View File

@ -1,7 +1,7 @@
use gpui::{ use gpui::{
elements::{Flex, Label, MouseEventHandler, ParentElement, Text}, elements::{Flex, Label, MouseEventHandler, ParentElement, Text},
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
Drawable, Element, Entity, View, ViewContext, ViewHandle, AnyElement, Element, Entity, View, ViewContext, ViewHandle,
}; };
use settings::Settings; use settings::Settings;
use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView}; use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView};
@ -29,7 +29,7 @@ impl View for FeedbackInfoText {
"FeedbackInfoText" "FeedbackInfoText"
} }
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 theme = cx.global::<Settings>().theme.clone();
Flex::row() Flex::row()
@ -68,7 +68,7 @@ impl View for FeedbackInfoText {
.aligned() .aligned()
.left() .left()
.clipped() .clipped()
.into_element() .into_any()
} }
} }

View File

@ -1,7 +1,7 @@
use gpui::{ use gpui::{
elements::{Label, MouseEventHandler}, elements::{Label, MouseEventHandler},
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
Drawable, Element, Entity, View, ViewContext, ViewHandle, AnyElement, Element, Entity, View, ViewContext, ViewHandle,
}; };
use settings::Settings; use settings::Settings;
use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView}; use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView};
@ -29,7 +29,7 @@ impl View for SubmitFeedbackButton {
"SubmitFeedbackButton" "SubmitFeedbackButton"
} }
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 theme = cx.global::<Settings>().theme.clone();
enum SubmitFeedbackButton {} enum SubmitFeedbackButton {}
MouseEventHandler::<SubmitFeedbackButton, Self>::new(0, cx, |state, _| { MouseEventHandler::<SubmitFeedbackButton, Self>::new(0, cx, |state, _| {
@ -52,7 +52,7 @@ impl View for SubmitFeedbackButton {
theme.tooltip.clone(), theme.tooltip.clone(),
cx, cx,
) )
.into_element() .into_any()
} }
} }

View File

@ -246,7 +246,7 @@ impl PickerDelegate for FileFinderDelegate {
mouse_state: &mut MouseState, mouse_state: &mut MouseState,
selected: bool, selected: bool,
cx: &AppContext, cx: &AppContext,
) -> Element<Picker<Self>> { ) -> AnyElement<Picker<Self>> {
let path_match = &self.matches[ix]; let path_match = &self.matches[ix];
let settings = cx.global::<Settings>(); let settings = cx.global::<Settings>();
let style = settings.theme.picker.item.style_for(mouse_state, selected); let style = settings.theme.picker.item.style_for(mouse_state, selected);
@ -262,7 +262,7 @@ impl PickerDelegate for FileFinderDelegate {
.flex(1., false) .flex(1., false)
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.into_named_element("match") .into_any_named("match")
} }
} }

View File

@ -143,7 +143,7 @@ impl View for GoToLine {
"GoToLine" "GoToLine"
} }
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.picker; let theme = &cx.global::<Settings>().theme.picker;
let label = format!( let label = format!(
@ -168,7 +168,7 @@ impl View for GoToLine {
.with_style(theme.container) .with_style(theme.container)
.constrained() .constrained()
.with_max_width(500.0) .with_max_width(500.0)
.into_named_element("go to line") .into_any_named("go to line")
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {

View File

@ -2,7 +2,7 @@ use gpui::{
color::Color, color::Color,
fonts::{Properties, Weight}, fonts::{Properties, Weight},
text_layout::RunStyle, text_layout::RunStyle,
Drawable, Element, Quad, SceneBuilder, View, ViewContext, AnyElement, Element, Quad, SceneBuilder, View, ViewContext,
}; };
use log::LevelFilter; use log::LevelFilter;
use pathfinder_geometry::rect::RectF; use pathfinder_geometry::rect::RectF;
@ -30,12 +30,12 @@ impl gpui::View for TextView {
"View" "View"
} }
fn render(&mut self, _: &mut gpui::ViewContext<Self>) -> Element<TextView> { fn render(&mut self, _: &mut gpui::ViewContext<Self>) -> AnyElement<TextView> {
TextElement.into_element() TextElement.into_any()
} }
} }
impl<V: View> Drawable<V> for TextElement { impl<V: View> Element<V> for TextElement {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -41,7 +41,7 @@ pub use test_app_context::{ContextHandle, TestAppContext};
use window_input_handler::WindowInputHandler; use window_input_handler::WindowInputHandler;
use crate::{ use crate::{
elements::{AnyRootElement, Element, RootElement}, elements::{AnyElement, AnyRootElement, RootElement},
executor::{self, Task}, executor::{self, Task},
keymap_matcher::{self, Binding, KeymapContext, KeymapMatcher, Keystroke, MatchResult}, keymap_matcher::{self, Binding, KeymapContext, KeymapMatcher, Keystroke, MatchResult},
platform::{ platform::{
@ -69,7 +69,7 @@ pub trait Entity: 'static {
pub trait View: Entity + Sized { pub trait View: Entity + Sized {
fn ui_name() -> &'static str; fn ui_name() -> &'static str;
fn render(&mut self, cx: &mut ViewContext<'_, '_, '_, Self>) -> Element<Self>; fn render(&mut self, cx: &mut ViewContext<'_, '_, '_, Self>) -> AnyElement<Self>;
fn focus_in(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {} fn focus_in(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {}
fn focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {} fn focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {}
fn key_down(&mut self, _: &KeyDownEvent, _: &mut ViewContext<Self>) -> bool { fn key_down(&mut self, _: &KeyDownEvent, _: &mut ViewContext<Self>) -> bool {
@ -4683,9 +4683,9 @@ mod tests {
} }
impl super::View for View { impl super::View for View {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
post_inc(&mut self.render_count); post_inc(&mut self.render_count);
Empty::new().into_element() Empty::new().into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
@ -4736,8 +4736,8 @@ mod tests {
} }
impl super::View for View { impl super::View for View {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
@ -4806,14 +4806,14 @@ mod tests {
} }
impl super::View for View { impl super::View for View {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
enum Handler {} enum Handler {}
let mouse_down_count = self.mouse_down_count.clone(); let mouse_down_count = self.mouse_down_count.clone();
MouseEventHandler::<Handler, _>::new(0, cx, |_, _| Empty::new()) MouseEventHandler::<Handler, _>::new(0, cx, |_, _| Empty::new())
.on_down(MouseButton::Left, move |_, _, _| { .on_down(MouseButton::Left, move |_, _, _| {
mouse_down_count.fetch_add(1, SeqCst); mouse_down_count.fetch_add(1, SeqCst);
}) })
.into_element() .into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
@ -4872,8 +4872,8 @@ mod tests {
"View" "View"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
} }
@ -5390,8 +5390,8 @@ mod tests {
} }
impl super::View for View { impl super::View for View {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
@ -5457,8 +5457,8 @@ mod tests {
} }
impl super::View for View { impl super::View for View {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
@ -5638,8 +5638,8 @@ mod tests {
} }
impl View for ViewA { impl View for ViewA {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
@ -5656,8 +5656,8 @@ mod tests {
} }
impl View for ViewB { impl View for ViewB {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
@ -5804,8 +5804,8 @@ mod tests {
} }
impl super::View for View { impl super::View for View {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
@ -5931,16 +5931,16 @@ mod tests {
} }
impl super::View for View1 { impl super::View for View1 {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
"View1" "View1"
} }
} }
impl super::View for View2 { impl super::View for View2 {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
fn ui_name() -> &'static str { fn ui_name() -> &'static str {
"View2" "View2"
@ -6109,8 +6109,8 @@ mod tests {
"test view" "test view"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
} }
@ -6171,8 +6171,8 @@ mod tests {
"test view" "test view"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_named_element(format!("render count: {}", post_inc(&mut self.0))) Empty::new().into_any_named(format!("render count: {}", post_inc(&mut self.0)))
} }
} }
@ -6260,8 +6260,8 @@ mod tests {
"test view" "test view"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
} }
@ -6340,9 +6340,9 @@ mod tests {
"child view" "child view"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
self.rendered.set(true); self.rendered.set(true);
Empty::new().into_element() Empty::new().into_any()
} }
} }
@ -6365,11 +6365,11 @@ mod tests {
"parent view" "parent view"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if let Some(child) = self.child.as_ref() { if let Some(child) = self.child.as_ref() {
ChildView::new(child, cx).into_element() ChildView::new(child, cx).into_any()
} else { } else {
Empty::new().into_element() Empty::new().into_any()
} }
} }
} }
@ -6407,8 +6407,8 @@ mod tests {
"TestView" "TestView"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
} }
} }

View File

@ -14,7 +14,7 @@ use crate::{
text_layout::TextLayoutCache, text_layout::TextLayoutCache,
util::post_inc, util::post_inc,
Action, AnyModelHandle, AnyView, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle, Action, AnyModelHandle, AnyView, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle,
AppContext, Drawable, Effect, Entity, Handle, ModelContext, ModelHandle, MouseRegion, AppContext, Effect, Element, Entity, Handle, ModelContext, ModelHandle, MouseRegion,
MouseRegionId, ParentId, ReadModel, ReadView, SceneBuilder, Subscription, UpdateModel, MouseRegionId, ParentId, ReadModel, ReadView, SceneBuilder, Subscription, UpdateModel,
UpdateView, UpgradeModelHandle, UpgradeViewHandle, View, ViewContext, ViewHandle, UpdateView, UpgradeModelHandle, UpgradeViewHandle, View, ViewContext, ViewHandle,
WeakModelHandle, WeakViewHandle, WindowInvalidation, WeakModelHandle, WeakViewHandle, WindowInvalidation,
@ -1391,7 +1391,7 @@ impl ChildView {
} }
} }
impl<V: View> Drawable<V> for ChildView { impl<V: View> Element<V> for ChildView {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -47,7 +47,7 @@ use std::{
}; };
use util::ResultExt; use util::ResultExt;
pub trait Drawable<V: View>: 'static { pub trait Element<V: View>: 'static {
type LayoutState; type LayoutState;
type PaintState; type PaintState;
@ -92,24 +92,22 @@ pub trait Drawable<V: View>: 'static {
cx: &ViewContext<V>, cx: &ViewContext<V>,
) -> serde_json::Value; ) -> serde_json::Value;
fn into_element(self) -> Element<V> fn into_any(self) -> AnyElement<V>
where where
Self: 'static + Sized, Self: 'static + Sized,
{ {
Element { AnyElement {
drawable: Box::new(Lifecycle::Init { element: self }), state: Box::new(ElementState::Init { element: self }),
view_type: PhantomData,
name: None, name: None,
} }
} }
fn into_named_element(self, name: impl Into<Cow<'static, str>>) -> Element<V> fn into_any_named(self, name: impl Into<Cow<'static, str>>) -> AnyElement<V>
where where
Self: 'static + Sized, Self: 'static + Sized,
{ {
Element { AnyElement {
drawable: Box::new(Lifecycle::Init { element: self }), state: Box::new(ElementState::Init { element: self }),
view_type: PhantomData,
name: Some(name.into()), name: Some(name.into()),
} }
} }
@ -119,7 +117,7 @@ pub trait Drawable<V: View>: 'static {
Self: 'static + Sized, Self: 'static + Sized,
{ {
RootElement { RootElement {
element: self.into_element(), element: self.into_any(),
view: cx.handle().downgrade(), view: cx.handle().downgrade(),
} }
} }
@ -128,49 +126,49 @@ pub trait Drawable<V: View>: 'static {
where where
Self: 'static + Sized, Self: 'static + Sized,
{ {
ConstrainedBox::new(self.into_element()) ConstrainedBox::new(self.into_any())
} }
fn aligned(self) -> Align<V> fn aligned(self) -> Align<V>
where where
Self: 'static + Sized, Self: 'static + Sized,
{ {
Align::new(self.into_element()) Align::new(self.into_any())
} }
fn clipped(self) -> Clipped<V> fn clipped(self) -> Clipped<V>
where where
Self: 'static + Sized, Self: 'static + Sized,
{ {
Clipped::new(self.into_element()) Clipped::new(self.into_any())
} }
fn contained(self) -> Container<V> fn contained(self) -> Container<V>
where where
Self: 'static + Sized, Self: 'static + Sized,
{ {
Container::new(self.into_element()) Container::new(self.into_any())
} }
fn expanded(self) -> Expanded<V> fn expanded(self) -> Expanded<V>
where where
Self: 'static + Sized, Self: 'static + Sized,
{ {
Expanded::new(self.into_element()) Expanded::new(self.into_any())
} }
fn flex(self, flex: f32, expanded: bool) -> FlexItem<V> fn flex(self, flex: f32, expanded: bool) -> FlexItem<V>
where where
Self: 'static + Sized, Self: 'static + Sized,
{ {
FlexItem::new(self.into_element()).flex(flex, expanded) FlexItem::new(self.into_any()).flex(flex, expanded)
} }
fn flex_float(self) -> FlexItem<V> fn flex_float(self) -> FlexItem<V>
where where
Self: 'static + Sized, Self: 'static + Sized,
{ {
FlexItem::new(self.into_element()).float() FlexItem::new(self.into_any()).float()
} }
fn with_tooltip<Tag: 'static>( fn with_tooltip<Tag: 'static>(
@ -184,7 +182,7 @@ pub trait Drawable<V: View>: 'static {
where where
Self: 'static + Sized, Self: 'static + Sized,
{ {
Tooltip::new::<Tag, V>(id, text, action, style, self.into_element(), cx) Tooltip::new::<Tag, V>(id, text, action, style, self.into_any(), cx)
} }
fn with_resize_handle<Tag: 'static>( fn with_resize_handle<Tag: 'static>(
@ -199,7 +197,7 @@ pub trait Drawable<V: View>: 'static {
Self: 'static + Sized, Self: 'static + Sized,
{ {
Resizable::new::<Tag, V>( Resizable::new::<Tag, V>(
self.into_element(), self.into_any(),
element_id, element_id,
side, side,
handle_size, handle_size,
@ -209,7 +207,7 @@ pub trait Drawable<V: View>: 'static {
} }
} }
trait AnyDrawable<V: View> { trait AnyElementState<V: View> {
fn layout( fn layout(
&mut self, &mut self,
constraint: SizeConstraint, constraint: SizeConstraint,
@ -240,7 +238,7 @@ trait AnyDrawable<V: View> {
fn metadata(&self) -> Option<&dyn Any>; fn metadata(&self) -> Option<&dyn Any>;
} }
enum Lifecycle<V: View, E: Drawable<V>> { enum ElementState<V: View, E: Element<V>> {
Empty, Empty,
Init { Init {
element: E, element: E,
@ -261,7 +259,7 @@ enum Lifecycle<V: View, E: Drawable<V>> {
}, },
} }
impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> { impl<V: View, E: Element<V>> AnyElementState<V> for ElementState<V, E> {
fn layout( fn layout(
&mut self, &mut self,
constraint: SizeConstraint, constraint: SizeConstraint,
@ -270,16 +268,16 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
) -> Vector2F { ) -> Vector2F {
let result; let result;
*self = match mem::take(self) { *self = match mem::take(self) {
Lifecycle::Empty => unreachable!(), ElementState::Empty => unreachable!(),
Lifecycle::Init { mut element } ElementState::Init { mut element }
| Lifecycle::PostLayout { mut element, .. } | ElementState::PostLayout { mut element, .. }
| Lifecycle::PostPaint { mut element, .. } => { | ElementState::PostPaint { mut element, .. } => {
let (size, layout) = element.layout(constraint, view, cx); let (size, layout) = element.layout(constraint, view, cx);
debug_assert!(size.x().is_finite()); debug_assert!(size.x().is_finite());
debug_assert!(size.y().is_finite()); debug_assert!(size.y().is_finite());
result = size; result = size;
Lifecycle::PostLayout { ElementState::PostLayout {
element, element,
constraint, constraint,
size, size,
@ -299,7 +297,7 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) { ) {
*self = match mem::take(self) { *self = match mem::take(self) {
Lifecycle::PostLayout { ElementState::PostLayout {
mut element, mut element,
constraint, constraint,
size, size,
@ -307,7 +305,7 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
} => { } => {
let bounds = RectF::new(origin, size); let bounds = RectF::new(origin, size);
let paint = element.paint(scene, bounds, visible_bounds, &mut layout, view, cx); let paint = element.paint(scene, bounds, visible_bounds, &mut layout, view, cx);
Lifecycle::PostPaint { ElementState::PostPaint {
element, element,
constraint, constraint,
bounds, bounds,
@ -316,7 +314,7 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
paint, paint,
} }
} }
Lifecycle::PostPaint { ElementState::PostPaint {
mut element, mut element,
constraint, constraint,
bounds, bounds,
@ -325,7 +323,7 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
} => { } => {
let bounds = RectF::new(origin, bounds.size()); let bounds = RectF::new(origin, bounds.size());
let paint = element.paint(scene, bounds, visible_bounds, &mut layout, view, cx); let paint = element.paint(scene, bounds, visible_bounds, &mut layout, view, cx);
Lifecycle::PostPaint { ElementState::PostPaint {
element, element,
constraint, constraint,
bounds, bounds,
@ -334,8 +332,8 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
paint, paint,
} }
} }
Lifecycle::Empty => panic!("invalid element lifecycle state"), ElementState::Empty => panic!("invalid element lifecycle state"),
Lifecycle::Init { .. } => { ElementState::Init { .. } => {
panic!("invalid element lifecycle state, paint called before layout") panic!("invalid element lifecycle state, paint called before layout")
} }
} }
@ -347,7 +345,7 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
view: &V, view: &V,
cx: &ViewContext<V>, cx: &ViewContext<V>,
) -> Option<RectF> { ) -> Option<RectF> {
if let Lifecycle::PostPaint { if let ElementState::PostPaint {
element, element,
bounds, bounds,
visible_bounds, visible_bounds,
@ -372,24 +370,26 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
fn size(&self) -> Vector2F { fn size(&self) -> Vector2F {
match self { match self {
Lifecycle::Empty | Lifecycle::Init { .. } => panic!("invalid element lifecycle state"), ElementState::Empty | ElementState::Init { .. } => {
Lifecycle::PostLayout { size, .. } => *size, panic!("invalid element lifecycle state")
Lifecycle::PostPaint { bounds, .. } => bounds.size(), }
ElementState::PostLayout { size, .. } => *size,
ElementState::PostPaint { bounds, .. } => bounds.size(),
} }
} }
fn metadata(&self) -> Option<&dyn Any> { fn metadata(&self) -> Option<&dyn Any> {
match self { match self {
Lifecycle::Empty => unreachable!(), ElementState::Empty => unreachable!(),
Lifecycle::Init { element } ElementState::Init { element }
| Lifecycle::PostLayout { element, .. } | ElementState::PostLayout { element, .. }
| Lifecycle::PostPaint { element, .. } => element.metadata(), | ElementState::PostPaint { element, .. } => element.metadata(),
} }
} }
fn debug(&self, view: &V, cx: &ViewContext<V>) -> serde_json::Value { fn debug(&self, view: &V, cx: &ViewContext<V>) -> serde_json::Value {
match self { match self {
Lifecycle::PostPaint { ElementState::PostPaint {
element, element,
constraint, constraint,
bounds, bounds,
@ -419,25 +419,24 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
} }
} }
impl<V: View, E: Drawable<V>> Default for Lifecycle<V, E> { impl<V: View, E: Element<V>> Default for ElementState<V, E> {
fn default() -> Self { fn default() -> Self {
Self::Empty Self::Empty
} }
} }
pub struct Element<V: View> { pub struct AnyElement<V: View> {
drawable: Box<dyn AnyDrawable<V>>, state: Box<dyn AnyElementState<V>>,
view_type: PhantomData<V>,
name: Option<Cow<'static, str>>, name: Option<Cow<'static, str>>,
} }
impl<V: View> Element<V> { impl<V: View> AnyElement<V> {
pub fn name(&self) -> Option<&str> { pub fn name(&self) -> Option<&str> {
self.name.as_deref() self.name.as_deref()
} }
pub fn metadata<T: 'static>(&self) -> Option<&T> { pub fn metadata<T: 'static>(&self) -> Option<&T> {
self.drawable self.state
.metadata() .metadata()
.and_then(|data| data.downcast_ref::<T>()) .and_then(|data| data.downcast_ref::<T>())
} }
@ -448,7 +447,7 @@ impl<V: View> Element<V> {
view: &mut V, view: &mut V,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) -> Vector2F { ) -> Vector2F {
self.drawable.layout(constraint, view, cx) self.state.layout(constraint, view, cx)
} }
pub fn paint( pub fn paint(
@ -459,7 +458,7 @@ impl<V: View> Element<V> {
view: &mut V, view: &mut V,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) { ) {
self.drawable.paint(scene, origin, visible_bounds, view, cx); self.state.paint(scene, origin, visible_bounds, view, cx);
} }
pub fn rect_for_text_range( pub fn rect_for_text_range(
@ -468,15 +467,15 @@ impl<V: View> Element<V> {
view: &V, view: &V,
cx: &ViewContext<V>, cx: &ViewContext<V>,
) -> Option<RectF> { ) -> Option<RectF> {
self.drawable.rect_for_text_range(range_utf16, view, cx) self.state.rect_for_text_range(range_utf16, view, cx)
} }
pub fn size(&self) -> Vector2F { pub fn size(&self) -> Vector2F {
self.drawable.size() self.state.size()
} }
pub fn debug(&self, view: &V, cx: &ViewContext<V>) -> json::Value { pub fn debug(&self, view: &V, cx: &ViewContext<V>) -> json::Value {
let mut value = self.drawable.debug(view, cx); let mut value = self.state.debug(view, cx);
if let Some(name) = &self.name { if let Some(name) = &self.name {
if let json::Value::Object(map) = &mut value { if let json::Value::Object(map) = &mut value {
@ -495,11 +494,11 @@ impl<V: View> Element<V> {
T: 'static, T: 'static,
F: FnOnce(Option<&T>) -> R, F: FnOnce(Option<&T>) -> R,
{ {
f(self.drawable.metadata().and_then(|m| m.downcast_ref())) f(self.state.metadata().and_then(|m| m.downcast_ref()))
} }
} }
impl<V: View> Drawable<V> for Element<V> { impl<V: View> Element<V> for AnyElement<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();
@ -549,7 +548,7 @@ impl<V: View> Drawable<V> for Element<V> {
self.debug(view, cx) self.debug(view, cx)
} }
fn into_element(self) -> Element<V> fn into_any(self) -> AnyElement<V>
where where
Self: Sized, Self: Sized,
{ {
@ -558,18 +557,18 @@ impl<V: View> Drawable<V> for Element<V> {
} }
pub struct RootElement<V: View> { pub struct RootElement<V: View> {
element: Element<V>, element: AnyElement<V>,
view: WeakViewHandle<V>, view: WeakViewHandle<V>,
} }
impl<V: View> RootElement<V> { impl<V: View> RootElement<V> {
pub fn new(element: Element<V>, view: WeakViewHandle<V>) -> Self { pub fn new(element: AnyElement<V>, view: WeakViewHandle<V>) -> Self {
Self { element, view } Self { element, view }
} }
} }
pub trait Component<V: View>: 'static { pub trait Component<V: View>: 'static {
fn render(&self, view: &mut V, cx: &mut ViewContext<V>) -> Element<V>; fn render(&self, view: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V>;
} }
pub struct ComponentHost<V: View, C: Component<V>> { pub struct ComponentHost<V: View, C: Component<V>> {
@ -591,8 +590,8 @@ impl<V: View, C: Component<V>> DerefMut for ComponentHost<V, C> {
} }
} }
impl<V: View, C: Component<V>> Drawable<V> for ComponentHost<V, C> { impl<V: View, C: Component<V>> Element<V> for ComponentHost<V, C> {
type LayoutState = Element<V>; type LayoutState = AnyElement<V>;
type PaintState = (); type PaintState = ();
fn layout( fn layout(
@ -600,7 +599,7 @@ impl<V: View, C: Component<V>> Drawable<V> for ComponentHost<V, C> {
constraint: SizeConstraint, constraint: SizeConstraint,
view: &mut V, view: &mut V,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) -> (Vector2F, Element<V>) { ) -> (Vector2F, AnyElement<V>) {
let mut element = self.component.render(view, cx); let mut element = self.component.render(view, cx);
let size = element.layout(constraint, view, cx); let size = element.layout(constraint, view, cx);
(size, element) (size, element)
@ -611,7 +610,7 @@ impl<V: View, C: Component<V>> Drawable<V> for ComponentHost<V, C> {
scene: &mut SceneBuilder, scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
element: &mut Element<V>, element: &mut AnyElement<V>,
view: &mut V, view: &mut V,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) { ) {
@ -623,7 +622,7 @@ impl<V: View, C: Component<V>> Drawable<V> for ComponentHost<V, C> {
range_utf16: Range<usize>, range_utf16: Range<usize>,
_: RectF, _: RectF,
_: RectF, _: RectF,
element: &Element<V>, element: &AnyElement<V>,
_: &(), _: &(),
view: &V, view: &V,
cx: &ViewContext<V>, cx: &ViewContext<V>,
@ -634,7 +633,7 @@ impl<V: View, C: Component<V>> Drawable<V> for ComponentHost<V, C> {
fn debug( fn debug(
&self, &self,
_: RectF, _: RectF,
element: &Element<V>, element: &AnyElement<V>,
_: &(), _: &(),
view: &V, view: &V,
cx: &ViewContext<V>, cx: &ViewContext<V>,
@ -718,7 +717,7 @@ impl<V: View> AnyRootElement for RootElement<V> {
} }
} }
impl<V: View, R: View> Drawable<V> for RootElement<R> { impl<V: View, R: View> Element<V> for RootElement<R> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();
@ -775,27 +774,27 @@ impl<V: View, R: View> Drawable<V> for RootElement<R> {
} }
} }
pub trait ParentElement<'a, V: View>: Extend<Element<V>> + Sized { pub trait ParentElement<'a, V: View>: Extend<AnyElement<V>> + Sized {
fn add_children<D: Drawable<V>>(&mut self, children: impl IntoIterator<Item = D>) { fn add_children<E: Element<V>>(&mut self, children: impl IntoIterator<Item = E>) {
self.extend(children.into_iter().map(|child| child.into_element())); self.extend(children.into_iter().map(|child| child.into_any()));
} }
fn add_child<D: Drawable<V>>(&mut self, child: D) { fn add_child<D: Element<V>>(&mut self, child: D) {
self.extend(Some(child.into_element())); self.extend(Some(child.into_any()));
} }
fn with_children<D: Drawable<V>>(mut self, children: impl IntoIterator<Item = D>) -> Self { fn with_children<D: Element<V>>(mut self, children: impl IntoIterator<Item = D>) -> Self {
self.extend(children.into_iter().map(|child| child.into_element())); self.extend(children.into_iter().map(|child| child.into_any()));
self self
} }
fn with_child<D: Drawable<V>>(mut self, child: D) -> Self { fn with_child<D: Element<V>>(mut self, child: D) -> Self {
self.extend(Some(child.into_element())); self.extend(Some(child.into_any()));
self self
} }
} }
impl<'a, V: View, T> ParentElement<'a, V> for T where T: Extend<Element<V>> {} impl<'a, V: View, T> ParentElement<'a, V> for T where T: Extend<AnyElement<V>> {}
pub fn constrain_size_preserving_aspect_ratio(max_size: Vector2F, size: Vector2F) -> Vector2F { pub fn constrain_size_preserving_aspect_ratio(max_size: Vector2F, size: Vector2F) -> Vector2F {
if max_size.x().is_infinite() && max_size.y().is_infinite() { if max_size.x().is_infinite() && max_size.y().is_infinite() {

View File

@ -1,18 +1,18 @@
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext, json, AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
use json::ToJson; use json::ToJson;
use serde_json::json; use serde_json::json;
pub struct Align<V: View> { pub struct Align<V: View> {
child: Element<V>, child: AnyElement<V>,
alignment: Vector2F, alignment: Vector2F,
} }
impl<V: View> Align<V> { impl<V: View> Align<V> {
pub fn new(child: Element<V>) -> Self { pub fn new(child: AnyElement<V>) -> Self {
Self { Self {
child, child,
alignment: Vector2F::zero(), alignment: Vector2F::zero(),
@ -40,7 +40,7 @@ impl<V: View> Align<V> {
} }
} }
impl<V: View> Drawable<V> for Align<V> { impl<V: View> Element<V> for Align<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -1,6 +1,6 @@
use std::marker::PhantomData; use std::marker::PhantomData;
use super::Drawable; use super::Element;
use crate::{ use crate::{
json::{self, json}, json::{self, json},
SceneBuilder, View, ViewContext, SceneBuilder, View, ViewContext,
@ -23,7 +23,7 @@ where
} }
} }
impl<V: View, F> Drawable<V> for Canvas<V, F> impl<V: View, F> Element<V> for Canvas<V, F>
where where
F: 'static + FnMut(&mut SceneBuilder, RectF, RectF, &mut V, &mut ViewContext<V>), F: 'static + FnMut(&mut SceneBuilder, RectF, RectF, &mut V, &mut ViewContext<V>),
{ {

View File

@ -3,19 +3,19 @@ use std::ops::Range;
use pathfinder_geometry::{rect::RectF, vector::Vector2F}; use pathfinder_geometry::{rect::RectF, vector::Vector2F};
use serde_json::json; use serde_json::json;
use crate::{json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext}; use crate::{json, AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext};
pub struct Clipped<V: View> { pub struct Clipped<V: View> {
child: Element<V>, child: AnyElement<V>,
} }
impl<V: View> Clipped<V> { impl<V: View> Clipped<V> {
pub fn new(child: Element<V>) -> Self { pub fn new(child: AnyElement<V>) -> Self {
Self { child } Self { child }
} }
} }
impl<V: View> Drawable<V> for Clipped<V> { impl<V: View> Element<V> for Clipped<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -5,11 +5,11 @@ use serde_json::json;
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext, json, AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
pub struct ConstrainedBox<V: View> { pub struct ConstrainedBox<V: View> {
child: Element<V>, child: AnyElement<V>,
constraint: Constraint<V>, constraint: Constraint<V>,
} }
@ -28,9 +28,9 @@ impl<V: View> ToJson for Constraint<V> {
} }
impl<V: View> ConstrainedBox<V> { impl<V: View> ConstrainedBox<V> {
pub fn new(child: impl Drawable<V>) -> Self { pub fn new(child: impl Element<V>) -> Self {
Self { Self {
child: child.into_element(), child: child.into_any(),
constraint: Constraint::Static(Default::default()), constraint: Constraint::Static(Default::default()),
} }
} }
@ -130,7 +130,7 @@ impl<V: View> ConstrainedBox<V> {
} }
} }
impl<V: View> Drawable<V> for ConstrainedBox<V> { impl<V: View> Element<V> for ConstrainedBox<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -10,7 +10,7 @@ use crate::{
json::ToJson, json::ToJson,
platform::CursorStyle, platform::CursorStyle,
scene::{self, Border, CursorRegion, Quad}, scene::{self, Border, CursorRegion, Quad},
Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext, AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
use serde::Deserialize; use serde::Deserialize;
use serde_json::json; use serde_json::json;
@ -36,12 +36,12 @@ pub struct ContainerStyle {
} }
pub struct Container<V: View> { pub struct Container<V: View> {
child: Element<V>, child: AnyElement<V>,
style: ContainerStyle, style: ContainerStyle,
} }
impl<V: View> Container<V> { impl<V: View> Container<V> {
pub fn new(child: Element<V>) -> Self { pub fn new(child: AnyElement<V>) -> Self {
Self { Self {
child, child,
style: Default::default(), style: Default::default(),
@ -184,7 +184,7 @@ impl<V: View> Container<V> {
} }
} }
impl<V: View> Drawable<V> for Container<V> { impl<V: View> Element<V> for Container<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -8,7 +8,7 @@ use crate::{
json::{json, ToJson}, json::{json, ToJson},
SceneBuilder, View, ViewContext, SceneBuilder, View, ViewContext,
}; };
use crate::{Drawable, SizeConstraint}; use crate::{Element, SizeConstraint};
#[derive(Default)] #[derive(Default)]
pub struct Empty { pub struct Empty {
@ -26,7 +26,7 @@ impl Empty {
} }
} }
impl<V: View> Drawable<V> for Empty { impl<V: View> Element<V> for Empty {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -2,20 +2,20 @@ use std::ops::Range;
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext, json, AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
use serde_json::json; use serde_json::json;
pub struct Expanded<V: View> { pub struct Expanded<V: View> {
child: Element<V>, child: AnyElement<V>,
full_width: bool, full_width: bool,
full_height: bool, full_height: bool,
} }
impl<V: View> Expanded<V> { impl<V: View> Expanded<V> {
pub fn new(child: impl Drawable<V>) -> Self { pub fn new(child: impl Element<V>) -> Self {
Self { Self {
child: child.into_element(), child: child.into_any(),
full_width: true, full_width: true,
full_height: true, full_height: true,
} }
@ -34,7 +34,7 @@ impl<V: View> Expanded<V> {
} }
} }
impl<V: View> Drawable<V> for Expanded<V> { impl<V: View> Element<V> for Expanded<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -2,7 +2,7 @@ use std::{any::Any, cell::Cell, f32::INFINITY, ops::Range, rc::Rc};
use crate::{ use crate::{
json::{self, ToJson, Value}, json::{self, ToJson, Value},
Axis, Drawable, Element, ElementStateHandle, SceneBuilder, SizeConstraint, Vector2FExt, View, AnyElement, Axis, Element, ElementStateHandle, SceneBuilder, SizeConstraint, Vector2FExt, View,
ViewContext, ViewContext,
}; };
use pathfinder_geometry::{ use pathfinder_geometry::{
@ -19,7 +19,7 @@ struct ScrollState {
pub struct Flex<V: View> { pub struct Flex<V: View> {
axis: Axis, axis: Axis,
children: Vec<Element<V>>, children: Vec<AnyElement<V>>,
scroll_state: Option<(ElementStateHandle<Rc<ScrollState>>, usize)>, scroll_state: Option<(ElementStateHandle<Rc<ScrollState>>, usize)>,
child_alignment: f32, child_alignment: f32,
} }
@ -111,13 +111,13 @@ impl<V: View> Flex<V> {
} }
} }
impl<V: View> Extend<Element<V>> for Flex<V> { impl<V: View> Extend<AnyElement<V>> for Flex<V> {
fn extend<T: IntoIterator<Item = Element<V>>>(&mut self, children: T) { fn extend<T: IntoIterator<Item = AnyElement<V>>>(&mut self, children: T) {
self.children.extend(children); self.children.extend(children);
} }
} }
impl<V: View> Drawable<V> for Flex<V> { impl<V: View> Element<V> for Flex<V> {
type LayoutState = f32; type LayoutState = f32;
type PaintState = (); type PaintState = ();
@ -399,17 +399,17 @@ struct FlexParentData {
pub struct FlexItem<V: View> { pub struct FlexItem<V: View> {
metadata: FlexParentData, metadata: FlexParentData,
child: Element<V>, child: AnyElement<V>,
} }
impl<V: View> FlexItem<V> { impl<V: View> FlexItem<V> {
pub fn new(child: impl Drawable<V>) -> Self { pub fn new(child: impl Element<V>) -> Self {
FlexItem { FlexItem {
metadata: FlexParentData { metadata: FlexParentData {
flex: None, flex: None,
float: false, float: false,
}, },
child: child.into_element(), child: child.into_any(),
} }
} }
@ -424,7 +424,7 @@ impl<V: View> FlexItem<V> {
} }
} }
impl<V: View> Drawable<V> for FlexItem<V> { impl<V: View> Element<V> for FlexItem<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -3,18 +3,18 @@ use std::ops::Range;
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json::json, json::json,
Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext, AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
pub struct Hook<V: View> { pub struct Hook<V: View> {
child: Element<V>, child: AnyElement<V>,
after_layout: Option<Box<dyn FnMut(Vector2F, &mut ViewContext<V>)>>, after_layout: Option<Box<dyn FnMut(Vector2F, &mut ViewContext<V>)>>,
} }
impl<V: View> Hook<V> { impl<V: View> Hook<V> {
pub fn new(child: impl Drawable<V>) -> Self { pub fn new(child: impl Element<V>) -> Self {
Self { Self {
child: child.into_element(), child: child.into_any(),
after_layout: None, after_layout: None,
} }
} }
@ -28,7 +28,7 @@ impl<V: View> Hook<V> {
} }
} }
impl<V: View> Drawable<V> for Hook<V> { impl<V: View> Element<V> for Hook<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -5,7 +5,7 @@ use crate::{
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
json::{json, ToJson}, json::{json, ToJson},
scene, Border, Drawable, ImageData, SceneBuilder, SizeConstraint, View, ViewContext, scene, Border, Element, ImageData, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
use serde::Deserialize; use serde::Deserialize;
use std::{ops::Range, sync::Arc}; use std::{ops::Range, sync::Arc};
@ -55,7 +55,7 @@ impl Image {
} }
} }
impl<V: View> Drawable<V> for Image { impl<V: View> Element<V> for Image {
type LayoutState = Option<Arc<ImageData>>; type LayoutState = Option<Arc<ImageData>>;
type PaintState = (); type PaintState = ();

View File

@ -2,7 +2,7 @@ use crate::{
elements::*, elements::*,
fonts::TextStyle, fonts::TextStyle,
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
Action, Element, SizeConstraint, Action, AnyElement, SizeConstraint,
}; };
use serde_json::json; use serde_json::json;
@ -31,8 +31,8 @@ impl KeystrokeLabel {
} }
} }
impl<V: View> Drawable<V> for KeystrokeLabel { impl<V: View> Element<V> for KeystrokeLabel {
type LayoutState = Element<V>; type LayoutState = AnyElement<V>;
type PaintState = (); type PaintState = ();
fn layout( fn layout(
@ -40,7 +40,7 @@ impl<V: View> Drawable<V> for KeystrokeLabel {
constraint: SizeConstraint, constraint: SizeConstraint,
view: &mut V, view: &mut V,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) -> (Vector2F, Element<V>) { ) -> (Vector2F, AnyElement<V>) {
let mut element = if let Some(keystrokes) = let mut element = if let Some(keystrokes) =
cx.keystrokes_for_action(self.view_id, self.action.as_ref()) cx.keystrokes_for_action(self.view_id, self.action.as_ref())
{ {
@ -50,9 +50,9 @@ impl<V: View> Drawable<V> for KeystrokeLabel {
.contained() .contained()
.with_style(self.container_style) .with_style(self.container_style)
})) }))
.into_element() .into_any()
} else { } else {
Empty::new().collapsed().into_element() Empty::new().collapsed().into_any()
}; };
let size = element.layout(constraint, view, cx); let size = element.layout(constraint, view, cx);
@ -64,7 +64,7 @@ impl<V: View> Drawable<V> for KeystrokeLabel {
scene: &mut SceneBuilder, scene: &mut SceneBuilder,
bounds: RectF, bounds: RectF,
visible_bounds: RectF, visible_bounds: RectF,
element: &mut Element<V>, element: &mut AnyElement<V>,
view: &mut V, view: &mut V,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) { ) {
@ -87,7 +87,7 @@ impl<V: View> Drawable<V> for KeystrokeLabel {
fn debug( fn debug(
&self, &self,
_: RectF, _: RectF,
element: &Element<V>, element: &AnyElement<V>,
_: &(), _: &(),
view: &V, view: &V,
cx: &ViewContext<V>, cx: &ViewContext<V>,

View File

@ -8,7 +8,7 @@ use crate::{
}, },
json::{ToJson, Value}, json::{ToJson, Value},
text_layout::{Line, RunStyle}, text_layout::{Line, RunStyle},
Drawable, SceneBuilder, SizeConstraint, View, ViewContext, Element, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
use serde::Deserialize; use serde::Deserialize;
use serde_json::json; use serde_json::json;
@ -127,7 +127,7 @@ impl Label {
} }
} }
impl<V: View> Drawable<V> for Label { impl<V: View> Element<V> for Label {
type LayoutState = Line; type LayoutState = Line;
type PaintState = (); type PaintState = ();

View File

@ -4,7 +4,7 @@ use crate::{
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
json::json, json::json,
Drawable, Element, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext, AnyElement, Element, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
use std::{cell::RefCell, collections::VecDeque, fmt::Debug, ops::Range, rc::Rc}; use std::{cell::RefCell, collections::VecDeque, fmt::Debug, ops::Range, rc::Rc};
use sum_tree::{Bias, SumTree}; use sum_tree::{Bias, SumTree};
@ -23,7 +23,7 @@ pub enum Orientation {
struct StateInner<V: View> { struct StateInner<V: View> {
last_layout_width: Option<f32>, last_layout_width: Option<f32>,
render_item: Box<dyn FnMut(&mut V, usize, &mut ViewContext<V>) -> Element<V>>, render_item: Box<dyn FnMut(&mut V, usize, &mut ViewContext<V>) -> AnyElement<V>>,
rendered_range: Range<usize>, rendered_range: Range<usize>,
items: SumTree<ListItem<V>>, items: SumTree<ListItem<V>>,
logical_scroll_top: Option<ListOffset>, logical_scroll_top: Option<ListOffset>,
@ -41,7 +41,7 @@ pub struct ListOffset {
enum ListItem<V: View> { enum ListItem<V: View> {
Unrendered, Unrendered,
Rendered(Rc<RefCell<Element<V>>>), Rendered(Rc<RefCell<AnyElement<V>>>),
Removed(f32), Removed(f32),
} }
@ -91,7 +91,7 @@ impl<V: View> List<V> {
} }
} }
impl<V: View> Drawable<V> for List<V> { impl<V: View> Element<V> for List<V> {
type LayoutState = ListOffset; type LayoutState = ListOffset;
type PaintState = (); type PaintState = ();
@ -354,14 +354,14 @@ impl<V: View> ListState<V> {
mut render_item: F, mut render_item: F,
) -> Self ) -> Self
where where
D: Drawable<V>, D: Element<V>,
F: 'static + FnMut(&mut V, usize, &mut ViewContext<V>) -> D, F: 'static + FnMut(&mut V, usize, &mut ViewContext<V>) -> D,
{ {
let mut items = SumTree::new(); let mut items = SumTree::new();
items.extend((0..element_count).map(|_| ListItem::Unrendered), &()); items.extend((0..element_count).map(|_| ListItem::Unrendered), &());
Self(Rc::new(RefCell::new(StateInner { Self(Rc::new(RefCell::new(StateInner {
last_layout_width: None, last_layout_width: None,
render_item: Box::new(move |view, ix, cx| render_item(view, ix, cx).into_element()), render_item: Box::new(move |view, ix, cx| render_item(view, ix, cx).into_any()),
rendered_range: 0..0, rendered_range: 0..0,
items, items,
logical_scroll_top: None, logical_scroll_top: None,
@ -453,7 +453,7 @@ impl<V: View> StateInner<V> {
constraint: SizeConstraint, constraint: SizeConstraint,
view: &mut V, view: &mut V,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) -> Option<Rc<RefCell<Element<V>>>> { ) -> Option<Rc<RefCell<AnyElement<V>>>> {
if let Some(ListItem::Rendered(element)) = existing_element { if let Some(ListItem::Rendered(element)) = existing_element {
Some(element.clone()) Some(element.clone())
} else { } else {
@ -475,7 +475,7 @@ impl<V: View> StateInner<V> {
&'a self, &'a self,
bounds: RectF, bounds: RectF,
scroll_top: &ListOffset, scroll_top: &ListOffset,
) -> impl Iterator<Item = (Rc<RefCell<Element<V>>>, Vector2F)> + 'a { ) -> impl Iterator<Item = (Rc<RefCell<AnyElement<V>>>, Vector2F)> + 'a {
let mut item_origin = bounds.origin() - vec2f(0., scroll_top.offset_in_item); let mut item_origin = bounds.origin() - vec2f(0., scroll_top.offset_in_item);
let mut cursor = self.items.cursor::<Count>(); let mut cursor = self.items.cursor::<Count>();
cursor.seek(&Count(scroll_top.item_ix), Bias::Right, &()); cursor.seek(&Count(scroll_top.item_ix), Bias::Right, &());
@ -660,7 +660,7 @@ mod tests {
let elements = elements.clone(); let elements = elements.clone();
move |_, ix, _| { move |_, ix, _| {
let (id, height) = elements.borrow()[ix]; let (id, height) = elements.borrow()[ix];
TestElement::new(id, height).into_element() TestElement::new(id, height).into_any()
} }
}); });
@ -765,7 +765,7 @@ mod tests {
let elements = elements.clone(); let elements = elements.clone();
move |_, ix, _| { move |_, ix, _| {
let (id, height) = elements.borrow()[ix]; let (id, height) = elements.borrow()[ix];
TestElement::new(id, height).into_element() TestElement::new(id, height).into_any()
} }
}); });
@ -920,8 +920,8 @@ mod tests {
"TestView" "TestView"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
} }
@ -939,7 +939,7 @@ mod tests {
} }
} }
impl<V: View> Drawable<V> for TestElement { impl<V: View> Element<V> for TestElement {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -10,14 +10,14 @@ use crate::{
CursorRegion, HandlerSet, MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseHover, CursorRegion, HandlerSet, MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseHover,
MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut, MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut,
}, },
Drawable, Element, EventContext, MouseRegion, MouseState, SceneBuilder, SizeConstraint, View, AnyElement, Element, EventContext, MouseRegion, MouseState, SceneBuilder, SizeConstraint, View,
ViewContext, ViewContext,
}; };
use serde_json::json; use serde_json::json;
use std::{marker::PhantomData, ops::Range}; use std::{marker::PhantomData, ops::Range};
pub struct MouseEventHandler<Tag: 'static, V: View> { pub struct MouseEventHandler<Tag: 'static, V: View> {
child: Element<V>, child: AnyElement<V>,
region_id: usize, region_id: usize,
cursor_style: Option<CursorStyle>, cursor_style: Option<CursorStyle>,
handlers: HandlerSet, handlers: HandlerSet,
@ -34,11 +34,11 @@ pub struct MouseEventHandler<Tag: 'static, V: View> {
impl<Tag, V: View> MouseEventHandler<Tag, V> { impl<Tag, V: View> MouseEventHandler<Tag, V> {
pub fn new<D, F>(region_id: usize, cx: &mut ViewContext<V>, render_child: F) -> Self pub fn new<D, F>(region_id: usize, cx: &mut ViewContext<V>, render_child: F) -> Self
where where
D: Drawable<V>, D: Element<V>,
F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> D, F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> D,
{ {
let mut mouse_state = cx.mouse_state::<Tag>(region_id); let mut mouse_state = cx.mouse_state::<Tag>(region_id);
let child = render_child(&mut mouse_state, cx).into_element(); let child = render_child(&mut mouse_state, cx).into_any();
let notify_on_hover = mouse_state.accessed_hovered(); let notify_on_hover = mouse_state.accessed_hovered();
let notify_on_click = mouse_state.accessed_clicked(); let notify_on_click = mouse_state.accessed_clicked();
Self { Self {
@ -60,7 +60,7 @@ impl<Tag, V: View> MouseEventHandler<Tag, V> {
/// gets the opportunity /// gets the opportunity
pub fn above<D, F>(region_id: usize, cx: &mut ViewContext<V>, render_child: F) -> Self pub fn above<D, F>(region_id: usize, cx: &mut ViewContext<V>, render_child: F) -> Self
where where
D: Drawable<V>, D: Element<V>,
F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> D, F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> D,
{ {
let mut handler = Self::new(region_id, cx, render_child); let mut handler = Self::new(region_id, cx, render_child);
@ -212,7 +212,7 @@ impl<Tag, V: View> MouseEventHandler<Tag, V> {
} }
} }
impl<Tag, V: View> Drawable<V> for MouseEventHandler<Tag, V> { impl<Tag, V: View> Element<V> for MouseEventHandler<Tag, V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -3,12 +3,12 @@ use std::ops::Range;
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json::ToJson, json::ToJson,
Axis, Drawable, Element, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext, AnyElement, Axis, Element, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
use serde_json::json; use serde_json::json;
pub struct Overlay<V: View> { pub struct Overlay<V: View> {
child: Element<V>, child: AnyElement<V>,
anchor_position: Option<Vector2F>, anchor_position: Option<Vector2F>,
anchor_corner: AnchorCorner, anchor_corner: AnchorCorner,
fit_mode: OverlayFitMode, fit_mode: OverlayFitMode,
@ -73,9 +73,9 @@ impl AnchorCorner {
} }
impl<V: View> Overlay<V> { impl<V: View> Overlay<V> {
pub fn new(child: impl Drawable<V>) -> Self { pub fn new(child: impl Element<V>) -> Self {
Self { Self {
child: child.into_element(), child: child.into_any(),
anchor_position: None, anchor_position: None,
anchor_corner: AnchorCorner::TopLeft, anchor_corner: AnchorCorner::TopLeft,
fit_mode: OverlayFitMode::None, fit_mode: OverlayFitMode::None,
@ -116,7 +116,7 @@ impl<V: View> Overlay<V> {
} }
} }
impl<V: View> Drawable<V> for Overlay<V> { impl<V: View> Element<V> for Overlay<V> {
type LayoutState = Vector2F; type LayoutState = Vector2F;
type PaintState = (); type PaintState = ();

View File

@ -7,7 +7,7 @@ use crate::{
geometry::rect::RectF, geometry::rect::RectF,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
scene::MouseDrag, scene::MouseDrag,
Axis, Drawable, Element, ElementStateHandle, MouseRegion, SceneBuilder, View, ViewContext, AnyElement, Axis, Element, ElementStateHandle, MouseRegion, SceneBuilder, View, ViewContext,
}; };
use super::{ConstrainedBox, Hook}; use super::{ConstrainedBox, Hook};
@ -78,14 +78,14 @@ struct ResizeHandleState {
pub struct Resizable<V: View> { pub struct Resizable<V: View> {
side: Side, side: Side,
handle_size: f32, handle_size: f32,
child: Element<V>, child: AnyElement<V>,
state: Rc<ResizeHandleState>, state: Rc<ResizeHandleState>,
_state_handle: ElementStateHandle<Rc<ResizeHandleState>>, _state_handle: ElementStateHandle<Rc<ResizeHandleState>>,
} }
impl<V: View> Resizable<V> { impl<V: View> Resizable<V> {
pub fn new<Tag: 'static, T: View>( pub fn new<Tag: 'static, T: View>(
child: Element<V>, child: AnyElement<V>,
element_id: usize, element_id: usize,
side: Side, side: Side,
handle_size: f32, handle_size: f32,
@ -115,7 +115,7 @@ impl<V: View> Resizable<V> {
state.actual_dimension.set(side.relevant_component(size)); state.actual_dimension.set(side.relevant_component(size));
} }
}) })
.into_element(); .into_any();
Self { Self {
side, side,
@ -131,7 +131,7 @@ impl<V: View> Resizable<V> {
} }
} }
impl<V: View> Drawable<V> for Resizable<V> { impl<V: View> Element<V> for Resizable<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -3,13 +3,13 @@ use std::ops::Range;
use crate::{ use crate::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
json::{self, json, ToJson}, json::{self, json, ToJson},
Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext, Element, AnyElement, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
/// Element which renders it's children in a stack on top of each other. /// Element which renders it's children in a stack on top of each other.
/// The first child determines the size of the others. /// The first child determines the size of the others.
pub struct Stack<V: View> { pub struct Stack<V: View> {
children: Vec<Element<V>>, children: Vec<AnyElement<V>>,
} }
impl<V: View> Default for Stack<V> { impl<V: View> Default for Stack<V> {
@ -26,7 +26,7 @@ impl<V: View> Stack<V> {
} }
} }
impl<V: View> Drawable<V> for Stack<V> { impl<V: View> Element<V> for Stack<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();
@ -98,8 +98,8 @@ impl<V: View> Drawable<V> for Stack<V> {
} }
} }
impl<V: View> Extend<Element<V>> for Stack<V> { impl<V: View> Extend<AnyElement<V>> for Stack<V> {
fn extend<T: IntoIterator<Item = Element<V>>>(&mut self, children: T) { fn extend<T: IntoIterator<Item = AnyElement<V>>>(&mut self, children: T) {
self.children.extend(children) self.children.extend(children)
} }
} }

View File

@ -8,7 +8,7 @@ use crate::{
rect::RectF, rect::RectF,
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
scene, Drawable, SceneBuilder, SizeConstraint, View, ViewContext, scene, Element, SceneBuilder, SizeConstraint, View, ViewContext,
}; };
pub struct Svg { pub struct Svg {
@ -30,7 +30,7 @@ impl Svg {
} }
} }
impl<V: View> Drawable<V> for Svg { impl<V: View> Element<V> for Svg {
type LayoutState = Option<usvg::Tree>; type LayoutState = Option<usvg::Tree>;
type PaintState = (); type PaintState = ();

View File

@ -7,7 +7,7 @@ use crate::{
}, },
json::{ToJson, Value}, json::{ToJson, Value},
text_layout::{Line, RunStyle, ShapedBoundary}, text_layout::{Line, RunStyle, ShapedBoundary},
Drawable, FontCache, SceneBuilder, SizeConstraint, TextLayoutCache, View, ViewContext, Element, FontCache, SceneBuilder, SizeConstraint, TextLayoutCache, View, ViewContext,
}; };
use log::warn; use log::warn;
use serde_json::json; use serde_json::json;
@ -52,7 +52,7 @@ impl Text {
} }
} }
impl<V: View> Drawable<V> for Text { impl<V: View> Element<V> for Text {
type LayoutState = LayoutState; type LayoutState = LayoutState;
type PaintState = (); type PaintState = ();
@ -276,7 +276,7 @@ pub fn layout_highlighted_chunks<'a>(
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{elements::Empty, fonts, AppContext, Element, Entity, View, ViewContext}; use crate::{elements::Empty, fonts, AnyElement, AppContext, Entity, View, ViewContext};
#[crate::test(self)] #[crate::test(self)]
fn test_soft_wrapping_with_carriage_returns(cx: &mut AppContext) { fn test_soft_wrapping_with_carriage_returns(cx: &mut AppContext) {
@ -307,8 +307,8 @@ mod tests {
"TestView" "TestView"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
} }
} }

View File

@ -1,5 +1,5 @@
use super::{ use super::{
ContainerStyle, Drawable, Element, Flex, KeystrokeLabel, MouseEventHandler, Overlay, AnyElement, ContainerStyle, Element, Flex, KeystrokeLabel, MouseEventHandler, Overlay,
OverlayFitMode, ParentElement, Text, OverlayFitMode, ParentElement, Text,
}; };
use crate::{ use crate::{
@ -20,8 +20,8 @@ use util::ResultExt;
const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(500); const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(500);
pub struct Tooltip<V: View> { pub struct Tooltip<V: View> {
child: Element<V>, child: AnyElement<V>,
tooltip: Option<Element<V>>, tooltip: Option<AnyElement<V>>,
_state: ElementStateHandle<Rc<TooltipState>>, _state: ElementStateHandle<Rc<TooltipState>>,
} }
@ -55,7 +55,7 @@ impl<V: View> Tooltip<V> {
text: String, text: String,
action: Option<Box<dyn Action>>, action: Option<Box<dyn Action>>,
style: TooltipStyle, style: TooltipStyle,
child: Element<V>, child: AnyElement<V>,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) -> Self { ) -> Self {
struct ElementState<Tag>(Tag); struct ElementState<Tag>(Tag);
@ -85,7 +85,7 @@ impl<V: View> Tooltip<V> {
) )
.with_fit_mode(OverlayFitMode::SwitchAnchor) .with_fit_mode(OverlayFitMode::SwitchAnchor)
.with_anchor_position(state.position.get()) .with_anchor_position(state.position.get())
.into_element(), .into_any(),
) )
} else { } else {
None None
@ -117,7 +117,7 @@ impl<V: View> Tooltip<V> {
cx.notify(); cx.notify();
} }
}) })
.into_element(); .into_any();
Self { Self {
child, child,
tooltip, tooltip,
@ -131,7 +131,7 @@ impl<V: View> Tooltip<V> {
style: TooltipStyle, style: TooltipStyle,
action: Option<Box<dyn Action>>, action: Option<Box<dyn Action>>,
measure: bool, measure: bool,
) -> impl Drawable<V> { ) -> impl Element<V> {
Flex::row() Flex::row()
.with_child({ .with_child({
let text = if let Some(max_text_width) = style.max_text_width { let text = if let Some(max_text_width) = style.max_text_width {
@ -143,9 +143,9 @@ impl<V: View> Tooltip<V> {
}; };
if measure { if measure {
text.flex(1., false).into_element() text.flex(1., false).into_any()
} else { } else {
text.flex(1., false).aligned().into_element() text.flex(1., false).aligned().into_any()
} }
}) })
.with_children(action.and_then(|action| { .with_children(action.and_then(|action| {
@ -156,9 +156,9 @@ impl<V: View> Tooltip<V> {
style.keystroke.text, style.keystroke.text,
); );
if measure { if measure {
Some(keystroke_label.into_element()) Some(keystroke_label.into_any())
} else { } else {
Some(keystroke_label.aligned().into_element()) Some(keystroke_label.aligned().into_any())
} }
})) }))
.contained() .contained()
@ -166,7 +166,7 @@ impl<V: View> Tooltip<V> {
} }
} }
impl<V: View> Drawable<V> for Tooltip<V> { impl<V: View> Element<V> for Tooltip<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -1,4 +1,4 @@
use super::{Drawable, SizeConstraint}; use super::{Element, SizeConstraint};
use crate::{ use crate::{
geometry::{ geometry::{
rect::RectF, rect::RectF,
@ -6,7 +6,7 @@ use crate::{
}, },
json::{self, json}, json::{self, json},
platform::ScrollWheelEvent, platform::ScrollWheelEvent,
Element, MouseRegion, SceneBuilder, View, ViewContext, AnyElement, MouseRegion, SceneBuilder, View, ViewContext,
}; };
use json::ToJson; use json::ToJson;
use std::{cell::RefCell, cmp, ops::Range, rc::Rc}; use std::{cell::RefCell, cmp, ops::Range, rc::Rc};
@ -39,14 +39,14 @@ struct StateInner {
pub struct LayoutState<V: View> { pub struct LayoutState<V: View> {
scroll_max: f32, scroll_max: f32,
item_height: f32, item_height: f32,
items: Vec<Element<V>>, items: Vec<AnyElement<V>>,
} }
pub struct UniformList<V: View> { pub struct UniformList<V: View> {
state: UniformListState, state: UniformListState,
item_count: usize, item_count: usize,
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
append_items: Box<dyn Fn(&mut V, Range<usize>, &mut Vec<Element<V>>, &mut ViewContext<V>)>, append_items: Box<dyn Fn(&mut V, Range<usize>, &mut Vec<AnyElement<V>>, &mut ViewContext<V>)>,
padding_top: f32, padding_top: f32,
padding_bottom: f32, padding_bottom: f32,
get_width_from_item: Option<usize>, get_width_from_item: Option<usize>,
@ -62,7 +62,7 @@ impl<V: View> UniformList<V> {
) -> Self ) -> Self
where where
V: View, V: View,
F: 'static + Fn(&mut V, Range<usize>, &mut Vec<Element<V>>, &mut ViewContext<V>), F: 'static + Fn(&mut V, Range<usize>, &mut Vec<AnyElement<V>>, &mut ViewContext<V>),
{ {
Self { Self {
state, state,
@ -151,7 +151,7 @@ impl<V: View> UniformList<V> {
} }
} }
impl<V: View> Drawable<V> for UniformList<V> { impl<V: View> Element<V> for UniformList<V> {
type LayoutState = LayoutState<V>; type LayoutState = LayoutState<V>;
type PaintState = (); type PaintState = ();

View File

@ -19,7 +19,7 @@ pub use scene::{Border, CursorRegion, MouseRegion, MouseRegionId, Quad, Scene, S
pub mod text_layout; pub mod text_layout;
pub use text_layout::TextLayoutCache; pub use text_layout::TextLayoutCache;
mod util; mod util;
pub use elements::{Drawable, Element}; pub use elements::{AnyElement, Element};
pub mod executor; pub mod executor;
pub use executor::Task; pub use executor::Task;
pub mod color; pub mod color;

View File

@ -19,7 +19,7 @@ use crate::{
platform, platform,
platform::Platform, platform::Platform,
util::CwdBacktrace, util::CwdBacktrace,
AppContext, Drawable, Element, Entity, FontCache, Handle, Subscription, TestAppContext, View, AnyElement, AppContext, Element, Entity, FontCache, Handle, Subscription, TestAppContext, View,
ViewContext, ViewContext,
}; };
@ -242,7 +242,7 @@ impl View for EmptyView {
"empty view" "empty view"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
} }

View File

@ -7,7 +7,7 @@ use crate::{
pub struct Select { pub struct Select {
handle: WeakViewHandle<Self>, handle: WeakViewHandle<Self>,
render_item: Box<dyn Fn(usize, ItemType, bool, &AppContext) -> Element<Self>>, render_item: Box<dyn Fn(usize, ItemType, bool, &AppContext) -> AnyElement<Self>>,
selected_item_ix: usize, selected_item_ix: usize,
item_count: usize, item_count: usize,
is_open: bool, is_open: bool,
@ -41,7 +41,7 @@ pub fn init(cx: &mut AppContext) {
} }
impl Select { impl Select {
pub fn new<F: 'static + Fn(usize, ItemType, bool, &AppContext) -> Element<Self>>( pub fn new<F: 'static + Fn(usize, ItemType, bool, &AppContext) -> AnyElement<Self>>(
item_count: usize, item_count: usize,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
render_item: F, render_item: F,
@ -92,9 +92,9 @@ impl View for Select {
"Select" "Select"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if self.item_count == 0 { if self.item_count == 0 {
return Empty::new().into_element(); return Empty::new().into_any();
} }
enum Header {} enum Header {}
@ -149,7 +149,7 @@ impl View for Select {
cx.dispatch_action(SelectItem(ix)) cx.dispatch_action(SelectItem(ix))
}, },
) )
.into_element() .into_any()
})) }))
}, },
) )
@ -159,6 +159,6 @@ impl View for Select {
.with_style(style.menu), .with_style(style.menu),
)); ));
} }
result.into_element() result.into_any()
} }
} }

View File

@ -50,7 +50,7 @@ impl View for ActiveBufferLanguage {
"ActiveBufferLanguage" "ActiveBufferLanguage"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if let Some(active_language) = self.active_language.as_ref() { if let Some(active_language) = self.active_language.as_ref() {
let active_language_text = if let Some(active_language_text) = active_language { let active_language_text = if let Some(active_language_text) = active_language {
active_language_text.to_string() active_language_text.to_string()
@ -69,9 +69,9 @@ impl View for ActiveBufferLanguage {
.on_click(MouseButton::Left, |_, _, cx| { .on_click(MouseButton::Left, |_, _, cx| {
cx.dispatch_action(crate::Toggle) cx.dispatch_action(crate::Toggle)
}) })
.into_element() .into_any()
} else { } else {
Empty::new().into_element() Empty::new().into_any()
} }
} }
} }

View File

@ -182,7 +182,7 @@ impl PickerDelegate for LanguageSelectorDelegate {
mouse_state: &mut MouseState, mouse_state: &mut MouseState,
selected: bool, selected: bool,
cx: &AppContext, cx: &AppContext,
) -> Element<Picker<Self>> { ) -> AnyElement<Picker<Self>> {
let settings = cx.global::<Settings>(); let settings = cx.global::<Settings>();
let theme = &settings.theme; let theme = &settings.theme;
let mat = &self.matches[ix]; let mat = &self.matches[ix];
@ -197,6 +197,6 @@ impl PickerDelegate for LanguageSelectorDelegate {
.with_highlights(mat.positions.clone()) .with_highlights(mat.positions.clone())
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.into_element() .into_any()
} }
} }

View File

@ -202,7 +202,7 @@ impl PickerDelegate for OutlineViewDelegate {
mouse_state: &mut MouseState, mouse_state: &mut MouseState,
selected: bool, selected: bool,
cx: &AppContext, cx: &AppContext,
) -> Element<Picker<Self>> { ) -> AnyElement<Picker<Self>> {
let settings = cx.global::<Settings>(); let settings = cx.global::<Settings>();
let string_match = &self.matches[ix]; let string_match = &self.matches[ix];
let style = settings.theme.picker.item.style_for(mouse_state, selected); let style = settings.theme.picker.item.style_for(mouse_state, selected);
@ -220,6 +220,6 @@ impl PickerDelegate for OutlineViewDelegate {
.with_padding_left(20. * outline_item.depth as f32) .with_padding_left(20. * outline_item.depth as f32)
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.into_element() .into_any()
} }
} }

View File

@ -4,7 +4,7 @@ use gpui::{
geometry::vector::{vec2f, Vector2F}, geometry::vector::{vec2f, Vector2F},
keymap_matcher::KeymapContext, keymap_matcher::KeymapContext,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
AnyViewHandle, AppContext, Axis, Element, Entity, MouseState, Task, View, ViewContext, AnyElement, AnyViewHandle, AppContext, Axis, Entity, MouseState, Task, View, ViewContext,
ViewHandle, ViewHandle,
}; };
use menu::{Cancel, Confirm, SelectFirst, SelectIndex, SelectLast, SelectNext, SelectPrev}; use menu::{Cancel, Confirm, SelectFirst, SelectIndex, SelectLast, SelectNext, SelectPrev};
@ -41,7 +41,7 @@ pub trait PickerDelegate: Sized + 'static {
state: &mut MouseState, state: &mut MouseState,
selected: bool, selected: bool,
cx: &AppContext, cx: &AppContext,
) -> Element<Picker<Self>>; ) -> AnyElement<Picker<Self>>;
fn center_selection_after_match_updates(&self) -> bool { fn center_selection_after_match_updates(&self) -> bool {
false false
} }
@ -56,7 +56,7 @@ impl<D: PickerDelegate> View for Picker<D> {
"Picker" "Picker"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let theme = (self.theme.lock())(&cx.global::<settings::Settings>().theme); let theme = (self.theme.lock())(&cx.global::<settings::Settings>().theme);
let query = self.query(cx); let query = self.query(cx);
let match_count = self.delegate.match_count(); let match_count = self.delegate.match_count();
@ -85,7 +85,7 @@ impl<D: PickerDelegate> View for Picker<D> {
Label::new("No matches", theme.no_matches.label.clone()) Label::new("No matches", theme.no_matches.label.clone())
.contained() .contained()
.with_style(theme.no_matches.container) .with_style(theme.no_matches.container)
.into_element(), .into_any(),
) )
} }
} else { } else {
@ -108,14 +108,14 @@ impl<D: PickerDelegate> View for Picker<D> {
cx.dispatch_action(SelectIndex(ix)) cx.dispatch_action(SelectIndex(ix))
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.into_element() .into_any()
})); }));
}, },
) )
.contained() .contained()
.with_margin_top(6.0) .with_margin_top(6.0)
.flex(1., false) .flex(1., false)
.into_element(), .into_any(),
) )
}) })
.contained() .contained()
@ -123,7 +123,7 @@ impl<D: PickerDelegate> View for Picker<D> {
.constrained() .constrained()
.with_max_width(self.max_size.x()) .with_max_width(self.max_size.x())
.with_max_height(self.max_size.y()) .with_max_height(self.max_size.y())
.into_named_element("picker") .into_any_named("picker")
} }
fn keymap_context(&self, _: &AppContext) -> KeymapContext { fn keymap_context(&self, _: &AppContext) -> KeymapContext {

View File

@ -13,7 +13,7 @@ use gpui::{
impl_internal_actions, impl_internal_actions,
keymap_matcher::KeymapContext, keymap_matcher::KeymapContext,
platform::{CursorStyle, MouseButton, PromptLevel}, platform::{CursorStyle, MouseButton, PromptLevel},
AppContext, ClipboardItem, Drawable, Element, Entity, ModelHandle, Task, View, ViewContext, AnyElement, AppContext, ClipboardItem, Element, Entity, ModelHandle, Task, View, ViewContext,
ViewHandle, ViewHandle,
}; };
use menu::{Confirm, SelectNext, SelectPrev}; use menu::{Confirm, SelectNext, SelectPrev};
@ -1098,7 +1098,7 @@ impl ProjectPanel {
row_container_style: ContainerStyle, row_container_style: ContainerStyle,
style: &ProjectPanelEntry, style: &ProjectPanelEntry,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
) -> Element<V> { ) -> AnyElement<V> {
let kind = details.kind; let kind = details.kind;
let show_editor = details.is_editing && !details.is_processing; let show_editor = details.is_editing && !details.is_processing;
@ -1127,21 +1127,21 @@ impl ProjectPanel {
.aligned() .aligned()
.left() .left()
.flex(1.0, true) .flex(1.0, true)
.into_element() .into_any()
} else { } else {
Label::new(details.filename.clone(), style.text.clone()) Label::new(details.filename.clone(), style.text.clone())
.contained() .contained()
.with_margin_left(style.icon_spacing) .with_margin_left(style.icon_spacing)
.aligned() .aligned()
.left() .left()
.into_element() .into_any()
}) })
.constrained() .constrained()
.with_height(style.height) .with_height(style.height)
.contained() .contained()
.with_style(row_container_style) .with_style(row_container_style)
.with_padding_left(padding) .with_padding_left(padding)
.into_named_element("project panel entry visual element") .into_any_named("project panel entry visual element")
} }
fn render_entry( fn render_entry(
@ -1151,7 +1151,7 @@ impl ProjectPanel {
dragged_entry_destination: &mut Option<Arc<Path>>, dragged_entry_destination: &mut Option<Arc<Path>>,
theme: &theme::ProjectPanel, theme: &theme::ProjectPanel,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Element<Self> { ) -> AnyElement<Self> {
let kind = details.kind; let kind = details.kind;
let path = details.path.clone(); let path = details.path.clone();
let padding = theme.container.padding.left + details.depth as f32 * theme.indent_width; let padding = theme.container.padding.left + details.depth as f32 * theme.indent_width;
@ -1255,7 +1255,7 @@ impl ProjectPanel {
} }
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.into_named_element("project panel entry") .into_any_named("project panel entry")
} }
} }
@ -1264,7 +1264,7 @@ impl View for ProjectPanel {
"ProjectPanel" "ProjectPanel"
} }
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> gpui::Element<Self> { fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> gpui::AnyElement<Self> {
enum ProjectPanel {} enum ProjectPanel {}
let theme = &cx.global::<Settings>().theme.project_panel; let theme = &cx.global::<Settings>().theme.project_panel;
let mut container_style = theme.container; let mut container_style = theme.container;
@ -1319,7 +1319,7 @@ impl View for ProjectPanel {
}), }),
) )
.with_child(ChildView::new(&self.context_menu, cx)) .with_child(ChildView::new(&self.context_menu, cx))
.into_named_element("project panel") .into_any_named("project panel")
} else { } else {
Flex::column() Flex::column()
.with_child( .with_child(
@ -1348,7 +1348,7 @@ impl View for ProjectPanel {
) )
.contained() .contained()
.with_style(container_style) .with_style(container_style)
.into_named_element("empty project panel") .into_any_named("empty project panel")
} }
} }

View File

@ -201,7 +201,7 @@ impl PickerDelegate for ProjectSymbolsDelegate {
mouse_state: &mut MouseState, mouse_state: &mut MouseState,
selected: bool, selected: bool,
cx: &AppContext, cx: &AppContext,
) -> Element<Picker<Self>> { ) -> AnyElement<Picker<Self>> {
let string_match = &self.matches[ix]; let string_match = &self.matches[ix];
let settings = cx.global::<Settings>(); let settings = cx.global::<Settings>();
let style = &settings.theme.picker.item; let style = &settings.theme.picker.item;
@ -240,7 +240,7 @@ impl PickerDelegate for ProjectSymbolsDelegate {
) )
.contained() .contained()
.with_style(current_style.container) .with_style(current_style.container)
.into_element() .into_any()
} }
} }

View File

@ -3,7 +3,7 @@ use std::path::Path;
use fuzzy::StringMatch; use fuzzy::StringMatch;
use gpui::{ use gpui::{
elements::{Label, LabelStyle}, elements::{Label, LabelStyle},
Drawable, Element, View, Element, AnyElement, View,
}; };
use workspace::WorkspaceLocation; use workspace::WorkspaceLocation;
@ -42,10 +42,10 @@ impl HighlightedText {
} }
} }
pub fn render<V: View>(self, style: impl Into<LabelStyle>) -> Element<V> { pub fn render<V: View>(self, style: impl Into<LabelStyle>) -> AnyElement<V> {
Label::new(self.text, style) Label::new(self.text, style)
.with_highlights(self.highlight_positions) .with_highlights(self.highlight_positions)
.into_element() .into_any()
} }
} }

View File

@ -5,7 +5,7 @@ use gpui::{
actions, actions,
anyhow::Result, anyhow::Result,
elements::{Flex, ParentElement}, elements::{Flex, ParentElement},
AppContext, Drawable, Element, Task, ViewContext, AnyElement, AppContext, Element, Task, ViewContext,
}; };
use highlighted_workspace_location::HighlightedWorkspaceLocation; use highlighted_workspace_location::HighlightedWorkspaceLocation;
use ordered_float::OrderedFloat; use ordered_float::OrderedFloat;
@ -156,7 +156,7 @@ impl PickerDelegate for RecentProjectsDelegate {
mouse_state: &mut gpui::MouseState, mouse_state: &mut gpui::MouseState,
selected: bool, selected: bool,
cx: &gpui::AppContext, cx: &gpui::AppContext,
) -> Element<Picker<Self>> { ) -> AnyElement<Picker<Self>> {
let settings = cx.global::<Settings>(); let settings = cx.global::<Settings>();
let string_match = &self.matches[ix]; let string_match = &self.matches[ix];
let style = settings.theme.picker.item.style_for(mouse_state, selected); let style = settings.theme.picker.item.style_for(mouse_state, selected);
@ -177,6 +177,6 @@ impl PickerDelegate for RecentProjectsDelegate {
.flex(1., false) .flex(1., false)
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.into_named_element("match") .into_any_named("match")
} }
} }

View File

@ -92,7 +92,7 @@ impl View for BufferSearchBar {
} }
} }
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 theme = cx.global::<Settings>().theme.clone();
let editor_container = if self.query_contains_error { let editor_container = if self.query_contains_error {
theme.search.invalid_editor theme.search.invalid_editor
@ -178,7 +178,7 @@ impl View for BufferSearchBar {
.with_child(self.render_close_button(&theme.search, cx)) .with_child(self.render_close_button(&theme.search, cx))
.contained() .contained()
.with_style(theme.search.container) .with_style(theme.search.container)
.into_named_element("search bar") .into_any_named("search bar")
} }
} }
@ -319,7 +319,7 @@ impl BufferSearchBar {
icon: &'static str, icon: &'static str,
option: SearchOption, option: SearchOption,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Option<Element<Self>> { ) -> Option<AnyElement<Self>> {
if !option_supported { if !option_supported {
return None; return None;
} }
@ -349,7 +349,7 @@ impl BufferSearchBar {
tooltip_style, tooltip_style,
cx, cx,
) )
.into_element(), .into_any(),
) )
} }
@ -358,7 +358,7 @@ impl BufferSearchBar {
icon: &'static str, icon: &'static str,
direction: Direction, direction: Direction,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Element<Self> { ) -> AnyElement<Self> {
let action: Box<dyn Action>; let action: Box<dyn Action>;
let tooltip; let tooltip;
match direction { match direction {
@ -397,14 +397,14 @@ impl BufferSearchBar {
tooltip_style, tooltip_style,
cx, cx,
) )
.into_element() .into_any()
} }
fn render_close_button( fn render_close_button(
&self, &self,
theme: &theme::Search, theme: &theme::Search,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Element<Self> { ) -> AnyElement<Self> {
let action = Box::new(Dismiss); let action = Box::new(Dismiss);
let tooltip = "Dismiss Buffer Search"; let tooltip = "Dismiss Buffer Search";
let tooltip_style = cx.global::<Settings>().theme.tooltip.clone(); let tooltip_style = cx.global::<Settings>().theme.tooltip.clone();
@ -428,7 +428,7 @@ impl BufferSearchBar {
}) })
.with_cursor_style(CursorStyle::PointingHand) .with_cursor_style(CursorStyle::PointingHand)
.with_tooltip::<CloseButton>(0, tooltip.to_string(), Some(action), tooltip_style, cx) .with_tooltip::<CloseButton>(0, tooltip.to_string(), Some(action), tooltip_style, cx)
.into_element() .into_any()
} }
fn deploy(pane: &mut Pane, action: &Deploy, cx: &mut ViewContext<Pane>) { fn deploy(pane: &mut Pane, action: &Deploy, cx: &mut ViewContext<Pane>) {

View File

@ -12,7 +12,7 @@ use gpui::{
actions, actions,
elements::*, elements::*,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
Action, AnyViewHandle, AppContext, Element, Entity, ModelContext, ModelHandle, Subscription, Action, AnyElement, AnyViewHandle, AppContext, Entity, ModelContext, ModelHandle, Subscription,
Task, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle, Task, View, ViewContext, ViewHandle, WeakModelHandle, WeakViewHandle,
}; };
use menu::Confirm; use menu::Confirm;
@ -178,7 +178,7 @@ impl View for ProjectSearchView {
"ProjectSearchView" "ProjectSearchView"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let model = &self.model.read(cx); let model = &self.model.read(cx);
if model.match_ranges.is_empty() { if model.match_ranges.is_empty() {
enum Status {} enum Status {}
@ -201,11 +201,11 @@ impl View for ProjectSearchView {
.on_down(MouseButton::Left, |_, _, cx| { .on_down(MouseButton::Left, |_, _, cx| {
cx.focus_parent_view(); cx.focus_parent_view();
}) })
.into_named_element("project search view") .into_any_named("project search view")
} else { } else {
ChildView::new(&self.results_editor, cx) ChildView::new(&self.results_editor, cx)
.flex(1., true) .flex(1., true)
.into_named_element("project search view") .into_any_named("project search view")
} }
} }
@ -253,7 +253,7 @@ impl Item for ProjectSearchView {
_detail: Option<usize>, _detail: Option<usize>,
tab_theme: &theme::Tab, tab_theme: &theme::Tab,
cx: &AppContext, cx: &AppContext,
) -> Element<T> { ) -> AnyElement<T> {
Flex::row() Flex::row()
.with_child( .with_child(
Svg::new("icons/magnifying_glass_12.svg") Svg::new("icons/magnifying_glass_12.svg")
@ -269,7 +269,7 @@ impl Item for ProjectSearchView {
Label::new(query_text, tab_theme.label.clone()).aligned() Label::new(query_text, tab_theme.label.clone()).aligned()
})) }))
.into_element() .into_any()
} }
fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) { fn for_each_project_item(&self, cx: &AppContext, f: &mut dyn FnMut(usize, &dyn project::Item)) {
@ -748,7 +748,7 @@ impl ProjectSearchBar {
icon: &'static str, icon: &'static str,
direction: Direction, direction: Direction,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Element<Self> { ) -> AnyElement<Self> {
let action: Box<dyn Action>; let action: Box<dyn Action>;
let tooltip; let tooltip;
match direction { match direction {
@ -787,7 +787,7 @@ impl ProjectSearchBar {
tooltip_style, tooltip_style,
cx, cx,
) )
.into_element() .into_any()
} }
fn render_option_button( fn render_option_button(
@ -795,7 +795,7 @@ impl ProjectSearchBar {
icon: &'static str, icon: &'static str,
option: SearchOption, option: SearchOption,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Element<Self> { ) -> AnyElement<Self> {
let tooltip_style = cx.global::<Settings>().theme.tooltip.clone(); let tooltip_style = cx.global::<Settings>().theme.tooltip.clone();
let is_active = self.is_option_enabled(option, cx); let is_active = self.is_option_enabled(option, cx);
MouseEventHandler::<Self, _>::new(option as usize, cx, |state, cx| { MouseEventHandler::<Self, _>::new(option as usize, cx, |state, cx| {
@ -820,7 +820,7 @@ impl ProjectSearchBar {
tooltip_style, tooltip_style,
cx, cx,
) )
.into_element() .into_any()
} }
fn is_option_enabled(&self, option: SearchOption, cx: &AppContext) -> bool { fn is_option_enabled(&self, option: SearchOption, cx: &AppContext) -> bool {
@ -846,7 +846,7 @@ impl View for ProjectSearchBar {
"ProjectSearchBar" "ProjectSearchBar"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if let Some(search) = self.active_project_search.as_ref() { if let Some(search) = self.active_project_search.as_ref() {
let search = search.read(cx); let search = search.read(cx);
let theme = cx.global::<Settings>().theme.clone(); let theme = cx.global::<Settings>().theme.clone();
@ -908,9 +908,9 @@ impl View for ProjectSearchBar {
.with_style(theme.search.container) .with_style(theme.search.container)
.aligned() .aligned()
.left() .left()
.into_named_element("project search") .into_any_named("project search")
} else { } else {
Empty::new().into_element() Empty::new().into_any()
} }
} }
} }

View File

@ -94,8 +94,8 @@ mod tests {
"TestView" "TestView"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
} }

View File

@ -3,7 +3,7 @@ use gpui::{
elements::*, elements::*,
impl_internal_actions, impl_internal_actions,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
AppContext, Drawable, Element, Entity, View, ViewContext, ViewHandle, WeakModelHandle, AnyElement, AppContext, Element, Entity, View, ViewContext, ViewHandle, WeakModelHandle,
WeakViewHandle, WeakViewHandle,
}; };
use settings::Settings; use settings::Settings;
@ -42,11 +42,11 @@ impl View for TerminalButton {
"TerminalButton" "TerminalButton"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
let workspace = self.workspace.upgrade(cx); let workspace = self.workspace.upgrade(cx);
let project = match workspace { let project = match workspace {
Some(workspace) => workspace.read(cx).project().read(cx), Some(workspace) => workspace.read(cx).project().read(cx),
None => return Empty::new().into_element(), None => return Empty::new().into_any(),
}; };
let focused_view = cx.focused_view_id(); let focused_view = cx.focused_view_id();
@ -79,7 +79,7 @@ impl View for TerminalButton {
.constrained() .constrained()
.with_width(style.icon_size) .with_width(style.icon_size)
.aligned() .aligned()
.into_named_element("terminals-icon"), .into_any_named("terminals-icon"),
) )
.with_children(has_terminals.then(|| { .with_children(has_terminals.then(|| {
Label::new(terminal_count.to_string(), style.label.text.clone()) Label::new(terminal_count.to_string(), style.label.text.clone())
@ -112,7 +112,7 @@ impl View for TerminalButton {
), ),
) )
.with_child(ChildView::new(&self.popup_menu, cx).aligned().top().right()) .with_child(ChildView::new(&self.popup_menu, cx).aligned().top().right())
.into_named_element("terminal button") .into_any_named("terminal button")
} }
} }

View File

@ -10,7 +10,7 @@ use gpui::{
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
serde_json::json, serde_json::json,
text_layout::{Line, RunStyle}, text_layout::{Line, RunStyle},
Drawable, Element, EventContext, FontCache, ModelContext, MouseRegion, Quad, SceneBuilder, AnyElement, Element, EventContext, FontCache, ModelContext, MouseRegion, Quad, SceneBuilder,
SizeConstraint, TextLayoutCache, ViewContext, WeakModelHandle, SizeConstraint, TextLayoutCache, ViewContext, WeakModelHandle,
}; };
use itertools::Itertools; use itertools::Itertools;
@ -45,7 +45,7 @@ pub struct LayoutState {
size: TerminalSize, size: TerminalSize,
mode: TermMode, mode: TermMode,
display_offset: usize, display_offset: usize,
hyperlink_tooltip: Option<Element<TerminalView>>, hyperlink_tooltip: Option<AnyElement<TerminalView>>,
} }
///Helper struct for converting data between alacritty's cursor points, and displayed cursor points ///Helper struct for converting data between alacritty's cursor points, and displayed cursor points
@ -551,7 +551,7 @@ impl TerminalElement {
} }
} }
impl Drawable<TerminalView> for TerminalElement { impl Element<TerminalView> for TerminalElement {
type LayoutState = LayoutState; type LayoutState = LayoutState;
type PaintState = (); type PaintState = ();
@ -603,7 +603,7 @@ impl Drawable<TerminalView> for TerminalElement {
.with_tooltip::<TerminalElement>(id, uri, None, tooltip_style, cx), .with_tooltip::<TerminalElement>(id, uri, None, tooltip_style, cx),
) )
.with_position_mode(gpui::elements::OverlayPositionMode::Local) .with_position_mode(gpui::elements::OverlayPositionMode::Local)
.into_element(); .into_any();
tooltip.layout( tooltip.layout(
SizeConstraint::new(Vector2F::zero(), cx.window_size()), SizeConstraint::new(Vector2F::zero(), cx.window_size()),

View File

@ -18,7 +18,7 @@ use gpui::{
impl_actions, impl_internal_actions, impl_actions, impl_internal_actions,
keymap_matcher::{KeymapContext, Keystroke}, keymap_matcher::{KeymapContext, Keystroke},
platform::KeyDownEvent, platform::KeyDownEvent,
AnyViewHandle, AppContext, Drawable, Element, Entity, ModelHandle, Task, View, ViewContext, AnyElement, AnyViewHandle, AppContext, Element, Entity, ModelHandle, Task, View, ViewContext,
ViewHandle, WeakViewHandle, ViewHandle, WeakViewHandle,
}; };
use project::{LocalWorktree, Project}; use project::{LocalWorktree, Project};
@ -387,7 +387,7 @@ impl View for TerminalView {
"Terminal" "Terminal"
} }
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> AnyElement<Self> {
let terminal_handle = self.terminal.clone().downgrade(); let terminal_handle = self.terminal.clone().downgrade();
let self_id = cx.view_id(); let self_id = cx.view_id();
@ -406,7 +406,7 @@ impl View for TerminalView {
.contained(), .contained(),
) )
.with_child(ChildView::new(&self.context_menu, cx)) .with_child(ChildView::new(&self.context_menu, cx))
.into_element() .into_any()
} }
fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, _: AnyViewHandle, cx: &mut ViewContext<Self>) {
@ -549,7 +549,7 @@ impl Item for TerminalView {
_detail: Option<usize>, _detail: Option<usize>,
tab_theme: &theme::Tab, tab_theme: &theme::Tab,
cx: &gpui::AppContext, cx: &gpui::AppContext,
) -> Element<T> { ) -> AnyElement<T> {
let title = self.terminal().read(cx).title(); let title = self.terminal().read(cx).title();
Flex::row() Flex::row()
@ -563,7 +563,7 @@ impl Item for TerminalView {
.with_margin_right(tab_theme.spacing), .with_margin_right(tab_theme.spacing),
) )
.with_child(Label::new(title, tab_theme.label.clone()).aligned()) .with_child(Label::new(title, tab_theme.label.clone()).aligned())
.into_element() .into_any()
} }
fn clone_on_split( fn clone_on_split(

View File

@ -11,7 +11,7 @@ use gpui::{
platform, platform,
platform::MouseButton, platform::MouseButton,
scene::MouseClick, scene::MouseClick,
Action, Drawable, EventContext, MouseState, View, ViewContext, Action, Element, EventContext, MouseState, View, ViewContext,
}; };
use serde::Deserialize; use serde::Deserialize;
@ -41,7 +41,7 @@ pub fn checkbox<Tag: 'static, V: View>(
checkbox_with_label(label, style, checked, cx, change) checkbox_with_label(label, style, checked, cx, change)
} }
pub fn checkbox_with_label<Tag: 'static, D: Drawable<V>, V: View>( pub fn checkbox_with_label<Tag: 'static, D: Element<V>, V: View>(
label: D, label: D,
style: &CheckboxStyle, style: &CheckboxStyle,
checked: bool, checked: bool,
@ -223,12 +223,12 @@ pub fn modal<Tag, V, I, D, F>(
style: &ModalStyle, style: &ModalStyle,
cx: &mut ViewContext<V>, cx: &mut ViewContext<V>,
build_modal: F, build_modal: F,
) -> impl Drawable<V> ) -> impl Element<V>
where where
Tag: 'static, Tag: 'static,
V: View, V: View,
I: Into<Cow<'static, str>>, I: Into<Cow<'static, str>>,
D: Drawable<V>, D: Element<V>,
F: FnOnce(&mut gpui::ViewContext<V>) -> D, F: FnOnce(&mut gpui::ViewContext<V>) -> D,
{ {
const TITLEBAR_HEIGHT: f32 = 28.; const TITLEBAR_HEIGHT: f32 = 28.;

View File

@ -1,5 +1,5 @@
use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{actions, elements::*, AppContext, Drawable, Element, MouseState, ViewContext}; use gpui::{actions, elements::*, AnyElement, AppContext, Element, MouseState, ViewContext};
use picker::{Picker, PickerDelegate, PickerEvent}; use picker::{Picker, PickerDelegate, PickerEvent};
use settings::{settings_file::SettingsFile, Settings}; use settings::{settings_file::SettingsFile, Settings};
use staff_mode::StaffMode; use staff_mode::StaffMode;
@ -207,7 +207,7 @@ impl PickerDelegate for ThemeSelectorDelegate {
mouse_state: &mut MouseState, mouse_state: &mut MouseState,
selected: bool, selected: bool,
cx: &AppContext, cx: &AppContext,
) -> Element<Picker<Self>> { ) -> AnyElement<Picker<Self>> {
let settings = cx.global::<Settings>(); let settings = cx.global::<Settings>();
let theme = &settings.theme; let theme = &settings.theme;
let theme_match = &self.matches[ix]; let theme_match = &self.matches[ix];
@ -217,6 +217,6 @@ impl PickerDelegate for ThemeSelectorDelegate {
.with_highlights(theme_match.positions.clone()) .with_highlights(theme_match.positions.clone())
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.into_element() .into_any()
} }
} }

View File

@ -2,11 +2,11 @@ use gpui::{
actions, actions,
color::Color, color::Color,
elements::{ elements::{
Canvas, Container, ContainerStyle, Element, Flex, Label, Margin, MouseEventHandler, AnyElement, Canvas, Container, ContainerStyle, Flex, Label, Margin, MouseEventHandler,
Padding, ParentElement, Padding, ParentElement,
}, },
fonts::TextStyle, fonts::TextStyle,
AppContext, Border, Drawable, Entity, ModelHandle, Quad, Task, View, ViewContext, ViewHandle, AppContext, Border, Element, Entity, ModelHandle, Quad, Task, View, ViewContext, ViewHandle,
WeakViewHandle, WeakViewHandle,
}; };
use project::Project; use project::Project;
@ -35,7 +35,7 @@ impl ThemeTestbench {
} }
fn render_ramps(color_scheme: &ColorScheme) -> Flex<Self> { fn render_ramps(color_scheme: &ColorScheme) -> Flex<Self> {
fn display_ramp(ramp: &Vec<Color>) -> Element<ThemeTestbench> { fn display_ramp(ramp: &Vec<Color>) -> AnyElement<ThemeTestbench> {
Flex::row() Flex::row()
.with_children(ramp.iter().cloned().map(|color| { .with_children(ramp.iter().cloned().map(|color| {
Canvas::new(move |scene, bounds, _, _, _| { Canvas::new(move |scene, bounds, _, _, _| {
@ -48,7 +48,7 @@ impl ThemeTestbench {
.flex(1.0, false) .flex(1.0, false)
})) }))
.flex(1.0, false) .flex(1.0, false)
.into_element() .into_any()
} }
Flex::column() Flex::column()
@ -173,7 +173,7 @@ impl ThemeTestbench {
style_set: &StyleSet, style_set: &StyleSet,
style_override: Option<fn(&StyleSet) -> &Style>, style_override: Option<fn(&StyleSet) -> &Style>,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Element<Self> { ) -> AnyElement<Self> {
enum TestBenchButton {} enum TestBenchButton {}
MouseEventHandler::<TestBenchButton, _>::new(layer_index + button_index, cx, |state, cx| { MouseEventHandler::<TestBenchButton, _>::new(layer_index + button_index, cx, |state, cx| {
let style = if let Some(style_override) = style_override { let style = if let Some(style_override) = style_override {
@ -216,7 +216,7 @@ impl ThemeTestbench {
}) })
}) })
.flex(1., true) .flex(1., true)
.into_element() .into_any()
} }
fn render_label(text: String, style: &Style, cx: &mut ViewContext<Self>) -> Label { fn render_label(text: String, style: &Style, cx: &mut ViewContext<Self>) -> Label {
@ -251,7 +251,7 @@ impl View for ThemeTestbench {
"ThemeTestbench" "ThemeTestbench"
} }
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> AnyElement<Self> {
let color_scheme = &cx.global::<Settings>().theme.clone().color_scheme; let color_scheme = &cx.global::<Settings>().theme.clone().color_scheme;
Flex::row() Flex::row()
@ -268,7 +268,7 @@ impl View for ThemeTestbench {
.with_child(Self::render_layer(300, &color_scheme.highest, cx).flex(1., true)) .with_child(Self::render_layer(300, &color_scheme.highest, cx).flex(1., true))
.flex(1., false), .flex(1., false),
) )
.into_element() .into_any()
} }
} }
@ -278,11 +278,11 @@ impl Item for ThemeTestbench {
_: Option<usize>, _: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
_: &AppContext, _: &AppContext,
) -> Element<T> { ) -> AnyElement<T> {
Label::new("Theme Testbench", style.label.clone()) Label::new("Theme Testbench", style.label.clone())
.aligned() .aligned()
.contained() .contained()
.into_element() .into_any()
} }
fn serialized_item_kind() -> Option<&'static str> { fn serialized_item_kind() -> Option<&'static str> {

View File

@ -3,7 +3,7 @@ use std::sync::Arc;
use fuzzy::{match_strings, StringMatch, StringMatchCandidate}; use fuzzy::{match_strings, StringMatch, StringMatchCandidate};
use gpui::{ use gpui::{
actions, actions,
elements::{Drawable as _, Label}, elements::{Element as _, Label},
AppContext, Task, ViewContext, AppContext, Task, ViewContext,
}; };
use picker::{Picker, PickerDelegate, PickerEvent}; use picker::{Picker, PickerDelegate, PickerEvent};
@ -134,7 +134,7 @@ impl PickerDelegate for BaseKeymapSelectorDelegate {
mouse_state: &mut gpui::MouseState, mouse_state: &mut gpui::MouseState,
selected: bool, selected: bool,
cx: &gpui::AppContext, cx: &gpui::AppContext,
) -> gpui::Element<Picker<Self>> { ) -> gpui::AnyElement<Picker<Self>> {
let theme = &cx.global::<Settings>().theme; let theme = &cx.global::<Settings>().theme;
let keymap_match = &self.matches[ix]; let keymap_match = &self.matches[ix];
let style = theme.picker.item.style_for(mouse_state, selected); let style = theme.picker.item.style_for(mouse_state, selected);
@ -143,6 +143,6 @@ impl PickerDelegate for BaseKeymapSelectorDelegate {
.with_highlights(keymap_match.positions.clone()) .with_highlights(keymap_match.positions.clone())
.contained() .contained()
.with_style(style.container) .with_style(style.container)
.into_element() .into_any()
} }
} }

View File

@ -5,7 +5,7 @@ use std::{borrow::Cow, sync::Arc};
use db::kvp::KEY_VALUE_STORE; use db::kvp::KEY_VALUE_STORE;
use gpui::{ use gpui::{
elements::{Flex, Label, ParentElement}, elements::{Flex, Label, ParentElement},
AppContext, Drawable, Element, Entity, Subscription, View, ViewContext, AnyElement, AppContext, Element, Entity, Subscription, View, ViewContext,
}; };
use settings::{settings_file::SettingsFile, Settings}; use settings::{settings_file::SettingsFile, Settings};
@ -55,7 +55,7 @@ impl View for WelcomePage {
"WelcomePage" "WelcomePage"
} }
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> AnyElement<Self> {
let self_handle = cx.handle(); let self_handle = cx.handle();
let settings = cx.global::<Settings>(); let settings = cx.global::<Settings>();
let theme = settings.theme.clone(); let theme = settings.theme.clone();
@ -181,9 +181,9 @@ impl View for WelcomePage {
.contained() .contained()
.with_uniform_padding(10.) .with_uniform_padding(10.)
.aligned() .aligned()
.into_element(), .into_any(),
) )
.into_named_element("welcome page") .into_any_named("welcome page")
} }
} }
@ -205,14 +205,14 @@ impl Item for WelcomePage {
_detail: Option<usize>, _detail: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
_cx: &gpui::AppContext, _cx: &gpui::AppContext,
) -> Element<T> { ) -> AnyElement<T> {
Flex::row() Flex::row()
.with_child( .with_child(
Label::new("Welcome to Zed!", style.label.clone()) Label::new("Welcome to Zed!", style.label.clone())
.aligned() .aligned()
.contained(), .contained(),
) )
.into_element() .into_any()
} }
fn show_toolbar(&self) -> bool { fn show_toolbar(&self) -> bool {

View File

@ -9,7 +9,7 @@ use gpui::{
geometry::vector::Vector2F, geometry::vector::Vector2F,
impl_internal_actions, impl_internal_actions,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
AppContext, Border, Drawable, Element, SizeConstraint, ViewContext, ViewHandle, AnyElement, AppContext, Border, Element, SizeConstraint, ViewContext, ViewHandle,
}; };
use settings::{DockAnchor, Settings}; use settings::{DockAnchor, Settings};
use theme::Theme; use theme::Theme;
@ -315,7 +315,7 @@ impl Dock {
theme: &Theme, theme: &Theme,
anchor: DockAnchor, anchor: DockAnchor,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> Option<Element<Workspace>> { ) -> Option<AnyElement<Workspace>> {
let style = &theme.workspace.dock; let style = &theme.workspace.dock;
self.position self.position
@ -382,7 +382,7 @@ impl Dock {
) )
}) })
} }
.into_element() .into_any()
} }
DockAnchor::Expanded => { DockAnchor::Expanded => {
enum ExpandedDockWash {} enum ExpandedDockWash {}
@ -411,7 +411,7 @@ impl Dock {
.contained() .contained()
.with_style(style.maximized), .with_style(style.maximized),
) )
.into_element() .into_any()
} }
}) })
} }

View File

@ -2,7 +2,7 @@ use gpui::{
elements::{Empty, MouseEventHandler, Svg}, elements::{Empty, MouseEventHandler, Svg},
platform::CursorStyle, platform::CursorStyle,
platform::MouseButton, platform::MouseButton,
Drawable, Element, Entity, View, ViewContext, ViewHandle, WeakViewHandle, AnyElement, Element, Entity, View, ViewContext, ViewHandle, WeakViewHandle,
}; };
use settings::Settings; use settings::Settings;
@ -34,11 +34,11 @@ impl View for ToggleDockButton {
"Dock Toggle" "Dock Toggle"
} }
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> AnyElement<Self> {
let workspace = self.workspace.upgrade(cx); let workspace = self.workspace.upgrade(cx);
if workspace.is_none() { if workspace.is_none() {
return Empty::new().into_element(); return Empty::new().into_any();
} }
let workspace = workspace.unwrap(); let workspace = workspace.unwrap();
@ -97,7 +97,7 @@ impl View for ToggleDockButton {
cx, cx,
) )
} }
.into_element() .into_any()
} }
} }

View File

@ -6,7 +6,7 @@ use crate::{
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use client::{proto, Client}; use client::{proto, Client};
use gpui::{ use gpui::{
fonts::HighlightStyle, AnyViewHandle, AppContext, Element, ModelHandle, Task, View, fonts::HighlightStyle, AnyElement, AnyViewHandle, AppContext, ModelHandle, Task, View,
ViewContext, ViewHandle, WeakViewHandle, WindowContext, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
}; };
use project::{Project, ProjectEntryId, ProjectPath}; use project::{Project, ProjectEntryId, ProjectPath};
@ -59,7 +59,7 @@ pub trait Item: View {
detail: Option<usize>, detail: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
cx: &AppContext, cx: &AppContext,
) -> Element<V>; ) -> AnyElement<V>;
fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project::Item)) {} fn for_each_project_item(&self, _: &AppContext, _: &mut dyn FnMut(usize, &dyn project::Item)) {}
fn is_singleton(&self, _cx: &AppContext) -> bool { fn is_singleton(&self, _cx: &AppContext) -> bool {
false false
@ -180,13 +180,13 @@ pub trait ItemHandle: 'static + fmt::Debug {
detail: Option<usize>, detail: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
cx: &AppContext, cx: &AppContext,
) -> Element<Pane>; ) -> AnyElement<Pane>;
fn dragged_tab_content( fn dragged_tab_content(
&self, &self,
detail: Option<usize>, detail: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
cx: &AppContext, cx: &AppContext,
) -> Element<Workspace>; ) -> AnyElement<Workspace>;
fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>; fn project_path(&self, cx: &AppContext) -> Option<ProjectPath>;
fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>; fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>;
fn project_item_model_ids(&self, cx: &AppContext) -> SmallVec<[usize; 3]>; fn project_item_model_ids(&self, cx: &AppContext) -> SmallVec<[usize; 3]>;
@ -283,7 +283,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
detail: Option<usize>, detail: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
cx: &AppContext, cx: &AppContext,
) -> Element<Pane> { ) -> AnyElement<Pane> {
self.read(cx).tab_content(detail, style, cx) self.read(cx).tab_content(detail, style, cx)
} }
@ -292,7 +292,7 @@ impl<T: Item> ItemHandle for ViewHandle<T> {
detail: Option<usize>, detail: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
cx: &AppContext, cx: &AppContext,
) -> Element<Workspace> { ) -> AnyElement<Workspace> {
self.read(cx).tab_content(detail, style, cx) self.read(cx).tab_content(detail, style, cx)
} }
@ -770,7 +770,7 @@ pub(crate) mod test {
use super::{Item, ItemEvent}; use super::{Item, ItemEvent};
use crate::{sidebar::SidebarItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId}; use crate::{sidebar::SidebarItem, ItemId, ItemNavHistory, Pane, Workspace, WorkspaceId};
use gpui::{ use gpui::{
elements::Empty, AppContext, Drawable, Element, Entity, ModelHandle, Task, View, elements::Empty, AnyElement, AppContext, Element, Entity, ModelHandle, Task, View,
ViewContext, ViewHandle, WeakViewHandle, ViewContext, ViewHandle, WeakViewHandle,
}; };
use project::{Project, ProjectEntryId, ProjectPath, WorktreeId}; use project::{Project, ProjectEntryId, ProjectPath, WorktreeId};
@ -929,8 +929,8 @@ pub(crate) mod test {
"TestItem" "TestItem"
} }
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_element() Empty::new().into_any()
} }
} }
@ -947,9 +947,9 @@ pub(crate) mod test {
detail: Option<usize>, detail: Option<usize>,
_: &theme::Tab, _: &theme::Tab,
_: &AppContext, _: &AppContext,
) -> Element<V> { ) -> AnyElement<V> {
self.tab_detail.set(detail); self.tab_detail.set(detail);
Empty::new().into_element() Empty::new().into_any()
} }
fn for_each_project_item( fn for_each_project_item(

View File

@ -140,7 +140,7 @@ pub mod simple_message_notification {
elements::{Flex, MouseEventHandler, Padding, ParentElement, Svg, Text}, elements::{Flex, MouseEventHandler, Padding, ParentElement, Svg, Text},
impl_actions, impl_actions,
platform::{CursorStyle, MouseButton}, platform::{CursorStyle, MouseButton},
Action, AppContext, Drawable, Entity, View, ViewContext, Action, AppContext, Element, Entity, View, ViewContext,
}; };
use menu::Cancel; use menu::Cancel;
use serde::Deserialize; use serde::Deserialize;
@ -229,7 +229,7 @@ pub mod simple_message_notification {
"MessageNotification" "MessageNotification"
} }
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> gpui::Element<Self> { fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> gpui::AnyElement<Self> {
let theme = cx.global::<Settings>().theme.clone(); let theme = cx.global::<Settings>().theme.clone();
let theme = &theme.simple_message_notification; let theme = &theme.simple_message_notification;
@ -317,7 +317,7 @@ pub mod simple_message_notification {
} else { } else {
CursorStyle::Arrow CursorStyle::Arrow
}) })
.into_element() .into_any()
} }
} }

View File

@ -1356,7 +1356,7 @@ impl Pane {
}); });
} }
fn render_tabs(&mut self, cx: &mut ViewContext<Self>) -> impl Drawable<Self> { fn render_tabs(&mut self, cx: &mut ViewContext<Self>) -> impl Element<Self> {
let theme = cx.global::<Settings>().theme.clone(); let theme = cx.global::<Settings>().theme.clone();
let pane = cx.handle().downgrade(); let pane = cx.handle().downgrade();
@ -1445,9 +1445,9 @@ impl Pane {
tooltip_theme, tooltip_theme,
cx, cx,
) )
.into_element() .into_any()
} else { } else {
mouse_event_handler.into_element() mouse_event_handler.into_any()
} }
} }
}); });
@ -1495,7 +1495,7 @@ impl Pane {
.with_border(filler_style.container.border) .with_border(filler_style.container.border)
}) })
.flex(1., true) .flex(1., true)
.into_named_element("filler"), .into_any_named("filler"),
); );
row row
@ -1546,7 +1546,7 @@ impl Pane {
hovered: bool, hovered: bool,
tab_style: &theme::Tab, tab_style: &theme::Tab,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Element<Self> { ) -> AnyElement<Self> {
let title = item.tab_content(detail, &tab_style, cx); let title = item.tab_content(detail, &tab_style, cx);
Self::render_tab_with_title(title, item, pane, first, hovered, tab_style, cx) Self::render_tab_with_title(title, item, pane, first, hovered, tab_style, cx)
} }
@ -1559,20 +1559,20 @@ impl Pane {
hovered: bool, hovered: bool,
tab_style: &theme::Tab, tab_style: &theme::Tab,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> Element<Workspace> { ) -> AnyElement<Workspace> {
let title = item.dragged_tab_content(detail, &tab_style, cx); let title = item.dragged_tab_content(detail, &tab_style, cx);
Self::render_tab_with_title(title, item, pane, first, hovered, tab_style, cx) Self::render_tab_with_title(title, item, pane, first, hovered, tab_style, cx)
} }
fn render_tab_with_title<T: View>( fn render_tab_with_title<T: View>(
title: Element<T>, title: AnyElement<T>,
item: &Box<dyn ItemHandle>, item: &Box<dyn ItemHandle>,
pane: WeakViewHandle<Pane>, pane: WeakViewHandle<Pane>,
first: bool, first: bool,
hovered: bool, hovered: bool,
tab_style: &theme::Tab, tab_style: &theme::Tab,
cx: &mut ViewContext<T>, cx: &mut ViewContext<T>,
) -> Element<T> { ) -> AnyElement<T> {
let mut container = tab_style.container.clone(); let mut container = tab_style.container.clone();
if first { if first {
container.border.left = false; container.border.left = false;
@ -1636,7 +1636,7 @@ impl Pane {
}) })
} }
}) })
.into_named_element("close-tab-icon") .into_any_named("close-tab-icon")
.constrained() .constrained()
} else { } else {
Empty::new().constrained() Empty::new().constrained()
@ -1648,14 +1648,14 @@ impl Pane {
.with_style(container) .with_style(container)
.constrained() .constrained()
.with_height(tab_style.height) .with_height(tab_style.height)
.into_element() .into_any()
} }
fn render_tab_bar_buttons( fn render_tab_bar_buttons(
&mut self, &mut self,
theme: &Theme, theme: &Theme,
cx: &mut ViewContext<Self>, cx: &mut ViewContext<Self>,
) -> Element<Self> { ) -> AnyElement<Self> {
Flex::row() Flex::row()
// New menu // New menu
.with_child(render_tab_bar_button( .with_child(render_tab_bar_button(
@ -1701,15 +1701,19 @@ impl Pane {
.contained() .contained()
.with_style(theme.workspace.tab_bar.pane_button_container) .with_style(theme.workspace.tab_bar.pane_button_container)
.flex(1., false) .flex(1., false)
.into_element() .into_any()
} }
fn render_blank_pane(&mut self, theme: &Theme, _cx: &mut ViewContext<Self>) -> Element<Self> { fn render_blank_pane(
&mut self,
theme: &Theme,
_cx: &mut ViewContext<Self>,
) -> AnyElement<Self> {
let background = theme.workspace.background; let background = theme.workspace.background;
Empty::new() Empty::new()
.contained() .contained()
.with_background_color(background) .with_background_color(background)
.into_element() .into_any()
} }
} }
@ -1722,7 +1726,7 @@ impl View for Pane {
"Pane" "Pane"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
enum MouseNavigationHandler {} enum MouseNavigationHandler {}
MouseEventHandler::<MouseNavigationHandler, _>::new(0, cx, |_, cx| { MouseEventHandler::<MouseNavigationHandler, _>::new(0, cx, |_, cx| {
@ -1750,11 +1754,8 @@ impl View for Pane {
), ),
); );
let mut tab_row = Flex::row().with_child( let mut tab_row = Flex::row()
self.render_tabs(cx) .with_child(self.render_tabs(cx).flex(1., true).into_any_named("tabs"));
.flex(1., true)
.into_named_element("tabs"),
);
if self.is_active { if self.is_active {
tab_row.add_child(self.render_tab_bar_buttons(&theme, cx)) tab_row.add_child(self.render_tab_bar_buttons(&theme, cx))
@ -1765,7 +1766,7 @@ impl View for Pane {
.constrained() .constrained()
.with_height(theme.workspace.tab_bar.height) .with_height(theme.workspace.tab_bar.height)
.flex(1., false) .flex(1., false)
.into_named_element("tab bar") .into_any_named("tab bar")
}) })
.with_child({ .with_child({
enum PaneContentTabDropTarget {} enum PaneContentTabDropTarget {}
@ -1797,7 +1798,7 @@ impl View for Pane {
.flex(1., true) .flex(1., true)
}) })
.with_child(ChildView::new(&self.tab_context_menu, cx)) .with_child(ChildView::new(&self.tab_context_menu, cx))
.into_element() .into_any()
} else { } else {
enum EmptyPane {} enum EmptyPane {}
let theme = cx.global::<Settings>().theme.clone(); let theme = cx.global::<Settings>().theme.clone();
@ -1808,7 +1809,7 @@ impl View for Pane {
.on_down(MouseButton::Left, |_, _, cx| { .on_down(MouseButton::Left, |_, _, cx| {
cx.focus_parent_view(); cx.focus_parent_view();
}) })
.into_element() .into_any()
} }
}) })
.on_down( .on_down(
@ -1824,7 +1825,7 @@ impl View for Pane {
cx.dispatch_action(GoForward { pane: Some(pane) }) cx.dispatch_action(GoForward { pane: Some(pane) })
} }
}) })
.into_named_element("pane") .into_any_named("pane")
} }
fn focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, focused: AnyViewHandle, cx: &mut ViewContext<Self>) {
@ -1876,7 +1877,7 @@ fn render_tab_bar_button<A: Action + Clone>(
cx: &mut ViewContext<Pane>, cx: &mut ViewContext<Pane>,
action: A, action: A,
context_menu: Option<ViewHandle<ContextMenu>>, context_menu: Option<ViewHandle<ContextMenu>>,
) -> Element<Pane> { ) -> AnyElement<Pane> {
enum TabBarButton {} enum TabBarButton {}
Stack::new() Stack::new()
@ -1902,7 +1903,7 @@ fn render_tab_bar_button<A: Action + Clone>(
context_menu.map(|menu| ChildView::new(&menu, cx).aligned().bottom().right()), context_menu.map(|menu| ChildView::new(&menu, cx).aligned().bottom().right()),
) )
.flex(1., false) .flex(1., false)
.into_named_element("tab bar button") .into_any_named("tab bar button")
} }
impl ItemNavHistory { impl ItemNavHistory {
@ -2008,11 +2009,11 @@ impl NavHistory {
pub struct PaneBackdrop<V: View> { pub struct PaneBackdrop<V: View> {
child_view: usize, child_view: usize,
child: Element<V>, child: AnyElement<V>,
} }
impl<V: View> PaneBackdrop<V> { impl<V: View> PaneBackdrop<V> {
pub fn new(pane_item_view: usize, child: Element<V>) -> Self { pub fn new(pane_item_view: usize, child: AnyElement<V>) -> Self {
PaneBackdrop { PaneBackdrop {
child, child,
child_view: pane_item_view, child_view: pane_item_view,
@ -2020,7 +2021,7 @@ impl<V: View> PaneBackdrop<V> {
} }
} }
impl<V: View> Drawable<V> for PaneBackdrop<V> { impl<V: View> Element<V> for PaneBackdrop<V> {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -5,7 +5,7 @@ use gpui::{
geometry::{rect::RectF, vector::Vector2F}, geometry::{rect::RectF, vector::Vector2F},
platform::MouseButton, platform::MouseButton,
scene::MouseUp, scene::MouseUp,
AppContext, Drawable, EventContext, MouseState, Quad, View, ViewContext, WeakViewHandle, AppContext, Element, EventContext, MouseState, Quad, View, ViewContext, WeakViewHandle,
}; };
use project::ProjectEntryId; use project::ProjectEntryId;
use settings::Settings; use settings::Settings;
@ -27,7 +27,7 @@ pub fn dragged_item_receiver<Tag, D, F>(
) -> MouseEventHandler<Tag, Pane> ) -> MouseEventHandler<Tag, Pane>
where where
Tag: 'static, Tag: 'static,
D: Drawable<Pane>, D: Element<Pane>,
F: FnOnce(&mut MouseState, &mut ViewContext<Pane>) -> D, F: FnOnce(&mut MouseState, &mut ViewContext<Pane>) -> D,
{ {
MouseEventHandler::<Tag, _>::above(region_id, cx, |state, cx| { MouseEventHandler::<Tag, _>::above(region_id, cx, |state, cx| {

View File

@ -71,7 +71,7 @@ impl PaneGroup {
active_call: Option<&ModelHandle<ActiveCall>>, active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>, active_pane: &ViewHandle<Pane>,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> Element<Workspace> { ) -> AnyElement<Workspace> {
self.root.render( self.root.render(
project, project,
theme, theme,
@ -132,7 +132,7 @@ impl Member {
active_call: Option<&ModelHandle<ActiveCall>>, active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>, active_pane: &ViewHandle<Pane>,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> Element<Workspace> { ) -> AnyElement<Workspace> {
enum FollowIntoExternalProject {} enum FollowIntoExternalProject {}
match self { match self {
@ -207,7 +207,7 @@ impl Member {
.aligned() .aligned()
.bottom() .bottom()
.right() .right()
.into_element(), .into_any(),
) )
} }
} }
@ -224,7 +224,7 @@ impl Member {
.aligned() .aligned()
.bottom() .bottom()
.right() .right()
.into_element(), .into_any(),
), ),
ParticipantLocation::External => Some( ParticipantLocation::External => Some(
Label::new( Label::new(
@ -239,7 +239,7 @@ impl Member {
.aligned() .aligned()
.bottom() .bottom()
.right() .right()
.into_element(), .into_any(),
), ),
} }
} else { } else {
@ -249,7 +249,7 @@ impl Member {
Stack::new() Stack::new()
.with_child(ChildView::new(pane, cx).contained().with_border(border)) .with_child(ChildView::new(pane, cx).contained().with_border(border))
.with_children(leader_status_box) .with_children(leader_status_box)
.into_element() .into_any()
} }
Member::Axis(axis) => axis.render( Member::Axis(axis) => axis.render(
project, project,
@ -361,7 +361,7 @@ impl PaneAxis {
active_call: Option<&ModelHandle<ActiveCall>>, active_call: Option<&ModelHandle<ActiveCall>>,
active_pane: &ViewHandle<Pane>, active_pane: &ViewHandle<Pane>,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> Element<Workspace> { ) -> AnyElement<Workspace> {
let last_member_ix = self.members.len() - 1; let last_member_ix = self.members.len() - 1;
Flex::new(self.axis) Flex::new(self.axis)
.with_children(self.members.iter().enumerate().map(|(ix, member)| { .with_children(self.members.iter().enumerate().map(|(ix, member)| {
@ -382,12 +382,12 @@ impl PaneAxis {
Axis::Vertical => border.bottom = true, Axis::Vertical => border.bottom = true,
Axis::Horizontal => border.right = true, Axis::Horizontal => border.right = true,
} }
member = member.contained().with_border(border).into_element(); member = member.contained().with_border(border).into_any();
} }
FlexItem::new(member).flex(flex, true) FlexItem::new(member).flex(flex, true)
})) }))
.into_element() .into_any()
} }
} }

View File

@ -69,7 +69,7 @@ impl View for SharedScreen {
"SharedScreen" "SharedScreen"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
enum Focus {} enum Focus {}
let frame = self.frame.clone(); let frame = self.frame.clone();
@ -91,7 +91,7 @@ impl View for SharedScreen {
.with_style(cx.global::<Settings>().theme.shared_screen) .with_style(cx.global::<Settings>().theme.shared_screen)
}) })
.on_down(MouseButton::Left, |_, _, cx| cx.focus_parent_view()) .on_down(MouseButton::Left, |_, _, cx| cx.focus_parent_view())
.into_element() .into_any()
} }
} }
@ -110,7 +110,7 @@ impl Item for SharedScreen {
_: Option<usize>, _: Option<usize>,
style: &theme::Tab, style: &theme::Tab,
_: &AppContext, _: &AppContext,
) -> gpui::Element<V> { ) -> gpui::AnyElement<V> {
Flex::row() Flex::row()
.with_child( .with_child(
Svg::new("icons/disable_screen_sharing_12.svg") Svg::new("icons/disable_screen_sharing_12.svg")
@ -128,7 +128,7 @@ impl Item for SharedScreen {
) )
.aligned(), .aligned(),
) )
.into_element() .into_any()
} }
fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) { fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext<Self>) {

View File

@ -188,7 +188,7 @@ impl View for Sidebar {
"Sidebar" "Sidebar"
} }
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> { fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if let Some(active_item) = self.active_item() { if let Some(active_item) = self.active_item() {
enum ResizeHandleTag {} enum ResizeHandleTag {}
let style = &cx.global::<Settings>().theme.workspace.sidebar; let style = &cx.global::<Settings>().theme.workspace.sidebar;
@ -202,9 +202,9 @@ impl View for Sidebar {
style.initial_size, style.initial_size,
cx, cx,
) )
.into_element() .into_any()
} else { } else {
Empty::new().into_element() Empty::new().into_any()
} }
} }
} }
@ -225,7 +225,7 @@ impl View for SidebarButtons {
"SidebarToggleButton" "SidebarToggleButton"
} }
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; let theme = &cx.global::<Settings>().theme;
let tooltip_style = theme.tooltip.clone(); let tooltip_style = theme.tooltip.clone();
let theme = &theme.workspace.status_bar.sidebar_buttons; let theme = &theme.workspace.status_bar.sidebar_buttons;
@ -294,7 +294,7 @@ impl View for SidebarButtons {
)) ))
.contained() .contained()
.with_style(group_style) .with_style(group_style)
.into_element() .into_any()
} }
} }

View File

@ -8,8 +8,8 @@ use gpui::{
vector::{vec2f, Vector2F}, vector::{vec2f, Vector2F},
}, },
json::{json, ToJson}, json::{json, ToJson},
AnyViewHandle, Element, Entity, SceneBuilder, SizeConstraint, Subscription, View, ViewContext, AnyElement, AnyViewHandle, Entity, SceneBuilder, SizeConstraint, Subscription, View,
ViewHandle, WindowContext, ViewContext, ViewHandle, WindowContext,
}; };
use settings::Settings; use settings::Settings;
@ -46,7 +46,7 @@ impl View for StatusBar {
"StatusBar" "StatusBar"
} }
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.workspace.status_bar; let theme = &cx.global::<Settings>().theme.workspace.status_bar;
StatusBarElement { StatusBarElement {
@ -57,7 +57,7 @@ impl View for StatusBar {
.contained() .contained()
.with_margin_right(theme.item_spacing) .with_margin_right(theme.item_spacing)
})) }))
.into_element(), .into_any(),
right: Flex::row() right: Flex::row()
.with_children(self.right_items.iter().rev().map(|i| { .with_children(self.right_items.iter().rev().map(|i| {
@ -66,13 +66,13 @@ impl View for StatusBar {
.contained() .contained()
.with_margin_left(theme.item_spacing) .with_margin_left(theme.item_spacing)
})) }))
.into_element(), .into_any(),
} }
.contained() .contained()
.with_style(theme.container) .with_style(theme.container)
.constrained() .constrained()
.with_height(theme.height) .with_height(theme.height)
.into_element() .into_any()
} }
} }
@ -145,11 +145,11 @@ impl From<&dyn StatusItemViewHandle> for AnyViewHandle {
} }
struct StatusBarElement { struct StatusBarElement {
left: Element<StatusBar>, left: AnyElement<StatusBar>,
right: Element<StatusBar>, right: AnyElement<StatusBar>,
} }
impl Drawable<StatusBar> for StatusBarElement { impl Element<StatusBar> for StatusBarElement {
type LayoutState = (); type LayoutState = ();
type PaintState = (); type PaintState = ();

View File

@ -1,7 +1,7 @@
use crate::{ItemHandle, Pane}; use crate::{ItemHandle, Pane};
use gpui::{ use gpui::{
elements::*, platform::CursorStyle, platform::MouseButton, Action, AnyViewHandle, AppContext, elements::*, platform::CursorStyle, platform::MouseButton, Action, AnyElement, AnyViewHandle,
Element, Entity, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext, AppContext, Entity, View, ViewContext, ViewHandle, WeakViewHandle, WindowContext,
}; };
use settings::Settings; use settings::Settings;
@ -59,7 +59,7 @@ impl View for Toolbar {
"Toolbar" "Toolbar"
} }
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.workspace.toolbar; let theme = &cx.global::<Settings>().theme.workspace.toolbar;
let mut primary_left_items = Vec::new(); let mut primary_left_items = Vec::new();
@ -77,9 +77,9 @@ impl View for Toolbar {
.contained() .contained()
.with_margin_right(spacing); .with_margin_right(spacing);
if let Some((flex, expanded)) = flex { if let Some((flex, expanded)) = flex {
primary_left_items.push(left_item.flex(flex, expanded).into_element()); primary_left_items.push(left_item.flex(flex, expanded).into_any());
} else { } else {
primary_left_items.push(left_item.into_element()); primary_left_items.push(left_item.into_any());
} }
} }
@ -90,9 +90,9 @@ impl View for Toolbar {
.with_margin_left(spacing) .with_margin_left(spacing)
.flex_float(); .flex_float();
if let Some((flex, expanded)) = flex { if let Some((flex, expanded)) = flex {
primary_right_items.push(right_item.flex(flex, expanded).into_element()); primary_right_items.push(right_item.flex(flex, expanded).into_any());
} else { } else {
primary_right_items.push(right_item.into_element()); primary_right_items.push(right_item.into_any());
} }
} }
@ -101,7 +101,7 @@ impl View for Toolbar {
ChildView::new(item.as_any(), cx) ChildView::new(item.as_any(), cx)
.constrained() .constrained()
.with_height(theme.height) .with_height(theme.height)
.into_element(), .into_any(),
); );
} }
} }
@ -156,7 +156,7 @@ impl View for Toolbar {
.with_children(secondary_item) .with_children(secondary_item)
.contained() .contained()
.with_style(container_style) .with_style(container_style)
.into_named_element("toolbar") .into_any_named("toolbar")
} }
} }
@ -171,7 +171,7 @@ fn nav_button<A: Action + Clone>(
tooltip_action: A, tooltip_action: A,
action_name: &str, action_name: &str,
cx: &mut ViewContext<Toolbar>, cx: &mut ViewContext<Toolbar>,
) -> Element<Toolbar> { ) -> AnyElement<Toolbar> {
MouseEventHandler::<A, _>::new(0, cx, |state, _| { MouseEventHandler::<A, _>::new(0, cx, |state, _| {
let style = if enabled { let style = if enabled {
style.style_for(state, false) style.style_for(state, false)
@ -207,7 +207,7 @@ fn nav_button<A: Action + Clone>(
) )
.contained() .contained()
.with_margin_right(spacing) .with_margin_right(spacing)
.into_named_element("nav button") .into_any_named("nav button")
} }
impl Toolbar { impl Toolbar {

View File

@ -2075,7 +2075,7 @@ impl Workspace {
self.leader_state.followers.contains(&peer_id) self.leader_state.followers.contains(&peer_id)
} }
fn render_titlebar(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> Element<Self> { fn render_titlebar(&self, theme: &Theme, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
// TODO: There should be a better system in place for this // TODO: There should be a better system in place for this
// (https://github.com/zed-industries/zed/issues/1290) // (https://github.com/zed-industries/zed/issues/1290)
let is_fullscreen = cx.window_is_fullscreen(); let is_fullscreen = cx.window_is_fullscreen();
@ -2105,7 +2105,7 @@ impl Workspace {
}) })
.constrained() .constrained()
.with_height(theme.workspace.titlebar.height) .with_height(theme.workspace.titlebar.height)
.into_named_element("titlebar") .into_any_named("titlebar")
} }
fn active_item_path_changed(&mut self, cx: &mut ViewContext<Self>) { fn active_item_path_changed(&mut self, cx: &mut ViewContext<Self>) {
@ -2173,7 +2173,7 @@ impl Workspace {
fn render_disconnected_overlay( fn render_disconnected_overlay(
&self, &self,
cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Workspace>,
) -> Option<Element<Workspace>> { ) -> Option<AnyElement<Workspace>> {
if self.project.read(cx).is_read_only() { if self.project.read(cx).is_read_only() {
enum DisconnectedOverlay {} enum DisconnectedOverlay {}
Some( Some(
@ -2189,7 +2189,7 @@ impl Workspace {
}) })
.with_cursor_style(CursorStyle::Arrow) .with_cursor_style(CursorStyle::Arrow)
.capture_all() .capture_all()
.into_named_element("disconnected overlay"), .into_any_named("disconnected overlay"),
) )
} else { } else {
None None
@ -2200,7 +2200,7 @@ impl Workspace {
&self, &self,
theme: &theme::Workspace, theme: &theme::Workspace,
cx: &AppContext, cx: &AppContext,
) -> Option<Element<Workspace>> { ) -> Option<AnyElement<Workspace>> {
if self.notifications.is_empty() { if self.notifications.is_empty() {
None None
} else { } else {
@ -2218,7 +2218,7 @@ impl Workspace {
.aligned() .aligned()
.bottom() .bottom()
.right() .right()
.into_element(), .into_any(),
) )
} }
} }
@ -2826,7 +2826,7 @@ impl View for Workspace {
"Workspace" "Workspace"
} }
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 theme = cx.global::<Settings>().theme.clone();
Stack::new() Stack::new()
.with_child( .with_child(
@ -2923,7 +2923,7 @@ impl View for Workspace {
) )
.with_children(DragAndDrop::render(cx)) .with_children(DragAndDrop::render(cx))
.with_children(self.render_disconnected_overlay(cx)) .with_children(self.render_disconnected_overlay(cx))
.into_named_element("workspace") .into_any_named("workspace")
} }
fn focus_in(&mut self, view: AnyViewHandle, cx: &mut ViewContext<Self>) { fn focus_in(&mut self, view: AnyViewHandle, cx: &mut ViewContext<Self>) {