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

Refactoring: internal widgets #875

Merged
merged 7 commits into from Apr 17, 2020

Conversation

toaster
Copy link
Member

@toaster toaster commented Apr 16, 2020

Description:

This PR moves several internal widgets (which are needed for the upcoming menu refactoring) into a new internal widget package.

Checklist:

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

@toaster toaster requested a review from andydotxyz April 16, 2020 21:01
Copy link
Member

@stuartmscott stuartmscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job Tilo, very readable code!

}

b.hidden = false
w.Refresh()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how come show uses w.Refresh(), but hide uses canvas.Refresh(w)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s because a hidden widget won’t be rendered. Therefore w.Refresh() is a waste of time there.

r.Layout(size)
}

func (b *base) show(w fyne.Widget) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to ask if show can be moved up next to hide, then I realized you have made all of these files declare members in alphabetical order and I think I prefer that, danke!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gern geschehen! (My pleasure!)

)

// NewBaseRenderer creates a new BaseRenderer.
func NewBaseRenderer(objects []fyne.CanvasObject) BaseRenderer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#827 says struct before constructor, but this looks okay too. I'd rather the codebase was consistent so should #827 be changed to this order?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops … I wrote this code before #827. Because everybody™ agreed to #827 I already did some other refactorings with structs before constructors.
I will adjust this PR.

"fyne.io/fyne/theme"
)

type baseRenderer struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand why this was moved into internal, however this convenience is no longer unaccessible for developers creating custom widgets. We could expose it as:

package widget

import "fyne.io/fyne/internal/widget"

type BaseRenderer struct {
  widget.baseRenderer
}

What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the advantage is too small to do so.
@andydotxyz convinced me to not add such a construct for the base widget where the advantage would be much bigger. Therefore I would not do that here and now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was not available to any custom widget creation because it was not exposed. The conversation I had with @toaster largely came to the conclusion that someone writing a widget could be expected to write a complete renderer, they do not have the same inheritance properties that widget objects do. Additionally if we make it too "simple" or "static" then there is a much higher chance that third party widgets would not respond well on refresh or theme change (I guess?).

There is another discussion about making it easier to create widgets with trivial renderers at #709 but honestly I am coming to the view that such enablers might encourage things that we don't think are good ideas (such as realising that customisation is difficult resorting to everything becoming a clickable image using a png that does not reflect theme colours)...

It's probably quite a big discussion but given that this was not exposed we can always decide to add your proposed solution in the future.

@andydotxyz andydotxyz merged commit 626c1aa into fyne-io:develop Apr 17, 2020
@toaster toaster deleted the refactoring/internal_widgets branch April 17, 2020 09:41
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.

None yet

3 participants