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

Merged
merged 4 commits into from
Aug 24, 2024
Merged

Fix: the gtk stack widget bugfix #1119

merged 4 commits into from
Aug 24, 2024

Conversation

ovalkonia
Copy link
Contributor

@ovalkonia ovalkonia commented Jun 18, 2024

Description

The :selected property had initially no effect and resulted in a warning stating that a child with the given name wasn't found. This exact issue has already been described here -> #1116.

Take a look at the following screenshot showing minimal configuration:
1722946531
As you can see, there's a warning and instead of the expected "1st", it shows "0th".
Although, if you update the variable, it will work, since all the children are already there:
1722946548

The problem is here:

let gtk_widget = gtk::Stack::new();
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()); },
// @prop transition - the name of the transition. Possible values: $transition
prop(transition: as_string = "crossfade") { gtk_widget.set_transition_type(parse_stack_transition(&transition)?); },
// @prop same-size - sets whether all children should be the same size
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)
}
}

gtk_widget.set_visible_child_name(&selected.to_string()) gets called before any children are actually added.

Fixes #1116

Usage

N/A

Showcase

Here is that same minimal configuration from before, but this time using the fixed version:
1718667805
No warnings and it shows "1st", just as expected!

Additional Notes

N/A

Checklist

Please make sure you can check all the boxes that apply to this PR.

  • All widgets I've added are correctly documented.
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/content/main directory has been adjusted to reflect my changes.
  • I used cargo fmt to automatically format all code before committing

@ovalkonia ovalkonia marked this pull request as draft June 18, 2024 00:30
@ovalkonia ovalkonia marked this pull request as ready for review June 18, 2024 00:31
@fabolous005
Copy link

fabolous005 commented Aug 6, 2024

Hi,
I'm also currently looking into the stack widget. So far with no luck.
I thought i could index the childs of the stack like this:

(defvar stack-index 0)

(stack
	:selected stack-index
        (child-widget1)
        (child-widget2)
)

This would be extremely useful because you could update the variable from on-hover events from eventbox!
Do you know how to archive this or if it is even possible (yet)?

@ovalkonia
Copy link
Contributor Author

@fabolous005 Yeah, absolutely you can can do that! Eww is quite flexible, the possibilities are endless. Try something like this:

(defvar stack-index 0)

(eventbox
        :onhover "${EWW_CMD} update stack-index=${(stack-index + 1) % 3}"
        (stack
            :selected stack-index
            (label :text "first")
            (label :text "second")
            (label :text "third")
        )
 )

It's just a stack wrapped inside of an eventbox. If you hover over, it will switch to the next child.

You can update variables using eww update variable=value, and EWW_CMD is just a shortcut for the current running configuration (see https://elkowar.github.io/eww/magic-vars.html#eww_cmd).

For eventbox docs, see https://elkowar.github.io/eww/widgets.html#eventbox. Hope it helped!

@fabolous005
Copy link

fabolous005 commented Aug 6, 2024

Yeah, i tried that, but whatever i try i get the error Child name '0' not found, even with your exact example.
eww version: eww 0.6.0 4d55e9ad63d1fae887726dffcd25a32def23d34f

@ovalkonia
Copy link
Contributor Author

Yeah, i tried that, but whatever i try i get the error Child name '0' not found, even with your exact example. evv version: eww 0.6.0 4d55e9ad63d1fae887726dffcd25a32def23d34f

Well, it is what it is for now, this pr solves this exact issue. Right now it essentially defaults to the 0th child. If you update the variable, it will work since all the children will be there. Just ignore the error message and try hovering over it, it should work.

@fabolous005
Copy link

Ohh! Sorry should've noticed that... Thank you.

Copy link
Contributor

@w-lfchen w-lfchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can probably just apply this from the web interface
apart from this minor nitpick lgtm

crates/eww/src/widgets/widget_definitions.rs Outdated Show resolved Hide resolved
@elkowar elkowar merged commit 3673639 into elkowar:master Aug 24, 2024
1 check passed
w-lfchen added a commit to w-lfchen/eww that referenced this pull request Aug 24, 2024
i introduced this in elkowar#1119, whoops
elkowar pushed a commit to w-lfchen/eww that referenced this pull request Aug 25, 2024
i introduced this in elkowar#1119, whoops
elkowar pushed a commit that referenced this pull request Aug 25, 2024
* fix!: eliminate some dead code

* fix: fix lints

Combined diff of a7a09ea and bfc5cb9

Co-authored-by: Johan Geluk <[email protected]>

* fix: remove unnecessary allow; fix capitalization

* chore: automatically update a few dependencies

* fix: fix lint

i introduced this in #1119, whoops

* docs: move #1132's changelog entry

---------

Co-authored-by: Johan Geluk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Can't control selected Stack Child using :selected
4 participants