summaryrefslogtreecommitdiff
path: root/iced_builder/src/types
diff options
context:
space:
mode:
Diffstat (limited to 'iced_builder/src/types')
-rw-r--r--iced_builder/src/types/project.rs16
-rwxr-xr-xiced_builder/src/types/rendered_element.rs24
2 files changed, 17 insertions, 23 deletions
diff --git a/iced_builder/src/types/project.rs b/iced_builder/src/types/project.rs
index 95de9e6..52da41c 100644
--- a/iced_builder/src/types/project.rs
+++ b/iced_builder/src/types/project.rs
@@ -12,7 +12,7 @@ use super::rendered_element::RenderedElement;
pub struct Project {
pub title: Option<String>,
pub theme: Option<String>,
- pub content: Option<RenderedElement>,
+ pub element_tree: Option<RenderedElement>,
}
impl Project {
@@ -20,7 +20,7 @@ impl Project {
Self {
title: None,
theme: None,
- content: None,
+ element_tree: None,
}
}
@@ -92,10 +92,10 @@ impl Project {
Ok(path)
}
- pub fn app_code(self) -> Result<String, Error> {
- match &self.content {
- Some(el) => {
- let (imports, view) = el.codegen();
+ pub fn app_code(&self) -> Result<String, Error> {
+ match self.element_tree {
+ Some(ref element_tree) => {
+ let (imports, view) = element_tree.codegen();
let mut app_code = format!("use iced::{{widget::{{{imports}}},Element}};");
app_code = format!(
@@ -119,8 +119,8 @@ impl Project {
{view}.into()
}}
}}"#,
- match &self.title {
- Some(t) => t,
+ match self.title {
+ Some(ref t) => t,
None => "New app",
},
self.get_theme().to_string().replace(" ", "")
diff --git a/iced_builder/src/types/rendered_element.rs b/iced_builder/src/types/rendered_element.rs
index 5b7777a..50e591a 100755
--- a/iced_builder/src/types/rendered_element.rs
+++ b/iced_builder/src/types/rendered_element.rs
@@ -127,7 +127,7 @@ impl RenderedElement {
match action {
ActionKind::Stop => Ok(()),
ActionKind::AddNew => Err(
- "The action was of kind `AddNew`, but invoking it on an existing element tree is not possible.".into(),
+ "the action was of kind `AddNew`, but invoking it on an existing element tree is not possible".into(),
),
ActionKind::PushFront(id) => {
let old_parent = element_tree.find_parent(self).unwrap();
@@ -335,14 +335,14 @@ impl ActionKind {
.find_by_id(id.clone())
.unwrap();
- match (
- element.is_parent(),
- element.name == ElementName::Container && !element.is_empty(),
- ) {
- (true, false) => {
+ // Element IS a parent but ISN'T a non-empty container
+ match element.is_parent()
+ && !(element.name == ElementName::Container && !element.is_empty())
+ {
+ true => {
action = Self::PushFront(id);
}
- _ if ids.len() > 2 => {
+ false if ids.len() > 2 => {
let parent = element_tree
.as_mut()
.unwrap()
@@ -396,15 +396,9 @@ pub fn container(content: Option<RenderedElement>) -> RenderedElement {
}
pub fn row(child_elements: Option<Vec<RenderedElement>>) -> RenderedElement {
- match child_elements {
- Some(els) => RenderedElement::with(ElementName::Row, els),
- None => RenderedElement::with(ElementName::Row, vec![]),
- }
+ RenderedElement::with(ElementName::Row, child_elements.unwrap_or_default())
}
pub fn column(child_elements: Option<Vec<RenderedElement>>) -> RenderedElement {
- match child_elements {
- Some(els) => RenderedElement::with(ElementName::Column, els),
- None => RenderedElement::with(ElementName::Column, vec![]),
- }
+ RenderedElement::with(ElementName::Column, child_elements.unwrap_or_default())
}