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 single ToggleButton border painting bugs #73780

Merged
merged 6 commits into from Jan 14, 2021

Conversation

xu-baolin
Copy link
Member

This patch fixes two bugs:

1, Does not apply border-radius when there is only one button

Expected:

image

Actual:

image

2, Border-radius paint incorrect when Radius.x or Radius.y equal 0.0

  borderRadius: BorderRadius.only(
    topRight: Radius.elliptical(10, 0),
    topLeft: Radius.elliptical(0, 10),
    bottomRight: Radius.elliptical(0, 10),
    bottomLeft: Radius.elliptical(10, 0),
  ),

Expected:

image

Actual:

image

Related Issues

Fixes #73725

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jan 12, 2021
@google-cla google-cla bot added the cla: yes label Jan 12, 2021
topLeft: (borderRadius.topLeft.x * borderRadius.topLeft.y != 0.0) ? borderRadius.topLeft : Radius.zero,
topRight: (borderRadius.topRight.x * borderRadius.topRight.y != 0.0) ? borderRadius.topRight : Radius.zero,
bottomLeft: (borderRadius.bottomLeft.x * borderRadius.bottomLeft.y != 0.0) ? borderRadius.bottomLeft : Radius.zero,
bottomRight: (borderRadius.bottomRight.x * borderRadius.bottomRight.y != 0.0) ? borderRadius.bottomRight : Radius.zero,
Copy link
Member Author

Choose a reason for hiding this comment

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

This change fixes the #2 bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

My first instinct was that some kind of elliptical rounded corner to be drawn anyway instead of having none at all. Is this because of the drawArc API that we're using? For now, this looks good.

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly correct.

// Only one button.
if (isFirstButton && isLastButton) {
final Path leadingPath = Path();
final double startX = (rrect.brRadiusX == 0.0) ? outer.right : rrect.right - rrect.brRadiusX;
Copy link
Member Author

@xu-baolin xu-baolin Jan 12, 2021

Choose a reason for hiding this comment

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

If the radius is zero, we should paint a little more to connect the start and stop ends.
Otherwise, there will be a gap like below:
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, good catch here

@skia-gold
Copy link

Gold has detected about 9 untriaged digest(s) on patchset 2.
View them at https://flutter-gold.skia.org/cl/github/73780

@@ -891,13 +891,6 @@ void main() {
expect(
toggleButtonRenderObject,
paints
// trailing side
Copy link
Member Author

Choose a reason for hiding this comment

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

If only one button, we can paint the border with one path now.

@skia-gold
Copy link

Gold has detected about 6 untriaged digest(s) on patchset 3.
View them at https://flutter-gold.skia.org/cl/github/73780

@skia-gold
Copy link

Gold has detected about 6 untriaged digest(s) on patchset 4.
View them at https://flutter-gold.skia.org/cl/github/73780

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #73780 at sha e1400cf

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Jan 12, 2021
Copy link
Contributor

@shihaohong shihaohong left a comment

Choose a reason for hiding this comment

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

LGTM with a small nit. Thanks for the fix!

topLeft: (borderRadius.topLeft.x * borderRadius.topLeft.y != 0.0) ? borderRadius.topLeft : Radius.zero,
topRight: (borderRadius.topRight.x * borderRadius.topRight.y != 0.0) ? borderRadius.topRight : Radius.zero,
bottomLeft: (borderRadius.bottomLeft.x * borderRadius.bottomLeft.y != 0.0) ? borderRadius.bottomLeft : Radius.zero,
bottomRight: (borderRadius.bottomRight.x * borderRadius.bottomRight.y != 0.0) ? borderRadius.bottomRight : Radius.zero,
Copy link
Contributor

Choose a reason for hiding this comment

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

My first instinct was that some kind of elliptical rounded corner to be drawn anyway instead of having none at all. Is this because of the drawArc API that we're using? For now, this looks good.

// Only one button.
if (isFirstButton && isLastButton) {
final Path leadingPath = Path();
final double startX = (rrect.brRadiusX == 0.0) ? outer.right : rrect.right - rrect.brRadiusX;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, good catch here

packages/flutter/test/material/toggle_buttons_test.dart Outdated Show resolved Hide resolved
packages/flutter/test/material/toggle_buttons_test.dart Outdated Show resolved Hide resolved
@shihaohong shihaohong changed the title fix toggleButton border paint bug Fix single ToggleButton border painting bugs Jan 14, 2021
@xu-baolin
Copy link
Member Author

Thanks for the review.
Could you triage the golden files for me additional? There seems to be something wrong with my permissions.

xu-baolin and others added 2 commits January 14, 2021 14:12
Co-authored-by: Shi-Hao Hong <shihaohong@google.com>
Co-authored-by: Shi-Hao Hong <shihaohong@google.com>
@skia-gold
Copy link

Gold has detected about 9 untriaged digest(s) on patchset 6.
View them at https://flutter-gold.skia.org/cl/github/73780

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #73780 at sha 6dda1a6

@shihaohong
Copy link
Contributor

Just approved the gold triage 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ToggleButtons widget does not apply border radius when there is only one child
4 participants