Merge branch 'main' into disclosable-component

This commit is contained in:
Mikayla
2023-08-23 16:30:27 -07:00
139 changed files with 13495 additions and 1061 deletions
+4 -4
View File
@@ -1,18 +1,18 @@
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
ViewContext,
};
use json::ToJson;
use serde_json::json;
pub struct Align<V: View> {
pub struct Align<V> {
child: AnyElement<V>,
alignment: Vector2F,
}
impl<V: View> Align<V> {
impl<V> Align<V> {
pub fn new(child: AnyElement<V>) -> Self {
Self {
child,
@@ -41,7 +41,7 @@ impl<V: View> Align<V> {
}
}
impl<V: View> Element<V> for Align<V> {
impl<V: 'static> Element<V> for Align<V> {
type LayoutState = ();
type PaintState = ();
+2 -3
View File
@@ -3,7 +3,7 @@ use std::marker::PhantomData;
use super::Element;
use crate::{
json::{self, json},
PaintContext, SceneBuilder, View, ViewContext,
PaintContext, SceneBuilder, ViewContext,
};
use json::ToJson;
use pathfinder_geometry::{
@@ -15,7 +15,6 @@ pub struct Canvas<V, F>(F, PhantomData<V>);
impl<V, F> Canvas<V, F>
where
V: View,
F: FnMut(&mut SceneBuilder, RectF, RectF, &mut V, &mut ViewContext<V>),
{
pub fn new(f: F) -> Self {
@@ -23,7 +22,7 @@ where
}
}
impl<V: View, F> Element<V> for Canvas<V, F>
impl<V: 'static, F> Element<V> for Canvas<V, F>
where
F: 'static + FnMut(&mut SceneBuilder, RectF, RectF, &mut V, &mut ViewContext<V>),
{
+4 -4
View File
@@ -4,21 +4,21 @@ use pathfinder_geometry::{rect::RectF, vector::Vector2F};
use serde_json::json;
use crate::{
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
ViewContext,
};
pub struct Clipped<V: View> {
pub struct Clipped<V> {
child: AnyElement<V>,
}
impl<V: View> Clipped<V> {
impl<V> Clipped<V> {
pub fn new(child: AnyElement<V>) -> Self {
Self { child }
}
}
impl<V: View> Element<V> for Clipped<V> {
impl<V: 'static> Element<V> for Clipped<V> {
type LayoutState = ();
type PaintState = ();
+25 -24
View File
@@ -3,17 +3,16 @@ use std::{any::Any, marker::PhantomData};
use pathfinder_geometry::{rect::RectF, vector::Vector2F};
use crate::{
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
ViewContext,
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext,
};
use super::Empty;
/// The core stateless component trait, simply rendering an element tree
pub trait Component {
fn render<V: View>(self, cx: &mut ViewContext<V>) -> AnyElement<V>;
fn render<V: 'static>(self, cx: &mut ViewContext<V>) -> AnyElement<V>;
fn element<V: View>(self) -> ComponentAdapter<V, Self>
fn element<V: 'static>(self) -> ComponentAdapter<V, Self>
where
Self: Sized,
{
@@ -27,7 +26,7 @@ pub trait Component {
StylableAdapter::new(self)
}
fn stateful<V: View>(self) -> StatefulAdapter<Self, V>
fn stateful<V: 'static>(self) -> StatefulAdapter<Self, V>
where
Self: Sized,
{
@@ -91,7 +90,7 @@ impl<C: Component> SafeStylable for StylableAdapter<C> {
/// want to take click handler callbacks Unfortunately, the generic bound on the
/// Component trait makes it incompatible with the stateless components above.
// So let's just replicate them for now
pub trait StatefulComponent<V: View> {
pub trait StatefulComponent<V: 'static> {
fn render(self, v: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V>;
fn element(self) -> ComponentAdapter<V, Self>
@@ -118,21 +117,21 @@ pub trait StatefulComponent<V: View> {
/// It is trivial to convert stateless components to stateful components, so lets
/// do so en masse. Note that the reverse is impossible without a helper.
impl<V: View, C: Component> StatefulComponent<V> for C {
impl<V: 'static, C: Component> StatefulComponent<V> for C {
fn render(self, _: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V> {
self.render(cx)
}
}
/// Same as stylable, but generic over a view type
pub trait StatefulStylable<V: View>: StatefulComponent<V> {
pub trait StatefulStylable<V: 'static>: StatefulComponent<V> {
type Style: Clone;
fn with_style(self, style: Self::Style) -> Self;
}
/// Same as SafeStylable, but generic over a view type
pub trait StatefulSafeStylable<V: View> {
pub trait StatefulSafeStylable<V: 'static> {
type Style: Clone;
type Output: StatefulComponent<V>;
@@ -140,7 +139,7 @@ pub trait StatefulSafeStylable<V: View> {
}
/// Converting from stateless to stateful
impl<V: View, C: SafeStylable> StatefulSafeStylable<V> for C {
impl<V: 'static, C: SafeStylable> StatefulSafeStylable<V> for C {
type Style = C::Style;
type Output = C::Output;
@@ -156,7 +155,7 @@ pub struct StatefulAdapter<C, V> {
phantom: std::marker::PhantomData<V>,
}
impl<C: Component, V: View> StatefulAdapter<C, V> {
impl<C: Component, V: 'static> StatefulAdapter<C, V> {
pub fn new(component: C) -> Self {
Self {
component,
@@ -165,7 +164,7 @@ impl<C: Component, V: View> StatefulAdapter<C, V> {
}
}
impl<C: Component, V: View> StatefulComponent<V> for StatefulAdapter<C, V> {
impl<C: Component, V: 'static> StatefulComponent<V> for StatefulAdapter<C, V> {
fn render(self, _: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V> {
self.component.render(cx)
}
@@ -173,12 +172,12 @@ impl<C: Component, V: View> StatefulComponent<V> for StatefulAdapter<C, V> {
// A helper for converting stateful but style-less components into stylable ones
// by using `()` as the style type
pub struct StatefulStylableAdapter<C: StatefulComponent<V>, V: View> {
pub struct StatefulStylableAdapter<C: StatefulComponent<V>, V: 'static> {
component: C,
phantom: std::marker::PhantomData<V>,
}
impl<C: StatefulComponent<V>, V: View> StatefulStylableAdapter<C, V> {
impl<C: StatefulComponent<V>, V: 'static> StatefulStylableAdapter<C, V> {
pub fn new(component: C) -> Self {
Self {
component,
@@ -187,7 +186,9 @@ impl<C: StatefulComponent<V>, V: View> StatefulStylableAdapter<C, V> {
}
}
impl<C: StatefulComponent<V>, V: View> StatefulSafeStylable<V> for StatefulStylableAdapter<C, V> {
impl<C: StatefulComponent<V>, V: 'static> StatefulSafeStylable<V>
for StatefulStylableAdapter<C, V>
{
type Style = ();
type Output = C;
@@ -205,7 +206,7 @@ pub struct StatelessElementAdapter {
}
impl StatelessElementAdapter {
pub fn new<V: View>(element: AnyElement<V>) -> Self {
pub fn new<V: 'static>(element: AnyElement<V>) -> Self {
StatelessElementAdapter {
element: Box::new(element) as Box<dyn Any>,
}
@@ -213,7 +214,7 @@ impl StatelessElementAdapter {
}
impl Component for StatelessElementAdapter {
fn render<V: View>(self, _: &mut ViewContext<V>) -> AnyElement<V> {
fn render<V: 'static>(self, _: &mut ViewContext<V>) -> AnyElement<V> {
*self
.element
.downcast::<AnyElement<V>>()
@@ -222,12 +223,12 @@ impl Component for StatelessElementAdapter {
}
// For converting elements into stateful components
pub struct StatefulElementAdapter<V: View> {
pub struct StatefulElementAdapter<V: 'static> {
element: AnyElement<V>,
_phantom: std::marker::PhantomData<V>,
}
impl<V: View> StatefulElementAdapter<V> {
impl<V: 'static> StatefulElementAdapter<V> {
pub fn new(element: AnyElement<V>) -> Self {
Self {
element,
@@ -236,7 +237,7 @@ impl<V: View> StatefulElementAdapter<V> {
}
}
impl<V: View> StatefulComponent<V> for StatefulElementAdapter<V> {
impl<V: 'static> StatefulComponent<V> for StatefulElementAdapter<V> {
fn render(self, _: &mut V, _: &mut ViewContext<V>) -> AnyElement<V> {
self.element
}
@@ -244,7 +245,7 @@ impl<V: View> StatefulComponent<V> for StatefulElementAdapter<V> {
/// A convenient shorthand for creating an empty component.
impl Component for () {
fn render<V: View>(self, _: &mut ViewContext<V>) -> AnyElement<V> {
fn render<V: 'static>(self, _: &mut ViewContext<V>) -> AnyElement<V> {
Empty::new().into_any()
}
}
@@ -258,13 +259,13 @@ impl Stylable for () {
}
// For converting components back into Elements
pub struct ComponentAdapter<V: View, E> {
pub struct ComponentAdapter<V: 'static, E> {
component: Option<E>,
element: Option<AnyElement<V>>,
phantom: PhantomData<V>,
}
impl<E, V: View> ComponentAdapter<V, E> {
impl<E, V: 'static> ComponentAdapter<V, E> {
pub fn new(e: E) -> Self {
Self {
component: Some(e),
@@ -274,7 +275,7 @@ impl<E, V: View> ComponentAdapter<V, E> {
}
}
impl<V: View, C: StatefulComponent<V> + 'static> Element<V> for ComponentAdapter<V, C> {
impl<V: 'static, C: StatefulComponent<V> + 'static> Element<V> for ComponentAdapter<V, C> {
type LayoutState = ();
type PaintState = ();
+6 -6
View File
@@ -5,21 +5,21 @@ use serde_json::json;
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
ViewContext,
};
pub struct ConstrainedBox<V: View> {
pub struct ConstrainedBox<V> {
child: AnyElement<V>,
constraint: Constraint<V>,
}
pub enum Constraint<V: View> {
pub enum Constraint<V> {
Static(SizeConstraint),
Dynamic(Box<dyn FnMut(SizeConstraint, &mut V, &mut LayoutContext<V>) -> SizeConstraint>),
}
impl<V: View> ToJson for Constraint<V> {
impl<V> ToJson for Constraint<V> {
fn to_json(&self) -> serde_json::Value {
match self {
Constraint::Static(constraint) => constraint.to_json(),
@@ -28,7 +28,7 @@ impl<V: View> ToJson for Constraint<V> {
}
}
impl<V: View> ConstrainedBox<V> {
impl<V: 'static> ConstrainedBox<V> {
pub fn new(child: impl Element<V>) -> Self {
Self {
child: child.into_any(),
@@ -132,7 +132,7 @@ impl<V: View> ConstrainedBox<V> {
}
}
impl<V: View> Element<V> for ConstrainedBox<V> {
impl<V: 'static> Element<V> for ConstrainedBox<V> {
type LayoutState = ();
type PaintState = ();
+5 -6
View File
@@ -10,8 +10,7 @@ use crate::{
json::ToJson,
platform::CursorStyle,
scene::{self, Border, CornerRadii, CursorRegion, Quad},
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
ViewContext,
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext,
};
use schemars::JsonSchema;
use serde::Deserialize;
@@ -55,12 +54,12 @@ impl ContainerStyle {
}
}
pub struct Container<V: View> {
pub struct Container<V> {
child: AnyElement<V>,
style: ContainerStyle,
}
impl<V: View> Container<V> {
impl<V> Container<V> {
pub fn new(child: AnyElement<V>) -> Self {
Self {
child,
@@ -207,7 +206,7 @@ impl<V: View> Container<V> {
}
}
impl<V: View> Element<V> for Container<V> {
impl<V: 'static> Element<V> for Container<V> {
type LayoutState = ();
type PaintState = ();
@@ -358,8 +357,8 @@ impl ToJson for ContainerStyle {
#[derive(Clone, Copy, Debug, Default, JsonSchema)]
pub struct Margin {
pub top: f32,
pub left: f32,
pub bottom: f32,
pub left: f32,
pub right: f32,
}
+2 -2
View File
@@ -6,7 +6,7 @@ use crate::{
vector::{vec2f, Vector2F},
},
json::{json, ToJson},
LayoutContext, PaintContext, SceneBuilder, View, ViewContext,
LayoutContext, PaintContext, SceneBuilder, ViewContext,
};
use crate::{Element, SizeConstraint};
@@ -26,7 +26,7 @@ impl Empty {
}
}
impl<V: View> Element<V> for Empty {
impl<V: 'static> Element<V> for Empty {
type LayoutState = ();
type PaintState = ();
+4 -4
View File
@@ -2,18 +2,18 @@ use std::ops::Range;
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
json, AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
ViewContext,
};
use serde_json::json;
pub struct Expanded<V: View> {
pub struct Expanded<V> {
child: AnyElement<V>,
full_width: bool,
full_height: bool,
}
impl<V: View> Expanded<V> {
impl<V: 'static> Expanded<V> {
pub fn new(child: impl Element<V>) -> Self {
Self {
child: child.into_any(),
@@ -35,7 +35,7 @@ impl<V: View> Expanded<V> {
}
}
impl<V: View> Element<V> for Expanded<V> {
impl<V: 'static> Element<V> for Expanded<V> {
type LayoutState = ();
type PaintState = ();
+8 -8
View File
@@ -3,7 +3,7 @@ use std::{any::Any, cell::Cell, f32::INFINITY, ops::Range, rc::Rc};
use crate::{
json::{self, ToJson, Value},
AnyElement, Axis, Element, ElementStateHandle, LayoutContext, PaintContext, SceneBuilder,
SizeConstraint, Vector2FExt, View, ViewContext,
SizeConstraint, Vector2FExt, ViewContext,
};
use pathfinder_geometry::{
rect::RectF,
@@ -17,7 +17,7 @@ struct ScrollState {
scroll_position: Cell<f32>,
}
pub struct Flex<V: View> {
pub struct Flex<V> {
axis: Axis,
children: Vec<AnyElement<V>>,
scroll_state: Option<(ElementStateHandle<Rc<ScrollState>>, usize)>,
@@ -25,7 +25,7 @@ pub struct Flex<V: View> {
spacing: f32,
}
impl<V: View> Flex<V> {
impl<V: 'static> Flex<V> {
pub fn new(axis: Axis) -> Self {
Self {
axis,
@@ -127,13 +127,13 @@ impl<V: View> Flex<V> {
}
}
impl<V: View> Extend<AnyElement<V>> for Flex<V> {
impl<V> Extend<AnyElement<V>> for Flex<V> {
fn extend<T: IntoIterator<Item = AnyElement<V>>>(&mut self, children: T) {
self.children.extend(children);
}
}
impl<V: View> Element<V> for Flex<V> {
impl<V: 'static> Element<V> for Flex<V> {
type LayoutState = f32;
type PaintState = ();
@@ -422,12 +422,12 @@ struct FlexParentData {
float: bool,
}
pub struct FlexItem<V: View> {
pub struct FlexItem<V> {
metadata: FlexParentData,
child: AnyElement<V>,
}
impl<V: View> FlexItem<V> {
impl<V: 'static> FlexItem<V> {
pub fn new(child: impl Element<V>) -> Self {
FlexItem {
metadata: FlexParentData {
@@ -449,7 +449,7 @@ impl<V: View> FlexItem<V> {
}
}
impl<V: View> Element<V> for FlexItem<V> {
impl<V: 'static> Element<V> for FlexItem<V> {
type LayoutState = ();
type PaintState = ();
+4 -5
View File
@@ -3,16 +3,15 @@ use std::ops::Range;
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json::json,
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
ViewContext,
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext,
};
pub struct Hook<V: View> {
pub struct Hook<V> {
child: AnyElement<V>,
after_layout: Option<Box<dyn FnMut(Vector2F, &mut ViewContext<V>)>>,
}
impl<V: View> Hook<V> {
impl<V: 'static> Hook<V> {
pub fn new(child: impl Element<V>) -> Self {
Self {
child: child.into_any(),
@@ -29,7 +28,7 @@ impl<V: View> Hook<V> {
}
}
impl<V: View> Element<V> for Hook<V> {
impl<V: 'static> Element<V> for Hook<V> {
type LayoutState = ();
type PaintState = ();
+2 -2
View File
@@ -6,7 +6,7 @@ use crate::{
},
json::{json, ToJson},
scene, Border, Element, ImageData, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
View, ViewContext,
ViewContext,
};
use schemars::JsonSchema;
use serde::Deserialize;
@@ -57,7 +57,7 @@ impl Image {
}
}
impl<V: View> Element<V> for Image {
impl<V: 'static> Element<V> for Image {
type LayoutState = Option<Arc<ImageData>>;
type PaintState = ();
+1 -1
View File
@@ -31,7 +31,7 @@ impl KeystrokeLabel {
}
}
impl<V: View> Element<V> for KeystrokeLabel {
impl<V: 'static> Element<V> for KeystrokeLabel {
type LayoutState = AnyElement<V>;
type PaintState = ();
+2 -2
View File
@@ -8,7 +8,7 @@ use crate::{
},
json::{ToJson, Value},
text_layout::{Line, RunStyle},
Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View, ViewContext,
Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, ViewContext,
};
use schemars::JsonSchema;
use serde::Deserialize;
@@ -128,7 +128,7 @@ impl Label {
}
}
impl<V: View> Element<V> for Label {
impl<V: 'static> Element<V> for Label {
type LayoutState = Line;
type PaintState = ();
+16 -16
View File
@@ -5,16 +5,16 @@ use crate::{
},
json::json,
AnyElement, Element, LayoutContext, MouseRegion, PaintContext, SceneBuilder, SizeConstraint,
View, ViewContext,
ViewContext,
};
use std::{cell::RefCell, collections::VecDeque, fmt::Debug, ops::Range, rc::Rc};
use sum_tree::{Bias, SumTree};
pub struct List<V: View> {
pub struct List<V> {
state: ListState<V>,
}
pub struct ListState<V: View>(Rc<RefCell<StateInner<V>>>);
pub struct ListState<V>(Rc<RefCell<StateInner<V>>>);
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Orientation {
@@ -22,7 +22,7 @@ pub enum Orientation {
Bottom,
}
struct StateInner<V: View> {
struct StateInner<V> {
last_layout_width: Option<f32>,
render_item: Box<dyn FnMut(&mut V, usize, &mut ViewContext<V>) -> AnyElement<V>>,
rendered_range: Range<usize>,
@@ -40,13 +40,13 @@ pub struct ListOffset {
pub offset_in_item: f32,
}
enum ListItem<V: View> {
enum ListItem<V> {
Unrendered,
Rendered(Rc<RefCell<AnyElement<V>>>),
Removed(f32),
}
impl<V: View> Clone for ListItem<V> {
impl<V> Clone for ListItem<V> {
fn clone(&self) -> Self {
match self {
Self::Unrendered => Self::Unrendered,
@@ -56,7 +56,7 @@ impl<V: View> Clone for ListItem<V> {
}
}
impl<V: View> Debug for ListItem<V> {
impl<V> Debug for ListItem<V> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Unrendered => write!(f, "Unrendered"),
@@ -86,13 +86,13 @@ struct UnrenderedCount(usize);
#[derive(Clone, Debug, Default)]
struct Height(f32);
impl<V: View> List<V> {
impl<V> List<V> {
pub fn new(state: ListState<V>) -> Self {
Self { state }
}
}
impl<V: View> Element<V> for List<V> {
impl<V: 'static> Element<V> for List<V> {
type LayoutState = ListOffset;
type PaintState = ();
@@ -347,7 +347,7 @@ impl<V: View> Element<V> for List<V> {
}
}
impl<V: View> ListState<V> {
impl<V: 'static> ListState<V> {
pub fn new<D, F>(
element_count: usize,
orientation: Orientation,
@@ -440,13 +440,13 @@ impl<V: View> ListState<V> {
}
}
impl<V: View> Clone for ListState<V> {
impl<V> Clone for ListState<V> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<V: View> StateInner<V> {
impl<V: 'static> StateInner<V> {
fn render_item(
&mut self,
ix: usize,
@@ -560,7 +560,7 @@ impl<V: View> StateInner<V> {
}
}
impl<V: View> ListItem<V> {
impl<V> ListItem<V> {
fn remove(&self) -> Self {
match self {
ListItem::Unrendered => ListItem::Unrendered,
@@ -570,7 +570,7 @@ impl<V: View> ListItem<V> {
}
}
impl<V: View> sum_tree::Item for ListItem<V> {
impl<V> sum_tree::Item for ListItem<V> {
type Summary = ListItemSummary;
fn summary(&self) -> Self::Summary {
@@ -944,7 +944,7 @@ mod tests {
type Event = ();
}
impl View for TestView {
impl crate::View for TestView {
fn ui_name() -> &'static str {
"TestView"
}
@@ -968,7 +968,7 @@ mod tests {
}
}
impl<V: View> Element<V> for TestElement {
impl<V: 'static> Element<V> for TestElement {
type LayoutState = ();
type PaintState = ();
@@ -11,12 +11,12 @@ use crate::{
MouseHover, MouseMove, MouseMoveOut, MouseScrollWheel, MouseUp, MouseUpOut,
},
AnyElement, Element, EventContext, LayoutContext, MouseRegion, MouseState, PaintContext,
SceneBuilder, SizeConstraint, TypeTag, View, ViewContext,
SceneBuilder, SizeConstraint, TypeTag, ViewContext,
};
use serde_json::json;
use std::ops::Range;
pub struct MouseEventHandler<V: View> {
pub struct MouseEventHandler<V: 'static> {
child: AnyElement<V>,
region_id: usize,
cursor_style: Option<CursorStyle>,
@@ -31,7 +31,7 @@ pub struct MouseEventHandler<V: View> {
/// Element which provides a render_child callback with a MouseState and paints a mouse
/// region under (or above) it for easy mouse event handling.
impl<V: View> MouseEventHandler<V> {
impl<V: 'static> MouseEventHandler<V> {
pub fn for_child<Tag: 'static>(child: impl Element<V>, region_id: usize) -> Self {
Self {
child: child.into_any(),
@@ -267,7 +267,7 @@ impl<V: View> MouseEventHandler<V> {
}
}
impl<V: View> Element<V> for MouseEventHandler<V> {
impl<V: 'static> Element<V> for MouseEventHandler<V> {
type LayoutState = ();
type PaintState = ();
+4 -4
View File
@@ -4,11 +4,11 @@ use crate::{
geometry::{rect::RectF, vector::Vector2F},
json::ToJson,
AnyElement, Axis, Element, LayoutContext, MouseRegion, PaintContext, SceneBuilder,
SizeConstraint, View, ViewContext,
SizeConstraint, ViewContext,
};
use serde_json::json;
pub struct Overlay<V: View> {
pub struct Overlay<V> {
child: AnyElement<V>,
anchor_position: Option<Vector2F>,
anchor_corner: AnchorCorner,
@@ -73,7 +73,7 @@ impl AnchorCorner {
}
}
impl<V: View> Overlay<V> {
impl<V: 'static> Overlay<V> {
pub fn new(child: impl Element<V>) -> Self {
Self {
child: child.into_any(),
@@ -117,7 +117,7 @@ impl<V: View> Overlay<V> {
}
}
impl<V: View> Element<V> for Overlay<V> {
impl<V: 'static> Element<V> for Overlay<V> {
type LayoutState = Vector2F;
type PaintState = ();
+5 -5
View File
@@ -59,7 +59,7 @@ where
.and_then(|map| map.0.get(&tag))
}
pub struct Resizable<V: View> {
pub struct Resizable<V: 'static> {
child: AnyElement<V>,
tag: TypeTag,
handle_side: HandleSide,
@@ -69,7 +69,7 @@ pub struct Resizable<V: View> {
const DEFAULT_HANDLE_SIZE: f32 = 4.0;
impl<V: View> Resizable<V> {
impl<V: 'static> Resizable<V> {
pub fn new<Tag: 'static>(
child: AnyElement<V>,
handle_side: HandleSide,
@@ -97,7 +97,7 @@ impl<V: View> Resizable<V> {
}
}
impl<V: View> Element<V> for Resizable<V> {
impl<V: 'static> Element<V> for Resizable<V> {
type LayoutState = SizeConstraint;
type PaintState = ();
@@ -219,12 +219,12 @@ impl<V: View> Element<V> for Resizable<V> {
#[derive(Debug, Default)]
struct ProviderMap(HashMap<TypeTag, (RectF, RectF)>);
pub struct BoundsProvider<V: View, P> {
pub struct BoundsProvider<V: 'static, P> {
child: AnyElement<V>,
phantom: std::marker::PhantomData<P>,
}
impl<V: View, P: 'static> BoundsProvider<V, P> {
impl<V: 'static, P: 'static> BoundsProvider<V, P> {
pub fn new(child: AnyElement<V>) -> Self {
Self {
child,
+6 -7
View File
@@ -3,17 +3,16 @@ use std::ops::Range;
use crate::{
geometry::{rect::RectF, vector::Vector2F},
json::{self, json, ToJson},
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, View,
ViewContext,
AnyElement, Element, LayoutContext, PaintContext, SceneBuilder, SizeConstraint, 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> {
pub struct Stack<V> {
children: Vec<AnyElement<V>>,
}
impl<V: View> Default for Stack<V> {
impl<V> Default for Stack<V> {
fn default() -> Self {
Self {
children: Vec::new(),
@@ -21,13 +20,13 @@ impl<V: View> Default for Stack<V> {
}
}
impl<V: View> Stack<V> {
impl<V> Stack<V> {
pub fn new() -> Self {
Self::default()
}
}
impl<V: View> Element<V> for Stack<V> {
impl<V: 'static> Element<V> for Stack<V> {
type LayoutState = ();
type PaintState = ();
@@ -99,7 +98,7 @@ impl<V: View> Element<V> for Stack<V> {
}
}
impl<V: View> Extend<AnyElement<V>> for Stack<V> {
impl<V> Extend<AnyElement<V>> for Stack<V> {
fn extend<T: IntoIterator<Item = AnyElement<V>>>(&mut self, children: T) {
self.children.extend(children)
}
+3 -3
View File
@@ -7,7 +7,7 @@ use crate::{
rect::RectF,
vector::{vec2f, Vector2F},
},
scene, Element, LayoutContext, SceneBuilder, SizeConstraint, View, ViewContext,
scene, Element, LayoutContext, SceneBuilder, SizeConstraint, ViewContext,
};
use schemars::JsonSchema;
use serde_derive::Deserialize;
@@ -27,7 +27,7 @@ impl Svg {
}
}
pub fn for_style<V: View>(style: SvgStyle) -> impl Element<V> {
pub fn for_style<V: 'static>(style: SvgStyle) -> impl Element<V> {
Self::new(style.asset)
.with_color(style.color)
.constrained()
@@ -41,7 +41,7 @@ impl Svg {
}
}
impl<V: View> Element<V> for Svg {
impl<V: 'static> Element<V> for Svg {
type LayoutState = Option<usvg::Tree>;
type PaintState = ();
+3 -3
View File
@@ -8,7 +8,7 @@ use crate::{
json::{ToJson, Value},
text_layout::{Line, RunStyle, ShapedBoundary},
AppContext, Element, FontCache, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
TextLayoutCache, View, ViewContext,
TextLayoutCache, ViewContext,
};
use log::warn;
use serde_json::json;
@@ -70,7 +70,7 @@ impl Text {
}
}
impl<V: View> Element<V> for Text {
impl<V: 'static> Element<V> for Text {
type LayoutState = LayoutState;
type PaintState = ();
@@ -338,7 +338,7 @@ impl<V: View> Element<V> for Text {
}
/// Perform text layout on a series of highlighted chunks of text.
fn layout_highlighted_chunks<'a>(
pub fn layout_highlighted_chunks<'a>(
chunks: impl Iterator<Item = (&'a str, Option<HighlightStyle>)>,
text_style: &TextStyle,
text_layout_cache: &TextLayoutCache,
+4 -4
View File
@@ -7,7 +7,7 @@ use crate::{
geometry::{rect::RectF, vector::Vector2F},
json::json,
Action, Axis, ElementStateHandle, LayoutContext, PaintContext, SceneBuilder, SizeConstraint,
Task, TypeTag, View, ViewContext,
Task, TypeTag, ViewContext,
};
use schemars::JsonSchema;
use serde::Deserialize;
@@ -22,7 +22,7 @@ use util::ResultExt;
const DEBOUNCE_TIMEOUT: Duration = Duration::from_millis(500);
pub struct Tooltip<V: View> {
pub struct Tooltip<V> {
child: AnyElement<V>,
tooltip: Option<AnyElement<V>>,
_state: ElementStateHandle<Rc<TooltipState>>,
@@ -52,7 +52,7 @@ pub struct KeystrokeStyle {
text: TextStyle,
}
impl<V: View> Tooltip<V> {
impl<V: 'static> Tooltip<V> {
pub fn new<Tag: 'static>(
id: usize,
text: impl Into<Cow<'static, str>>,
@@ -181,7 +181,7 @@ impl<V: View> Tooltip<V> {
}
}
impl<V: View> Element<V> for Tooltip<V> {
impl<V: 'static> Element<V> for Tooltip<V> {
type LayoutState = ();
type PaintState = ();
+5 -6
View File
@@ -6,7 +6,7 @@ use crate::{
},
json::{self, json},
platform::ScrollWheelEvent,
AnyElement, LayoutContext, MouseRegion, PaintContext, SceneBuilder, View, ViewContext,
AnyElement, LayoutContext, MouseRegion, PaintContext, SceneBuilder, ViewContext,
};
use json::ToJson;
use std::{cell::RefCell, cmp, ops::Range, rc::Rc};
@@ -36,13 +36,13 @@ struct StateInner {
scroll_to: Option<ScrollTarget>,
}
pub struct UniformListLayoutState<V: View> {
pub struct UniformListLayoutState<V> {
scroll_max: f32,
item_height: f32,
items: Vec<AnyElement<V>>,
}
pub struct UniformList<V: View> {
pub struct UniformList<V> {
state: UniformListState,
item_count: usize,
#[allow(clippy::type_complexity)]
@@ -53,7 +53,7 @@ pub struct UniformList<V: View> {
view_id: usize,
}
impl<V: View> UniformList<V> {
impl<V: 'static> UniformList<V> {
pub fn new<F>(
state: UniformListState,
item_count: usize,
@@ -61,7 +61,6 @@ impl<V: View> UniformList<V> {
append_items: F,
) -> Self
where
V: View,
F: 'static + Fn(&mut V, Range<usize>, &mut Vec<AnyElement<V>>, &mut ViewContext<V>),
{
Self {
@@ -151,7 +150,7 @@ impl<V: View> UniformList<V> {
}
}
impl<V: View> Element<V> for UniformList<V> {
impl<V: 'static> Element<V> for UniformList<V> {
type LayoutState = UniformListLayoutState<V>;
type PaintState = ();