mirror of
https://github.com/zed-industries/zed.git
synced 2026-11-19 06:59:22 +01:00
gpui: Remove hand-written IntoElement impls for elements (#64864)
Custom elements previously had to hand-write an `IntoElement` impl that just returned `self`. Replace that boilerplate with a blanket `impl<T: Element> IntoElement for T`, and relax the `Element` supertrait bound from `IntoElement` to `Sized`. Any type implementing `Element` is now usable as a child element without extra code. `AnyElement` overrides `into_any` to return `self`, so converting one does not nest a boxed element inside another. To make that easy to notice, the private `AnyElement::new` is renamed to `new_please_call_into_any_to_avoid_double_box`. Remove the now-redundant `IntoElement` impls across gpui and its consumers. ## Testing Manually test your changes; report results, mention platforms if relevant. How can reviewers test this easily? Include setup and steps. ## Self-review - [x] I've reviewed my diff for quality, security, reliability, and performance. - [ ] UI changes follow the [checklist](https://zed.dev/docs/development/ui-checklist). - [ ] Tests cover the new or changed behavior. Release Notes: - [GPUI] (breaking) Added blanket impl for `IntoElement` trait with `ElementType = Self` when `Self` implements `Element`. --------- Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -10250,14 +10250,6 @@ impl ScrollbarLayoutInformation {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for EditorElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EditorLayout {
|
||||
position_map: Rc<PositionMap>,
|
||||
hitbox: Hitbox,
|
||||
|
||||
@@ -261,14 +261,6 @@ struct SplitBufferHeadersPrepaintState {
|
||||
non_sticky_headers: Vec<BufferHeaderLayout>,
|
||||
}
|
||||
|
||||
impl IntoElement for SplitBufferHeadersElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for SplitBufferHeadersElement {
|
||||
type RequestLayoutState = ();
|
||||
type PrepaintState = SplitBufferHeadersPrepaintState;
|
||||
|
||||
@@ -470,14 +470,6 @@ struct PrepaintState {
|
||||
selection: Option<PaintQuad>,
|
||||
}
|
||||
|
||||
impl IntoElement for TextElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for TextElement {
|
||||
type RequestLayoutState = ();
|
||||
type PrepaintState = PrepaintState;
|
||||
|
||||
@@ -349,14 +349,6 @@ struct EditorTextPrepaint {
|
||||
cursor: Option<PaintQuad>,
|
||||
}
|
||||
|
||||
impl IntoElement for EditorText {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for EditorText {
|
||||
type RequestLayoutState = ();
|
||||
type PrepaintState = EditorTextPrepaint;
|
||||
|
||||
+17
-20
@@ -49,7 +49,7 @@ use std::{
|
||||
/// Elements form a tree and are laid out according to web-based layout rules, as implemented by Taffy.
|
||||
/// You can create custom elements by implementing this trait, see the module-level documentation
|
||||
/// for more details.
|
||||
pub trait Element: 'static + IntoElement {
|
||||
pub trait Element: 'static + Sized {
|
||||
/// The type of state returned from [`Element::request_layout`]. A mutable reference to this state is subsequently
|
||||
/// provided to [`Element::prepaint`] and [`Element::paint`].
|
||||
type RequestLayoutState: 'static;
|
||||
@@ -138,7 +138,15 @@ pub trait Element: 'static + IntoElement {
|
||||
|
||||
/// Convert this element into a dynamically-typed [`AnyElement`].
|
||||
fn into_any(self) -> AnyElement {
|
||||
AnyElement::new(self)
|
||||
AnyElement::new_please_call_into_any_to_avoid_double_box(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Element> IntoElement for T {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -650,7 +658,12 @@ where
|
||||
pub struct AnyElement(ArenaBox<dyn ElementObject>);
|
||||
|
||||
impl AnyElement {
|
||||
pub(crate) fn new<E>(element: E) -> Self
|
||||
/// Boxes `element` into an `AnyElement`, erasing its concrete type.
|
||||
///
|
||||
/// This always allocates and always adds a level of boxing, even when `element` is
|
||||
/// already an [`AnyElement`], which would nest one `AnyElement` inside another. Call
|
||||
/// [`Element::into_any`] instead; it skips the wrapper for `AnyElement` itself.
|
||||
fn new_please_call_into_any_to_avoid_double_box<E>(element: E) -> Self
|
||||
where
|
||||
E: 'static + Element,
|
||||
E::RequestLayoutState: Any,
|
||||
@@ -772,16 +785,8 @@ impl Element for AnyElement {
|
||||
) {
|
||||
self.paint(window, cx);
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for AnyElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
|
||||
fn into_any_element(self) -> AnyElement {
|
||||
fn into_any(self) -> AnyElement {
|
||||
self
|
||||
}
|
||||
}
|
||||
@@ -789,14 +794,6 @@ impl IntoElement for AnyElement {
|
||||
/// The empty element, which renders nothing.
|
||||
pub struct Empty;
|
||||
|
||||
impl IntoElement for Empty {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for Empty {
|
||||
type RequestLayoutState = ();
|
||||
type PrepaintState = ();
|
||||
|
||||
@@ -4,8 +4,8 @@ use smallvec::SmallVec;
|
||||
|
||||
use crate::{
|
||||
Anchor, AnyElement, App, Axis, Bounds, Display, Edges, Element, GlobalElementId,
|
||||
InspectorElementId, IntoElement, LayoutId, ParentElement, Pixels, Point, Position, Size, Style,
|
||||
Window, point, px,
|
||||
InspectorElementId, LayoutId, ParentElement, Pixels, Point, Position, Size, Style, Window,
|
||||
point, px,
|
||||
};
|
||||
|
||||
/// The state that the anchored element element uses to track its children.
|
||||
@@ -307,14 +307,6 @@ impl Element for Anchored {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for Anchored {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Which side of a box `anchor` is on along `axis`. `Less` is left or top, `Equal` is the
|
||||
/// center, and `Greater` is right or bottom.
|
||||
fn side_along(anchor: Anchor, axis: Axis) -> Ordering {
|
||||
|
||||
@@ -196,14 +196,6 @@ impl<E> SpringAnimationElement<E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: IntoElement + 'static> IntoElement for SpringAnimationElement<E> {
|
||||
type Element = SpringAnimationElement<E>;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: ParentElement> ParentElement for AnimationElement<E> {
|
||||
fn extend(&mut self, elements: impl IntoIterator<Item = AnyElement>) {
|
||||
let Some(element) = &mut self.element else {
|
||||
@@ -223,14 +215,6 @@ impl<E> AnimationElement<E> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: IntoElement + 'static> IntoElement for AnimationElement<E> {
|
||||
type Element = AnimationElement<E>;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
struct AnimationState {
|
||||
start: Instant,
|
||||
animation_ix: usize,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use refineable::Refineable as _;
|
||||
|
||||
use crate::{
|
||||
App, Bounds, Element, ElementId, GlobalElementId, InspectorElementId, IntoElement, Pixels,
|
||||
Style, StyleRefinement, Styled, Window,
|
||||
App, Bounds, Element, ElementId, GlobalElementId, InspectorElementId, Pixels, Style,
|
||||
StyleRefinement, Styled, Window,
|
||||
};
|
||||
|
||||
/// Construct a canvas element with the given paint callback.
|
||||
@@ -26,14 +26,6 @@ pub struct Canvas<T> {
|
||||
style: StyleRefinement,
|
||||
}
|
||||
|
||||
impl<T: 'static> IntoElement for Canvas<T> {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static> Element for Canvas<T> {
|
||||
type RequestLayoutState = Style;
|
||||
type PrepaintState = Option<T>;
|
||||
|
||||
@@ -111,14 +111,6 @@ impl Element for ContainerQuery {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for ContainerQuery {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Styled for ContainerQuery {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
|
||||
@@ -78,14 +78,6 @@ impl Element for Deferred {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for Deferred {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Deferred {
|
||||
/// Sets a priority for the element. A higher priority conceptually means painting the element
|
||||
/// on top of deferred draws with a lower priority (i.e. closer to the viewer).
|
||||
|
||||
@@ -19,12 +19,12 @@ use crate::{
|
||||
Action, AnyDrag, AnyElement, AnyTooltip, AnyView, App, BackGestureEvent, Bounds, ClickEvent,
|
||||
DispatchPhase, Display, Element, ElementId, Entity, EntityId, ExternalDragPayload,
|
||||
ExternalDragPayloadSource, FileDropEvent, FocusHandle, Global, GlobalElementId, Hitbox,
|
||||
HitboxBehavior, HitboxId, InspectorElementId, IntoElement, IsZero, KeyContext, KeyDownEvent,
|
||||
KeyUpEvent, KeyboardButton, KeyboardClickEvent, LayoutId, LongPressEvent,
|
||||
ModifiersChangedEvent, MouseButton, MouseClickEvent, MouseDownEvent, MouseExitEvent,
|
||||
MouseMoveEvent, MousePressureEvent, MouseUpEvent, OngoingScroll, Overflow, ParentElement,
|
||||
PinchEvent, Pixels, Point, Render, ScrollEvent, SharedString, Size, Style, StyleRefinement,
|
||||
Styled, Task, TooltipId, TouchPhase, Visibility, Window, WindowControlArea, point, px, size,
|
||||
HitboxBehavior, HitboxId, InspectorElementId, IsZero, KeyContext, KeyDownEvent, KeyUpEvent,
|
||||
KeyboardButton, KeyboardClickEvent, LayoutId, LongPressEvent, ModifiersChangedEvent,
|
||||
MouseButton, MouseClickEvent, MouseDownEvent, MouseExitEvent, MouseMoveEvent,
|
||||
MousePressureEvent, MouseUpEvent, OngoingScroll, Overflow, ParentElement, PinchEvent, Pixels,
|
||||
Point, Render, ScrollEvent, SharedString, Size, Style, StyleRefinement, Styled, Task,
|
||||
TooltipId, TouchPhase, Visibility, Window, WindowControlArea, point, px, size,
|
||||
};
|
||||
use collections::HashMap;
|
||||
use gpui_util::ResultExt;
|
||||
@@ -2196,14 +2196,6 @@ impl Element for Div {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for Div {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct AriaProperties {
|
||||
pub(crate) author_id: Option<SharedString>,
|
||||
@@ -4282,17 +4274,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> IntoElement for Stateful<E>
|
||||
where
|
||||
E: Element,
|
||||
{
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> ParentElement for Stateful<E>
|
||||
where
|
||||
E: ParentElement,
|
||||
@@ -4555,8 +4536,9 @@ impl ScrollHandle {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
AnyWindowHandle, AppContext as _, Context, GestureTuning, InputEvent, Keystroke,
|
||||
MouseMoveEvent, TestAppContext, TouchEvent, TouchId, canvas, util::FluentBuilder as _,
|
||||
AnyWindowHandle, AppContext as _, Context, GestureTuning, InputEvent, IntoElement,
|
||||
Keystroke, MouseMoveEvent, TestAppContext, TouchEvent, TouchId, canvas,
|
||||
util::FluentBuilder as _,
|
||||
};
|
||||
use std::{cell::Cell, rc::Weak};
|
||||
|
||||
@@ -4900,14 +4882,6 @@ mod tests {
|
||||
captured_active_tooltip: CapturedActiveTooltip,
|
||||
}
|
||||
|
||||
impl IntoElement for TooltipCaptureElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for TooltipCaptureElement {
|
||||
type RequestLayoutState = ();
|
||||
type PrepaintState = ();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
AnyElement, AnyEntity, App, AppContext, Asset, AssetLogger, Bounds, Element, ElementId, Entity,
|
||||
GlobalElementId, ImageAssetLoader, ImageCacheError, InspectorElementId, IntoElement, LayoutId,
|
||||
GlobalElementId, ImageAssetLoader, ImageCacheError, InspectorElementId, LayoutId,
|
||||
ParentElement, Pixels, RenderImage, Resource, Style, StyleRefinement, Styled, Window, hash,
|
||||
};
|
||||
|
||||
@@ -86,14 +86,6 @@ impl Styled for ImageCacheElement {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for ImageCacheElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for ImageCacheElement {
|
||||
type RequestLayoutState = SmallVec<[LayoutId; 4]>;
|
||||
type PrepaintState = ();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
AnyElement, AnyImageCache, App, Asset, AssetLogger, Bounds, DefiniteLength, Element, ElementId,
|
||||
Entity, GlobalElementId, Hitbox, Image, ImageCache, InspectorElementId, InteractiveElement,
|
||||
Interactivity, IntoElement, LayoutId, Length, ObjectFit, Pixels, RenderImage, Resource,
|
||||
SharedString, SharedUri, StyleRefinement, Styled, Task, Window, decode_gif_image,
|
||||
decode_static_image, decode_webp_image, px,
|
||||
Interactivity, LayoutId, Length, ObjectFit, Pixels, RenderImage, Resource, SharedString,
|
||||
SharedUri, StyleRefinement, Styled, Task, Window, decode_gif_image, decode_static_image,
|
||||
decode_webp_image, px,
|
||||
};
|
||||
use anyhow::Result;
|
||||
|
||||
@@ -518,14 +518,6 @@ impl InteractiveElement for Img {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for Img {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl StatefulInteractiveElement for Img {}
|
||||
|
||||
impl ImageSource {
|
||||
@@ -736,7 +728,7 @@ impl From<image::ImageError> for ImageCacheError {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{ParentElement as _, TestAppContext, canvas, div, point, px, size};
|
||||
use crate::{IntoElement, ParentElement as _, TestAppContext, canvas, div, point, px, size};
|
||||
use image::{Frame, ImageBuffer, Rgba};
|
||||
use smallvec::SmallVec;
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
use crate::{
|
||||
Along as _, AnyElement, App, AvailableSpace, Axis, Bounds, ContentMask, DispatchPhase, Edges,
|
||||
Element, EntityId, FocusHandle, GlobalElementId, Hitbox, HitboxBehavior, InspectorElementId,
|
||||
IntoElement, Overflow, Pixels, Point, ScrollDelta, ScrollEvent, Size, Style, StyleRefinement,
|
||||
Styled, Window, point, px, size,
|
||||
Overflow, Pixels, Point, ScrollDelta, ScrollEvent, Size, Style, StyleRefinement, Styled,
|
||||
Window, point, px, size,
|
||||
};
|
||||
use collections::VecDeque;
|
||||
use refineable::Refineable as _;
|
||||
@@ -1658,14 +1658,6 @@ fn content_insets(style: &Style, size: Size<Pixels>, rem_size: Pixels) -> Edges<
|
||||
padding + border
|
||||
}
|
||||
|
||||
impl IntoElement for List {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Styled for List {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
App, Bounds, Element, ElementId, GlobalElementId, InspectorElementId, IntoElement, LayoutId,
|
||||
ObjectFit, Pixels, Style, StyleRefinement, Styled, Window,
|
||||
App, Bounds, Element, ElementId, GlobalElementId, InspectorElementId, LayoutId, ObjectFit,
|
||||
Pixels, Style, StyleRefinement, Styled, Window,
|
||||
};
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
use objc2_core_foundation::CFRetained;
|
||||
@@ -119,14 +119,6 @@ impl Element for Surface {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for Surface {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Styled for Surface {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.style
|
||||
|
||||
@@ -7,8 +7,8 @@ use std::{
|
||||
|
||||
use crate::{
|
||||
App, Asset, Bounds, Element, GlobalElementId, Hitbox, InspectorElementId, InteractiveElement,
|
||||
Interactivity, IntoElement, LayoutId, Pixels, Point, Radians, SharedString, Size,
|
||||
StyleRefinement, Styled, TransformationMatrix, Window, point, px, radians, size,
|
||||
Interactivity, LayoutId, Pixels, Point, Radians, SharedString, Size, StyleRefinement, Styled,
|
||||
TransformationMatrix, Window, point, px, radians, size,
|
||||
};
|
||||
use gpui_util::ResultExt;
|
||||
|
||||
@@ -189,14 +189,6 @@ impl Element for Svg {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for Svg {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Styled for Svg {
|
||||
fn style(&mut self) -> &mut StyleRefinement {
|
||||
&mut self.interactivity.base_style
|
||||
|
||||
@@ -166,14 +166,6 @@ macro_rules! text {
|
||||
}};
|
||||
}
|
||||
|
||||
impl IntoElement for Text {
|
||||
type Element = Self;
|
||||
#[inline]
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for Text {
|
||||
type RequestLayoutState = TextLayout;
|
||||
type PrepaintState = ();
|
||||
@@ -301,14 +293,6 @@ impl Element for &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for &'static str {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for String {
|
||||
type Element = SharedString;
|
||||
|
||||
@@ -375,14 +359,6 @@ impl Element for SharedString {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for SharedString {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Renders text with runs of different styles.
|
||||
///
|
||||
/// Callers are responsible for setting the correct style for each run.
|
||||
@@ -601,14 +577,6 @@ impl Element for StyledText {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for StyledText {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// The Layout for TextElement. This can be used to map indices to pixels and vice versa.
|
||||
#[derive(Default, Clone)]
|
||||
pub struct TextLayout(Rc<RefCell<Option<TextLayoutInner>>>);
|
||||
@@ -1308,14 +1276,6 @@ impl Element for InteractiveText {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for InteractiveText {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -570,14 +570,6 @@ impl Element for UniformList {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for UniformList {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// A decoration for a [`UniformList`]. This can be used for various things,
|
||||
/// such as rendering indent guides, or other visual effects.
|
||||
pub trait UniformListDecoration {
|
||||
|
||||
@@ -736,14 +736,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for PendingTextInputTestView {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl InputHandler for PendingTextInputTestView {
|
||||
fn accepts_text_input(&mut self, _: &mut Window, _: &mut App) -> bool {
|
||||
self.accepts_text_input.get()
|
||||
@@ -1214,14 +1206,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for CustomElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl InputHandler for CustomElement {
|
||||
fn selected_text_range(
|
||||
&mut self,
|
||||
|
||||
@@ -312,14 +312,6 @@ impl<V: View> ViewElement<V> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> IntoElement for ViewElement<V> {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
struct ViewElementState {
|
||||
prepaint_range: Range<PrepaintStateIndex>,
|
||||
paint_range: Range<PaintIndex>,
|
||||
|
||||
@@ -367,14 +367,6 @@ impl ImageContentElement {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for ImageContentElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for ImageContentElement {
|
||||
type RequestLayoutState = ();
|
||||
type PrepaintState = Option<(AnyElement, bool)>;
|
||||
|
||||
@@ -3671,14 +3671,6 @@ fn render_copy_code_block_button(
|
||||
})
|
||||
}
|
||||
|
||||
impl IntoElement for MarkdownElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub enum AnyDiv {
|
||||
Div(Div),
|
||||
Stateful(Stateful<Div>),
|
||||
@@ -4468,14 +4460,6 @@ impl Element for RenderedLineElement {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for RenderedLineElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
struct RenderedLine {
|
||||
layout: TextLayout,
|
||||
visible_bounds: Cell<Option<Bounds<Pixels>>>,
|
||||
@@ -8637,14 +8621,6 @@ mod tests {
|
||||
rendered_text: Rc<RefCell<Option<RenderedText>>>,
|
||||
}
|
||||
|
||||
impl IntoElement for CapturingMarkdownElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for CapturingMarkdownElement {
|
||||
type RequestLayoutState = RenderedMarkdown;
|
||||
type PrepaintState = Hitbox;
|
||||
|
||||
@@ -1753,14 +1753,6 @@ impl Element for TerminalElement {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for TerminalElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
struct TerminalInputHandler {
|
||||
terminal_view: Entity<TerminalView>,
|
||||
workspace: WeakEntity<Workspace>,
|
||||
|
||||
@@ -432,14 +432,6 @@ impl Element for IndentGuidesElement {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for IndentGuidesElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn compute_indent_guides(
|
||||
indents: &[usize],
|
||||
offset: usize,
|
||||
|
||||
@@ -503,14 +503,6 @@ impl<M: ManagedView> Element for PopoverMenu<M> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: ManagedView> IntoElement for PopoverMenu<M> {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use gpui::{EventEmitter, FocusHandle, Focusable, TestAppContext, VisualTestContext};
|
||||
|
||||
@@ -299,11 +299,3 @@ impl<M: ManagedView> Element for RightClickMenu<M> {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<M: ManagedView> IntoElement for RightClickMenu<M> {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ use std::{any::Any, fmt::Debug, ops::Not, time::Duration};
|
||||
use web_time::Instant;
|
||||
|
||||
use gpui::{
|
||||
Along, Anchor, AnyElement, App, AppContext as _, Axis as ScrollbarAxis, BorderStyle, Bounds,
|
||||
ContentMask, Context, Corners, CursorStyle, DispatchPhase, Div, Edges, Element, ElementId,
|
||||
Entity, EntityId, GlobalElementId, Hitbox, HitboxBehavior, Hsla, InteractiveElement,
|
||||
IntoElement, IsZero, LayoutId, ListState, MouseButton, MouseDownEvent, MouseMoveEvent,
|
||||
MouseUpEvent, ParentElement, Pixels, Point, Position, Render, ScrollEvent, ScrollHandle, Size,
|
||||
Stateful, StatefulInteractiveElement, Style, StyleRefinement, Styled, Subscription, Task,
|
||||
Along, Anchor, App, AppContext as _, Axis as ScrollbarAxis, BorderStyle, Bounds, ContentMask,
|
||||
Context, Corners, CursorStyle, DispatchPhase, Div, Edges, Element, ElementId, Entity, EntityId,
|
||||
GlobalElementId, Hitbox, HitboxBehavior, Hsla, InteractiveElement, IntoElement, IsZero,
|
||||
LayoutId, ListState, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement,
|
||||
Pixels, Point, Position, Render, ScrollEvent, ScrollHandle, Size, Stateful,
|
||||
StatefulInteractiveElement, Style, StyleRefinement, Styled, Subscription, Task,
|
||||
UniformListDecoration, UniformListScrollHandle, Window, ease_in_out, fill,
|
||||
prelude::FluentBuilder as _, px, quad, relative, size,
|
||||
};
|
||||
@@ -1011,11 +1011,6 @@ impl ThumbState {
|
||||
}
|
||||
|
||||
impl ScrollableHandle for UniformListScrollHandle {
|
||||
#[inline(never)]
|
||||
fn into_scrollbar_element(element: ScrollbarElement<Self>) -> AnyElement {
|
||||
element.into_any()
|
||||
}
|
||||
|
||||
fn max_offset(&self) -> Point<Pixels> {
|
||||
self.0.borrow().base_handle.max_offset()
|
||||
}
|
||||
@@ -1034,11 +1029,6 @@ impl ScrollableHandle for UniformListScrollHandle {
|
||||
}
|
||||
|
||||
impl ScrollableHandle for ListState {
|
||||
#[inline(never)]
|
||||
fn into_scrollbar_element(element: ScrollbarElement<Self>) -> AnyElement {
|
||||
element.into_any()
|
||||
}
|
||||
|
||||
fn max_offset(&self) -> Point<Pixels> {
|
||||
self.max_offset_for_scrollbar()
|
||||
}
|
||||
@@ -1065,11 +1055,6 @@ impl ScrollableHandle for ListState {
|
||||
}
|
||||
|
||||
impl ScrollableHandle for ScrollHandle {
|
||||
#[inline(never)]
|
||||
fn into_scrollbar_element(element: ScrollbarElement<Self>) -> AnyElement {
|
||||
element.into_any()
|
||||
}
|
||||
|
||||
fn max_offset(&self) -> Point<Pixels> {
|
||||
self.max_offset()
|
||||
}
|
||||
@@ -1088,10 +1073,6 @@ impl ScrollableHandle for ScrollHandle {
|
||||
}
|
||||
|
||||
pub trait ScrollableHandle: 'static + Any + Sized + Clone {
|
||||
fn into_scrollbar_element(element: ScrollbarElement<Self>) -> AnyElement {
|
||||
element.into_any()
|
||||
}
|
||||
|
||||
fn max_offset(&self) -> Point<Pixels>;
|
||||
fn set_offset(&self, point: Point<Pixels>);
|
||||
fn offset(&self) -> Point<Pixels>;
|
||||
@@ -1751,18 +1732,6 @@ impl<T: ScrollableHandle> Element for ScrollbarElement<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ScrollableHandle> IntoElement for ScrollbarElement<T> {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
|
||||
fn into_any_element(self) -> AnyElement {
|
||||
T::into_scrollbar_element(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -66,14 +66,6 @@ struct StickyItemsElement {
|
||||
rest_decorations: SmallVec<[AnyElement; 1]>,
|
||||
}
|
||||
|
||||
impl IntoElement for StickyItemsElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for StickyItemsElement {
|
||||
type RequestLayoutState = ();
|
||||
type PrepaintState = ();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use gpui::{
|
||||
AnyElement, App, Bounds, Div, DivFrameState, Element, ElementId, GlobalElementId, Hitbox,
|
||||
InteractiveElement as _, IntoElement, LayoutId, ParentElement, Pixels, StyleRefinement, Styled,
|
||||
Window, div,
|
||||
InteractiveElement as _, LayoutId, ParentElement, Pixels, StyleRefinement, Styled, Window, div,
|
||||
};
|
||||
|
||||
/// An element that sets a particular rem size for its children.
|
||||
@@ -104,11 +103,3 @@ impl Element for WithRemSize {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for WithRemSize {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1142,8 +1142,8 @@ mod element {
|
||||
|
||||
use gpui::{
|
||||
Along, AnyElement, App, Axis, BorderStyle, Bounds, Element, GlobalElementId,
|
||||
HitboxBehavior, IntoElement, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement,
|
||||
Pixels, Point, Size, Style, WeakEntity, Window, px, relative, size,
|
||||
HitboxBehavior, MouseDownEvent, MouseMoveEvent, MouseUpEvent, ParentElement, Pixels, Point,
|
||||
Size, Style, WeakEntity, Window, px, relative, size,
|
||||
};
|
||||
use gpui::{CursorStyle, Hitbox};
|
||||
use parking_lot::Mutex;
|
||||
@@ -1347,14 +1347,6 @@ mod element {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoElement for PaneAxisElement {
|
||||
type Element = Self;
|
||||
|
||||
fn into_element(self) -> Self::Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Element for PaneAxisElement {
|
||||
type RequestLayoutState = ();
|
||||
type PrepaintState = PaneAxisLayout;
|
||||
|
||||
Reference in New Issue
Block a user