From a2f3e993ac1e0d4f57d7c41d6601f7067190255b Mon Sep 17 00:00:00 2001 From: pml68 Date: Sat, 26 Oct 2024 21:52:37 +0200 Subject: feat: add C-S-s keybind for `Save As` --- iced_builder/src/types/project.rs | 16 ++++++++-------- iced_builder/src/types/rendered_element.rs | 24 +++++++++--------------- 2 files changed, 17 insertions(+), 23 deletions(-) (limited to 'iced_builder/src/types') 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, pub theme: Option, - pub content: Option, + pub element_tree: Option, } 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 { - match &self.content { - Some(el) => { - let (imports, view) = el.codegen(); + pub fn app_code(&self) -> Result { + 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 { } pub fn row(child_elements: Option>) -> 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>) -> 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()) } -- cgit v1.2.3