egui/epaint/src/stroke.rs

35 lines
786 B
Rust
Raw Normal View History

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