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

@ -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 = ();