summaryrefslogtreecommitdiff
path: root/iced_builder/src/types
diff options
context:
space:
mode:
authorpml68 <contact@pml68.me>2024-10-28 01:00:07 +0100
committerpml68 <contact@pml68.me>2024-10-28 01:00:12 +0100
commit726e9023c4629d70410174ddbd1e6d43f7583fe5 (patch)
tree569c3d25033f06ca708279565eafba76b0ca52ec /iced_builder/src/types
parentMerge pull request #3 from pml68/refactor/internal-restructuring (diff)
downloadiced-builder-726e9023c4629d70410174ddbd1e6d43f7583fe5.tar.gz
feat: implement very basic playground
fix: `is_dirty` was never checked for in the main update fn, allowing unsaved work to easily be overwritten
Diffstat (limited to 'iced_builder/src/types')
-rw-r--r--iced_builder/src/types/element_name.rs1
-rw-r--r--iced_builder/src/types/mod.rs4
-rwxr-xr-xiced_builder/src/types/rendered_element.rs67
3 files changed, 68 insertions, 4 deletions
diff --git a/iced_builder/src/types/element_name.rs b/iced_builder/src/types/element_name.rs
index 93e12a1..bf38120 100644
--- a/iced_builder/src/types/element_name.rs
+++ b/iced_builder/src/types/element_name.rs
@@ -44,6 +44,7 @@ impl ElementName {
};
match action {
Action::Stop => Ok(None),
+ Action::Drop => Ok(None),
Action::AddNew => Ok(Some(element)),
Action::PushFront(id) => {
element_tree
diff --git a/iced_builder/src/types/mod.rs b/iced_builder/src/types/mod.rs
index a48a2d8..0012905 100644
--- a/iced_builder/src/types/mod.rs
+++ b/iced_builder/src/types/mod.rs
@@ -2,6 +2,10 @@ pub mod element_name;
pub mod project;
pub mod rendered_element;
+pub use element_name::ElementName;
+pub use project::Project;
+pub use rendered_element::*;
+
#[derive(Debug, Clone)]
pub enum DesignerPage {
Designer,
diff --git a/iced_builder/src/types/rendered_element.rs b/iced_builder/src/types/rendered_element.rs
index 08d7ba3..3dad8e7 100755
--- a/iced_builder/src/types/rendered_element.rs
+++ b/iced_builder/src/types/rendered_element.rs
@@ -7,14 +7,14 @@ use unique_id::{string::StringGenerator, Generator};
use crate::{Error, Message};
-use super::element_name::ElementName;
+use super::ElementName;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RenderedElement {
id: String,
- pub child_elements: Option<Vec<RenderedElement>>,
- pub name: ElementName,
- pub options: IndexMap<String, Option<String>>,
+ child_elements: Option<Vec<RenderedElement>>,
+ name: ElementName,
+ options: IndexMap<String, Option<String>>,
}
impl RenderedElement {
@@ -126,6 +126,12 @@ impl RenderedElement {
match action {
Action::Stop => Ok(()),
+ Action::Drop => {
+ let parent = element_tree.find_parent(self).unwrap();
+ parent.remove(self);
+
+ Ok(())
+ }
Action::AddNew => Err(
"the action was of kind `AddNew`, but invoking it on an existing element tree is not possible".into(),
),
@@ -299,11 +305,62 @@ impl std::fmt::Display for RenderedElement {
}
}
+impl<'a> From<RenderedElement> for Element<'a, Message> {
+ fn from(value: RenderedElement) -> Self {
+ let child_elements = match value.child_elements {
+ Some(ref elements) => elements.clone(),
+ None => vec![],
+ };
+
+ let content: Element<'a, Message> = match value.name.clone() {
+ ElementName::Text(s) => {
+ if s == String::new() {
+ widget::text("New Text").into()
+ } else {
+ widget::text(s).into()
+ }
+ }
+ ElementName::Button(s) => {
+ if s == String::new() {
+ widget::button(widget::text("New Button")).into()
+ } else {
+ widget::button(widget::text(s)).into()
+ }
+ }
+ ElementName::SVG(p) => widget::svg(p).into(),
+ ElementName::Image(p) => widget::image(p).into(),
+ ElementName::Container => widget::container(if child_elements.len() == 1 {
+ child_elements[0].clone().into()
+ } else {
+ Element::from("")
+ })
+ .padding(20)
+ .into(),
+ ElementName::Row => {
+ widget::Row::from_iter(child_elements.into_iter().map(|el| el.into()))
+ .padding(20)
+ .into()
+ }
+ ElementName::Column => {
+ widget::Column::from_iter(child_elements.into_iter().map(|el| el.into()))
+ .padding(20)
+ .into()
+ }
+ };
+ iced_drop::droppable(content)
+ .id(value.get_id())
+ .drag_hide(true)
+ .on_drop(move |point, rect| Message::MoveElement(value.clone(), point, rect))
+ .into()
+ }
+}
+
#[derive(Debug, Clone)]
pub enum Action {
AddNew,
PushFront(Id),
InsertAfter(Id, Id),
+ Drop,
Stop,
}
@@ -317,6 +374,8 @@ impl Action {
if ids.len() == 1 {
if element_tree.is_none() {
action = Self::AddNew;
+ } else {
+ action = Self::Drop;
}
} else {
let id: Id = match source_id {