azul_css/props/style/
selection.rs1use alloc::string::String;
10
11use crate::props::{
12 basic::color::{parse_css_color, ColorU, CssColorParseError, CssColorParseErrorOwned},
13 formatter::PrintAsCssValue,
14};
15
16const DEFAULT_SELECTION_BG: ColorU = ColorU::new(173, 214, 255, 255);
18
19#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
23#[repr(C)]
24pub struct SelectionBackgroundColor {
25 pub inner: ColorU,
26}
27
28impl Default for SelectionBackgroundColor {
29 fn default() -> Self {
30 Self {
31 inner: DEFAULT_SELECTION_BG,
32 }
33 }
34}
35
36impl PrintAsCssValue for SelectionBackgroundColor {
37 fn print_as_css_value(&self) -> String {
38 self.inner.to_hash()
39 }
40}
41
42impl crate::codegen::format::FormatAsRustCode for SelectionBackgroundColor {
43 fn format_as_rust_code(&self, _tabs: usize) -> String {
44 format!(
45 "SelectionBackgroundColor {{ inner: {} }}",
46 crate::codegen::format::format_color_value(&self.inner)
47 )
48 }
49}
50
51#[cfg(feature = "parser")]
53pub fn parse_selection_background_color(
57 input: &str,
58) -> Result<SelectionBackgroundColor, CssColorParseError<'_>> {
59 parse_css_color(input).map(|inner| SelectionBackgroundColor { inner })
60}
61
62#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
66#[repr(C)]
67pub struct SelectionColor {
68 pub inner: ColorU,
69}
70
71impl Default for SelectionColor {
72 fn default() -> Self {
73 Self {
74 inner: ColorU::BLACK,
75 }
76 }
77}
78
79impl PrintAsCssValue for SelectionColor {
80 fn print_as_css_value(&self) -> String {
81 self.inner.to_hash()
82 }
83}
84
85impl crate::codegen::format::FormatAsRustCode for SelectionColor {
86 fn format_as_rust_code(&self, _tabs: usize) -> String {
87 format!(
88 "SelectionColor {{ inner: {} }}",
89 crate::codegen::format::format_color_value(&self.inner)
90 )
91 }
92}
93
94#[cfg(feature = "parser")]
96pub fn parse_selection_color(input: &str) -> Result<SelectionColor, CssColorParseError<'_>> {
100 parse_css_color(input).map(|inner| SelectionColor { inner })
101}
102
103use crate::props::basic::{
106 pixel::{parse_pixel_value, CssPixelValueParseError, CssPixelValueParseErrorOwned, PixelValue},
107 SizeMetric,
108};
109
110#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
112#[repr(C)]
113pub struct SelectionRadius {
114 pub inner: PixelValue,
115}
116
117impl Default for SelectionRadius {
118 fn default() -> Self {
119 Self {
120 inner: PixelValue::zero(),
121 }
122 }
123}
124
125impl PrintAsCssValue for SelectionRadius {
126 fn print_as_css_value(&self) -> String {
127 self.inner.to_string()
128 }
129}
130
131impl crate::codegen::format::FormatAsRustCode for SelectionRadius {
132 fn format_as_rust_code(&self, _tabs: usize) -> String {
133 format!(
135 "SelectionRadius {{ inner: PixelValue::from_metric(SizeMetric::{:?}, {}) }}",
136 self.inner.metric,
137 self.inner.number.get()
138 )
139 }
140}
141
142#[cfg(feature = "parser")]
144pub fn parse_selection_radius(input: &str) -> Result<SelectionRadius, CssPixelValueParseError<'_>> {
148 parse_pixel_value(input).map(|inner| SelectionRadius { inner })
149}