summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpml68 <contact@pml68.me>2024-09-03 08:29:54 +0200
committerpml68 <contact@pml68.me>2024-09-22 23:55:11 +0200
commita2dc182cec0db1c6035a47cc17a853fa29ae53ab (patch)
treefcc760a7d71209a35832cb4a290bd1443c9a03fd
parentfeat: start codegen (diff)
downloadiced-builder-a2dc182cec0db1c6035a47cc17a853fa29ae53ab.tar.gz
feat: format children nodes into code (without props)
-rw-r--r--Cargo.lock15
-rw-r--r--Cargo.toml3
-rw-r--r--src/codegen/mod.rs27
-rw-r--r--src/types/mod.rs24
4 files changed, 52 insertions, 17 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c877aa9..2d33a26 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1183,11 +1183,22 @@ name = "iced-builder"
version = "0.1.0"
dependencies = [
"iced",
+ "iced_aw",
"rust-format",
"tokio",
]
[[package]]
+name = "iced_aw"
+version = "0.9.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6e68c330918a95bd73176206d65b84efe9aee6581da0e6dea0390cd146d7214c"
+dependencies = [
+ "cfg-if",
+ "iced",
+]
+
+[[package]]
name = "iced_core"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3012,9 +3023,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
-version = "1.39.3"
+version = "1.40.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5"
+checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998"
dependencies = [
"backtrace",
"pin-project-lite",
diff --git a/Cargo.toml b/Cargo.toml
index 50b4017..36eabed 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,5 +10,6 @@ keywords = ["gui", "iced"]
[dependencies]
iced = { version = "0.12.1", features = [ "image","svg","canvas","qr_code","advanced","tokio","highlighter"] }
-tokio = {version = "1.39.3",features = ["fs"]}
+iced_aw = { version = "0.9.3", default-features = false, features = ["menu","color_picker"] }
+tokio = { version = "1.40.0", features = ["fs"] }
rust-format = "0.3.4"
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs
index 37ada3a..8e31dc3 100644
--- a/src/codegen/mod.rs
+++ b/src/codegen/mod.rs
@@ -4,12 +4,35 @@ impl RenderedElement {
pub fn codegen(&self) -> Result<(String, String), &str> {
let mut imports = String::new();
let mut view = String::new();
+ let mut props = String::new();
+
+ let mut elements = String::new();
+
+ match self.children {
+ Some(els) => {
+ for el in els {
+ let mut children = String::new();
+
+ match el.codegen() {
+ Ok(e) => (children, imports) = e,
+ Err(err) => return Err(err),
+ }
+ elements = format!("{elements},{}", children);
+ }
+ }
+ None => {}
+ }
match self.name {
ElementName::Row => {
- imports = format!("{imports}\nuse iced::widget::row");
- view = format!("{view}\nrow![]");
+ imports = format!("{imports}\nuse iced::widget::row;");
+ view = format!("{view}\nrow![{elements}]{props};");
+ }
+ ElementName::Container => {
+ imports = format!("{imports}\nuse iced::widget::container;");
+ view = format!("{view}\ncontainer({elements}){props};");
}
+ _ => {}
}
}
}
diff --git a/src/types/mod.rs b/src/types/mod.rs
index 31c233d..09b0f07 100644
--- a/src/types/mod.rs
+++ b/src/types/mod.rs
@@ -30,18 +30,18 @@ pub enum ElementName {
}
pub struct Props {
- align_items: Option<Alignment>,
- align_x: Option<Horizontal>,
- align_y: Option<Vertical>,
- horizontal_alignment: Option<Horizontal>,
- vertical_alignment: Option<Vertical>,
- height: Option<Length>,
- width: Option<Length>,
- font: Option<Font>,
- padding: Option<i32>,
- spacing: Option<i32>,
- content_fit: Option<ContentFit>,
- shaping: Option<Shaping>,
+ pub align_items: Option<Alignment>,
+ pub align_x: Option<Horizontal>,
+ pub align_y: Option<Vertical>,
+ pub horizontal_alignment: Option<Horizontal>,
+ pub vertical_alignment: Option<Vertical>,
+ pub height: Option<Length>,
+ pub width: Option<Length>,
+ pub font: Option<Font>,
+ pub padding: Option<i32>,
+ pub spacing: Option<i32>,
+ pub content_fit: Option<ContentFit>,
+ pub shaping: Option<Shaping>,
}
pub enum DesignerPage {