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

Fix/consistentbasewidget #2264

Merged
merged 5 commits into from
Jun 3, 2021

Conversation

andydotxyz
Copy link
Member

Description:

Move our internal Base widget (that could not be extended) to be consistent with the public BaseWidget.
Now we have just 1 API and the ability to extend both.
It is still 2 different classes due to the cycle issues. One cannot be an alias of the other due to certain unexported APIs.
This will be further tidied before 2.1 by hopefully replacing the ExtendBaseWidget idea - but for now it should unblock some keyboard operation items.

Checklist:

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

This needs to be improved through design updates, but for now this is clearer.
It means we can extend internal widgets and not be confused which API is used
@andydotxyz andydotxyz requested a review from toaster May 26, 2021 22:25
Comment on lines 13 to 15
size fyne.Size
position fyne.Position
hidden bool
Copy link
Member

Choose a reason for hiding this comment

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

FMI: why did you remove the alphabetical 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.

A mistake, sorry

RefreshWidget(s)
func (s *Scroll) Resize(sz fyne.Size) {
s.Base.Resize(sz)
s.Refresh()
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn’t we keep the refreshes limited to actual changes of the size (size != s.size)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good catch thanks.

@@ -199,6 +160,7 @@ func (r *menuBarRenderer) Refresh() {
r.Layout(r.b.Size())
r.background.FillColor = theme.ButtonColor()
r.background.Refresh()
r.ShadowingRenderer.RefreshShadow()
Copy link
Member

Choose a reason for hiding this comment

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

FYI: I guess, this is not really related to the base widget change and therefore should have been in a separate commit, right?

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 had assumed it was something that I broke in the refactoring. If it was already broken then yes it should be a separate commit.
I don't think it's worth unpicking and force pushing a better version, but I will try to keep an eye out in future commits.
If you disagree say so and I'll rework the history

widget/tree.go Outdated
@@ -643,6 +643,12 @@ func (n *treeNode) Tapped(*fyne.PointEvent) {
n.tree.Select(n.uid)
}

func (n *treeNode) Resize(s fyne.Size) {
n.BaseWidget.Resize(s)
// TODO find out if the indentation changed. If not, and size is the same, then we can skip this as normal
Copy link
Member

Choose a reason for hiding this comment

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

TBH, I think that a caller of Resize should never rely on the refresh. If the indentation gets changed at some point and depends on the refresh of a Resize call with the same size, this is wrong. Instead the change of the indentation should trigger a refresh.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not relying on a Refresh - it's the Layout that we care about.
Normally we can ignore Resize if the size has not changed - but in the case of Tree it may be the same size but need to have the content moved when it's reused (because increased indent does not change size).
Maybe there is a better solution, but I cannot think of one right 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 still don’t fully understand why a Resize of a tree node has to handle indentation change. AFAICS an indentation change is implemented by the node’s update method which should then do the appropriate things.
Also, AFAIK, the BaseWidget's Resize doesn’t do anything if the size didn’t change (apart from heating the world).

Copy link
Member Author

Choose a reason for hiding this comment

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

Quite right, I managed to track down the root cause. The leaf and branch widgets were having the treeNode widget inside accessed directly, which was part of the issue. The rest was that the partialRefresh called when depth changed was not updating the node layout.

With this in place it should be fixed much more satisfactorily.

Copy link
Member

@toaster toaster left a comment

Choose a reason for hiding this comment

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

A couple of questions/suggestions as normal comments (not needed for my approval).
And one objection to the menu bar refresh fix.

Comment on lines 116 to 120

if i.Parent.active {
i.Parent.canvas.Focus(i)
}
i.Refresh()
Copy link
Member

Choose a reason for hiding this comment

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

There is no test for this, therefore I don’t know which bug you’re trying to fix with it.
But I think this is partly wrong. The parent’s toggle already focuses the item on activation and unfocuses it on deactivation.
So, if the menu is active after the toggle, the item should already be focused and the added focus code does nothing.
If the additional Refresh fixes some bug, we should try to add a test case for it and also move it to MenuBar’s toggle(). Currently, the item gets refreshed before it is being focused. Maybe that’s to early?

Copy link
Member Author

@andydotxyz andydotxyz Jun 1, 2021

Choose a reason for hiding this comment

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

Apologies it was not a bug fix, I had misread the code in the refactor and you are right it should not have been needed. What has changed is sequence of refresh request events I think, so potentially extra refresh calls were previously made that have been reduced, so some areas are now not refreshing enough. I tracked down that activateChild does not actually refresh the button - only the bar. The bar's refresh does not cascade to the list of items it would seem. I have put in place what feels like a better fix in activateChild, what do you think?

Copy link
Member Author

@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.

Thanks for the notes, I hope these comments and the commit help :)

@@ -199,6 +160,7 @@ func (r *menuBarRenderer) Refresh() {
r.Layout(r.b.Size())
r.background.FillColor = theme.ButtonColor()
r.background.Refresh()
r.ShadowingRenderer.RefreshShadow()
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 had assumed it was something that I broke in the refactoring. If it was already broken then yes it should be a separate commit.
I don't think it's worth unpicking and force pushing a better version, but I will try to keep an eye out in future commits.
If you disagree say so and I'll rework the history

Comment on lines 116 to 120

if i.Parent.active {
i.Parent.canvas.Focus(i)
}
i.Refresh()
Copy link
Member Author

@andydotxyz andydotxyz Jun 1, 2021

Choose a reason for hiding this comment

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

Apologies it was not a bug fix, I had misread the code in the refactor and you are right it should not have been needed. What has changed is sequence of refresh request events I think, so potentially extra refresh calls were previously made that have been reduced, so some areas are now not refreshing enough. I tracked down that activateChild does not actually refresh the button - only the bar. The bar's refresh does not cascade to the list of items it would seem. I have put in place what feels like a better fix in activateChild, what do you think?

Comment on lines 13 to 15
size fyne.Size
position fyne.Position
hidden bool
Copy link
Member Author

Choose a reason for hiding this comment

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

A mistake, sorry

RefreshWidget(s)
func (s *Scroll) Resize(sz fyne.Size) {
s.Base.Resize(sz)
s.Refresh()
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good catch thanks.

widget/tree.go Outdated
@@ -643,6 +643,12 @@ func (n *treeNode) Tapped(*fyne.PointEvent) {
n.tree.Select(n.uid)
}

func (n *treeNode) Resize(s fyne.Size) {
n.BaseWidget.Resize(s)
// TODO find out if the indentation changed. If not, and size is the same, then we can skip this as normal
Copy link
Member Author

Choose a reason for hiding this comment

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

It's not relying on a Refresh - it's the Layout that we care about.
Normally we can ignore Resize if the size has not changed - but in the case of Tree it may be the same size but need to have the content moved when it's reused (because increased indent does not change size).
Maybe there is a better solution, but I cannot think of one right now.

@andydotxyz andydotxyz requested a review from toaster June 3, 2021 11:34
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.

This looks good and sensible to me, though I would have preferred to get rid of .ExtendBaseWidget() entirely ;)

@andydotxyz
Copy link
Member Author

This looks good and sensible to me, though I would have preferred to get rid of .ExtendBaseWidget() entirely ;)

Yes, that is the plan. But it will be easier to get rid of from a consistent place :).
Plus I don't yet know how we will do it, but I do know that this was blocking.

@toaster
Copy link
Member

toaster commented Jun 3, 2021

This looks good and sensible to me, though I would have preferred to get rid of .ExtendBaseWidget() entirely ;)

Yeah, that’s something @andydotxyz and me discussed already. Sadly, it’s not trivial.

@andydotxyz andydotxyz merged commit 72d5607 into fyne-io:develop Jun 3, 2021
@andydotxyz andydotxyz deleted the fix/consistentbasewidget branch June 3, 2021 13:21
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.

3 participants