Skip to content

Conversation

@gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Jul 20, 2022

Description

This adds StarBorder, along with the interpolations to/from CircleBorder, RoundedRectBorder, and StadiumBorder.

The example looks like this Dartpad. (If it won't load because GitHub's API is overloaded, copy the Gist here into your own DartPad).

Related Issues

Tests

  • Needs tests (hence the Draft).

@gspencergoog gspencergoog marked this pull request as draft July 20, 2022 00:47
@gspencergoog gspencergoog changed the title Star border Add StarBorder and StarBorder.polygon Jul 20, 2022
@flutter-dashboard flutter-dashboard bot added a: animation Animation APIs d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos documentation f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. labels Jul 20, 2022
@bernaferrari
Copy link
Contributor

Wow. That's so good. I would never be able to do something like this that fast.

@gspencergoog
Copy link
Contributor Author

Thanks.. I have been doing this for a while, though. Plus graphics stuff is my favorite kind of thing to build.

@bernaferrari
Copy link
Contributor

Did you take a look at the Android implementation? Or is it 100% from your mind? It is so sophisticated...

@gspencergoog gspencergoog force-pushed the polygon_border branch 11 times, most recently from 55797f4 to e451429 Compare July 23, 2022 01:07
@bernaferrari
Copy link
Contributor

bernaferrari commented Jul 24, 2022

This is small, don't worry if it is too hard to fix, but lerp 0.00 to 0.01 changes the size:

Screen.Recording.2022-07-24.at.20.00.18.mov

I think squash is the reason:

Screen.Recording.2022-07-24.at.20.25.15.mov

@bernaferrari
Copy link
Contributor

bernaferrari commented Jul 24, 2022

Suggestion: add a constructor that calculates valleyRounding and pointRounding from side.borderRadius (maybe could be the default one, maybe not. If default, they could go to custom). Could be something like clampDouble(borderRadius / rect, 0, 0.5) and then it applies this to both valleyRounding and pointRounding. You would hide two (kind of) confusing variables from the user and make star work with the BorderRadius user already know and love.

