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

Add .SetIcon() to custom dialogs #5386

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

lostdusty
Copy link
Contributor

@lostdusty lostdusty commented Jan 9, 2025

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:

  • Tests included.
  • Lint and formatter run with no errors.
  • Tests all pass.

Where applicable:

  • Public APIs match existing style and have Since: line.

@lostdusty lostdusty mentioned this pull request Jan 9, 2025
4 tasks
Copy link
Member

@Jacalz Jacalz left a 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.

@Jacalz
Copy link
Member

Jacalz commented Jan 9, 2025

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 Since: 2.6.0 for the new APIs.

Copy link
Member

@andydotxyz andydotxyz left a 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?

Copy link
Member

@Jacalz Jacalz left a 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

func (d *CustomDialog) SetButtons(buttons []fyne.CanvasObject) {
on the custom dialog struct.

@lostdusty
Copy link
Contributor Author

I have tried adding a SetIcon on custom but it did not work, at least not with NewCustomDialog

@Jacalz
Copy link
Member

Jacalz commented Jan 9, 2025

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 .create() to populate the internal layout and objects. I worked around this, or optimized it, with setButtons to avoid recreating the whole dialog.

@lostdusty
Copy link
Contributor Author

I think I managed to do it
image

@coveralls
Copy link

coveralls commented Jan 9, 2025

Coverage Status

coverage: 59.341% (+0.01%) from 59.329%
when pulling 0cb1e9d on lostdusty:patch-1
into 1bfc24c on fyne-io:develop.

@Jacalz Jacalz changed the title Proposal: CustomMessage dialogs Add .SetIcon() to custom dialogs Jan 10, 2025
Copy link
Member

@Jacalz Jacalz left a 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

dialog/base.go Show resolved Hide resolved
dialog/custom.go Outdated Show resolved Hide resolved
Copy link
Member

@Jacalz Jacalz left a 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).

dialog/base.go Show resolved Hide resolved
@lostdusty
Copy link
Contributor Author

How do I make the test image? Should I use the window.Canvas().Capture() function?

@lostdusty
Copy link
Contributor Author

Used it, all tests passed for me :)
image

Copy link
Member

@Jacalz Jacalz left a 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 :)

Comment on lines +159 to +173
}

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())
Copy link
Member

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.

Copy link
Member

@Jacalz Jacalz Jan 11, 2025

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.

@andydotxyz
Copy link
Member

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.

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.

4 participants