-
-
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 .SetIcon() to custom dialogs #5386
base: develop
Are you sure you want to change the base?
Conversation
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.
We discussed new dialogs a long time ago with some v2 dialog stuff that I intended to work on but never got around to. The problem now is that a lot of details are internal (like your new dialogs just being exported functions that call a single internal one) and the dialog API is very old and fragile without much happening. It just doesn't scale well and feels unintuitive compared to more modern and developer friendly APIs that we have in other places.
I think we really should be very careful about adding more dialogs until we have a better API and can expose settings in a tidier way. Adding a new exported constructor API just to change a single internal parameter does not scale well.
A better API in the meantime would perhaps be to just allow setting the icon on some of the other dialogs? You can look at the button row changes that I did a while ago. PS: It should be |
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 don't think this belongs in the info files - we have other source for custom dialogs don't we?
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.
Yeah, I would personally just add a method similar to
Line 53 in 4a875d9
func (d *CustomDialog) SetButtons(buttons []fyne.CanvasObject) { |
I have tried adding a |
It should definitely be possible to do, or might require tweaking some minor stuff, but you might have been bitten by the strange semantics of how dialogs work. You basically have to recreate the dialog with a call to |
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. Looking good. Just a few suggestions inline
Co-authored-by: Jacob Alzén <[email protected]>
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. I noticed a small bug when setting the icon to nil, left a note inline.
I forgot to write this earlier but would you please add some tests? You can look at how the tests around the setButton functionality was done.
FYI: We usually work on the principle that the one adding the review comment is the one that decide when it is resolved (and marks it as such).
How do I make the test image? Should I use the window.Canvas().Capture() function? |
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. Well done with the tests. Really close now. Let's just combine the tests into one and use correct naming :)
} | ||
|
||
func TestCustomSetIconNil(t *testing.T) { | ||
test.NewTempApp(t) | ||
w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) | ||
size := fyne.NewSize(200, 300) | ||
w.Resize(size) | ||
|
||
test.ApplyTheme(t, test.Theme()) | ||
label := widget.NewLabel("Test was successful.") | ||
d := NewCustom("Fyne test", "Dimiss", label, w) | ||
d.SetIcon(nil) | ||
d.Show() | ||
|
||
test.AssertRendersToImage(t, "dialog-custom-seticon-nil.png", w.Canvas()) |
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.
You don't need two different test functions just for setting different values. There is just unnecessary code duplication between them. I'd rather call the test TestCustom_SetIcon
to be consistent with the other tests (that is the standard for naming) and then just at the end of the first one you have, set the icon to nil and do a new assert to image.
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.
Basically keep the first test intact but change the name and then add .SetIcon(nil)
and the asserting to image call. No more than two lines need to be added to the first test, I think.
I am pretty sure the failures were resolved in more recent commits on develop branch, if you rebase or merge it in things should be looking pretty good. |
Description:
I've wanted to include for some time a new API that allows the developer to set whatever resource for the text-based dialog(s) icon. This allows for an example, a success dialog, confirming the user changes.
Checklist:
Where applicable: