WIP
This commit is contained in:
parent
40896352ff
commit
a25f962185
90 changed files with 587 additions and 501 deletions
|
@ -1,18 +1,18 @@
|
|||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json, Element, ElementBox, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
};
|
||||
use json::ToJson;
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
pub struct Align<V: View> {
|
||||
child: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
alignment: Vector2F,
|
||||
}
|
||||
|
||||
impl<V: View> Align<V> {
|
||||
pub fn new(child: ElementBox<V>) -> Self {
|
||||
pub fn new(child: Element<V>) -> Self {
|
||||
Self {
|
||||
child,
|
||||
alignment: Vector2F::zero(),
|
||||
|
@ -40,7 +40,7 @@ impl<V: View> Align<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Align<V> {
|
||||
impl<V: View> Drawable<V> for Align<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::marker::PhantomData;
|
||||
|
||||
use super::Element;
|
||||
use super::Drawable;
|
||||
use crate::{
|
||||
json::{self, json},
|
||||
SceneBuilder, View, ViewContext,
|
||||
|
@ -23,7 +23,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View, F> Element<V> for Canvas<V, F>
|
||||
impl<V: View, F> Drawable<V> for Canvas<V, F>
|
||||
where
|
||||
F: FnMut(&mut SceneBuilder, RectF, RectF, &mut V, &mut ViewContext<V>),
|
||||
{
|
||||
|
|
|
@ -3,19 +3,19 @@ use std::ops::Range;
|
|||
use pathfinder_geometry::{rect::RectF, vector::Vector2F};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::{json, Element, ElementBox, SceneBuilder, SizeConstraint, View, ViewContext};
|
||||
use crate::{json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext};
|
||||
|
||||
pub struct Clipped<V: View> {
|
||||
child: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
}
|
||||
|
||||
impl<V: View> Clipped<V> {
|
||||
pub fn new(child: ElementBox<V>) -> Self {
|
||||
pub fn new(child: Element<V>) -> Self {
|
||||
Self { child }
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Clipped<V> {
|
||||
impl<V: View> Drawable<V> for Clipped<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@ use serde_json::json;
|
|||
|
||||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json, Element, ElementBox, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
};
|
||||
|
||||
pub struct ConstrainedBox<V: View> {
|
||||
child: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
constraint: Constraint<V>,
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ impl<V: View> ToJson for Constraint<V> {
|
|||
}
|
||||
|
||||
impl<V: View> ConstrainedBox<V> {
|
||||
pub fn new(child: ElementBox<V>) -> Self {
|
||||
pub fn new(child: Element<V>) -> Self {
|
||||
Self {
|
||||
child,
|
||||
constraint: Constraint::Static(Default::default()),
|
||||
|
@ -130,7 +130,7 @@ impl<V: View> ConstrainedBox<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for ConstrainedBox<V> {
|
||||
impl<V: View> Drawable<V> for ConstrainedBox<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
json::ToJson,
|
||||
platform::CursorStyle,
|
||||
scene::{self, Border, CursorRegion, Quad},
|
||||
Element, ElementBox, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
Drawable, 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: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
style: ContainerStyle,
|
||||
}
|
||||
|
||||
impl<V: View> Container<V> {
|
||||
pub fn new(child: ElementBox<V>) -> Self {
|
||||
pub fn new(child: Element<V>) -> Self {
|
||||
Self {
|
||||
child,
|
||||
style: Default::default(),
|
||||
|
@ -184,7 +184,7 @@ impl<V: View> Container<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Container<V> {
|
||||
impl<V: View> Drawable<V> for Container<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
json::{json, ToJson},
|
||||
SceneBuilder, View, ViewContext,
|
||||
};
|
||||
use crate::{Element, SizeConstraint};
|
||||
use crate::{Drawable, SizeConstraint};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Empty {
|
||||
|
@ -26,7 +26,7 @@ impl Empty {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Empty {
|
||||
impl<V: View> Drawable<V> for Empty {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -2,18 +2,18 @@ use std::ops::Range;
|
|||
|
||||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json, Element, ElementBox, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
json, Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
pub struct Expanded<V: View> {
|
||||
child: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
full_width: bool,
|
||||
full_height: bool,
|
||||
}
|
||||
|
||||
impl<V: View> Expanded<V> {
|
||||
pub fn new(child: ElementBox<V>) -> Self {
|
||||
pub fn new(child: Element<V>) -> Self {
|
||||
Self {
|
||||
child,
|
||||
full_width: true,
|
||||
|
@ -34,7 +34,7 @@ impl<V: View> Expanded<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Expanded<V> {
|
||||
impl<V: View> Drawable<V> for Expanded<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::{any::Any, cell::Cell, f32::INFINITY, ops::Range, rc::Rc};
|
|||
|
||||
use crate::{
|
||||
json::{self, ToJson, Value},
|
||||
Axis, Element, ElementBox, ElementStateHandle, SceneBuilder, SizeConstraint, Vector2FExt, View,
|
||||
Axis, Drawable, 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<ElementBox<V>>,
|
||||
children: Vec<Element<V>>,
|
||||
scroll_state: Option<(ElementStateHandle<Rc<ScrollState>>, usize)>,
|
||||
child_alignment: f32,
|
||||
}
|
||||
|
@ -111,13 +111,13 @@ impl<V: View> Flex<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Extend<ElementBox<V>> for Flex<V> {
|
||||
fn extend<T: IntoIterator<Item = ElementBox<V>>>(&mut self, children: T) {
|
||||
impl<V: View> Extend<Element<V>> for Flex<V> {
|
||||
fn extend<T: IntoIterator<Item = Element<V>>>(&mut self, children: T) {
|
||||
self.children.extend(children);
|
||||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Flex<V> {
|
||||
impl<V: View> Drawable<V> for Flex<V> {
|
||||
type LayoutState = f32;
|
||||
type PaintState = ();
|
||||
|
||||
|
@ -399,11 +399,11 @@ struct FlexParentData {
|
|||
|
||||
pub struct FlexItem<V: View> {
|
||||
metadata: FlexParentData,
|
||||
child: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
}
|
||||
|
||||
impl<V: View> FlexItem<V> {
|
||||
pub fn new(child: ElementBox<V>) -> Self {
|
||||
pub fn new(child: Element<V>) -> Self {
|
||||
FlexItem {
|
||||
metadata: FlexParentData {
|
||||
flex: None,
|
||||
|
@ -424,7 +424,7 @@ impl<V: View> FlexItem<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for FlexItem<V> {
|
||||
impl<V: View> Drawable<V> for FlexItem<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -3,16 +3,16 @@ use std::ops::Range;
|
|||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json::json,
|
||||
Element, ElementBox, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
Drawable, Element, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
};
|
||||
|
||||
pub struct Hook<V: View> {
|
||||
child: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
after_layout: Option<Box<dyn FnMut(Vector2F, &mut ViewContext<V>)>>,
|
||||
}
|
||||
|
||||
impl<V: View> Hook<V> {
|
||||
pub fn new(child: ElementBox<V>) -> Self {
|
||||
pub fn new(child: Element<V>) -> Self {
|
||||
Self {
|
||||
child,
|
||||
after_layout: None,
|
||||
|
@ -28,7 +28,7 @@ impl<V: View> Hook<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Hook<V> {
|
||||
impl<V: View> Drawable<V> for Hook<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
|||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
json::{json, ToJson},
|
||||
scene, Border, Element, ImageData, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
scene, Border, Drawable, ImageData, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::{ops::Range, sync::Arc};
|
||||
|
@ -55,7 +55,7 @@ impl Image {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Image {
|
||||
impl<V: View> Drawable<V> for Image {
|
||||
type LayoutState = Option<Arc<ImageData>>;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::{
|
|||
elements::*,
|
||||
fonts::TextStyle,
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
Action, ElementBox, SizeConstraint,
|
||||
Action, Element, SizeConstraint,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
|
@ -34,8 +34,8 @@ impl KeystrokeLabel {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for KeystrokeLabel {
|
||||
type LayoutState = ElementBox<V>;
|
||||
impl<V: View> Drawable<V> for KeystrokeLabel {
|
||||
type LayoutState = Element<V>;
|
||||
type PaintState = ();
|
||||
|
||||
fn layout(
|
||||
|
@ -43,7 +43,7 @@ impl<V: View> Element<V> for KeystrokeLabel {
|
|||
constraint: SizeConstraint,
|
||||
view: &mut V,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> (Vector2F, ElementBox<V>) {
|
||||
) -> (Vector2F, Element<V>) {
|
||||
let mut element = if let Some(keystrokes) =
|
||||
cx.keystrokes_for_action(self.window_id, self.view_id, self.action.as_ref())
|
||||
{
|
||||
|
@ -68,7 +68,7 @@ impl<V: View> Element<V> for KeystrokeLabel {
|
|||
scene: &mut SceneBuilder,
|
||||
bounds: RectF,
|
||||
visible_bounds: RectF,
|
||||
element: &mut ElementBox<V>,
|
||||
element: &mut Element<V>,
|
||||
view: &mut V,
|
||||
cx: &mut ViewContext<V>,
|
||||
) {
|
||||
|
@ -91,7 +91,7 @@ impl<V: View> Element<V> for KeystrokeLabel {
|
|||
fn debug(
|
||||
&self,
|
||||
_: RectF,
|
||||
element: &ElementBox<V>,
|
||||
element: &Element<V>,
|
||||
_: &(),
|
||||
view: &V,
|
||||
cx: &ViewContext<V>,
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
},
|
||||
json::{ToJson, Value},
|
||||
text_layout::{Line, RunStyle},
|
||||
Element, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
Drawable, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
|
@ -127,7 +127,7 @@ impl Label {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Label {
|
||||
impl<V: View> Drawable<V> for Label {
|
||||
type LayoutState = Line;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
json::json,
|
||||
Element, ElementBox, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
Drawable, 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>) -> ElementBox<V>>,
|
||||
render_item: Box<dyn FnMut(&mut V, usize, &mut ViewContext<V>) -> Element<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<ElementBox<V>>>),
|
||||
Rendered(Rc<RefCell<Element<V>>>),
|
||||
Removed(f32),
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ impl<V: View> List<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for List<V> {
|
||||
impl<V: View> Drawable<V> for List<V> {
|
||||
type LayoutState = ListOffset;
|
||||
type PaintState = ();
|
||||
|
||||
|
@ -355,7 +355,7 @@ impl<V: View> ListState<V> {
|
|||
) -> Self
|
||||
where
|
||||
V: View,
|
||||
F: 'static + FnMut(&mut V, usize, &mut ViewContext<V>) -> ElementBox<V>,
|
||||
F: 'static + FnMut(&mut V, usize, &mut ViewContext<V>) -> Element<V>,
|
||||
{
|
||||
let mut items = SumTree::new();
|
||||
items.extend((0..element_count).map(|_| ListItem::Unrendered), &());
|
||||
|
@ -453,7 +453,7 @@ impl<V: View> StateInner<V> {
|
|||
constraint: SizeConstraint,
|
||||
view: &mut V,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> Option<Rc<RefCell<ElementBox<V>>>> {
|
||||
) -> Option<Rc<RefCell<Element<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<ElementBox<V>>>, Vector2F)> + 'a {
|
||||
) -> impl Iterator<Item = (Rc<RefCell<Element<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, &());
|
||||
|
@ -922,7 +922,7 @@ mod tests {
|
|||
"TestView"
|
||||
}
|
||||
|
||||
fn render(&mut self, _: &mut ViewContext<Self>) -> ElementBox<Self> {
|
||||
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
|
||||
Empty::new().boxed()
|
||||
}
|
||||
}
|
||||
|
@ -941,7 +941,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for TestElement {
|
||||
impl<V: View> Drawable<V> for TestElement {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -10,14 +10,14 @@ use crate::{
|
|||
CursorRegion, HandlerSet, MouseClick, MouseDown, MouseDownOut, MouseDrag, MouseHover,
|
||||
MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut,
|
||||
},
|
||||
Element, ElementBox, EventContext, MouseRegion, MouseState, SceneBuilder, SizeConstraint, View,
|
||||
Drawable, 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: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
region_id: usize,
|
||||
cursor_style: Option<CursorStyle>,
|
||||
handlers: HandlerSet,
|
||||
|
@ -35,7 +35,7 @@ impl<Tag, V: View> MouseEventHandler<Tag, V> {
|
|||
pub fn new<F>(region_id: usize, cx: &mut ViewContext<V>, render_child: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> ElementBox<V>,
|
||||
F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> Element<V>,
|
||||
{
|
||||
let mut mouse_state = cx.mouse_state::<Tag>(region_id);
|
||||
let child = render_child(&mut mouse_state, cx);
|
||||
|
@ -61,7 +61,7 @@ impl<Tag, V: View> MouseEventHandler<Tag, V> {
|
|||
pub fn above<F>(region_id: usize, cx: &mut ViewContext<V>, render_child: F) -> Self
|
||||
where
|
||||
V: View,
|
||||
F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> ElementBox<V>,
|
||||
F: FnOnce(&mut MouseState, &mut ViewContext<V>) -> Element<V>,
|
||||
{
|
||||
let mut handler = Self::new(region_id, cx, render_child);
|
||||
handler.above = true;
|
||||
|
@ -212,7 +212,7 @@ impl<Tag, V: View> MouseEventHandler<Tag, V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Tag, V: View> Element<V> for MouseEventHandler<Tag, V> {
|
||||
impl<Tag, V: View> Drawable<V> for MouseEventHandler<Tag, V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -3,12 +3,12 @@ use std::ops::Range;
|
|||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json::ToJson,
|
||||
Axis, Element, ElementBox, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
Axis, Drawable, Element, MouseRegion, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
};
|
||||
use serde_json::json;
|
||||
|
||||
pub struct Overlay<V: View> {
|
||||
child: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
anchor_position: Option<Vector2F>,
|
||||
anchor_corner: AnchorCorner,
|
||||
fit_mode: OverlayFitMode,
|
||||
|
@ -73,7 +73,7 @@ impl AnchorCorner {
|
|||
}
|
||||
|
||||
impl<V: View> Overlay<V> {
|
||||
pub fn new(child: ElementBox<V>) -> Self {
|
||||
pub fn new(child: Element<V>) -> Self {
|
||||
Self {
|
||||
child,
|
||||
anchor_position: None,
|
||||
|
@ -116,7 +116,7 @@ impl<V: View> Overlay<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Overlay<V> {
|
||||
impl<V: View> Drawable<V> for Overlay<V> {
|
||||
type LayoutState = Vector2F;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
geometry::rect::RectF,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
scene::MouseDrag,
|
||||
Axis, Element, ElementBox, ElementStateHandle, MouseRegion, SceneBuilder, View, ViewContext,
|
||||
Axis, Drawable, 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: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
state: Rc<ResizeHandleState>,
|
||||
_state_handle: ElementStateHandle<Rc<ResizeHandleState>>,
|
||||
}
|
||||
|
||||
impl<V: View> Resizable<V> {
|
||||
pub fn new<Tag: 'static, T: View>(
|
||||
child: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
element_id: usize,
|
||||
side: Side,
|
||||
handle_size: f32,
|
||||
|
@ -132,7 +132,7 @@ impl<V: View> Resizable<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Resizable<V> {
|
||||
impl<V: View> Drawable<V> for Resizable<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -3,13 +3,13 @@ use std::ops::Range;
|
|||
use crate::{
|
||||
geometry::{rect::RectF, vector::Vector2F},
|
||||
json::{self, json, ToJson},
|
||||
Element, ElementBox, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
Drawable, Element, 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<ElementBox<V>>,
|
||||
children: Vec<Element<V>>,
|
||||
}
|
||||
|
||||
impl<V: View> Default for Stack<V> {
|
||||
|
@ -26,7 +26,7 @@ impl<V: View> Stack<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Stack<V> {
|
||||
impl<V: View> Drawable<V> for Stack<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
@ -98,8 +98,8 @@ impl<V: View> Element<V> for Stack<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Extend<ElementBox<V>> for Stack<V> {
|
||||
fn extend<T: IntoIterator<Item = ElementBox<V>>>(&mut self, children: T) {
|
||||
impl<V: View> Extend<Element<V>> for Stack<V> {
|
||||
fn extend<T: IntoIterator<Item = Element<V>>>(&mut self, children: T) {
|
||||
self.children.extend(children)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
rect::RectF,
|
||||
vector::{vec2f, Vector2F},
|
||||
},
|
||||
scene, Element, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
scene, Drawable, SceneBuilder, SizeConstraint, View, ViewContext,
|
||||
};
|
||||
|
||||
pub struct Svg {
|
||||
|
@ -30,7 +30,7 @@ impl Svg {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Svg {
|
||||
impl<V: View> Drawable<V> for Svg {
|
||||
type LayoutState = Option<usvg::Tree>;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
|||
},
|
||||
json::{ToJson, Value},
|
||||
text_layout::{Line, RunStyle, ShapedBoundary},
|
||||
Element, FontCache, SceneBuilder, SizeConstraint, TextLayoutCache, View, ViewContext,
|
||||
Drawable, FontCache, SceneBuilder, SizeConstraint, TextLayoutCache, View, ViewContext,
|
||||
};
|
||||
use log::warn;
|
||||
use serde_json::json;
|
||||
|
@ -52,7 +52,7 @@ impl Text {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Text {
|
||||
impl<V: View> Drawable<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, ElementBox, Entity, View, ViewContext};
|
||||
use crate::{elements::Empty, fonts, AppContext, Element, Entity, View, ViewContext};
|
||||
|
||||
#[crate::test(self)]
|
||||
fn test_soft_wrapping_with_carriage_returns(cx: &mut AppContext) {
|
||||
|
@ -306,7 +306,7 @@ mod tests {
|
|||
"TestView"
|
||||
}
|
||||
|
||||
fn render(&mut self, _: &mut ViewContext<Self>) -> ElementBox<Self> {
|
||||
fn render(&mut self, _: &mut ViewContext<Self>) -> Element<Self> {
|
||||
Empty::new().boxed()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::{
|
||||
ContainerStyle, Element, ElementBox, Flex, KeystrokeLabel, MouseEventHandler, Overlay,
|
||||
ContainerStyle, Drawable, Element, Flex, KeystrokeLabel, MouseEventHandler, Overlay,
|
||||
OverlayFitMode, ParentElement, Text,
|
||||
};
|
||||
use crate::{
|
||||
|
@ -19,8 +19,8 @@ use std::{
|
|||
const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(500);
|
||||
|
||||
pub struct Tooltip<V: View> {
|
||||
child: ElementBox<V>,
|
||||
tooltip: Option<ElementBox<V>>,
|
||||
child: Element<V>,
|
||||
tooltip: Option<Element<V>>,
|
||||
_state: ElementStateHandle<Rc<TooltipState>>,
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ impl<V: View> Tooltip<V> {
|
|||
text: String,
|
||||
action: Option<Box<dyn Action>>,
|
||||
style: TooltipStyle,
|
||||
child: ElementBox<V>,
|
||||
child: Element<V>,
|
||||
cx: &mut ViewContext<V>,
|
||||
) -> Self {
|
||||
struct ElementState<Tag>(Tag);
|
||||
|
@ -134,7 +134,7 @@ impl<V: View> Tooltip<V> {
|
|||
style: TooltipStyle,
|
||||
action: Option<Box<dyn Action>>,
|
||||
measure: bool,
|
||||
) -> impl Element<V> {
|
||||
) -> impl Drawable<V> {
|
||||
Flex::row()
|
||||
.with_child({
|
||||
let text = Text::new(text, style.text)
|
||||
|
@ -165,7 +165,7 @@ impl<V: View> Tooltip<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for Tooltip<V> {
|
||||
impl<V: View> Drawable<V> for Tooltip<V> {
|
||||
type LayoutState = ();
|
||||
type PaintState = ();
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::{Element, SizeConstraint};
|
||||
use super::{Drawable, SizeConstraint};
|
||||
use crate::{
|
||||
geometry::{
|
||||
rect::RectF,
|
||||
|
@ -6,7 +6,7 @@ use crate::{
|
|||
},
|
||||
json::{self, json},
|
||||
platform::ScrollWheelEvent,
|
||||
ElementBox, MouseRegion, SceneBuilder, View, ViewContext,
|
||||
Element, 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<ElementBox<V>>,
|
||||
items: Vec<Element<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<ElementBox<V>>, &mut ViewContext<V>)>,
|
||||
append_items: Box<dyn Fn(&mut V, Range<usize>, &mut Vec<Element<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<ElementBox<V>>, &mut ViewContext<V>),
|
||||
F: 'static + Fn(&mut V, Range<usize>, &mut Vec<Element<V>>, &mut ViewContext<V>),
|
||||
{
|
||||
Self {
|
||||
state,
|
||||
|
@ -151,7 +151,7 @@ impl<V: View> UniformList<V> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<V: View> Element<V> for UniformList<V> {
|
||||
impl<V: View> Drawable<V> for UniformList<V> {
|
||||
type LayoutState = LayoutState<V>;
|
||||
type PaintState = ();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue