egui/epaint/src/stroke.rs
Emil Ernerfeldt 5dd68337c4 Use Rgba (4xf32) instead of Color32 in all interfaces
This simplifies a few things, but some benchmarks gets worse,
probably due to the increased memory use (and thus more cache misses).

I don't plan to merge this, but leave it here as an experiment
2021-08-15 20:15:14 +02:00

34 lines
786 B
Rust

use super::*;
/// Describes the width and color of a line.
///
/// The default stroke is the same as [`Stroke::none`].
#[derive(Clone, Copy, Debug, Default, PartialEq)]
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
pub struct Stroke {
pub width: f32,
pub color: Rgba,
}
impl Stroke {
/// Same as [`Stroke::default`].
pub fn none() -> Self {
Self::new(0.0, Rgba::TRANSPARENT)
}
pub fn new(width: impl Into<f32>, color: impl Into<Rgba>) -> Self {
Self {
width: width.into(),
color: color.into(),
}
}
}
impl<Color> From<(f32, Color)> for Stroke
where
Color: Into<Rgba>,
{
fn from((width, color): (f32, Color)) -> Stroke {
Stroke::new(width, color)
}
}