Also, I don't know what I did here, but it doesn't seem fine (again, if it is too hard or just an edge case, don't worry):
image

@gspencergoog gspencergoog force-pushed the polygon_border branch 3 times, most recently from 76a7488 to 62eee7a Compare July 25, 2022 16:21
@gspencergoog
Copy link
Contributor Author

What you're seeing there in the last one you posted is numerical instability as the inner radius ratio goes to zero. I'm now clamping it to a minimum of 1e-6, which should avoid that.

As for your suggestion around borderRadius, I'm not sure that it's any more clear. I can't calculate the exact radius because I'm scaling it all at the end to keep it the same size as the inner radius ratio goes to zero (which is also the source of the numerical instability), so the number in the radius would be pretty arbitrary (e.g. you'd specify 100, but get back something with radius 10, and as you change the inner radius ratio you'd have to also change the borderRadius to keep it drawn at a constant size). Also, the squash parameter would change any Radius.circular to an ellipse.

@gspencergoog gspencergoog force-pushed the polygon_border branch 2 times, most recently from 4103ad1 to dd9a500 Compare July 25, 2022 17:31
@bernaferrari
Copy link
Contributor

bernaferrari commented Jul 25, 2022

borderRadius

Hmmm.. :( makes sense. I still wish there were a 'simpler' way of dealing with valleyRounding and pointRounding, like an unified API for 90% of users that applies the same value for both of them. [0-1] that's divided by 2 and applied to both. My dream. Every other API works with [0-1].

That said, I like them, I think they should be exposed, just maybe not 'by default'.

@gspencergoog gspencergoog force-pushed the polygon_border branch 2 times, most recently from 47d8011 to b0d5615 Compare July 26, 2022 20:25
@gspencergoog gspencergoog marked this pull request as ready for review July 26, 2022 21:32
@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 #107979 at sha 2632c9a

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Jul 26, 2022
@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 #107979 at sha b058831

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

A star is born!

LGTM

@override
void dispose() {
super.dispose();
_model.removeListener(_modelChanged);
Copy link
Contributor

Choose a reason for hiding this comment

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

textController.dispose()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

fontStyle: FontStyle.normal,
),
child: SliderTheme(
data: SliderTheme.of(context).copyWith(),
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems odd. If it's necessary, a comment that explains why would help.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it was a half-compelted thought that happened to compile. Removed.

mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: Container(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could factor out a widget here and below, like:

class StarBorderView extends StatelessWidget {
  const StarBorderView(this.star, this.title);

  final StarBorder star;
  final String title;

  @override
  Widget build(BuildContext) {
    return Container(
      key: UniqueKey(),
      alignment: Alignment.center,
      padding: const EdgeInsets.all(20),
      width: 150,
      height: 100,
      decoration: ShapeDecoration(
        color: Colors.blue.shade100,
        shape: star,
      ),
      child: const Text(title),
    );
  }
}

There are other places where you could do this kind of thing. Not a big deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I factored this out. It does help with illustrating how to use it too, aside from the refactor.

Expanded(
child: Container(
color: Colors.black12,
margin: const EdgeInsets.all(16.0),
Copy link
Contributor

Choose a reason for hiding this comment

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

padding: const EdgeInsets.all(32) has the same effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, margin is on the outside, padding is on the inside.


@override
void dispose() {
super.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

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

Conventionally super.dispose() is last (here and elsewhere).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, fixed.

points: points ?? this.points,
rotation: rotation ?? this.rotation,
innerRadiusRatio: innerRadiusRatio ?? this.innerRadiusRatio,
pointRounding: valleyRounding ?? this.pointRounding,
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a typo here => valleyRounding

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ooh! Good catch, thanks!

@bernaferrari
Copy link
Contributor

bernaferrari commented Jul 27, 2022

ContinuousRectangleBorder can't lerp to anything, it is one of the weirdest OutlinedBorders. Maybe you could apply what you learned in the star to make it better? Maybe it could extend StarBorder so it gets lerp for free?

It seems like your polygonal is pretty close to ContinuousRectangleBorder and could help achieve what people want: #91523

image

@gspencergoog
Copy link
Contributor Author

It seems like your polygonal is pretty close to ContinuousRectangleBorder and could help achieve what people want

Well, sort of. I don't think I could generate a superellipse with the polygon generator: it would generate something similar but not quite the same, and because it would have to be rotated 45 degrees (and I use the non-rotated radius to calculate the scale), it would be smaller than they expected.

Best would be to just fix the ContinuousRectangleBorder to generate a squircles properly, and add some lerping targets to it. It's probably just not scaling them properly.

@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 #107979 at sha c8afc82

@bernaferrari
Copy link
Contributor

Best would be to just fix the ContinuousRectangleBorder

Shall I open the issue? lol
But I'm not sure I can help a lot, that's 100% path.

@gspencergoog gspencergoog added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 27, 2022
@gspencergoog gspencergoog changed the title Add StarBorder and StarBorder.polygon [Abandoned] Add StarBorder and StarBorder.polygon Jul 27, 2022
@gspencergoog
Copy link
Contributor Author

I'm abandoning this PR for a fresh copy: #108489

This is because Skia Gold got really confused about which patchsets were which because of my force-pushing to this PR.

The contents are the same.

@gspencergoog
Copy link
Contributor Author

Leaving this open for a few days so the Skia Gold team can take a look at it.

@Piinks
Copy link
Contributor

Piinks commented Jul 27, 2022

@gspencergoog gspencergoog removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 27, 2022
@gspencergoog
Copy link
Contributor Author

@kjlubick @LeandroLovisolo Please let me know when you're done investigating so that I can can close this stale PR.

@gspencergoog gspencergoog deleted the polygon_border branch October 7, 2022 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: animation Animation APIs c: contributor-productivity Team-specific productivity, code health, technical debt. d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos 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.

[Request] Scallop / Sunflower / Star Material 3 Shape

4 participants