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 #828: tab container update handling #998

Merged
merged 12 commits into from May 19, 2020
Merged

Conversation

toaster
Copy link
Member

@toaster toaster commented May 17, 2020

Description:

This PR refactors the tab container widget’s update handling and fixes issues when adding/removing items to an existing tab container.
It also removes the tab container widget’s dependency from the renderer cache.
As a side-effect it introduces TabContainer.SetItems which might be used to replace the tab items completely.

Fixes #828

Checklist:

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

Where applicable:

  • Public APIs match existing style.

This prepares the move of the tests to the widget_test package
which is necessary to use image based tests.

The tests that have a misleading name due to this change will
be adjusted in a later commit.
The refactoring of the tab container tests to reside in the widget_test
package and to use image based tests if necessary (no access to renderer)
revealed fyne-io#828.
The refactoring of the tab container update handling fixed the issues.
@toaster toaster changed the title Bugfix/828 Fix #828: tab container update handling May 17, 2020
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.

It is more difficult to review the logic changes when the file has been re-ordered this much, but overall the code quality is higher, there are more tests, and test images are grouped by widget. Good job Tilo

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.

Nice, just a couple of questions.

return false
}
for i, item := range r.container.Items {
if item.Content != r.objects[i] {
Copy link
Member

Choose a reason for hiding this comment

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

What about if the tab text or icon changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I’m not sure if this really is a use case but it can be done, so I’ll add a test for this.

}
var buttons, objects []fyne.CanvasObject
for i, item := range r.container.Items {
button := r.buildButton(item, iconPos)
Copy link
Member

Choose a reason for hiding this comment

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

Is it not worth re-using the existing buttons, if there are enough?

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 don’t think so.

  1. A tab container usually doesn’t have more than a couple of tabs.
  2. Modifying the tab list probably doesn’t happen that often.
  3. Checking if an item is reusable introduces a complexity with limited use (see 1. and 2.)

@toaster
Copy link
Member Author

toaster commented May 17, 2020

It is more difficult to review the logic changes when the file has been re-ordered this much, but overall the code quality is higher, there are more tests, and test images are grouped by widget.

@stuartmscott you didn’t reviewed all commits at once, didn’t you?
In retrospect I’d say I could have done the refactoring in smaller steps. I only wanted to refactor the tests to add a test for #828 and then it turned out that a lot of already tested cases were broken (visually) and then I fixed them :/.

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.

Ah yes it is much easier to review each commit independantly - I was reviewing the combined diff

widget/tabcontainer.go Outdated Show resolved Hide resolved
andydotxyz
andydotxyz previously approved these changes May 17, 2020
stuartmscott
stuartmscott previously approved these changes May 18, 2020
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.

LGTM

You will need to merge develop and fix any conflicts before merging

@toaster toaster dismissed stale reviews from stuartmscott and andydotxyz via 79bbed8 May 19, 2020 09:54
@toaster
Copy link
Member Author

toaster commented May 19, 2020

@stuartmscott @andydotxyz I merged by hand and that dismissed the approvals, sorry.

@toaster
Copy link
Member Author

toaster commented May 19, 2020

Notable changes due to the merge:

  • all tab container rendering tests had to be separated into mobile and desktop
  • software painter now renders centred or right adjusted text correctly

@andydotxyz andydotxyz merged commit 3135c88 into fyne-io:develop May 19, 2020
@stuartmscott stuartmscott mentioned this pull request May 19, 2020
5 tasks
@toaster toaster deleted the bugfix/828 branch May 20, 2020 06:16
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