iced_graphics/geometry/fill.rs
1//! Fill [`Geometry`] with a certain style.
2//!
3//! [`Geometry`]: super::Renderer::Geometry
4pub use crate::geometry::Style;
5
6use crate::core::Color;
7use crate::gradient::{self, Gradient};
8
9/// The style used to fill geometry.
10#[derive(Debug, Clone, Copy)]
11pub struct Fill {
12 /// The color or gradient of the fill.
13 ///
14 /// By default, it is set to [`Style::Solid`] with [`Color::BLACK`].
15 pub style: Style,
16
17 /// The fill rule defines how to determine what is inside and what is
18 /// outside of a shape.
19 ///
20 /// See the [SVG specification][1] for more details.
21 ///
22 /// By default, it is set to `NonZero`.
23 ///
24 /// [1]: https://www.w3.org/TR/SVG/painting.html#FillRuleProperty
25 pub rule: Rule,
26}
27
28impl Default for Fill {
29 fn default() -> Self {
30 Self {
31 style: Style::Solid(Color::BLACK),
32 rule: Rule::NonZero,
33 }
34 }
35}
36
37impl From<Color> for Fill {
38 fn from(color: Color) -> Fill {
39 Fill {
40 style: Style::Solid(color),
41 ..Fill::default()
42 }
43 }
44}
45
46impl From<Gradient> for Fill {
47 fn from(gradient: Gradient) -> Self {
48 Fill {
49 style: Style::Gradient(gradient),
50 ..Default::default()
51 }
52 }
53}
54
55impl From<gradient::Linear> for Fill {
56 fn from(gradient: gradient::Linear) -> Self {
57 Fill {
58 style: Style::Gradient(Gradient::Linear(gradient)),
59 ..Default::default()
60 }
61 }
62}
63
64/// The fill rule defines how to determine what is inside and what is outside of
65/// a shape.
66///
67/// See the [SVG specification][1].
68///
69/// [1]: https://www.w3.org/TR/SVG/painting.html#FillRuleProperty
70#[derive(Debug, Clone, Copy, PartialEq, Eq)]
71#[allow(missing_docs)]
72pub enum Rule {
73 NonZero,
74 EvenOdd,
75}