Lines
0 %
Functions
Branches
100 %
//! CSS properties for styling text selections (`-azul-selection-*`).
//!
//! Defines the following properties (analogous to the `::selection` pseudo-element):
//! - `-azul-selection-background-color` ([`SelectionBackgroundColor`])
//! - `-azul-selection-color` ([`SelectionColor`])
//! - `-azul-selection-radius` ([`SelectionRadius`])
use alloc::string::String;
use crate::props::{
basic::color::{parse_css_color, ColorU, CssColorParseError, CssColorParseErrorOwned},
formatter::PrintAsCssValue,
};
/// Default selection highlight background — light blue, similar to macOS.
const DEFAULT_SELECTION_BG: ColorU = ColorU::new(173, 214, 255, 255);
// --- -azul-selection-background-color ---
/// Parsed value for the `-azul-selection-background-color` CSS property.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)]
pub struct SelectionBackgroundColor {
pub inner: ColorU,
}
impl Default for SelectionBackgroundColor {
fn default() -> Self {
Self {
inner: DEFAULT_SELECTION_BG,
impl PrintAsCssValue for SelectionBackgroundColor {
fn print_as_css_value(&self) -> String {
self.inner.to_hash()
impl crate::format_rust_code::FormatAsRustCode for SelectionBackgroundColor {
fn format_as_rust_code(&self, _tabs: usize) -> String {
format!(
"SelectionBackgroundColor {{ inner: {} }}",
crate::format_rust_code::format_color_value(&self.inner)
)
/// Parses a `-azul-selection-background-color` CSS value.
#[cfg(feature = "parser")]
pub fn parse_selection_background_color(
input: &str,
) -> Result<SelectionBackgroundColor, CssColorParseError<'_>> {
parse_css_color(input).map(|inner| SelectionBackgroundColor { inner })
// --- -azul-selection-color ---
/// Parsed value for the `-azul-selection-color` CSS property.
pub struct SelectionColor {
impl Default for SelectionColor {
inner: ColorU::BLACK,
impl PrintAsCssValue for SelectionColor {
impl crate::format_rust_code::FormatAsRustCode for SelectionColor {
"SelectionColor {{ inner: {} }}",
/// Parses a `-azul-selection-color` CSS value.
pub fn parse_selection_color(input: &str) -> Result<SelectionColor, CssColorParseError<'_>> {
parse_css_color(input).map(|inner| SelectionColor { inner })
// --- -azul-selection-radius ---
use crate::props::basic::{
pixel::{parse_pixel_value, CssPixelValueParseError, CssPixelValueParseErrorOwned, PixelValue},
SizeMetric,
/// Parsed value for the `-azul-selection-radius` CSS property.
pub struct SelectionRadius {
pub inner: PixelValue,
impl Default for SelectionRadius {
inner: PixelValue::zero(),
impl PrintAsCssValue for SelectionRadius {
self.inner.to_string()
impl crate::format_rust_code::FormatAsRustCode for SelectionRadius {
// Use the Display implementation of PixelValue to get a string like "5px" or "1em"
"SelectionRadius {{ inner: PixelValue::from_metric(SizeMetric::{:?}, {}) }}",
self.inner.metric,
self.inner.number.get()
/// Parses a `-azul-selection-radius` CSS value.
pub fn parse_selection_radius(input: &str) -> Result<SelectionRadius, CssPixelValueParseError<'_>> {
parse_pixel_value(input).map(|inner| SelectionRadius { inner })