From b66f5d57013243211c37fa52dbe26fe0b241bd07 Mon Sep 17 00:00:00 2001 From: pml68 Date: Tue, 22 Oct 2024 12:57:35 +0200 Subject: feat: disable appending to container if it already has children fix: Column element now showing in element list --- iced_builder/src/main.rs | 24 +++++++++++++----------- iced_builder/src/types/element_name.rs | 2 +- iced_builder/src/types/rendered_element.rs | 13 +++++++++++-- 3 files changed, 25 insertions(+), 14 deletions(-) (limited to 'iced_builder/src') diff --git a/iced_builder/src/main.rs b/iced_builder/src/main.rs index 8efad3e..0c76374 100644 --- a/iced_builder/src/main.rs +++ b/iced_builder/src/main.rs @@ -361,34 +361,36 @@ fn items_list_view<'a>(items: Vec) -> Element<'a, Message> { .width(Length::Fill); for item in items { - let value = item.clone(); column = column.push( - droppable(text(value.to_string())) - .on_drop(move |point, rect| Message::DropNewElement(value.clone(), point, rect)), + droppable(text(item.clone().to_string())) + .on_drop(move |point, rect| Message::DropNewElement(item.clone(), point, rect)), ); } - container(column).height(250.0).width(300).into() + container(column) + .width(Length::Fill) + .height(Length::Fill) + .into() } mod style { - use iced::widget::container::Style as CStyle; + use iced::widget::container::Style; use iced::{Border, Theme}; - pub fn title_bar(theme: &Theme) -> CStyle { + pub fn title_bar(theme: &Theme) -> Style { let palette = theme.extended_palette(); - CStyle { + Style { text_color: Some(palette.background.strong.text), background: Some(palette.background.strong.color.into()), ..Default::default() } } - pub fn pane_active(theme: &Theme) -> CStyle { + pub fn pane_active(theme: &Theme) -> Style { let palette = theme.extended_palette(); - CStyle { + Style { background: Some(palette.background.weak.color.into()), border: Border { width: 1.0, @@ -399,10 +401,10 @@ mod style { } } - pub fn pane_focused(theme: &Theme) -> CStyle { + pub fn pane_focused(theme: &Theme) -> Style { let palette = theme.extended_palette(); - CStyle { + Style { background: Some(palette.background.weak.color.into()), border: Border { width: 4.0, diff --git a/iced_builder/src/types/element_name.rs b/iced_builder/src/types/element_name.rs index ca0668c..c30d6e3 100644 --- a/iced_builder/src/types/element_name.rs +++ b/iced_builder/src/types/element_name.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::Error; use super::rendered_element::{ - self, button, column, container, image, row, svg, text, ActionKind, RenderedElement, + button, column, container, image, row, svg, text, ActionKind, RenderedElement, }; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] diff --git a/iced_builder/src/types/rendered_element.rs b/iced_builder/src/types/rendered_element.rs index 827e8c2..6b01bc3 100644 --- a/iced_builder/src/types/rendered_element.rs +++ b/iced_builder/src/types/rendered_element.rs @@ -317,8 +317,17 @@ impl ActionKind { }; let element = element_tree.as_mut().unwrap().find_by_id(id.clone()); - match element.unwrap().is_parent() { - true => action = Self::PushFront(id), + match element.as_ref().unwrap().is_parent() { + true => { + let element = &element.unwrap(); + if element.name == ElementName::Container + && element.child_elements != Some(vec![]) + { + action = Self::Stop; + } else { + action = Self::PushFront(id); + } + } false => { if ids.len() > 2 { action = Self::InsertAfter( -- cgit v1.2.3