From 71743cb18fbb69430d092df59a722f5995be31c3 Mon Sep 17 00:00:00 2001 From: pml68 Date: Thu, 19 Sep 2024 23:26:22 +0200 Subject: feat: rework props w --- src/types/mod.rs | 6 +++--- src/types/props.rs | 44 ------------------------------------------- src/types/rendered_element.rs | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 51 deletions(-) delete mode 100644 src/types/props.rs (limited to 'src/types') diff --git a/src/types/mod.rs b/src/types/mod.rs index 1fa23d4..c837ee1 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,4 +1,3 @@ -pub mod props; pub mod rendered_element; use iced::widget::text_editor; @@ -10,9 +9,10 @@ pub struct DesignerState { pub designer_page: DesignerPage, } +#[derive(Debug)] pub enum ElementName { - Text(String), - Button(String), + Text(&'static str), + Button(&'static str), TextEditor(text_editor::Content), SVG(PathBuf), Image(PathBuf), diff --git a/src/types/props.rs b/src/types/props.rs deleted file mode 100644 index 6dbb0a4..0000000 --- a/src/types/props.rs +++ /dev/null @@ -1,44 +0,0 @@ -use core::f32; - -use iced::{ - alignment::{Horizontal, Vertical}, - widget::text::Shaping, - Alignment, ContentFit, Font, Length, Padding, -}; -pub struct Props { - pub align_items: Option, - pub align_x: Option, - pub align_y: Option, - pub horizontal_alignment: Option, - pub vertical_alignment: Option, - pub width: Option, - pub height: Option, - pub max_width: Option, - pub max_height: Option, - pub font: Option, - pub padding: Option, - pub spacing: Option, - pub content_fit: Option, - pub shaping: Option, -} - -impl Default for Props { - fn default() -> Self { - Self { - align_items: None, - align_x: None, - align_y: None, - horizontal_alignment: None, - vertical_alignment: None, - width: None, - height: None, - max_width: None, - max_height: None, - font: None, - padding: None, - spacing: None, - content_fit: None, - shaping: None, - } - } -} diff --git a/src/types/rendered_element.rs b/src/types/rendered_element.rs index e909ac5..cbc923d 100644 --- a/src/types/rendered_element.rs +++ b/src/types/rendered_element.rs @@ -1,11 +1,15 @@ +use std::collections::HashMap; + use unique_id::{string::StringGenerator, Generator}; -use super::{props::Props, ElementName}; +use super::ElementName; + +#[derive(Debug)] pub struct RenderedElement { pub id: String, pub child_elements: Vec, pub name: ElementName, - pub props: Props, + pub props: HashMap<&'static str, &'static str>, } impl RenderedElement { @@ -15,7 +19,7 @@ impl RenderedElement { id: gen.next_id(), child_elements: vec![], name, - props: Props::default(), + props: HashMap::new(), } } @@ -25,7 +29,7 @@ impl RenderedElement { id: gen.next_id(), child_elements, name, - props: Props::default(), + props: HashMap::new(), } } @@ -33,4 +37,9 @@ impl RenderedElement { self.child_elements.push(element); self } + + pub fn set_property(&mut self, prop: &'static str, value: &'static str) { + let prop_ref = self.props.entry(prop).or_insert(value); + *prop_ref = value; + } } -- cgit v1.2.3