Skip to content

Commit

Permalink
Fix: the gtk stack widget bugfix (#1119)
Browse files Browse the repository at this point in the history
* Fixed the gtk stack widget

* Add changelog entry for the stack widget bugfix

* Small code style improvement

Co-authored-by: Wölfchen <[email protected]>

---------

Co-authored-by: ElKowar <[email protected]>
Co-authored-by: Wölfchen <[email protected]>
  • Loading branch information
3 people authored Aug 24, 2024
1 parent b62094f commit 3673639
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to eww will be listed here, starting at changes since versio
- Re-enable some scss features (By: w-lfchen)
- Fix and refactor nix flake (By: w-lfchen)
- Fix remove items from systray (By: vnva)
- Fix the gtk `stack` widget (By: ovalkonia)

### Features
- Update rust toolchain to 1.80.1 (By: w-lfchen)
Expand Down
44 changes: 22 additions & 22 deletions crates/eww/src/widgets/widget_definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,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<gtk::Stack> {
let gtk_widget = gtk::Stack::new();

if bargs.widget_use.children.len() < 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()); },
Expand All @@ -1098,28 +1119,7 @@ fn build_gtk_stack(bargs: &mut BuilderArgs) -> Result<gtk::Stack> {
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";
Expand Down

0 comments on commit 3673639

Please sign in to comment.