-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add the ability to disable ToolbarActions #2306 #4347
Add the ability to disable ToolbarActions #2306 #4347
Conversation
I also experience some weird rendering behavior in the fyne_demo after making my changes. After a refresh, the alignment of the toolbar items seems to be off. I am not sure if this a local bug for me, or if it is caused by my changes: The code that I am using is
Could you try it on your side and let me know if it happens as well on your machine? |
Wasn't implementing the disablable interface desirable though? Maybe it isn't possible as the toolbar action is not really a widget? |
I intentionally used the Disabled property, since this is also what the I am not sure how you handled such situations in the past. Let me know if I should change the implementation, or how you want to continue. |
By the way, what is the reasoning behind not making the toolbarItems widgets? Line 42 in ccc6a1c
|
0634bc7
to
4dc9db5
Compare
Rebased branch to current develop state |
It's about the public API. Internally menuItem is a widget, but the public api fyne.MenuItem is not. Using public APIs that are abstractions allows us to keep the widgets consistent. A container will give the user control over its content through adding arbitrary widgets, but it is rare for a widget to do this. If you want a "toolbar that accepts anything" then wouldn't that just be a VBox with a background rectangle? That said I don't know what the issue is here, the ToolbarObject returns a CanvasObject for its "implementation detail" and this can be a widget, disablable widget or anything else. So why would this be easier if the main object was a widget? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't quite see how the disabled item is refreshed without internal API access.
I try to give more detail inline - let me know if it is not clear.
Any idea why the tests are always failing with:
? I don't see any connection to the code that I have changed. |
@maruu It is not your fault. It’s a bug in versions of Go older than 1.20. We need to look at how we should address that on our next contributor meeting for Fyne. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More thoughts inline - good to have the feature working though.
Hi @andydotxyz @dweymouth, as discussed here: #4347 (comment) I changed the PR to now use the Button directly. The benefits from my point of view are that the state management is not duplicated, but can be reused from the Button itself. I again tested the functionality with an extension of the fyne_demo app (see my initial PR description for the code if you want to give it a try). Let me know what you think. |
…ctionButton" This reverts commit 97ecd65.
636deb5
to
a701d5f
Compare
Rebased branch to current develop state |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, but this will crash if you just create a &ToolbarAction{} directly as the constructor function is optional.
Since the ToolbarAction can also be created without the constructor, the pointer to the button could be nil.
You are totally correct. Since I cannot store a reference to the button directly (because it cannot be copied) I chose to use lazy initialization. I also added a test for this, hope that's okay. Let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. I have a few suggestions that will clean up the code a bit once resolved
Please resolve the issues reported by the static analysis workflow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done and thanks, this is a great addition
Description:
Added ability to disable ToolbarActions.
I chose to embed the button directly, since it already handles the disable-state logic.
Also, since the button is returned as a pointer, no separate refreshing logic is required. This seems to have been an issue with previous PRs for this issue.
Please let me know if the "Since:" comment with version 2.5 is fine, or if you prefer another version.
I don't necessarily like that the state of Icon & OnActivated are now essentially duplicated (once in the ToolbarAction and once in the underlying Button itself), but I did not want to break backward compatibility by changing the public interface. Let me know what your thoughts are on this.
Fixes #2306
I have tested the code using the following addition to the fyne-demo (
cmd/fyne_demo/tutorials/widget.go
):Checklist:
Where applicable: