Skip to main content

floem_picker/
lib.rs

1//! # floem-picker
2//!
3//! A color picker widget for [Floem](https://github.com/lapce/floem).
4//!
5//! Provides an inline HSB color picker with 2D saturation/brightness area, hue
6//! slider, optional alpha slider, numeric inputs, and hex editing.
7//!
8//! ## Usage
9//!
10//! ```rust,no_run
11//! use floem::prelude::*;
12//! use floem_picker::{solid_picker, SolidColor};
13//!
14//! let color = RwSignal::new(SolidColor::from_hex("3B82F6").unwrap());
15//! // Use `solid_picker(color)` in Floem view tree.
16//! ```
17
18mod color;
19
20#[cfg(feature = "alpha")]
21mod alpha_slider;
22mod brightness_slider;
23#[cfg(feature = "alpha")]
24mod checkerboard;
25mod color_editor;
26mod color_wheel;
27mod constants;
28#[cfg(all(feature = "eyedropper", target_os = "macos"))]
29mod eyedropper;
30mod inputs;
31mod math;
32
33pub use color::SolidColor;
34
35use std::sync::Once;
36
37use floem::prelude::*;
38use floem::reactive::RwSignal;
39use floem::text::FONT_SYSTEM;
40
41static LOAD_LUCIDE_FONT: Once = Once::new();
42
43/// Creates the top-level color picker view.
44///
45/// The picker reads from and writes to `color`. Any external changes to the
46/// signal are reflected in the UI, and user edits update the signal.
47pub fn solid_picker(color: RwSignal<SolidColor>) -> impl IntoView {
48    LOAD_LUCIDE_FONT.call_once(|| {
49        FONT_SYSTEM
50            .lock()
51            .db_mut()
52            .load_font_data(lucide_icons::LUCIDE_FONT_BYTES.to_vec());
53    });
54    color_editor::color_editor(color)
55}