Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to return impl Element from render in Render trait #3820

Merged
merged 4 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions crates/activity_indicator2/src/activity_indicator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use auto_update::{AutoUpdateStatus, AutoUpdater, DismissErrorMessage};
use editor::Editor;
use futures::StreamExt;
use gpui::{
actions, svg, AppContext, CursorStyle, Div, EventEmitter, InteractiveElement as _, Model,
ParentElement as _, Render, SharedString, Stateful, StatefulInteractiveElement, Styled, View,
actions, svg, AppContext, CursorStyle, EventEmitter, InteractiveElement as _, Model,
ParentElement as _, Render, SharedString, StatefulInteractiveElement, Styled, View,
ViewContext, VisualContext as _,
};
use language::{LanguageRegistry, LanguageServerBinaryStatus};
Expand Down Expand Up @@ -304,9 +304,7 @@ impl ActivityIndicator {
impl EventEmitter<Event> for ActivityIndicator {}

impl Render for ActivityIndicator {
type Element = Stateful<Div>;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
let content = self.content_to_render(cx);

let mut result = h_stack()
Expand Down
18 changes: 6 additions & 12 deletions crates/assistant2/src/assistant_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ use fs::Fs;
use futures::StreamExt;
use gpui::{
canvas, div, point, relative, rems, uniform_list, Action, AnyElement, AppContext,
AsyncWindowContext, AvailableSpace, ClipboardItem, Context, Div, EventEmitter, FocusHandle,
Focusable, FocusableView, FontStyle, FontWeight, HighlightStyle, InteractiveElement,
IntoElement, Model, ModelContext, ParentElement, Pixels, PromptLevel, Render, SharedString,
AsyncWindowContext, AvailableSpace, ClipboardItem, Context, EventEmitter, FocusHandle,
FocusableView, FontStyle, FontWeight, HighlightStyle, InteractiveElement, IntoElement, Model,
ModelContext, ParentElement, Pixels, PromptLevel, Render, SharedString,
StatefulInteractiveElement, Styled, Subscription, Task, TextStyle, UniformListScrollHandle,
View, ViewContext, VisualContext, WeakModel, WeakView, WhiteSpace, WindowContext,
};
Expand Down Expand Up @@ -1101,9 +1101,7 @@ fn build_api_key_editor(cx: &mut ViewContext<AssistantPanel>) -> View<Editor> {
}

impl Render for AssistantPanel {
type Element = Focusable<Div>;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
if let Some(api_key_editor) = self.api_key_editor.clone() {
v_stack()
.on_action(cx.listener(AssistantPanel::save_credentials))
Expand Down Expand Up @@ -2513,9 +2511,7 @@ impl ConversationEditor {
impl EventEmitter<ConversationEditorEvent> for ConversationEditor {}

impl Render for ConversationEditor {
type Element = Div;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
div()
.key_context("ConversationEditor")
.capture_action(cx.listener(ConversationEditor::cancel_last_assist))
Expand Down Expand Up @@ -2618,9 +2614,7 @@ struct InlineAssistant {
impl EventEmitter<InlineAssistantEvent> for InlineAssistant {}

impl Render for InlineAssistant {
type Element = Div;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
let measurements = self.measurements.get();
h_stack()
.w_full()
Expand Down
6 changes: 2 additions & 4 deletions crates/auto_update2/src/update_notification.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use gpui::{
div, DismissEvent, Div, EventEmitter, InteractiveElement, ParentElement, Render,
div, DismissEvent, Element, EventEmitter, InteractiveElement, ParentElement, Render,
SemanticVersion, StatefulInteractiveElement, Styled, ViewContext,
};
use menu::Cancel;
Expand All @@ -13,9 +13,7 @@ pub struct UpdateNotification {
impl EventEmitter<DismissEvent> for UpdateNotification {}

impl Render for UpdateNotification {
type Element = Div;

fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut gpui::ViewContext<Self>) -> impl Element {
let app_name = cx.global::<ReleaseChannel>().display_name();

v_stack()
Expand Down
6 changes: 2 additions & 4 deletions crates/breadcrumbs2/src/breadcrumbs.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use editor::Editor;
use gpui::{
Div, Element, EventEmitter, IntoElement, ParentElement, Render, StyledText, Subscription,
Element, EventEmitter, IntoElement, ParentElement, Render, StyledText, Subscription,
ViewContext,
};
use itertools::Itertools;
Expand Down Expand Up @@ -30,9 +30,7 @@ impl Breadcrumbs {
impl EventEmitter<ToolbarItemEvent> for Breadcrumbs {}

impl Render for Breadcrumbs {
type Element = Div;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
let element = h_stack().text_ui();
let Some(active_item) = self.active_item.as_ref() else {
return element;
Expand Down
6 changes: 2 additions & 4 deletions crates/collab_ui2/src/channel_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,8 @@ impl ChannelView {
impl EventEmitter<EditorEvent> for ChannelView {}

impl Render for ChannelView {
type Element = AnyView;

fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
self.editor.clone().into()
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl Element {
self.editor.clone()
}
}

Expand Down
8 changes: 3 additions & 5 deletions crates/collab_ui2/src/chat_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use db::kvp::KEY_VALUE_STORE;
use editor::Editor;
use gpui::{
actions, div, list, prelude::*, px, serde_json, AnyElement, AppContext, AsyncWindowContext,
ClickEvent, Div, ElementId, EventEmitter, FocusableView, ListOffset, ListScrollEvent,
ListState, Model, Render, Subscription, Task, View, ViewContext, VisualContext, WeakView,
ClickEvent, ElementId, EventEmitter, FocusableView, ListOffset, ListScrollEvent, ListState,
Model, Render, Subscription, Task, View, ViewContext, VisualContext, WeakView,
};
use language::LanguageRegistry;
use menu::Confirm;
Expand Down Expand Up @@ -549,9 +549,7 @@ impl ChatPanel {
impl EventEmitter<Event> for ChatPanel {}

impl Render for ChatPanel {
type Element = Div;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
div()
.full()
.child(if self.client.user_id().is_some() {
Expand Down
6 changes: 2 additions & 4 deletions crates/collab_ui2/src/chat_panel/message_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use client::UserId;
use collections::HashMap;
use editor::{AnchorRangeExt, Editor};
use gpui::{
AnyView, AsyncWindowContext, FocusableView, Model, Render, SharedString, Task, View,
AsyncWindowContext, Element, FocusableView, Model, Render, SharedString, Task, View,
ViewContext, WeakView,
};
use language::{language_settings::SoftWrap, Buffer, BufferSnapshot, LanguageRegistry};
Expand Down Expand Up @@ -196,9 +196,7 @@ impl MessageEditor {
}

impl Render for MessageEditor {
type Element = AnyView;

fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl Element {
self.editor.to_any()
}
}
Expand Down
14 changes: 5 additions & 9 deletions crates/collab_ui2/src/collab_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{
actions, canvas, div, fill, list, overlay, point, prelude::*, px, serde_json, AnyElement,
AppContext, AsyncWindowContext, Bounds, ClipboardItem, DismissEvent, Div, EventEmitter,
FocusHandle, Focusable, FocusableView, InteractiveElement, IntoElement, ListOffset, ListState,
Model, MouseDownEvent, ParentElement, Pixels, Point, PromptLevel, Render, RenderOnce,
SharedString, Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView,
FocusHandle, FocusableView, InteractiveElement, IntoElement, ListOffset, ListState, Model,
MouseDownEvent, ParentElement, Pixels, Point, PromptLevel, Render, RenderOnce, SharedString,
Styled, Subscription, Task, View, ViewContext, VisualContext, WeakView,
};
use menu::{Cancel, Confirm, SelectNext, SelectPrev};
use project::{Fs, Project};
Expand Down Expand Up @@ -2263,9 +2263,7 @@ fn render_tree_branch(is_last: bool, cx: &mut WindowContext) -> impl IntoElement
}

impl Render for CollabPanel {
type Element = Focusable<Div>;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
v_stack()
.key_context("CollabPanel")
.on_action(cx.listener(CollabPanel::cancel))
Expand Down Expand Up @@ -2453,9 +2451,7 @@ struct DraggedChannelView {
}

impl Render for DraggedChannelView {
type Element = Div;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
let ui_font = ThemeSettings::get_global(cx).ui_font.family.clone();
h_stack()
.font(ui_font)
Expand Down
10 changes: 4 additions & 6 deletions crates/collab_ui2/src/collab_panel/channel_modal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use client::{
};
use fuzzy::{match_strings, StringMatchCandidate};
use gpui::{
actions, div, overlay, AppContext, ClipboardItem, DismissEvent, Div, EventEmitter,
FocusableView, Model, ParentElement, Render, Styled, Subscription, Task, View, ViewContext,
VisualContext, WeakView,
actions, div, overlay, AppContext, ClipboardItem, DismissEvent, EventEmitter, FocusableView,
Model, ParentElement, Render, Styled, Subscription, Task, View, ViewContext, VisualContext,
WeakView,
};
use picker::{Picker, PickerDelegate};
use std::sync::Arc;
Expand Down Expand Up @@ -142,9 +142,7 @@ impl FocusableView for ChannelModal {
}

impl Render for ChannelModal {
type Element = Div;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
let channel_store = self.channel_store.read(cx);
let Some(channel) = channel_store.channel_for_id(self.channel_id) else {
return div();
Expand Down
8 changes: 3 additions & 5 deletions crates/collab_ui2/src/collab_panel/contact_finder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use client::{ContactRequestStatus, User, UserStore};
use gpui::{
AppContext, DismissEvent, Div, EventEmitter, FocusHandle, FocusableView, Model,
ParentElement as _, Render, Styled, Task, View, ViewContext, VisualContext, WeakView,
AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView, Model, ParentElement as _,
Render, Styled, Task, View, ViewContext, VisualContext, WeakView,
};
use picker::{Picker, PickerDelegate};
use std::sync::Arc;
Expand Down Expand Up @@ -35,7 +35,7 @@ impl ContactFinder {
}

impl Render for ContactFinder {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
v_stack()
.elevation_3(cx)
.child(
Expand All @@ -51,8 +51,6 @@ impl Render for ContactFinder {
.child(self.picker.clone())
.w(rems(34.))
}

type Element = Div;
}

pub struct ContactFinderDelegate {
Expand Down
8 changes: 3 additions & 5 deletions crates/collab_ui2/src/collab_titlebar_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use auto_update::AutoUpdateStatus;
use call::{ActiveCall, ParticipantLocation, Room};
use client::{proto::PeerId, Client, ParticipantIndex, User, UserStore};
use gpui::{
actions, canvas, div, point, px, rems, Action, AnyElement, AppContext, Div, Element, Hsla,
InteractiveElement, IntoElement, Model, ParentElement, Path, Render, Stateful,
actions, canvas, div, point, px, rems, Action, AnyElement, AppContext, Element, Hsla,
InteractiveElement, IntoElement, Model, ParentElement, Path, Render,
StatefulInteractiveElement, Styled, Subscription, View, ViewContext, VisualContext, WeakView,
WindowBounds,
};
Expand Down Expand Up @@ -56,9 +56,7 @@ pub struct CollabTitlebarItem {
}

impl Render for CollabTitlebarItem {
type Element = Stateful<Div>;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
let room = ActiveCall::global(cx).read(cx).room().cloned();
let current_user = self.user_store.read(cx).current_user();
let client = self.client.clone();
Expand Down
12 changes: 4 additions & 8 deletions crates/collab_ui2/src/notification_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use db::kvp::KEY_VALUE_STORE;
use futures::StreamExt;
use gpui::{
actions, div, img, list, px, serde_json, AnyElement, AppContext, AsyncWindowContext,
CursorStyle, DismissEvent, Div, Element, EventEmitter, FocusHandle, FocusableView,
CursorStyle, DismissEvent, Element, EventEmitter, FocusHandle, FocusableView,
InteractiveElement, IntoElement, ListAlignment, ListScrollEvent, ListState, Model,
ParentElement, Render, Stateful, StatefulInteractiveElement, Styled, Task, View, ViewContext,
ParentElement, Render, StatefulInteractiveElement, Styled, Task, View, ViewContext,
VisualContext, WeakView, WindowContext,
};
use notifications::{NotificationEntry, NotificationEvent, NotificationStore};
Expand Down Expand Up @@ -540,9 +540,7 @@ impl NotificationPanel {
}

impl Render for NotificationPanel {
type Element = Div;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Div {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
v_stack()
.size_full()
.child(
Expand Down Expand Up @@ -706,9 +704,7 @@ impl NotificationToast {
}

impl Render for NotificationToast {
type Element = Stateful<Div>;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
let user = self.actor.clone();

h_stack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::notification_window_options;
use call::{ActiveCall, IncomingCall};
use futures::StreamExt;
use gpui::{
img, px, AppContext, Div, ParentElement, Render, RenderOnce, Styled, ViewContext,
img, px, AppContext, ParentElement, Render, RenderOnce, Styled, ViewContext,
VisualContext as _, WindowHandle,
};
use settings::Settings;
Expand Down Expand Up @@ -117,9 +117,7 @@ impl IncomingCallNotification {
}

impl Render for IncomingCallNotification {
type Element = Div;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
// TODO: Is there a better place for us to initialize the font?
let (ui_font, ui_font_size) = {
let theme_settings = ThemeSettings::get_global(cx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use crate::notification_window_options;
use call::{room, ActiveCall};
use client::User;
use collections::HashMap;
use gpui::{
img, px, AppContext, Div, ParentElement, Render, Size, Styled, ViewContext, VisualContext,
};
use gpui::{img, px, AppContext, ParentElement, Render, Size, Styled, ViewContext, VisualContext};
use settings::Settings;
use std::sync::{Arc, Weak};
use theme::ThemeSettings;
Expand Down Expand Up @@ -120,9 +118,7 @@ impl ProjectSharedNotification {
}

impl Render for ProjectSharedNotification {
type Element = Div;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
// TODO: Is there a better place for us to initialize the font?
let (ui_font, ui_font_size) = {
let theme_settings = ThemeSettings::get_global(cx);
Expand Down
6 changes: 2 additions & 4 deletions crates/command_palette2/src/command_palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
use collections::{CommandPaletteFilter, HashMap};
use fuzzy::{StringMatch, StringMatchCandidate};
use gpui::{
actions, Action, AppContext, DismissEvent, Div, EventEmitter, FocusHandle, FocusableView,
actions, Action, AppContext, DismissEvent, EventEmitter, FocusHandle, FocusableView,
ParentElement, Render, Styled, View, ViewContext, VisualContext, WeakView,
};
use picker::{Picker, PickerDelegate};
Expand Down Expand Up @@ -83,9 +83,7 @@ impl FocusableView for CommandPalette {
}

impl Render for CommandPalette {
type Element = Div;

fn render(&mut self, _cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, _cx: &mut ViewContext<Self>) -> impl Element {
v_stack().w(rems(34.)).child(self.picker.clone())
}
}
Expand Down
10 changes: 4 additions & 6 deletions crates/copilot2/src/sign_in.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{request::PromptUserDeviceFlow, Copilot, Status};
use gpui::{
div, size, AppContext, Bounds, ClipboardItem, Div, Element, GlobalPixels, InteractiveElement,
IntoElement, ParentElement, Point, Render, Stateful, Styled, ViewContext, VisualContext,
WindowBounds, WindowHandle, WindowKind, WindowOptions,
div, size, AppContext, Bounds, ClipboardItem, Element, GlobalPixels, InteractiveElement,
IntoElement, ParentElement, Point, Render, Styled, ViewContext, VisualContext, WindowBounds,
WindowHandle, WindowKind, WindowOptions,
};
use theme::ActiveTheme;
use ui::{prelude::*, Button, Icon, IconElement, Label};
Expand Down Expand Up @@ -181,9 +181,7 @@ impl CopilotCodeVerification {
}

impl Render for CopilotCodeVerification {
type Element = Stateful<Div>;

fn render(&mut self, cx: &mut ViewContext<Self>) -> Self::Element {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element {
let prompt = match &self.status {
Status::SigningIn {
prompt: Some(prompt),
Expand Down
Loading