This commit is contained in:
2026-03-20 20:28:48 -04:00
parent f71e03317d
commit d79a3bb728
9 changed files with 702 additions and 52 deletions

View File

@@ -1,6 +1,19 @@
use crate::scene::Color;
use crate::text::{TextSpan, TextStyle, TextWrap};
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct ElementId(u64);
impl ElementId {
pub const fn new(raw: u64) -> Self {
Self(raw)
}
pub const fn raw(self) -> u64 {
self.0
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum FlexDirection {
Row,
@@ -51,6 +64,7 @@ pub struct Style {
pub gap: f32,
pub padding: Edges,
pub background: Option<Color>,
pub pointer_events: bool,
}
impl Default for Style {
@@ -63,6 +77,7 @@ impl Default for Style {
gap: 0.0,
padding: Edges::ZERO,
background: None,
pointer_events: true,
}
}
}
@@ -81,6 +96,7 @@ pub(crate) struct TextNode {
#[derive(Clone, Debug, PartialEq)]
pub struct Element {
pub id: Option<ElementId>,
pub style: Style,
pub children: Vec<Element>,
content: ElementContent,
@@ -89,6 +105,7 @@ pub struct Element {
impl Element {
pub fn new() -> Self {
Self {
id: None,
style: Style::default(),
children: Vec::new(),
content: ElementContent::Container,
@@ -101,6 +118,7 @@ impl Element {
pub fn spans(spans: impl IntoIterator<Item = TextSpan>, style: TextStyle) -> Self {
Self {
id: None,
style: Style::default(),
children: Vec::new(),
content: ElementContent::Text(TextNode {
@@ -161,6 +179,16 @@ impl Element {
self
}
pub fn id(mut self, id: ElementId) -> Self {
self.id = Some(id);
self
}
pub fn pointer_events(mut self, pointer_events: bool) -> Self {
self.style.pointer_events = pointer_events;
self
}
pub fn child(mut self, child: Element) -> Self {
self.assert_container();
self.children.push(child);