-
-
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
Fix/consistentbasewidget #2264
Fix/consistentbasewidget #2264
Conversation
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
internal/widget/base.go
Outdated
size fyne.Size | ||
position fyne.Position | ||
hidden bool |
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.
FMI: why did you remove the alphabetical order?
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.
A mistake, sorry
RefreshWidget(s) | ||
func (s *Scroll) Resize(sz fyne.Size) { | ||
s.Base.Resize(sz) | ||
s.Refresh() |
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.
Shouldn’t we keep the refreshes limited to actual changes of the size (size != s.size
)?
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.
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() |
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.
FYI: I guess, this is not really related to the base widget change and therefore should have been in a separate commit, right?
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 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 |
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.
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.
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.
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.
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 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).
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.
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.
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.
A couple of questions/suggestions as normal comments (not needed for my approval).
And one objection to the menu bar refresh fix.
|
||
if i.Parent.active { | ||
i.Parent.canvas.Focus(i) | ||
} | ||
i.Refresh() |
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.
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?
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.
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?
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 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() |
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 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
|
||
if i.Parent.active { | ||
i.Parent.canvas.Focus(i) | ||
} | ||
i.Refresh() |
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.
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?
internal/widget/base.go
Outdated
size fyne.Size | ||
position fyne.Position | ||
hidden bool |
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.
A mistake, sorry
RefreshWidget(s) | ||
func (s *Scroll) Resize(sz fyne.Size) { | ||
s.Base.Resize(sz) | ||
s.Refresh() |
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.
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 |
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.
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.
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.
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 :). |
Yeah, that’s something @andydotxyz and me discussed already. Sadly, it’s not trivial. |
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: