2023-09-09 21:08:23 +02:00
|
|
|
//! Fill [`Geometry`] with a certain style.
|
|
|
|
|
//!
|
|
|
|
|
//! [`Geometry`]: super::Renderer::Geometry
|
2023-03-03 04:57:55 +01:00
|
|
|
pub use crate::geometry::Style;
|
2023-05-19 03:32:21 +02:00
|
|
|
|
|
|
|
|
use crate::core::Color;
|
|
|
|
|
use crate::gradient::{self, Gradient};
|
2022-09-29 10:52:58 -07:00
|
|
|
|
2020-02-18 08:48:54 +01:00
|
|
|
/// The style used to fill geometry.
|
2024-06-21 11:55:42 +01:00
|
|
|
#[derive(Debug, Clone, Copy)]
|
2022-11-03 05:50:53 +01:00
|
|
|
pub struct Fill {
|
2022-09-29 10:52:58 -07:00
|
|
|
/// The color or gradient of the fill.
|
2020-06-02 02:21:07 +02:00
|
|
|
///
|
2022-11-10 00:10:53 +01:00
|
|
|
/// By default, it is set to [`Style::Solid`] with [`Color::BLACK`].
|
2022-11-03 05:50:53 +01:00
|
|
|
pub style: Style,
|
2020-06-02 02:21:07 +02:00
|
|
|
|
|
|
|
|
/// The fill rule defines how to determine what is inside and what is
|
|
|
|
|
/// outside of a shape.
|
|
|
|
|
///
|
|
|
|
|
/// See the [SVG specification][1] for more details.
|
|
|
|
|
///
|
|
|
|
|
/// By default, it is set to `NonZero`.
|
|
|
|
|
///
|
|
|
|
|
/// [1]: https://www.w3.org/TR/SVG/painting.html#FillRuleProperty
|
2023-03-01 21:34:26 +01:00
|
|
|
pub rule: Rule,
|
2020-02-12 09:12:35 +01:00
|
|
|
}
|
|
|
|
|
|
2022-11-03 05:50:53 +01:00
|
|
|
impl Default for Fill {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
2022-10-04 18:24:46 -07:00
|
|
|
style: Style::Solid(Color::BLACK),
|
2023-03-01 21:34:26 +01:00
|
|
|
rule: Rule::NonZero,
|
2020-06-02 02:21:07 +02:00
|
|
|
}
|
2020-02-12 09:12:35 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-04-14 06:38:06 +02:00
|
|
|
|
2022-11-03 05:50:53 +01:00
|
|
|
impl From<Color> for Fill {
|
|
|
|
|
fn from(color: Color) -> Fill {
|
2020-06-02 02:21:07 +02:00
|
|
|
Fill {
|
2022-10-04 18:24:46 -07:00
|
|
|
style: Style::Solid(color),
|
2020-06-02 02:21:07 +02:00
|
|
|
..Fill::default()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-03 05:50:53 +01:00
|
|
|
impl From<Gradient> for Fill {
|
|
|
|
|
fn from(gradient: Gradient) -> Self {
|
2022-10-07 16:28:13 -07:00
|
|
|
Fill {
|
2022-11-03 04:53:27 +01:00
|
|
|
style: Style::Gradient(gradient),
|
2022-10-07 16:28:13 -07:00
|
|
|
..Default::default()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-19 03:32:21 +02:00
|
|
|
impl From<gradient::Linear> for Fill {
|
|
|
|
|
fn from(gradient: gradient::Linear) -> Self {
|
|
|
|
|
Fill {
|
|
|
|
|
style: Style::Gradient(Gradient::Linear(gradient)),
|
|
|
|
|
..Default::default()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-02 02:21:07 +02:00
|
|
|
/// The fill rule defines how to determine what is inside and what is outside of
|
|
|
|
|
/// a shape.
|
|
|
|
|
///
|
|
|
|
|
/// See the [SVG specification][1].
|
|
|
|
|
///
|
|
|
|
|
/// [1]: https://www.w3.org/TR/SVG/painting.html#FillRuleProperty
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
#[allow(missing_docs)]
|
2023-03-01 21:34:26 +01:00
|
|
|
pub enum Rule {
|
2020-06-02 02:21:07 +02:00
|
|
|
NonZero,
|
|
|
|
|
EvenOdd,
|
|
|
|
|
}
|