Skip to main content

day_spec/controls/
colorpicker.rs

1// Copyright © The Daybrite Project
2// SPDX-License-Identifier: MPL-2.0
3
4use crate::Color;
5
6pub const KIND: &str = "day.piece.colorpicker";
7
8/// The tag every in-process native arm reports a pick under. Across a JNI / C-ABI / JS boundary
9/// the tag cannot be a `&'static str`, so it arrives empty and only the payload matters (§8.2);
10/// the front-end reads the text either way.
11pub const PICK_TAG: &str = "colorpicker:value";
12
13/// Full props (realize) for the native leaf. `alpha` and `title` are set once at build; only
14/// `color` patches. The composed idiom realizes no leaf and never builds these.
15#[derive(Clone, Debug, PartialEq)]
16pub struct ColorProps {
17    pub color: Color,
18    /// Offer an opacity channel in the chooser. Off by default: most pickers hide the alpha
19    /// slider unless asked, and a color that can go transparent behind the app's back is rarely
20    /// what a tint or a brand swatch wants.
21    pub alpha: bool,
22    /// The chooser's title, where the platform shows one (`""` = the platform default).
23    pub title: String,
24}
25
26impl Default for ColorProps {
27    fn default() -> Self {
28        ColorProps {
29            color: Color::BLACK,
30            alpha: false,
31            title: String::new(),
32        }
33    }
34}
35
36/// The single imperative update: show `color` in the well (and in the chooser, if it is open).
37#[derive(Clone, Copy, Debug, PartialEq)]
38pub enum ColorPatch {
39    SetColor(Color),
40}