Remove unnecessary Element impl for RootElement

This commit is contained in:
Antonio Scandurra 2023-05-02 10:09:57 +02:00
parent f62ba2eec7
commit 4c1cba6def

View File

@ -45,7 +45,6 @@ use std::{
mem,
ops::{Deref, DerefMut, Range},
};
use util::ResultExt;
pub trait Element<V: View>: 'static {
type LayoutState;
@ -717,63 +716,6 @@ impl<V: View> AnyRootElement for RootElement<V> {
}
}
impl<V: View, R: View> Element<V> for RootElement<R> {
type LayoutState = ();
type PaintState = ();
fn layout(
&mut self,
constraint: SizeConstraint,
_view: &mut V,
cx: &mut ViewContext<V>,
) -> (Vector2F, ()) {
let size = AnyRootElement::layout(self, constraint, cx)
.log_err()
.unwrap_or_else(|| Vector2F::zero());
(size, ())
}
fn paint(
&mut self,
scene: &mut SceneBuilder,
bounds: RectF,
visible_bounds: RectF,
_layout: &mut Self::LayoutState,
_view: &mut V,
cx: &mut ViewContext<V>,
) {
AnyRootElement::paint(self, scene, bounds.origin(), visible_bounds, cx).log_err();
}
fn rect_for_text_range(
&self,
range_utf16: Range<usize>,
_bounds: RectF,
_visible_bounds: RectF,
_layout: &Self::LayoutState,
_paint: &Self::PaintState,
_view: &V,
cx: &ViewContext<V>,
) -> Option<RectF> {
AnyRootElement::rect_for_text_range(self, range_utf16, cx)
.log_err()
.flatten()
}
fn debug(
&self,
_bounds: RectF,
_layout: &Self::LayoutState,
_paint: &Self::PaintState,
_view: &V,
cx: &ViewContext<V>,
) -> serde_json::Value {
AnyRootElement::debug(self, cx)
.log_err()
.unwrap_or_default()
}
}
pub trait ParentElement<'a, V: View>: Extend<AnyElement<V>> + Sized {
fn add_children<E: Element<V>>(&mut self, children: impl IntoIterator<Item = E>) {
self.extend(children.into_iter().map(|child| child.into_any()));