From 58d05fc93c118661a09688f530b5c62339eba6e0 Mon Sep 17 00:00:00 2001 From: pml68 Date: Mon, 2 Sep 2024 23:36:51 +0200 Subject: feat: start codegen --- src/codegen/mod.rs | 15 +++++++++++++++ src/main.rs | 1 + src/types/mod.rs | 42 ++++++++++++++++++++++++++++++++---------- 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 src/codegen/mod.rs diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs new file mode 100644 index 0000000..37ada3a --- /dev/null +++ b/src/codegen/mod.rs @@ -0,0 +1,15 @@ +use crate::types::{ElementName, RenderedElement}; + +impl RenderedElement { + pub fn codegen(&self) -> Result<(String, String), &str> { + let mut imports = String::new(); + let mut view = String::new(); + + match self.name { + ElementName::Row => { + imports = format!("{imports}\nuse iced::widget::row"); + view = format!("{view}\nrow![]"); + } + } + } +} diff --git a/src/main.rs b/src/main.rs index 6ee558b..16a1daa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,4 @@ +mod codegen; mod types; use iced::{ diff --git a/src/types/mod.rs b/src/types/mod.rs index 69df615..31c233d 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,4 +1,10 @@ -use iced::{Font, Length}; +use std::path::PathBuf; + +use iced::{ + alignment::{Horizontal, Vertical}, + widget::{text::Shaping, text_editor}, + Alignment, ContentFit, Font, Length, +}; pub struct DesignerState { pub designer_content: Vec, @@ -7,19 +13,35 @@ pub struct DesignerState { pub struct RenderedElement { pub id: String, - pub children: Vec, + pub children: Option>, pub name: ElementName, - pub props: Vec, + pub props: Props, } -pub enum ElementName {} +pub enum ElementName { + Text(String), + Button(String), + TextEditor(text_editor::Content), + SVG(PathBuf), + Image(PathBuf), + Container, + Row, + Column, +} -pub enum Prop { - String(String, String), - Decimal(String, i32), - Float(String, f32), - Font(String, Font), - Length(String, Length), +pub struct Props { + align_items: Option, + align_x: Option, + align_y: Option, + horizontal_alignment: Option, + vertical_alignment: Option, + height: Option, + width: Option, + font: Option, + padding: Option, + spacing: Option, + content_fit: Option, + shaping: Option, } pub enum DesignerPage { -- cgit v1.2.3