-
-
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
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 :)
dialog/custom_test.go
Outdated
} | ||
|
||
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. |
Does it looks better now? I'll try rebasing now... |
Hope its good now :) |
Oh no. You are running into the horrible test failure that I encountered |
It is a test that hard-codes the lookup of the amount of files in the folder where you put your images. Now there are 11 instead of 9 so it is failing everywhere |
That test is really smelly. We need to do something about that: Lines 420 to 450 in 4a875d9
|
Mind if I ask why its hard-coded? |
I don't know. I suppose the one who wrote the test didn't think of the consequences of having it fail any time someone adds a new file to the folder but it doesn't matter much. We all make mistakes. I added those warning comments last time I ran into it. The fact that it is problematic remains :) |
At the same time it's a pretty easy fix. Files added, test fails, update number, tests pass. |
I mean I thought it had a particular reason, I'll update the file :) |
Just to make sure, I just need to change from 9 to 11, other numbers should be fine, right? |
You can run the test locally to see what it says. It should print an expected and an actual number. Just edit that and you should see when it passes |
Should be working now, had to update two numbers. |
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.
Clean addition thanks.
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.
Great addition indeed. Well done!
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: