Move render_view into View::render_with

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra 2023-11-15 18:45:51 +01:00
parent 9ff238921f
commit c7b7f7dfd5
2 changed files with 30 additions and 38 deletions

View File

@ -39,12 +39,12 @@ use futures::FutureExt;
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use git::diff_hunk_to_display; use git::diff_hunk_to_display;
use gpui::{ use gpui::{
action, actions, div, point, prelude::*, px, relative, rems, render_view, size, uniform_list, action, actions, div, point, prelude::*, px, relative, rems, size, uniform_list, AnyElement,
AnyElement, AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, AppContext, AsyncWindowContext, BackgroundExecutor, Bounds, ClipboardItem, Component, Context,
Component, Context, EventEmitter, FocusHandle, FontFeatures, FontStyle, FontWeight, EventEmitter, FocusHandle, FontFeatures, FontStyle, FontWeight, HighlightStyle, Hsla,
HighlightStyle, Hsla, InputHandler, KeyContext, Model, MouseButton, ParentComponent, Pixels, InputHandler, KeyContext, Model, MouseButton, ParentComponent, Pixels, Render, Styled,
Render, Styled, Subscription, Task, TextStyle, UniformListScrollHandle, View, ViewContext, Subscription, Task, TextStyle, UniformListScrollHandle, View, ViewContext, VisualContext,
VisualContext, WeakView, WindowContext, WeakView, WindowContext,
}; };
use highlight_matching_bracket::refresh_matching_bracket_highlights; use highlight_matching_bracket::refresh_matching_bracket_highlights;
use hover_popover::{hide_hover, HoverState}; use hover_popover::{hide_hover, HoverState};
@ -7777,25 +7777,18 @@ impl Editor {
} }
div() div()
.pl(cx.anchor_x) .pl(cx.anchor_x)
.child(render_view( .child(rename_editor.render_with(EditorElement::new(
&rename_editor, &rename_editor,
EditorElement::new( EditorStyle {
&rename_editor, background: cx.theme().system().transparent,
EditorStyle { local_player: cx.editor_style.local_player,
background: cx.theme().system().transparent, text: text_style,
local_player: cx.editor_style.local_player, scrollbar_width: cx.editor_style.scrollbar_width,
text: text_style, syntax: cx.editor_style.syntax.clone(),
scrollbar_width: cx diagnostic_style:
.editor_style cx.editor_style.diagnostic_style.clone(),
.scrollbar_width, },
syntax: cx.editor_style.syntax.clone(), )))
diagnostic_style: cx
.editor_style
.diagnostic_style
.clone(),
},
),
))
.render() .render()
} }
}), }),

View File

@ -63,6 +63,16 @@ impl<V: 'static> View<V> {
pub fn read<'a>(&self, cx: &'a AppContext) -> &'a V { pub fn read<'a>(&self, cx: &'a AppContext) -> &'a V {
self.model.read(cx) self.model.read(cx)
} }
pub fn render_with<C>(&self, component: C) -> RenderViewWith<C, V>
where
C: 'static + Component<V>,
{
RenderViewWith {
view: self.clone(),
component: Some(component),
}
}
} }
impl<V> Clone for View<V> { impl<V> Clone for View<V> {
@ -281,12 +291,12 @@ where
} }
} }
pub struct RenderView<C, V> { pub struct RenderViewWith<C, V> {
view: View<V>, view: View<V>,
component: Option<C>, component: Option<C>,
} }
impl<C, ParentViewState, ViewState> Component<ParentViewState> for RenderView<C, ViewState> impl<C, ParentViewState, ViewState> Component<ParentViewState> for RenderViewWith<C, ViewState>
where where
C: 'static + Component<ViewState>, C: 'static + Component<ViewState>,
ParentViewState: 'static, ParentViewState: 'static,
@ -297,7 +307,7 @@ where
} }
} }
impl<C, ParentViewState, ViewState> Element<ParentViewState> for RenderView<C, ViewState> impl<C, ParentViewState, ViewState> Element<ParentViewState> for RenderViewWith<C, ViewState>
where where
C: 'static + Component<ViewState>, C: 'static + Component<ViewState>,
ParentViewState: 'static, ParentViewState: 'static,
@ -348,17 +358,6 @@ where
} }
} }
pub fn render_view<C, V>(view: &View<V>, component: C) -> RenderView<C, V>
where
C: 'static + Component<V>,
V: 'static,
{
RenderView {
view: view.clone(),
component: Some(component),
}
}
mod any_view { mod any_view {
use crate::{AnyElement, AnyView, BorrowWindow, LayoutId, Render, WindowContext}; use crate::{AnyElement, AnyView, BorrowWindow, LayoutId, Render, WindowContext};
use std::any::Any; use std::any::Any;