add children on initial build and add sorted slice macro
This commit is contained in:
1 parent
3b06059834
commit
0fb9aed273
7 files changed
+221
-414
No files matched your search
+192
-14
@@ -2,21 +2,46 @@ use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
use dioxus_core::*;
|
||||
use dioxus_native_core::dioxus_native_core_macro::sorted_str_slice;
|
||||
use dioxus_native_core::layout_attributes::apply_layout_attributes;
|
||||
use dioxus_native_core::state::{AttributeMask, ChildDepState, NodeMask, NodeView};
|
||||
use stretch2::prelude::*;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub(crate) enum PossiblyUninitalized<T> {
|
||||
Uninitalized,
|
||||
Initialized(T),
|
||||
}
|
||||
impl<T> PossiblyUninitalized<T> {
|
||||
pub fn unwrap(self) -> T {
|
||||
match self {
|
||||
Self::Initialized(i) => i,
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<T> Default for PossiblyUninitalized<T> {
|
||||
fn default() -> Self {
|
||||
Self::Uninitalized
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Default, Debug)]
|
||||
pub struct StretchLayout {
|
||||
pub(crate) struct StretchLayout {
|
||||
pub style: Style,
|
||||
pub node: Option<Node>,
|
||||
pub node: PossiblyUninitalized<Node>,
|
||||
}
|
||||
|
||||
impl ChildDepState for StretchLayout {
|
||||
type Ctx = Rc<RefCell<Stretch>>;
|
||||
type DepState = Self;
|
||||
// todo: update mask
|
||||
const NODE_MASK: NodeMask = NodeMask::new(AttributeMask::All, false, false, true);
|
||||
const NODE_MASK: NodeMask = NodeMask::new(
|
||||
AttributeMask::Static(SORTED_LAYOUT_ATTRS),
|
||||
false,
|
||||
false,
|
||||
true,
|
||||
);
|
||||
|
||||
/// Setup the layout
|
||||
fn reduce<'a>(
|
||||
@@ -44,16 +69,18 @@ impl ChildDepState for StretchLayout {
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
if let Some(n) = self.node {
|
||||
if let PossiblyUninitalized::Initialized(n) = self.node {
|
||||
if self.style != style {
|
||||
stretch.set_style(n, style).unwrap();
|
||||
}
|
||||
} else {
|
||||
self.node = Some(stretch.new_node(style, &[]).unwrap());
|
||||
self.node =
|
||||
PossiblyUninitalized::Initialized(stretch.new_node(style, &[]).unwrap());
|
||||
}
|
||||
} else {
|
||||
// gather up all the styles from the attribute list
|
||||
for &Attribute { name, value, .. } in node.attributes() {
|
||||
assert!(SORTED_LAYOUT_ATTRS.binary_search(&name).is_ok());
|
||||
apply_layout_attributes(name, value, &mut style);
|
||||
}
|
||||
|
||||
@@ -69,14 +96,7 @@ impl ChildDepState for StretchLayout {
|
||||
child_layout.push(l.node.unwrap());
|
||||
}
|
||||
|
||||
if let Some(n) = self.node {
|
||||
if self.style != style {
|
||||
stretch.set_style(n, style).unwrap();
|
||||
}
|
||||
} else {
|
||||
self.node = Some(stretch.new_node(style, &[]).unwrap());
|
||||
}
|
||||
if let Some(n) = self.node {
|
||||
if let PossiblyUninitalized::Initialized(n) = self.node {
|
||||
if self.style != style {
|
||||
stretch.set_style(n, style).unwrap();
|
||||
}
|
||||
@@ -84,7 +104,9 @@ impl ChildDepState for StretchLayout {
|
||||
stretch.set_children(n, &child_layout).unwrap();
|
||||
}
|
||||
} else {
|
||||
self.node = Some(stretch.new_node(style, &[]).unwrap());
|
||||
self.node = PossiblyUninitalized::Initialized(
|
||||
stretch.new_node(style, &child_layout).unwrap(),
|
||||
);
|
||||
}
|
||||
}
|
||||
if self.style != style {
|
||||
@@ -94,3 +116,159 @@ impl ChildDepState for StretchLayout {
|
||||
changed
|
||||
}
|
||||
}
|
||||
|
||||
// these are the attributes in layout_attiributes in native-core
|
||||
const SORTED_LAYOUT_ATTRS: &'static [&'static str] = &sorted_str_slice!([
|
||||
"align-content",
|
||||
"align-items",
|
||||
"align-self",
|
||||
"animation",
|
||||
"animation-delay",
|
||||
"animation-direction",
|
||||
"animation-duration",
|
||||
"animation-fill-mode",
|
||||
"animation-iteration-count",
|
||||
"animation-name",
|
||||
"animation-play-state",
|
||||
"animation-timing-function",
|
||||
"backface-visibility",
|
||||
"border",
|
||||
"border-bottom",
|
||||
"border-bottom-color",
|
||||
"border-bottom-left-radius",
|
||||
"border-bottom-right-radius",
|
||||
"border-bottom-style",
|
||||
"border-bottom-width",
|
||||
"border-collapse",
|
||||
"border-color",
|
||||
"border-image",
|
||||
"border-image-outset",
|
||||
"border-image-repeat",
|
||||
"border-image-slice",
|
||||
"border-image-source",
|
||||
"border-image-width",
|
||||
"border-left",
|
||||
"border-left-color",
|
||||
"border-left-style",
|
||||
"border-left-width",
|
||||
"border-radius",
|
||||
"border-right",
|
||||
"border-right-color",
|
||||
"border-right-style",
|
||||
"border-right-width",
|
||||
"border-spacing",
|
||||
"border-style",
|
||||
"border-top",
|
||||
"border-top-color",
|
||||
"border-top-left-radius",
|
||||
"border-top-right-radius",
|
||||
"border-top-style",
|
||||
"border-top-width",
|
||||
"border-width",
|
||||
"bottom",
|
||||
"box-shadow",
|
||||
"box-sizing",
|
||||
"caption-side",
|
||||
"clear",
|
||||
"clip",
|
||||
"column-count",
|
||||
"column-fill",
|
||||
"column-gap",
|
||||
"column-rule",
|
||||
"column-rule-color",
|
||||
"column-rule-style",
|
||||
"column-rule-width",
|
||||
"column-span",
|
||||
"column-width",
|
||||
"columns",
|
||||
"content",
|
||||
"counter-increment",
|
||||
"counter-reset",
|
||||
"cursor",
|
||||
"direction",
|
||||
"ltr",
|
||||
"rtl",
|
||||
"display",
|
||||
"empty-cells",
|
||||
"flex",
|
||||
"flex-basis",
|
||||
"flex-direction",
|
||||
"flex-flow",
|
||||
"flex-grow",
|
||||
"flex-shrink",
|
||||
"flex-wrap",
|
||||
"float",
|
||||
"height",
|
||||
"justify-content",
|
||||
"flex-start",
|
||||
"flex-end",
|
||||
"center",
|
||||
"space-between",
|
||||
"space-around",
|
||||
"space-evenly",
|
||||
"left",
|
||||
"letter-spacing",
|
||||
"line-height",
|
||||
"list-style",
|
||||
"list-style-image",
|
||||
"list-style-position",
|
||||
"list-style-type",
|
||||
"margin",
|
||||
"margin-bottom",
|
||||
"margin-left",
|
||||
"margin-right",
|
||||
"margin-top",
|
||||
"max-height",
|
||||
"max-width",
|
||||
"min-height",
|
||||
"min-width",
|
||||
"opacity",
|
||||
"order",
|
||||
"outline",
|
||||
"outline-color",
|
||||
"outline-offset",
|
||||
"outline-style",
|
||||
"outline-width",
|
||||
"overflow",
|
||||
"overflow-x",
|
||||
"overflow-y",
|
||||
"padding",
|
||||
"padding-bottom",
|
||||
"padding-left",
|
||||
"padding-right",
|
||||
"padding-top",
|
||||
"page-break-after",
|
||||
"page-break-before",
|
||||
"page-break-inside",
|
||||
"perspective",
|
||||
"perspective-origin",
|
||||
"position",
|
||||
"static",
|
||||
"relative",
|
||||
"fixed",
|
||||
"absolute",
|
||||
"sticky",
|
||||
"pointer-events",
|
||||
"quotes",
|
||||
"resize",
|
||||
"right",
|
||||
"tab-size",
|
||||
"table-layout",
|
||||
"top",
|
||||
"transform",
|
||||
"transform-origin",
|
||||
"transform-style",
|
||||
"transition",
|
||||
"transition-delay",
|
||||
"transition-duration",
|
||||
"transition-property",
|
||||
"transition-timing-function",
|
||||
"vertical-align",
|
||||
"visibility",
|
||||
"white-space",
|
||||
"width",
|
||||
"word-break",
|
||||
"word-spacing",
|
||||
"word-wrap",
|
||||
"z-index"
|
||||
]);
|
||||
@@ -215,7 +215,6 @@ fn render_vdom(
|
||||
}
|
||||
|
||||
{
|
||||
// resolve events before rendering
|
||||
let evts = handler.get_events(&stretch.borrow(), &mut rdom);
|
||||
for e in evts {
|
||||
vdom.handle_message(SchedulerMsg::Event(e));
|
||||
|
||||
@@ -30,7 +30,6 @@ pub(crate) fn render_vnode(
|
||||
}
|
||||
|
||||
let Layout { location, size, .. } = layout.layout(node.state.layout.node.unwrap()).unwrap();
|
||||
// println!("rendering {node:?} {location:?} {size:?}");
|
||||
|
||||
let Point { x, y } = location;
|
||||
let Size { width, height } = size;
|
||||
|
||||
Reference in new issue
Block a user