document corner radius

This commit is contained in:
griffi-gh 2024-03-23 23:32:21 +01:00
parent f60087f12e
commit f8bf39342b

View file

@ -3,6 +3,7 @@ use crate::rect::Corners;
//TODO uneven corners (separate width/height for each corner) //TODO uneven corners (separate width/height for each corner)
/// Calculate the number of points based on the maximum corner radius
fn point_count(corners: Corners<f32>) -> NonZeroU16 { fn point_count(corners: Corners<f32>) -> NonZeroU16 {
//Increase for higher quality //Increase for higher quality
const VTX_PER_CORER_RADIUS_PIXEL: f32 = 0.5; const VTX_PER_CORER_RADIUS_PIXEL: f32 = 0.5;
@ -11,19 +12,31 @@ fn point_count(corners: Corners<f32>) -> NonZeroU16 {
).unwrap() ).unwrap()
} }
/// Low-level options for rendering rounded corners
#[derive(Clone, Copy, Debug, PartialEq)] #[derive(Clone, Copy, Debug, PartialEq)]
pub struct RoundedCorners { pub struct RoundedCorners {
/// Corner radius of each corner
pub radius: Corners<f32>, pub radius: Corners<f32>,
/// Number of points to use for each corner
///
/// This value affects all corners, regardless of their individual radius
pub point_count: NonZeroU16, pub point_count: NonZeroU16,
} }
impl From<Corners<f32>> for RoundedCorners { impl From<Corners<f32>> for RoundedCorners {
/// Create a new `RoundedCorners` from [`Corners<f32>`](crate::rect::Corners)
///
/// Point count will be calculated automatically based on the maximum radius
fn from(radius: Corners<f32>) -> Self { fn from(radius: Corners<f32>) -> Self {
Self::from_radius(radius) Self::from_radius(radius)
} }
} }
impl RoundedCorners { impl RoundedCorners {
/// Create a new `RoundedCorners` from [`Corners<f32>`](crate::rect::Corners)
///
/// Point count will be calculated automatically based on the maximum radius
pub fn from_radius(radius: Corners<f32>) -> Self { pub fn from_radius(radius: Corners<f32>) -> Self {
Self { Self {
radius, radius,