Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: the gtk stack widget bugfix #1119

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
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 @@ -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<gtk::Stack> {
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()); },
Expand All @@ -1097,28 +1118,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