From 90cdc46852f8c3aa4923a6b4573d065ab45b5a37 Mon Sep 17 00:00:00 2001 From: ovalkonia Date: Tue, 18 Jun 2024 02:21:30 +0300 Subject: [PATCH 1/3] Fixed the gtk stack widget --- crates/eww/src/widgets/widget_definitions.rs | 44 ++++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index d5d97fb4..54930d53 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -1088,6 +1088,27 @@ const WIDGET_NAME_STACK: &str = "stack"; /// @desc A widget that displays one of its children at a time fn build_gtk_stack(bargs: &mut BuilderArgs) -> Result { let gtk_widget = gtk::Stack::new(); + + if let Ordering::Less = bargs.widget_use.children.len().cmp(&1) { + return Err(DiagError(gen_diagnostic!("stack must contain at least one element", bargs.widget_use.span)).into()); + } + + let children = bargs.widget_use.children.iter().map(|child| { + build_gtk_widget( + bargs.scope_graph, + bargs.widget_defs.clone(), + bargs.calling_scope, + child.clone(), + bargs.custom_widget_invocation.clone(), + ) + }); + + for (i, child) in children.enumerate() { + let child = child?; + gtk_widget.add_named(&child, &i.to_string()); + child.show(); + } + def_widget!(bargs, _g, gtk_widget, { // @prop selected - index of child which should be shown prop(selected: as_i32) { gtk_widget.set_visible_child_name(&selected.to_string()); }, @@ -1097,28 +1118,7 @@ fn build_gtk_stack(bargs: &mut BuilderArgs) -> Result { prop(same_size: as_bool = false) { gtk_widget.set_homogeneous(same_size); } }); - match bargs.widget_use.children.len().cmp(&1) { - Ordering::Less => { - Err(DiagError(gen_diagnostic!("stack must contain at least one element", bargs.widget_use.span)).into()) - } - Ordering::Greater | Ordering::Equal => { - let children = bargs.widget_use.children.iter().map(|child| { - build_gtk_widget( - bargs.scope_graph, - bargs.widget_defs.clone(), - bargs.calling_scope, - child.clone(), - bargs.custom_widget_invocation.clone(), - ) - }); - for (i, child) in children.enumerate() { - let child = child?; - gtk_widget.add_named(&child, &i.to_string()); - child.show(); - } - Ok(gtk_widget) - } - } + Ok(gtk_widget) } const WIDGET_NAME_TRANSFORM: &str = "transform"; From ede9063d6f1aecbe1a3be94475542481b6757e06 Mon Sep 17 00:00:00 2001 From: ovalkonia Date: Tue, 18 Jun 2024 02:27:38 +0300 Subject: [PATCH 2/3] Add changelog entry for the stack widget bugfix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32e2aa82..b3696bbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to eww will be listed here, starting at changes since versio ### Fixes - Fix and refactor nix flake (By: w-lfchen) - Fix remove items from systray (By: vnva) +- Fix the gtk `stack` widget (By: ovalkonia) ### Features - Add `:truncate` property to labels, disabled by default (except in cases where truncation would be enabled in version `0.5.0` and before) (By: Rayzeq). From 18f88549efcb445692e7492c26a777cd8393c4bd Mon Sep 17 00:00:00 2001 From: ElKowar Date: Sat, 24 Aug 2024 12:29:54 +0200 Subject: [PATCH 3/3] Small code style improvement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Wölfchen --- crates/eww/src/widgets/widget_definitions.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eww/src/widgets/widget_definitions.rs b/crates/eww/src/widgets/widget_definitions.rs index 54930d53..2b606706 100644 --- a/crates/eww/src/widgets/widget_definitions.rs +++ b/crates/eww/src/widgets/widget_definitions.rs @@ -1089,7 +1089,7 @@ const WIDGET_NAME_STACK: &str = "stack"; fn build_gtk_stack(bargs: &mut BuilderArgs) -> Result { let gtk_widget = gtk::Stack::new(); - if let Ordering::Less = bargs.widget_use.children.len().cmp(&1) { + if bargs.widget_use.children.len() < 1 { return Err(DiagError(gen_diagnostic!("stack must contain at least one element", bargs.widget_use.span)).into()); }