diff --git a/crates/color-ui/src/ui/disc.rs b/crates/color-ui/src/ui/disc.rs index d9d0acf7f..f946c0084 100644 --- a/crates/color-ui/src/ui/disc.rs +++ b/crates/color-ui/src/ui/disc.rs @@ -4,7 +4,7 @@ use super::channels::{finite, primary}; use super::wheel::{hue_at, hue_direction, vertex}; use craft_behavior::nav::{Arrows, NavShape, Roving}; -use craft_behavior::{CancelReason, HitShape, Metrics, NavMove, PartKey, PressPhase, Sense}; +use craft_behavior::{CancelReason, HitShape, Metrics, NavMove, PartKey, PointerButton, PressPhase, Sense}; use craft_theme::{ColorModel, HsbModel, ModelValues, Srgba}; use craft_ui::contract::{ Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, Focus as _, Input, MeasureCx, Name, Numeric, Outcome, @@ -36,12 +36,17 @@ const CENTRE: f32 = 0.5; /// Degrees a hue key moves, and percents a saturation key moves; Shift moves ten times as far. const KEY_STEP: f32 = 1.0; const FAR: f32 = 10.0; +/// The segmented look: hue sectors round the disc, rings out from its centre, and the degrees one sector spans. +const SECTORS: u32 = 24; +const PATCH_RINGS: u32 = 5; +const SECTOR_DEGREES: f32 = 15.0; craft_ui::words! { /// The words of colour discs. pub struct ColorDiscWords { marker: template "colorDisc.marker" = "Color {n}"; value: template "colorDisc.value" = "Hue {hue} degrees, saturation {saturation} %"; + value_brightness: template "colorDisc.valueBrightness" = "Hue {hue} degrees, brightness {brightness} %"; } } @@ -110,8 +115,9 @@ pub enum DiscRadius { /// The centre of the segmented patch at `hue` and `radial`, as `(hue, radial)`: sector `round(h/15) mod 24`, ring /// `floor(r*5).min(4)`. pub fn patch_at(hue: f32, radial: f32) -> (f32, f32) { - let _ = (hue, radial); - todo!("wg.W43") + let sector = (finite(hue).rem_euclid(360.0) / SECTOR_DEGREES).round() as u32 % SECTORS; + let ring = ((finite(radial).clamp(0.0, 1.0) * PATCH_RINGS as f32).floor() as u32).min(PATCH_RINGS - 1); + (sector as f32 * SECTOR_DEGREES, (ring as f32 + 0.5) / PATCH_RINGS as f32) } /// The style of a colour disc. @@ -220,6 +226,8 @@ pub struct ColorDisc<'a> { names: Vec