Refine naming of element-related types and traits

Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Nathan Sobo 2023-04-21 13:04:03 -06:00
parent 03619dfa55
commit fe492eacbf
93 changed files with 661 additions and 656 deletions

View file

@ -2,7 +2,7 @@ use gpui::{
color::Color,
fonts::{Properties, Weight},
text_layout::RunStyle,
Drawable, Element, Quad, SceneBuilder, View, ViewContext,
AnyElement, Element, Quad, SceneBuilder, View, ViewContext,
};
use log::LevelFilter;
use pathfinder_geometry::rect::RectF;
@ -30,12 +30,12 @@ impl gpui::View for TextView {
"View"
}
fn render(&mut self, _: &mut gpui::ViewContext<Self>) -> Element<TextView> {
TextElement.into_element()
fn render(&mut self, _: &mut gpui::ViewContext<Self>) -> AnyElement<TextView> {
TextElement.into_any()
}
}
impl<V: View> Drawable<V> for TextElement {
impl<V: View> Element<V> for TextElement {
type LayoutState = ();
type PaintState = ();

View file

@ -41,7 +41,7 @@ pub use test_app_context::{ContextHandle, TestAppContext};
use window_input_handler::WindowInputHandler;
use crate::{
elements::{AnyRootElement, Element, RootElement},
elements::{AnyElement, AnyRootElement, RootElement},
executor::{self, Task},
keymap_matcher::{self, Binding, KeymapContext, KeymapMatcher, Keystroke, MatchResult},
platform::{
@ -69,7 +69,7 @@ pub trait Entity: 'static {
pub trait View: Entity + Sized {
fn ui_name() -> &'static str;
fn render(&mut self, cx: &mut ViewContext<'_, '_, '_, Self>) -> Element<Self>;
fn render(&mut self, cx: &mut ViewContext<'_, '_, '_, Self>) -> AnyElement<Self>;
fn focus_in(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {}
fn focus_out(&mut self, _: AnyViewHandle, _: &mut ViewContext<Self>) {}
fn key_down(&mut self, _: &KeyDownEvent, _: &mut ViewContext<Self>) -> bool {
@ -4683,9 +4683,9 @@ mod tests {
}
impl super::View for View {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
post_inc(&mut self.render_count);
Empty::new().into_element()
Empty::new().into_any()
}
fn ui_name() -> &'static str {
@ -4736,8 +4736,8 @@ mod tests {
}
impl super::View for View {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
fn ui_name() -> &'static str {
@ -4806,14 +4806,14 @@ mod tests {
}
impl super::View for View {
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
enum Handler {}
let mouse_down_count = self.mouse_down_count.clone();
MouseEventHandler::<Handler, _>::new(0, cx, |_, _| Empty::new())
.on_down(MouseButton::Left, move |_, _, _| {
mouse_down_count.fetch_add(1, SeqCst);
})
.into_element()
.into_any()
}
fn ui_name() -> &'static str {
@ -4872,8 +4872,8 @@ mod tests {
"View"
}
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
}
@ -5390,8 +5390,8 @@ mod tests {
}
impl super::View for View {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
fn ui_name() -> &'static str {
@ -5457,8 +5457,8 @@ mod tests {
}
impl super::View for View {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
fn ui_name() -> &'static str {
@ -5638,8 +5638,8 @@ mod tests {
}
impl View for ViewA {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
fn ui_name() -> &'static str {
@ -5656,8 +5656,8 @@ mod tests {
}
impl View for ViewB {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
fn ui_name() -> &'static str {
@ -5804,8 +5804,8 @@ mod tests {
}
impl super::View for View {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
fn ui_name() -> &'static str {
@ -5931,16 +5931,16 @@ mod tests {
}
impl super::View for View1 {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
fn ui_name() -> &'static str {
"View1"
}
}
impl super::View for View2 {
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
fn ui_name() -> &'static str {
"View2"
@ -6109,8 +6109,8 @@ mod tests {
"test view"
}
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
}
@ -6171,8 +6171,8 @@ mod tests {
"test view"
}
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_named_element(format!("render count: {}", post_inc(&mut self.0)))
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any_named(format!("render count: {}", post_inc(&mut self.0)))
}
}
@ -6260,8 +6260,8 @@ mod tests {
"test view"
}
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
}
@ -6340,9 +6340,9 @@ mod tests {
"child view"
}
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
self.rendered.set(true);
Empty::new().into_element()
Empty::new().into_any()
}
}
@ -6365,11 +6365,11 @@ mod tests {
"parent view"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if let Some(child) = self.child.as_ref() {
ChildView::new(child, cx).into_element()
ChildView::new(child, cx).into_any()
} else {
Empty::new().into_element()
Empty::new().into_any()
}
}
}
@ -6407,8 +6407,8 @@ mod tests {
"TestView"
}
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
}
}

View file

@ -14,7 +14,7 @@ use crate::{
text_layout::TextLayoutCache,
util::post_inc,
Action, AnyModelHandle, AnyView, AnyViewHandle, AnyWeakModelHandle, AnyWeakViewHandle,
AppContext, Drawable, Effect, Entity, Handle, ModelContext, ModelHandle, MouseRegion,
AppContext, Effect, Element, Entity, Handle, ModelContext, ModelHandle, MouseRegion,
MouseRegionId, ParentId, ReadModel, ReadView, SceneBuilder, Subscription, UpdateModel,
UpdateView, UpgradeModelHandle, UpgradeViewHandle, View, ViewContext, ViewHandle,
WeakModelHandle, WeakViewHandle, WindowInvalidation,
@ -1391,7 +1391,7 @@ impl ChildView {
}
}
impl<V: View> Drawable<V> for ChildView {
impl<V: View> Element<V> for ChildView {
type LayoutState = ();
type PaintState = ();

View file

@ -47,7 +47,7 @@ use std::{
};
use util::ResultExt;
pub trait Drawable<V: View>: 'static {
pub trait Element<V: View>: 'static {
type LayoutState;
type PaintState;
@ -92,24 +92,22 @@ pub trait Drawable<V: View>: 'static {
cx: &ViewContext<V>,
) -> serde_json::Value;
fn into_element(self) -> Element<V>
fn into_any(self) -> AnyElement<V>
where
Self: 'static + Sized,
{
Element {
drawable: Box::new(Lifecycle::Init { element: self }),
view_type: PhantomData,
AnyElement {
state: Box::new(ElementState::Init { element: self }),
name: None,
}
}
fn into_named_element(self, name: impl Into<Cow<'static, str>>) -> Element<V>
fn into_any_named(self, name: impl Into<Cow<'static, str>>) -> AnyElement<V>
where
Self: 'static + Sized,
{
Element {
drawable: Box::new(Lifecycle::Init { element: self }),
view_type: PhantomData,
AnyElement {
state: Box::new(ElementState::Init { element: self }),
name: Some(name.into()),
}
}
@ -119,7 +117,7 @@ pub trait Drawable<V: View>: 'static {
Self: 'static + Sized,
{
RootElement {
element: self.into_element(),
element: self.into_any(),
view: cx.handle().downgrade(),
}
}
@ -128,49 +126,49 @@ pub trait Drawable<V: View>: 'static {
where
Self: 'static + Sized,
{
ConstrainedBox::new(self.into_element())
ConstrainedBox::new(self.into_any())
}
fn aligned(self) -> Align<V>
where
Self: 'static + Sized,
{
Align::new(self.into_element())
Align::new(self.into_any())
}
fn clipped(self) -> Clipped<V>
where
Self: 'static + Sized,
{
Clipped::new(self.into_element())
Clipped::new(self.into_any())
}
fn contained(self) -> Container<V>
where
Self: 'static + Sized,
{
Container::new(self.into_element())
Container::new(self.into_any())
}
fn expanded(self) -> Expanded<V>
where
Self: 'static + Sized,
{
Expanded::new(self.into_element())
Expanded::new(self.into_any())
}
fn flex(self, flex: f32, expanded: bool) -> FlexItem<V>
where
Self: 'static + Sized,
{
FlexItem::new(self.into_element()).flex(flex, expanded)
FlexItem::new(self.into_any()).flex(flex, expanded)
}
fn flex_float(self) -> FlexItem<V>
where
Self: 'static + Sized,
{
FlexItem::new(self.into_element()).float()
FlexItem::new(self.into_any()).float()
}
fn with_tooltip<Tag: 'static>(
@ -184,7 +182,7 @@ pub trait Drawable<V: View>: 'static {
where
Self: 'static + Sized,
{
Tooltip::new::<Tag, V>(id, text, action, style, self.into_element(), cx)
Tooltip::new::<Tag, V>(id, text, action, style, self.into_any(), cx)
}
fn with_resize_handle<Tag: 'static>(
@ -199,7 +197,7 @@ pub trait Drawable<V: View>: 'static {
Self: 'static + Sized,
{
Resizable::new::<Tag, V>(
self.into_element(),
self.into_any(),
element_id,
side,
handle_size,
@ -209,7 +207,7 @@ pub trait Drawable<V: View>: 'static {
}
}
trait AnyDrawable<V: View> {
trait AnyElementState<V: View> {
fn layout(
&mut self,
constraint: SizeConstraint,
@ -240,7 +238,7 @@ trait AnyDrawable<V: View> {
fn metadata(&self) -> Option<&dyn Any>;
}
enum Lifecycle<V: View, E: Drawable<V>> {
enum ElementState<V: View, E: Element<V>> {
Empty,
Init {
element: E,
@ -261,7 +259,7 @@ enum Lifecycle<V: View, E: Drawable<V>> {
},
}
impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
impl<V: View, E: Element<V>> AnyElementState<V> for ElementState<V, E> {
fn layout(
&mut self,
constraint: SizeConstraint,
@ -270,16 +268,16 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
) -> Vector2F {
let result;
*self = match mem::take(self) {
Lifecycle::Empty => unreachable!(),
Lifecycle::Init { mut element }
| Lifecycle::PostLayout { mut element, .. }
| Lifecycle::PostPaint { mut element, .. } => {
ElementState::Empty => unreachable!(),
ElementState::Init { mut element }
| ElementState::PostLayout { mut element, .. }
| ElementState::PostPaint { mut element, .. } => {
let (size, layout) = element.layout(constraint, view, cx);
debug_assert!(size.x().is_finite());
debug_assert!(size.y().is_finite());
result = size;
Lifecycle::PostLayout {
ElementState::PostLayout {
element,
constraint,
size,
@ -299,7 +297,7 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
cx: &mut ViewContext<V>,
) {
*self = match mem::take(self) {
Lifecycle::PostLayout {
ElementState::PostLayout {
mut element,
constraint,
size,
@ -307,7 +305,7 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
} => {
let bounds = RectF::new(origin, size);
let paint = element.paint(scene, bounds, visible_bounds, &mut layout, view, cx);
Lifecycle::PostPaint {
ElementState::PostPaint {
element,
constraint,
bounds,
@ -316,7 +314,7 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
paint,
}
}
Lifecycle::PostPaint {
ElementState::PostPaint {
mut element,
constraint,
bounds,
@ -325,7 +323,7 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
} => {
let bounds = RectF::new(origin, bounds.size());
let paint = element.paint(scene, bounds, visible_bounds, &mut layout, view, cx);
Lifecycle::PostPaint {
ElementState::PostPaint {
element,
constraint,
bounds,
@ -334,8 +332,8 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
paint,
}
}
Lifecycle::Empty => panic!("invalid element lifecycle state"),
Lifecycle::Init { .. } => {
ElementState::Empty => panic!("invalid element lifecycle state"),
ElementState::Init { .. } => {
panic!("invalid element lifecycle state, paint called before layout")
}
}
@ -347,7 +345,7 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
view: &V,
cx: &ViewContext<V>,
) -> Option<RectF> {
if let Lifecycle::PostPaint {
if let ElementState::PostPaint {
element,
bounds,
visible_bounds,
@ -372,24 +370,26 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
fn size(&self) -> Vector2F {
match self {
Lifecycle::Empty | Lifecycle::Init { .. } => panic!("invalid element lifecycle state"),
Lifecycle::PostLayout { size, .. } => *size,
Lifecycle::PostPaint { bounds, .. } => bounds.size(),
ElementState::Empty | ElementState::Init { .. } => {
panic!("invalid element lifecycle state")
}
ElementState::PostLayout { size, .. } => *size,
ElementState::PostPaint { bounds, .. } => bounds.size(),
}
}
fn metadata(&self) -> Option<&dyn Any> {
match self {
Lifecycle::Empty => unreachable!(),
Lifecycle::Init { element }
| Lifecycle::PostLayout { element, .. }
| Lifecycle::PostPaint { element, .. } => element.metadata(),
ElementState::Empty => unreachable!(),
ElementState::Init { element }
| ElementState::PostLayout { element, .. }
| ElementState::PostPaint { element, .. } => element.metadata(),
}
}
fn debug(&self, view: &V, cx: &ViewContext<V>) -> serde_json::Value {
match self {
Lifecycle::PostPaint {
ElementState::PostPaint {
element,
constraint,
bounds,
@ -419,25 +419,24 @@ impl<V: View, E: Drawable<V>> AnyDrawable<V> for Lifecycle<V, E> {
}
}
impl<V: View, E: Drawable<V>> Default for Lifecycle<V, E> {
impl<V: View, E: Element<V>> Default for ElementState<V, E> {
fn default() -> Self {
Self::Empty
}
}
pub struct Element<V: View> {
drawable: Box<dyn AnyDrawable<V>>,
view_type: PhantomData<V>,
pub struct AnyElement<V: View> {
state: Box<dyn AnyElementState<V>>,
name: Option<Cow<'static, str>>,
}
impl<V: View> Element<V> {
impl<V: View> AnyElement<V> {
pub fn name(&self) -> Option<&str> {
self.name.as_deref()
}
pub fn metadata<T: 'static>(&self) -> Option<&T> {
self.drawable
self.state
.metadata()
.and_then(|data| data.downcast_ref::<T>())
}
@ -448,7 +447,7 @@ impl<V: View> Element<V> {
view: &mut V,
cx: &mut ViewContext<V>,
) -> Vector2F {
self.drawable.layout(constraint, view, cx)
self.state.layout(constraint, view, cx)
}
pub fn paint(
@ -459,7 +458,7 @@ impl<V: View> Element<V> {
view: &mut V,
cx: &mut ViewContext<V>,
) {
self.drawable.paint(scene, origin, visible_bounds, view, cx);
self.state.paint(scene, origin, visible_bounds, view, cx);
}
pub fn rect_for_text_range(
@ -468,15 +467,15 @@ impl<V: View> Element<V> {
view: &V,
cx: &ViewContext<V>,
) -> Option<RectF> {
self.drawable.rect_for_text_range(range_utf16, view, cx)
self.state.rect_for_text_range(range_utf16, view, cx)
}
pub fn size(&self) -> Vector2F {
self.drawable.size()
self.state.size()
}
pub fn debug(&self, view: &V, cx: &ViewContext<V>) -> json::Value {
let mut value = self.drawable.debug(view, cx);
let mut value = self.state.debug(view, cx);
if let Some(name) = &self.name {
if let json::Value::Object(map) = &mut value {
@ -495,11 +494,11 @@ impl<V: View> Element<V> {
T: 'static,
F: FnOnce(Option<&T>) -> R,
{
f(self.drawable.metadata().and_then(|m| m.downcast_ref()))
f(self.state.metadata().and_then(|m| m.downcast_ref()))
}
}
impl<V: View> Drawable<V> for Element<V> {
impl<V: View> Element<V> for AnyElement<V> {
type LayoutState = ();
type PaintState = ();
@ -549,7 +548,7 @@ impl<V: View> Drawable<V> for Element<V> {
self.debug(view, cx)
}
fn into_element(self) -> Element<V>
fn into_any(self) -> AnyElement<V>
where
Self: Sized,
{
@ -558,18 +557,18 @@ impl<V: View> Drawable<V> for Element<V> {
}
pub struct RootElement<V: View> {
element: Element<V>,
element: AnyElement<V>,
view: WeakViewHandle<V>,
}
impl<V: View> RootElement<V> {
pub fn new(element: Element<V>, view: WeakViewHandle<V>) -> Self {
pub fn new(element: AnyElement<V>, view: WeakViewHandle<V>) -> Self {
Self { element, view }
}
}
pub trait Component<V: View>: 'static {
fn render(&self, view: &mut V, cx: &mut ViewContext<V>) -> Element<V>;
fn render(&self, view: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V>;
}
pub struct ComponentHost<V: View, C: Component<V>> {
@ -591,8 +590,8 @@ impl<V: View, C: Component<V>> DerefMut for ComponentHost<V, C> {
}
}
impl<V: View, C: Component<V>> Drawable<V> for ComponentHost<V, C> {
type LayoutState = Element<V>;
impl<V: View, C: Component<V>> Element<V> for ComponentHost<V, C> {
type LayoutState = AnyElement<V>;
type PaintState = ();
fn layout(
@ -600,7 +599,7 @@ impl<V: View, C: Component<V>> Drawable<V> for ComponentHost<V, C> {
constraint: SizeConstraint,
view: &mut V,
cx: &mut ViewContext<V>,
) -> (Vector2F, Element<V>) {
) -> (Vector2F, AnyElement<V>) {
let mut element = self.component.render(view, cx);
let size = element.layout(constraint, view, cx);
(size, element)
@ -611,7 +610,7 @@ impl<V: View, C: Component<V>> Drawable<V> for ComponentHost<V, C> {
scene: &mut SceneBuilder,
bounds: RectF,
visible_bounds: RectF,
element: &mut Element<V>,
element: &mut AnyElement<V>,
view: &mut V,
cx: &mut ViewContext<V>,
) {
@ -623,7 +622,7 @@ impl<V: View, C: Component<V>> Drawable<V> for ComponentHost<V, C> {
range_utf16: Range<usize>,
_: RectF,
_: RectF,
element: &Element<V>,
element: &AnyElement<V>,
_: &(),
view: &V,
cx: &ViewContext<V>,
@ -634,7 +633,7 @@ impl<V: View, C: Component<V>> Drawable<V> for ComponentHost<V, C> {
fn debug(
&self,
_: RectF,
element: &Element<V>,
element: &AnyElement<V>,
_: &(),
view: &V,
cx: &ViewContext<V>,
@ -718,7 +717,7 @@ impl<V: View> AnyRootElement for RootElement<V> {
}
}
impl<V: View, R: View> Drawable<V> for RootElement<R> {
impl<V: View, R: View> Element<V> for RootElement<R> {
type LayoutState = ();
type PaintState = ();
@ -775,27 +774,27 @@ impl<V: View, R: View> Drawable<V> for RootElement<R> {
}
}
pub trait ParentElement<'a, V: View>: Extend<Element<V>> + Sized {
fn add_children<D: Drawable<V>>(&mut self, children: impl IntoIterator<Item = D>) {
self.extend(children.into_iter().map(|child| child.into_element()));
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()));
}
fn add_child<D: Drawable<V>>(&mut self, child: D) {
self.extend(Some(child.into_element()));
fn add_child<D: Element<V>>(&mut self, child: D) {
self.extend(Some(child.into_any()));
}
fn with_children<D: Drawable<V>>(mut self, children: impl IntoIterator<Item = D>) -> Self {
self.extend(children.into_iter().map(|child| child.into_element()));
fn with_children<D: Element<V>>(mut self, children: impl IntoIterator<Item = D>) -> Self {
self.extend(children.into_iter().map(|child| child.into_any()));
self
}
fn with_child<D: Drawable<V>>(mut self, child: D) -> Self {
self.extend(Some(child.into_element()));
fn with_child<D: Element<V>>(mut self, child: D) -> Self {
self.extend(Some(child.into_any()));
self
}
}
impl<'a, V: View, T> ParentElement<'a, V> for T where T: Extend<Element<V>> {}
impl<'a, V: View, T> ParentElement<'a, V> for T where T: Extend<AnyElement<V>> {}
pub fn constrain_size_preserving_aspect_ratio(max_size: Vector2F, size: Vector2F) -> Vector2F {
if max_size.x().is_infinite() && max_size.y().is_infinite() {

View file

@ -1,18 +1,18 @@
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext,
json, AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext,
};
use json::ToJson;
use serde_json::json;
pub struct Align<V: View> {
child: Element<V>,
child: AnyElement<V>,
alignment: Vector2F,
}
impl<V: View> Align<V> {
pub fn new(child: Element<V>) -> Self {
pub fn new(child: AnyElement<V>) -> Self {
Self {
child,
alignment: Vector2F::zero(),
@ -40,7 +40,7 @@ impl<V: View> Align<V> {
}
}
impl<V: View> Drawable<V> for Align<V> {
impl<V: View> Element<V> for Align<V> {
type LayoutState = ();
type PaintState = ();

View file

@ -1,6 +1,6 @@
use std::marker::PhantomData;
use super::Drawable;
use super::Element;
use crate::{
json::{self, json},
SceneBuilder, View, ViewContext,
@ -23,7 +23,7 @@ where
}
}
impl<V: View, F> Drawable<V> for Canvas<V, F>
impl<V: View, F> Element<V> for Canvas<V, F>
where
F: 'static + FnMut(&mut SceneBuilder, RectF, RectF, &mut V, &mut ViewContext<V>),
{

View file

@ -3,19 +3,19 @@ use std::ops::Range;
use pathfinder_geometry::{rect::RectF, vector::Vector2F};
use serde_json::json;
use crate::{json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext};
use crate::{json, AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext};
pub struct Clipped<V: View> {
child: Element<V>,
child: AnyElement<V>,
}
impl<V: View> Clipped<V> {
pub fn new(child: Element<V>) -> Self {
pub fn new(child: AnyElement<V>) -> Self {
Self { child }
}
}
impl<V: View> Drawable<V> for Clipped<V> {
impl<V: View> Element<V> for Clipped<V> {
type LayoutState = ();
type PaintState = ();

View file

@ -5,11 +5,11 @@ use serde_json::json;
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext,
json, AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext,
};
pub struct ConstrainedBox<V: View> {
child: Element<V>,
child: AnyElement<V>,
constraint: Constraint<V>,
}
@ -28,9 +28,9 @@ impl<V: View> ToJson for Constraint<V> {
}
impl<V: View> ConstrainedBox<V> {
pub fn new(child: impl Drawable<V>) -> Self {
pub fn new(child: impl Element<V>) -> Self {
Self {
child: child.into_element(),
child: child.into_any(),
constraint: Constraint::Static(Default::default()),
}
}
@ -130,7 +130,7 @@ impl<V: View> ConstrainedBox<V> {
}
}
impl<V: View> Drawable<V> for ConstrainedBox<V> {
impl<V: View> Element<V> for ConstrainedBox<V> {
type LayoutState = ();
type PaintState = ();

View file

@ -10,7 +10,7 @@ use crate::{
json::ToJson,
platform::CursorStyle,
scene::{self, Border, CursorRegion, Quad},
Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext,
AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext,
};
use serde::Deserialize;
use serde_json::json;
@ -36,12 +36,12 @@ pub struct ContainerStyle {
}
pub struct Container<V: View> {
child: Element<V>,
child: AnyElement<V>,
style: ContainerStyle,
}
impl<V: View> Container<V> {
pub fn new(child: Element<V>) -> Self {
pub fn new(child: AnyElement<V>) -> Self {
Self {
child,
style: Default::default(),
@ -184,7 +184,7 @@ impl<V: View> Container<V> {
}
}
impl<V: View> Drawable<V> for Container<V> {
impl<V: View> Element<V> for Container<V> {
type LayoutState = ();
type PaintState = ();

View file

@ -8,7 +8,7 @@ use crate::{
json::{json, ToJson},
SceneBuilder, View, ViewContext,
};
use crate::{Drawable, SizeConstraint};
use crate::{Element, SizeConstraint};
#[derive(Default)]
pub struct Empty {
@ -26,7 +26,7 @@ impl Empty {
}
}
impl<V: View> Drawable<V> for Empty {
impl<V: View> Element<V> for Empty {
type LayoutState = ();
type PaintState = ();

View file

@ -2,20 +2,20 @@ use std::ops::Range;
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext,
json, AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext,
};
use serde_json::json;
pub struct Expanded<V: View> {
child: Element<V>,
child: AnyElement<V>,
full_width: bool,
full_height: bool,
}
impl<V: View> Expanded<V> {
pub fn new(child: impl Drawable<V>) -> Self {
pub fn new(child: impl Element<V>) -> Self {
Self {
child: child.into_element(),
child: child.into_any(),
full_width: true,
full_height: true,
}
@ -34,7 +34,7 @@ impl<V: View> Expanded<V> {
}
}
impl<V: View> Drawable<V> for Expanded<V> {
impl<V: View> Element<V> for Expanded<V> {
type LayoutState = ();
type PaintState = ();

View file

@ -2,7 +2,7 @@ use std::{any::Any, cell::Cell, f32::INFINITY, ops::Range, rc::Rc};
use crate::{
json::{self, ToJson, Value},
Axis, Drawable, Element, ElementStateHandle, SceneBuilder, SizeConstraint, Vector2FExt, View,
AnyElement, Axis, Element, ElementStateHandle, SceneBuilder, SizeConstraint, Vector2FExt, View,
ViewContext,
};
use pathfinder_geometry::{
@ -19,7 +19,7 @@ struct ScrollState {
pub struct Flex<V: View> {
axis: Axis,
children: Vec<Element<V>>,
children: Vec<AnyElement<V>>,
scroll_state: Option<(ElementStateHandle<Rc<ScrollState>>, usize)>,
child_alignment: f32,
}
@ -111,13 +111,13 @@ impl<V: View> Flex<V> {
}
}
impl<V: View> Extend<Element<V>> for Flex<V> {
fn extend<T: IntoIterator<Item = Element<V>>>(&mut self, children: T) {
impl<V: View> Extend<AnyElement<V>> for Flex<V> {
fn extend<T: IntoIterator<Item = AnyElement<V>>>(&mut self, children: T) {
self.children.extend(children);
}
}
impl<V: View> Drawable<V> for Flex<V> {
impl<V: View> Element<V> for Flex<V> {
type LayoutState = f32;
type PaintState = ();
@ -399,17 +399,17 @@ struct FlexParentData {
pub struct FlexItem<V: View> {
metadata: FlexParentData,
child: Element<V>,
child: AnyElement<V>,
}
impl<V: View> FlexItem<V> {
pub fn new(child: impl Drawable<V>) -> Self {
pub fn new(child: impl Element<V>) -> Self {
FlexItem {
metadata: FlexParentData {
flex: None,
float: false,
},
child: child.into_element(),
child: child.into_any(),
}
}
@ -424,7 +424,7 @@ impl<V: View> FlexItem<V> {
}
}
impl<V: View> Drawable<V> for FlexItem<V> {
impl<V: View> Element<V> for FlexItem<V> {
type LayoutState = ();
type PaintState = ();

View file

@ -3,18 +3,18 @@ use std::ops::Range;
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json::json,
Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext,
AnyElement, Element, SceneBuilder, SizeConstraint, View, ViewContext,
};
pub struct Hook<V: View> {
child: Element<V>,
child: AnyElement<V>,
after_layout: Option<Box<dyn FnMut(Vector2F, &mut ViewContext<V>)>>,
}
impl<V: View> Hook<V> {
pub fn new(child: impl Drawable<V>) -> Self {
pub fn new(child: impl Element<V>) -> Self {
Self {
child: child.into_element(),
child: child.into_any(),
after_layout: None,
}
}
@ -28,7 +28,7 @@ impl<V: View> Hook<V> {
}
}
impl<V: View> Drawable<V> for Hook<V> {
impl<V: View> Element<V> for Hook<V> {
type LayoutState = ();
type PaintState = ();

View file

@ -5,7 +5,7 @@ use crate::{
vector::{vec2f, Vector2F},
},
json::{json, ToJson},
scene, Border, Drawable, ImageData, SceneBuilder, SizeConstraint, View, ViewContext,
scene, Border, Element, ImageData, SceneBuilder, SizeConstraint, View, ViewContext,
};
use serde::Deserialize;
use std::{ops::Range, sync::Arc};
@ -55,7 +55,7 @@ impl Image {
}
}
impl<V: View> Drawable<V> for Image {
impl<V: View> Element<V> for Image {
type LayoutState = Option<Arc<ImageData>>;
type PaintState = ();

View file

@ -2,7 +2,7 @@ use crate::{
elements::*,
fonts::TextStyle,
geometry::{rect::RectF, vector::Vector2F},
Action, Element, SizeConstraint,
Action, AnyElement, SizeConstraint,
};
use serde_json::json;
@ -31,8 +31,8 @@ impl KeystrokeLabel {
}
}
impl<V: View> Drawable<V> for KeystrokeLabel {
type LayoutState = Element<V>;
impl<V: View> Element<V> for KeystrokeLabel {
type LayoutState = AnyElement<V>;
type PaintState = ();
fn layout(
@ -40,7 +40,7 @@ impl<V: View> Drawable<V> for KeystrokeLabel {
constraint: SizeConstraint,
view: &mut V,
cx: &mut ViewContext<V>,
) -> (Vector2F, Element<V>) {
) -> (Vector2F, AnyElement<V>) {
let mut element = if let Some(keystrokes) =
cx.keystrokes_for_action(self.view_id, self.action.as_ref())
{
@ -50,9 +50,9 @@ impl<V: View> Drawable<V> for KeystrokeLabel {
.contained()
.with_style(self.container_style)
}))
.into_element()
.into_any()
} else {
Empty::new().collapsed().into_element()
Empty::new().collapsed().into_any()
};
let size = element.layout(constraint, view, cx);
@ -64,7 +64,7 @@ impl<V: View> Drawable<V> for KeystrokeLabel {
scene: &mut SceneBuilder,
bounds: RectF,
visible_bounds: RectF,
element: &mut Element<V>,
element: &mut AnyElement<V>,
view: &mut V,
cx: &mut ViewContext<V>,
) {
@ -87,7 +87,7 @@ impl<V: View> Drawable<V> for KeystrokeLabel {
fn debug(
&self,
_: RectF,
element: &Element<V>,
element: &AnyElement<V>,
_: &(),
view: &V,
cx: &ViewContext<V>,

View file

@ -8,7 +8,7 @@ use crate::{
},
json::{ToJson, Value},
text_layout::{Line, RunStyle},
Drawable, SceneBuilder, SizeConstraint, View, ViewContext,
Element, SceneBuilder, SizeConstraint, View, ViewContext,
};
use serde::Deserialize;
use serde_json::json;
@ -127,7 +127,7 @@ impl Label {
}
}
impl<V: View> Drawable<V> for Label {
impl<V: View> Element<V> for Label {
type LayoutState = Line;
type PaintState = ();

View file

@ -4,7 +4,7 @@ use crate::{
vector::{vec2f, Vector2F},
},
json::json,
Drawable, Element, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext,
AnyElement, Element, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext,
};
use std::{cell::RefCell, collections::VecDeque, fmt::Debug, ops::Range, rc::Rc};
use sum_tree::{Bias, SumTree};
@ -23,7 +23,7 @@ pub enum Orientation {
struct StateInner<V: View> {
last_layout_width: Option<f32>,
render_item: Box<dyn FnMut(&mut V, usize, &mut ViewContext<V>) -> Element<V>>,
render_item: Box<dyn FnMut(&mut V, usize, &mut ViewContext<V>) -> AnyElement<V>>,
rendered_range: Range<usize>,
items: SumTree<ListItem<V>>,
logical_scroll_top: Option<ListOffset>,
@ -41,7 +41,7 @@ pub struct ListOffset {
enum ListItem<V: View> {
Unrendered,
Rendered(Rc<RefCell<Element<V>>>),
Rendered(Rc<RefCell<AnyElement<V>>>),
Removed(f32),
}
@ -91,7 +91,7 @@ impl<V: View> List<V> {
}
}
impl<V: View> Drawable<V> for List<V> {
impl<V: View> Element<V> for List<V> {
type LayoutState = ListOffset;
type PaintState = ();
@ -354,14 +354,14 @@ impl<V: View> ListState<V> {
mut render_item: F,
) -> Self
where
D: Drawable<V>,
D: Element<V>,
F: 'static + FnMut(&mut V, usize, &mut ViewContext<V>) -> D,
{
let mut items = SumTree::new();
items.extend((0..element_count).map(|_| ListItem::Unrendered), &());
Self(Rc::new(RefCell::new(StateInner {
last_layout_width: None,
render_item: Box::new(move |view, ix, cx| render_item(view, ix, cx).into_element()),
render_item: Box::new(move |view, ix, cx| render_item(view, ix, cx).into_any()),
rendered_range: 0..0,
items,
logical_scroll_top: None,
@ -453,7 +453,7 @@ impl<V: View> StateInner<V> {
constraint: SizeConstraint,
view: &mut V,
cx: &mut ViewContext<V>,
) -> Option<Rc<RefCell<Element<V>>>> {
) -> Option<Rc<RefCell<AnyElement<V>>>> {
if let Some(ListItem::Rendered(element)) = existing_element {
Some(element.clone())
} else {
@ -475,7 +475,7 @@ impl<V: View> StateInner<V> {
&'a self,
bounds: RectF,
scroll_top: &ListOffset,
) -> impl Iterator<Item = (Rc<RefCell<Element<V>>>, Vector2F)> + 'a {
) -> impl Iterator<Item = (Rc<RefCell<AnyElement<V>>>, Vector2F)> + 'a {
let mut item_origin = bounds.origin() - vec2f(0., scroll_top.offset_in_item);
let mut cursor = self.items.cursor::<Count>();
cursor.seek(&Count(scroll_top.item_ix), Bias::Right, &());
@ -660,7 +660,7 @@ mod tests {
let elements = elements.clone();
move |_, ix, _| {
let (id, height) = elements.borrow()[ix];
TestElement::new(id, height).into_element()
TestElement::new(id, height).into_any()
}
});
@ -765,7 +765,7 @@ mod tests {
let elements = elements.clone();
move |_, ix, _| {
let (id, height) = elements.borrow()[ix];
TestElement::new(id, height).into_element()
TestElement::new(id, height).into_any()
}
});
@ -920,8 +920,8 @@ mod tests {
"TestView"
}
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
}
@ -939,7 +939,7 @@ mod tests {
}
}
impl<V: View> Drawable<V> for TestElement {
impl<V: View> Element<V> for TestElement {
type LayoutState = ();
type PaintState = ();

View file

@ -10,14 +10,14 @@ use crate::{
CursorRegion, HandlerSet, MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseHover,
MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut,
},
Drawable, Element, EventContext, MouseRegion, MouseState, SceneBuilder, SizeConstraint, View,
AnyElement, Element, EventContext, MouseRegion, MouseState, SceneBuilder, SizeConstraint, View,
ViewContext,
};
use serde_json::json;
use std::{marker::PhantomData, ops::Range};
pub struct MouseEventHandler<Tag: 'static, V: View> {
child: Element<V>,
child: AnyElement<V>,
region_id: usize,
cursor_style: Option<CursorStyle>,
handlers: HandlerSet,
@ -34,11 +34,11 @@ pub struct MouseEventHandler<Tag: 'static, V: View> {
impl<Tag, V: View> MouseEventHandler<Tag, V> {
pub fn new<D, F>(region_id: usize, cx: &mut ViewContext<V>, render_child: F) -> Self
where
D: Drawable<V>,
D: Element<V>,
F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> D,
{
let mut mouse_state = cx.mouse_state::<Tag>(region_id);
let child = render_child(&mut mouse_state, cx).into_element();
let child = render_child(&mut mouse_state, cx).into_any();
let notify_on_hover = mouse_state.accessed_hovered();
let notify_on_click = mouse_state.accessed_clicked();
Self {
@ -60,7 +60,7 @@ impl<Tag, V: View> MouseEventHandler<Tag, V> {
/// gets the opportunity
pub fn above<D, F>(region_id: usize, cx: &mut ViewContext<V>, render_child: F) -> Self
where
D: Drawable<V>,
D: Element<V>,
F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> D,
{
let mut handler = Self::new(region_id, cx, render_child);
@ -212,7 +212,7 @@ impl<Tag, V: View> MouseEventHandler<Tag, V> {
}
}
impl<Tag, V: View> Drawable<V> for MouseEventHandler<Tag, V> {
impl<Tag, V: View> Element<V> for MouseEventHandler<Tag, V> {
type LayoutState = ();
type PaintState = ();

View file

@ -3,12 +3,12 @@ use std::ops::Range;
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json::ToJson,
Axis, Drawable, Element, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext,
AnyElement, Axis, Element, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext,
};
use serde_json::json;
pub struct Overlay<V: View> {
child: Element<V>,
child: AnyElement<V>,
anchor_position: Option<Vector2F>,
anchor_corner: AnchorCorner,
fit_mode: OverlayFitMode,
@ -73,9 +73,9 @@ impl AnchorCorner {
}
impl<V: View> Overlay<V> {
pub fn new(child: impl Drawable<V>) -> Self {
pub fn new(child: impl Element<V>) -> Self {
Self {
child: child.into_element(),
child: child.into_any(),
anchor_position: None,
anchor_corner: AnchorCorner::TopLeft,
fit_mode: OverlayFitMode::None,
@ -116,7 +116,7 @@ impl<V: View> Overlay<V> {
}
}
impl<V: View> Drawable<V> for Overlay<V> {
impl<V: View> Element<V> for Overlay<V> {
type LayoutState = Vector2F;
type PaintState = ();

View file

@ -7,7 +7,7 @@ use crate::{
geometry::rect::RectF,
platform::{CursorStyle, MouseButton},
scene::MouseDrag,
Axis, Drawable, Element, ElementStateHandle, MouseRegion, SceneBuilder, View, ViewContext,
AnyElement, Axis, Element, ElementStateHandle, MouseRegion, SceneBuilder, View, ViewContext,
};
use super::{ConstrainedBox, Hook};
@ -78,14 +78,14 @@ struct ResizeHandleState {
pub struct Resizable<V: View> {
side: Side,
handle_size: f32,
child: Element<V>,
child: AnyElement<V>,
state: Rc<ResizeHandleState>,
_state_handle: ElementStateHandle<Rc<ResizeHandleState>>,
}
impl<V: View> Resizable<V> {
pub fn new<Tag: 'static, T: View>(
child: Element<V>,
child: AnyElement<V>,
element_id: usize,
side: Side,
handle_size: f32,
@ -115,7 +115,7 @@ impl<V: View> Resizable<V> {
state.actual_dimension.set(side.relevant_component(size));
}
})
.into_element();
.into_any();
Self {
side,
@ -131,7 +131,7 @@ impl<V: View> Resizable<V> {
}
}
impl<V: View> Drawable<V> for Resizable<V> {
impl<V: View> Element<V> for Resizable<V> {
type LayoutState = ();
type PaintState = ();

View file

@ -3,13 +3,13 @@ use std::ops::Range;
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json::{self, json, ToJson},
Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext,
Element, AnyElement, SceneBuilder, SizeConstraint, View, ViewContext,
};
/// Element which renders it's children in a stack on top of each other.
/// The first child determines the size of the others.
pub struct Stack<V: View> {
children: Vec<Element<V>>,
children: Vec<AnyElement<V>>,
}
impl<V: View> Default for Stack<V> {
@ -26,7 +26,7 @@ impl<V: View> Stack<V> {
}
}
impl<V: View> Drawable<V> for Stack<V> {
impl<V: View> Element<V> for Stack<V> {
type LayoutState = ();
type PaintState = ();
@ -98,8 +98,8 @@ impl<V: View> Drawable<V> for Stack<V> {
}
}
impl<V: View> Extend<Element<V>> for Stack<V> {
fn extend<T: IntoIterator<Item = Element<V>>>(&mut self, children: T) {
impl<V: View> Extend<AnyElement<V>> for Stack<V> {
fn extend<T: IntoIterator<Item = AnyElement<V>>>(&mut self, children: T) {
self.children.extend(children)
}
}

View file

@ -8,7 +8,7 @@ use crate::{
rect::RectF,
vector::{vec2f, Vector2F},
},
scene, Drawable, SceneBuilder, SizeConstraint, View, ViewContext,
scene, Element, SceneBuilder, SizeConstraint, View, ViewContext,
};
pub struct Svg {
@ -30,7 +30,7 @@ impl Svg {
}
}
impl<V: View> Drawable<V> for Svg {
impl<V: View> Element<V> for Svg {
type LayoutState = Option<usvg::Tree>;
type PaintState = ();

View file

@ -7,7 +7,7 @@ use crate::{
},
json::{ToJson, Value},
text_layout::{Line, RunStyle, ShapedBoundary},
Drawable, FontCache, SceneBuilder, SizeConstraint, TextLayoutCache, View, ViewContext,
Element, FontCache, SceneBuilder, SizeConstraint, TextLayoutCache, View, ViewContext,
};
use log::warn;
use serde_json::json;
@ -52,7 +52,7 @@ impl Text {
}
}
impl<V: View> Drawable<V> for Text {
impl<V: View> Element<V> for Text {
type LayoutState = LayoutState;
type PaintState = ();
@ -276,7 +276,7 @@ pub fn layout_highlighted_chunks<'a>(
#[cfg(test)]
mod tests {
use super::*;
use crate::{elements::Empty, fonts, AppContext, Element, Entity, View, ViewContext};
use crate::{elements::Empty, fonts, AnyElement, AppContext, Entity, View, ViewContext};
#[crate::test(self)]
fn test_soft_wrapping_with_carriage_returns(cx: &mut AppContext) {
@ -307,8 +307,8 @@ mod tests {
"TestView"
}
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
}
}

View file

@ -1,5 +1,5 @@
use super::{
ContainerStyle, Drawable, Element, Flex, KeystrokeLabel, MouseEventHandler, Overlay,
AnyElement, ContainerStyle, Element, Flex, KeystrokeLabel, MouseEventHandler, Overlay,
OverlayFitMode, ParentElement, Text,
};
use crate::{
@ -20,8 +20,8 @@ use util::ResultExt;
const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(500);
pub struct Tooltip<V: View> {
child: Element<V>,
tooltip: Option<Element<V>>,
child: AnyElement<V>,
tooltip: Option<AnyElement<V>>,
_state: ElementStateHandle<Rc<TooltipState>>,
}
@ -55,7 +55,7 @@ impl<V: View> Tooltip<V> {
text: String,
action: Option<Box<dyn Action>>,
style: TooltipStyle,
child: Element<V>,
child: AnyElement<V>,
cx: &mut ViewContext<V>,
) -> Self {
struct ElementState<Tag>(Tag);
@ -85,7 +85,7 @@ impl<V: View> Tooltip<V> {
)
.with_fit_mode(OverlayFitMode::SwitchAnchor)
.with_anchor_position(state.position.get())
.into_element(),
.into_any(),
)
} else {
None
@ -117,7 +117,7 @@ impl<V: View> Tooltip<V> {
cx.notify();
}
})
.into_element();
.into_any();
Self {
child,
tooltip,
@ -131,7 +131,7 @@ impl<V: View> Tooltip<V> {
style: TooltipStyle,
action: Option<Box<dyn Action>>,
measure: bool,
) -> impl Drawable<V> {
) -> impl Element<V> {
Flex::row()
.with_child({
let text = if let Some(max_text_width) = style.max_text_width {
@ -143,9 +143,9 @@ impl<V: View> Tooltip<V> {
};
if measure {
text.flex(1., false).into_element()
text.flex(1., false).into_any()
} else {
text.flex(1., false).aligned().into_element()
text.flex(1., false).aligned().into_any()
}
})
.with_children(action.and_then(|action| {
@ -156,9 +156,9 @@ impl<V: View> Tooltip<V> {
style.keystroke.text,
);
if measure {
Some(keystroke_label.into_element())
Some(keystroke_label.into_any())
} else {
Some(keystroke_label.aligned().into_element())
Some(keystroke_label.aligned().into_any())
}
}))
.contained()
@ -166,7 +166,7 @@ impl<V: View> Tooltip<V> {
}
}
impl<V: View> Drawable<V> for Tooltip<V> {
impl<V: View> Element<V> for Tooltip<V> {
type LayoutState = ();
type PaintState = ();

View file

@ -1,4 +1,4 @@
use super::{Drawable, SizeConstraint};
use super::{Element, SizeConstraint};
use crate::{
geometry::{
rect::RectF,
@ -6,7 +6,7 @@ use crate::{
},
json::{self, json},
platform::ScrollWheelEvent,
Element, MouseRegion, SceneBuilder, View, ViewContext,
AnyElement, MouseRegion, SceneBuilder, View, ViewContext,
};
use json::ToJson;
use std::{cell::RefCell, cmp, ops::Range, rc::Rc};
@ -39,14 +39,14 @@ struct StateInner {
pub struct LayoutState<V: View> {
scroll_max: f32,
item_height: f32,
items: Vec<Element<V>>,
items: Vec<AnyElement<V>>,
}
pub struct UniformList<V: View> {
state: UniformListState,
item_count: usize,
#[allow(clippy::type_complexity)]
append_items: Box<dyn Fn(&mut V, Range<usize>, &mut Vec<Element<V>>, &mut ViewContext<V>)>,
append_items: Box<dyn Fn(&mut V, Range<usize>, &mut Vec<AnyElement<V>>, &mut ViewContext<V>)>,
padding_top: f32,
padding_bottom: f32,
get_width_from_item: Option<usize>,
@ -62,7 +62,7 @@ impl<V: View> UniformList<V> {
) -> Self
where
V: View,
F: 'static + Fn(&mut V, Range<usize>, &mut Vec<Element<V>>, &mut ViewContext<V>),
F: 'static + Fn(&mut V, Range<usize>, &mut Vec<AnyElement<V>>, &mut ViewContext<V>),
{
Self {
state,
@ -151,7 +151,7 @@ impl<V: View> UniformList<V> {
}
}
impl<V: View> Drawable<V> for UniformList<V> {
impl<V: View> Element<V> for UniformList<V> {
type LayoutState = LayoutState<V>;
type PaintState = ();

View file

@ -19,7 +19,7 @@ pub use scene::{Border, CursorRegion, MouseRegion, MouseRegionId, Quad, Scene, S
pub mod text_layout;
pub use text_layout::TextLayoutCache;
mod util;
pub use elements::{Drawable, Element};
pub use elements::{AnyElement, Element};
pub mod executor;
pub use executor::Task;
pub mod color;

View file

@ -19,7 +19,7 @@ use crate::{
platform,
platform::Platform,
util::CwdBacktrace,
AppContext, Drawable, Element, Entity, FontCache, Handle, Subscription, TestAppContext, View,
AnyElement, AppContext, Element, Entity, FontCache, Handle, Subscription, TestAppContext, View,
ViewContext,
};
@ -242,7 +242,7 @@ impl View for EmptyView {
"empty view"
}
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
Empty::new().into_element()
fn render(&mut self, _: &mut ViewContext<Self>) -> AnyElement<Self> {
Empty::new().into_any()
}
}

View file

@ -7,7 +7,7 @@ use crate::{
pub struct Select {
handle: WeakViewHandle<Self>,
render_item: Box<dyn Fn(usize, ItemType, bool, &AppContext) -> Element<Self>>,
render_item: Box<dyn Fn(usize, ItemType, bool, &AppContext) -> AnyElement<Self>>,
selected_item_ix: usize,
item_count: usize,
is_open: bool,
@ -41,7 +41,7 @@ pub fn init(cx: &mut AppContext) {
}
impl Select {
pub fn new<F: 'static + Fn(usize, ItemType, bool, &AppContext) -> Element<Self>>(
pub fn new<F: 'static + Fn(usize, ItemType, bool, &AppContext) -> AnyElement<Self>>(
item_count: usize,
cx: &mut ViewContext<Self>,
render_item: F,
@ -92,9 +92,9 @@ impl View for Select {
"Select"
}
fn render(&mut self, cx: &mut ViewContext<Self>) -> Element<Self> {
fn render(&mut self, cx: &mut ViewContext<Self>) -> AnyElement<Self> {
if self.item_count == 0 {
return Empty::new().into_element();
return Empty::new().into_any();
}
enum Header {}
@ -149,7 +149,7 @@ impl View for Select {
cx.dispatch_action(SelectItem(ix))
},
)
.into_element()
.into_any()
}))
},
)
@ -159,6 +159,6 @@ impl View for Select {
.with_style(style.menu),
));
}
result.into_element()
result.into_any()
}
}