Skip to content

rounded rectangle graphics#2491

Merged
hecrj merged 1 commit into
iced-rs:masterfrom
gintsgints:master
Sep 12, 2024
Merged

rounded rectangle graphics#2491
hecrj merged 1 commit into
iced-rs:masterfrom
gintsgints:master

Conversation

@gintsgints

@gintsgints gintsgints commented Jul 2, 2024

Copy link
Copy Markdown
Contributor

This is my attempt to add functionality for additional canvas shape, rounded rectangle.

@vladh

vladh commented Jul 4, 2024

Copy link
Copy Markdown
Contributor

I don't think this approach is flexible enough. For example, I would expect drawing a square with a very high border radius to result in a circle. This is what happens in iced::Border::rounded and also in CSS. However, in your implementation, a buggy shape is drawn.

For example, here's the result of drawing examples/graphics with a radius of 80:

2024-07-04-12-16-51

@gintsgints

Copy link
Copy Markdown
Contributor Author

Hmm, so what should flexible solution do instead?
I can make radius relative to the width of the rectangle or disallow too big radius.

@vladh

vladh commented Jul 4, 2024

Copy link
Copy Markdown
Contributor

Hmm, so what should flexible solution do instead?

It looks like, at the very least, you want something like:

radius = min(radius, min(height / 2, width / 2))

See:

It would also be nice to be able to specify horizontal and vertical radius, and to specify individual radii for each of the 4 corners, by using or extending the existing iced::Border::Radius.

@gintsgints

Copy link
Copy Markdown
Contributor Author

One commit implement just min check, other use Radius as argument, so it is possible to specify different radius for each corner.

Comment thread core/src/border.rs Outdated
/// top-left, top-right, bottom-right, bottom-left.
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Radius([f32; 4]);
pub struct Radius(pub [f32; 4]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this needs to be pub — the from() methods can be used.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, you are right. Fixed.

Comment thread graphics/src/geometry/path.rs Outdated
}

/// Creates a new [`Path`] representing a rounded rectangle given its top-left
/// corner coordinate, its `Size` and radius.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe:

its [`Size`] and border [`Radius`]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment thread graphics/src/geometry/path/builder.rs Outdated
}

/// Adds a rounded rectangle to the [`Path`] given its top-left
/// corner coordinate its `Size` and curve radius.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe:

its [`Size`] and border [`Radius`]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

@vladh

vladh commented Jul 5, 2024

Copy link
Copy Markdown
Contributor

This looks okay to me right now, but I'm not a maintainer so you'll have to wait for one to look at this.

@hecrj hecrj added this to the 0.13 milestone Sep 12, 2024
@hecrj hecrj added feature New feature or request widget canvas addition labels Sep 12, 2024

@hecrj hecrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

I have removed the example since we already have too many.

@hecrj hecrj enabled auto-merge September 12, 2024 22:59
@hecrj hecrj merged commit f392f4a into iced-rs:master Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants