1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
// The following code was copied and modified from
// https://github.com/iced-rs/iced/blob/31d1d5fecbef50fa319cabd5d4194f1e4aaefa21/core/src/border.rs
// Iced license (MIT): https://github.com/iced-rs/iced/blob/31d1d5fecbef50fa319cabd5d4194f1e4aaefa21/LICENSE
use rootvg_core::color::PackedSrgb;
/// A struct defining a border.
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Border {
/// The color of the border.
pub color: PackedSrgb,
/// The width of the border in logical points.
pub width: f32,
/// The radius of the border in logical points.
pub radius: Radius,
}
/// The border radii in logical points
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Radius {
pub top_left: f32,
pub top_right: f32,
pub bottom_right: f32,
pub bottom_left: f32,
}
impl From<f32> for Radius {
fn from(w: f32) -> Self {
Self {
top_left: w,
top_right: w,
bottom_right: w,
bottom_left: w,
}
}
}
impl From<u8> for Radius {
fn from(w: u8) -> Self {
Self {
top_left: f32::from(w),
top_right: f32::from(w),
bottom_right: f32::from(w),
bottom_left: f32::from(w),
}
}
}
impl From<[f32; 4]> for Radius {
fn from(radi: [f32; 4]) -> Self {
Self {
top_left: radi[0],
top_right: radi[1],
bottom_right: radi[2],
bottom_left: radi[3],
}
}
}
impl From<Radius> for [f32; 4] {
fn from(radi: Radius) -> Self {
[
radi.top_left,
radi.top_right,
radi.bottom_right,
radi.bottom_left,
]
}
}