Use existing AnyElement::draw

This commit is contained in:
Antonio Scandurra 2023-12-21 15:32:05 +01:00
parent 5e4557ed16
commit 01947ed730
3 changed files with 13 additions and 23 deletions

View file

@ -30,9 +30,9 @@ use fs::Fs;
use futures::StreamExt; use futures::StreamExt;
use gpui::{ use gpui::{
canvas, div, point, relative, rems, uniform_list, Action, AnyElement, AppContext, canvas, div, point, relative, rems, uniform_list, Action, AnyElement, AppContext,
AsyncWindowContext, ClipboardItem, Context, Div, EventEmitter, FocusHandle, Focusable, AsyncWindowContext, AvailableSpace, ClipboardItem, Context, Div, EventEmitter, FocusHandle,
FocusableView, FontStyle, FontWeight, HighlightStyle, InteractiveElement, IntoElement, Model, Focusable, FocusableView, FontStyle, FontWeight, HighlightStyle, InteractiveElement,
ModelContext, ParentElement, Pixels, PromptLevel, Render, SharedString, IntoElement, Model, ModelContext, ParentElement, Pixels, PromptLevel, Render, SharedString,
StatefulInteractiveElement, Styled, Subscription, Task, TextStyle, UniformListScrollHandle, StatefulInteractiveElement, Styled, Subscription, Task, TextStyle, UniformListScrollHandle,
View, ViewContext, VisualContext, WeakModel, WeakView, WhiteSpace, WindowContext, View, ViewContext, VisualContext, WeakModel, WeakView, WhiteSpace, WindowContext,
}; };
@ -1199,9 +1199,10 @@ impl Render for AssistantPanel {
}, },
) )
.track_scroll(scroll_handle) .track_scroll(scroll_handle)
.into_any_element()
.draw( .draw(
bounds.origin, bounds.origin,
bounds.size, bounds.size.map(AvailableSpace::Definite),
cx, cx,
); );
}) })

View file

@ -23,17 +23,6 @@ pub trait IntoElement: Sized {
self.into_element().into_any() self.into_element().into_any()
} }
fn draw<T>(self, origin: Point<Pixels>, available_space: Size<T>, cx: &mut WindowContext)
where
T: Clone + Default + Debug + Into<AvailableSpace>,
{
let element = DrawableElement {
element: Some(self.into_element()),
phase: ElementDrawPhase::Start,
};
DrawableElement::draw(element, origin, available_space.map(Into::into), cx);
}
fn draw_and_update_state<T, R>( fn draw_and_update_state<T, R>(
self, self,
origin: Point<Pixels>, origin: Point<Pixels>,

View file

@ -1,11 +1,11 @@
use editor::{Cursor, HighlightedRange, HighlightedRangeLine}; use editor::{Cursor, HighlightedRange, HighlightedRangeLine};
use gpui::{ use gpui::{
black, div, fill, point, px, red, relative, AnyElement, AsyncWindowContext, BorrowWindow, black, div, fill, point, px, red, relative, AnyElement, AsyncWindowContext, AvailableSpace,
Bounds, DispatchPhase, Element, ElementId, ExternalPaths, FocusHandle, Font, FontStyle, BorrowWindow, Bounds, DispatchPhase, Element, ElementId, ExternalPaths, FocusHandle, Font,
FontWeight, HighlightStyle, Hsla, InteractiveElement, InteractiveElementState, Interactivity, FontStyle, FontWeight, HighlightStyle, Hsla, InteractiveElement, InteractiveElementState,
IntoElement, LayoutId, Model, ModelContext, ModifiersChangedEvent, MouseButton, Pixels, Interactivity, IntoElement, LayoutId, Model, ModelContext, ModifiersChangedEvent, MouseButton,
PlatformInputHandler, Point, Rgba, ShapedLine, StatefulInteractiveElement, Styled, TextRun, Pixels, PlatformInputHandler, Point, Rgba, ShapedLine, StatefulInteractiveElement, Styled,
TextStyle, TextSystem, UnderlineStyle, WhiteSpace, WindowContext, TextRun, TextStyle, TextSystem, UnderlineStyle, WhiteSpace, WindowContext,
}; };
use itertools::Itertools; use itertools::Itertools;
use language::CursorShape; use language::CursorShape;
@ -854,8 +854,8 @@ impl Element for TerminalElement {
}); });
} }
if let Some(element) = layout.hyperlink_tooltip.take() { if let Some(mut element) = layout.hyperlink_tooltip.take() {
element.draw(origin, bounds.size, cx) element.draw(origin, bounds.size.map(AvailableSpace::Definite), cx)
} }
}); });
} }