Fix: the gtk stack
widget bugfix
#1119
Open
+23
−22
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The
stack
widget was essentially useless, since the:selected
property had 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.I faced this problem trying to implement a clock that would change the format of the output on request. Also, I searched for configurations from other users that use this widget, but to no avail. It's as if nobody ever used it or something. Take a look at the following screenshot showing minimal configuration:
![1718663452](https://private-user-images.githubusercontent.com/60359793/340486118-37b34362-e241-4a84-b216-31a2803ab110.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5NzQ5MzQsIm5iZiI6MTcxOTk3NDYzNCwicGF0aCI6Ii82MDM1OTc5My8zNDA0ODYxMTgtMzdiMzQzNjItZTI0MS00YTg0LWIyMTYtMzFhMjgwM2FiMTEwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAzVDAyNDM1NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTc2MGM0NjRkNmMzOTNiYzUwZDY4NjdjNTI2NjM3NDE3MTkwOTJkMTJlNzk4OGM4MjJjM2NhZWUzYmJlZmU3NzcmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.5qGSq1o4oPxOhb3uV52WGMUSC3dbijH50i-BpcofMfU)
As you can see, there's a warning and instead of the expected "1st", it shows "0th". It was tested under both Xorg and Wayland with the latest stable version of Eww from both github and AUR.
Looking at the code managing this widget, it appears that
gtk_widget.set_visible_child_name(&selected.to_string());
gets called before any of the actual children in the following match statement get added, which results in unexpected behaviour (easier to just check the diff).Fixes #1116
Usage
N/A
Showcase
Here is that same minimal configuration from before, but this time using the fixed version:
![1718667805](https://private-user-images.githubusercontent.com/60359793/340487853-b2d459f4-752c-4e34-a851-33b3086040e9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk5NzQ5MzQsIm5iZiI6MTcxOTk3NDYzNCwicGF0aCI6Ii82MDM1OTc5My8zNDA0ODc4NTMtYjJkNDU5ZjQtNzUyYy00ZTM0LWE4NTEtMzNiMzA4NjA0MGU5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MDMlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzAzVDAyNDM1NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTlmMGJiNWQwMTBjYzdiYmZmYTM1N2ZhMzNjMzE5NGRkZjE3ZjliZjg1MjFlMmM2MTZhMzRiZGM5Nzk5MzQ2MzkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.SgsSJ8ogcdCHpR_sOPRq19psGv3_ucpJZPyCJV-xa7k)
No warnings and it shows "1st", just as expected!
Additional Notes
The very fact that this issue had gone unnoticed for almost four months seems reeeeeally weird to me, so maybe I'm just a dumbass. I have no idea how the stack widget worked in the showcase when it was added, since it seems like the issue was there from the very beginning. Anyway, let me know what you think!
P. S. Alright, it does work, but only after the variable fed to the
:selected
property gets updated, and it makes sense. At the time of updating the variable, all the children are already there, so it makes sense how it worked in the showcase and this widget is, in fact, not useless, that's my bad. Although, this is still a bug, and needs to be fixedChecklist
Please make sure you can check all the boxes that apply to this PR.
docs/content/main
directory has been adjusted to reflect my changes.cargo fmt
to automatically format all code before committing