From 622f18768c0db682adcf65df32076e9f571cabac Mon Sep 17 00:00:00 2001 From: aiongg Date: Fri, 13 Nov 2026 12:55:14 +0000 Subject: [PATCH] Color panel look: a leaf with Sizing::Fill fills both axes; the Hue and Brightness Cubes take the height the readout leaves; ChannelRow is one line with the channel's letter and a triangle thumb (SliderField::thumb) --- crates/color/src/ui/area.rs | 10 +++- crates/color/src/ui/panel.rs | 54 ++++++++++++++-------- crates/color/src/ui/picker/channel.rs | 42 +++++++++++++---- crates/color/src/ui/picker/compact.rs | 1 + crates/color/src/ui/picker/mod.rs | 2 +- crates/color/src/ui/strip.rs | 7 ++- crates/ui-contract/src/contract/props.rs | 2 + crates/ui-contract/src/contract/run.rs | 6 ++- crates/ui-widgets/src/form/slider_field.rs | 10 +++- 9 files changed, 100 insertions(+), 34 deletions(-) diff --git a/crates/color/src/ui/area.rs b/crates/color/src/ui/area.rs index c11070192..e88109975 100644 --- a/crates/color/src/ui/area.rs +++ b/crates/color/src/ui/area.rs @@ -5,7 +5,8 @@ use crate::AreaMode; use craft_behavior::{Metrics, Mixed, Sense}; use craft_theme::ModelValues; use craft_ui::contract::{ - Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, MeasureCx, PaintUi, Props as _, Role, WordSetCx as _, + Access, Bind, BindMut, Common, Component, Cx, DisabledLook, Edit as _, EditResponse, MeasureCx, PaintUi, Props as _, Role, Sizing, + WordSetCx as _, }; use craft_ui::primitives::ContentPainterCx; use craft_ui::runtime::env::Label; @@ -38,6 +39,9 @@ pub struct ColorAreaStyle { /// changed, so a host that keeps the values it was sent keeps the hue of a grey and the hue and saturation of black. /// The area keeps its axes right to left: across still grows to the right. Its value text names both components /// ("Saturation 40 %, Brightness 70 %", from [`names`](ColorArea::names)). +/// +/// It is at least `size.plot` and fills the width its row leaves; with `Props::sizing(Sizing::Fill)` it takes the room +/// on both axes, however small (the Color panel's field, as tall as its dock group leaves it). #[derive(craft_ui::contract::Component, craft_ui::contract::Props)] pub struct ColorArea<'a> { #[common] @@ -116,6 +120,10 @@ impl Component for ColorArea<'_> { } fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { + // An area that fills its room (the Color panel's, as tall as its group leaves it) keeps no plot size of its own. + if cx.resolved.sizing() == Some(Sizing::Fill) { + return Vec2::splat(cx.tokens.size.hit.target); + } let mut picker = self.picker(cx.value(), false); cx.child("picker", &mut picker, cx.proposal) } diff --git a/crates/color/src/ui/panel.rs b/crates/color/src/ui/panel.rs index 5728b309f..0b9d65f6d 100644 --- a/crates/color/src/ui/panel.rs +++ b/crates/color/src/ui/panel.rs @@ -8,7 +8,10 @@ use craft_behavior::{EditEvent, GesturePhase, IconId, Mixed}; use craft_cms::convert::CmykConverter; use craft_theme::{ColorModel, HsbModel, LabModel, ModelValues, RgbModel, Srgba}; use craft_ui::buttons::IconButton; -use craft_ui::contract::{Bind, CommandSet, Held, NoValue, Outcome, Pattern, Props as _, Remember as _, Show as _, ShowContainer as _, clicked}; +use craft_ui::contract::{ + Bind, CommandSet, Held, LabelScheme, NoValue, Outcome, Pattern, Props as _, Remember as _, Scroll, Show as _, ShowContainer as _, Sizing, + clicked, +}; use craft_ui::layout::RowAlign; use craft_ui::layout_components::{Row, Stack}; use craft_ui::menu::{Menu, MenuItem, PanelRow}; @@ -18,7 +21,7 @@ use craft_ui::runtime::requests::ColorRequest; use egui::{Response, Ui}; use super::channels::finite_values; -use super::picker::{ChannelRow, ChannelRule, channel_name}; +use super::picker::{ChannelRow, ChannelRule, ChannelUnit, channel_name}; use super::{ AreaMode, ColorArea, ColorPickerDialogWords, ColorRamp, ColorReadout, ColorStrip, ColorWarning, ColorWarningChip, ColorWheel, PairWell, PickedColor, RampKind, SwatchPair, Well, @@ -322,7 +325,7 @@ impl<'a> ColorPanel<'a> { let (words, dialog) = (env.words::(), env.words::()); let mut held = Held::new(state); let (mut edits, mut pick_color, mut add_to_swatches) = (Vec::new(), None, None); - let mut shown = Stack::new().label(words.title.clone()).show(ui, |ui, cx| { + let mut shown = Stack::new().label(words.title.clone()).fill().show(ui, |ui, cx| { let before = held.read(cx)?; let target = if before.background { PanelTarget::Background } else { PanelTarget::Foreground }; let mut body = Body { @@ -536,10 +539,15 @@ impl Body<'_> { self.events.push((target, event)); } + /// The cubes take the height the readout leaves them, as Photoshop's field fills its dock group; the slider modes and + /// the wheel scroll where the group is shorter than they are. fn show(&mut self, ui: &mut Ui) { let mode = self.now.mode; - Stack::new().show(ui, |ui, _| { - Row::new().show(ui, |ui, _| { + let cube = mode.is_cube(); + let body = if cube { Stack::new().fill() } else { Stack::new().fill().scroll(Scroll::vertical()) }; + body.show(ui, |ui, _| { + let top = if cube { Row::new().fill() } else { Row::new() }; + top.show(ui, |ui, _| { Stack::new().show(ui, |ui, _| { self.wells(ui); // The cubes show the out-of-gamut chip only: the web-colour chip is for Web Color. @@ -547,17 +555,20 @@ impl Body<'_> { self.warnings(ui, mode == ColorPanelMode::WebColorSliders); } }); - Stack::new().fill_width().show(ui, |ui, _| match mode { + match mode { ColorPanelMode::HueCube => self.cube(ui, AreaMode::Hue), ColorPanelMode::BrightnessCube => self.cube(ui, AreaMode::Brightness), - ColorPanelMode::ColorWheel => self.rows(ui, &HsbModel, false), - ColorPanelMode::GrayscaleSlider => self.rows(ui, &GrayModel, false), - ColorPanelMode::RgbSliders => self.rows(ui, &RgbModel, false), - ColorPanelMode::HsbSliders => self.rows(ui, &HsbModel, false), - ColorPanelMode::CmykSliders => self.rows(ui, &CmykModel::new(self.converter.clone()), false), - ColorPanelMode::LabSliders => self.rows(ui, &LabModel, false), - ColorPanelMode::WebColorSliders => self.rows(ui, &RgbModel, true), - }); + _ => { + Stack::new().fill_width().labels(LabelScheme::Inspector).show(ui, |ui, _| match mode { + ColorPanelMode::GrayscaleSlider => self.rows(ui, &GrayModel, false), + ColorPanelMode::RgbSliders => self.rows(ui, &RgbModel, false), + ColorPanelMode::CmykSliders => self.rows(ui, &CmykModel::new(self.converter.clone()), false), + ColorPanelMode::LabSliders => self.rows(ui, &LabModel, false), + ColorPanelMode::WebColorSliders => self.rows(ui, &RgbModel, true), + _ => self.rows(ui, &HsbModel, false), + }); + } + } }); match mode { ColorPanelMode::HueCube | ColorPanelMode::BrightnessCube => self.readout(ui), @@ -674,8 +685,8 @@ impl Body<'_> { ); } - /// The channel rows of `model`: a label that scrubs the number field at the row's end, and the slider over the - /// channel's colours. Web Color has sliders that step by the web levels. + /// The channel rows of `model`, one line each: the channel's letter, which scrubs the value, the slider over the + /// channel's colours, and the number field with its unit. Web Color has sliders that step by the web levels. fn rows(&mut self, ui: &mut Ui, model: &dyn ColorModel, web: bool) { let current = self.values(model); // Dynamic Color Sliders off: the tracks keep the colours they had when a drag began. @@ -698,14 +709,18 @@ impl Body<'_> { track_values.values[2] = 100.0; } let track = model.track(i, &track_values); - let row = ChannelRow::new(channel_name(model, i, &[model]), Bind::given(f64::from(current.values[i])), rule).track(track).show(ui); + let row = ChannelRow::new(channel_name(model, i, &[model]), Bind::given(f64::from(current.values[i])), rule) + .short(ch.label) + .unit(ChannelUnit::of(ch.unit)) + .track(track) + .show(ui); for event in row.into_iter().flat_map(|row| row.events) { self.channel_event(model, current, i, event); } } } - /// Hue Cube or Brightness Cube: the area and the strip of `mode`. + /// Hue Cube or Brightness Cube: the area and the strip of `mode`, in the room the wells and the readout leave. fn cube(&mut self, ui: &mut Ui, mode: AreaMode) { let model = mode.model(); let values = self.values(model); @@ -713,8 +728,9 @@ impl Body<'_> { let names = [channel_name(model, across, &[model]), channel_name(model, down, &[model])]; let (area_name, strip_name) = (Label::from(mode.name()), channel_name(model, mode.strip(), &[model])); let (area, strip) = Row::new() + .fill() .show(ui, |ui, _| { - let area = ColorArea::new(area_name.clone(), mode, Bind::given(values)).names(names.clone()).show(ui); + let area = ColorArea::new(area_name.clone(), mode, Bind::given(values)).names(names.clone()).sizing(Sizing::Fill).show(ui); let strip = ColorStrip::new(strip_name.clone(), mode, Bind::given(values)).show(ui); (area, strip) }) diff --git a/crates/color/src/ui/picker/channel.rs b/crates/color/src/ui/picker/channel.rs index 8db7e0e16..304398e4c 100644 --- a/crates/color/src/ui/picker/channel.rs +++ b/crates/color/src/ui/picker/channel.rs @@ -1,16 +1,18 @@ -//! The channel row: a label that scrubs a slider whose track shows the channel's colours, and a number field after -//! it. Shared with the panels that show channels. +//! The channel row: on one line, a label that scrubs, a slider whose track shows the channel's colours, and a number +//! field after it. Shared with the panels that show channels. use std::ops::RangeInclusive; use craft_behavior::{Axis, Sense}; use craft_theme::{Channel, ColorModel, Srgba}; -use craft_ui::contract::{Bind, Common, Component, Cx, DisabledLook, EditResponse, MeasureCx, Role, Show as _}; -use craft_ui::form::SliderField; +use craft_ui::contract::{ + Bind, Common, Component, Cx, DisabledLook, EditResponse, GlyphLabel, LabelKind, MeasureCx, Role, Show as _, ShowContainer as _, SideLabel, +}; +use craft_ui::form::{Field, SliderField, SliderFieldLayout}; use craft_ui::primitives::{PaintShape, StrokeWidth}; use craft_ui::runtime::env::{Label, UnitKind}; use craft_ui::style::{ComponentStyle, DataColor, StyleColor, StyleCx}; -use craft_ui::value_drag::TrackFace; +use craft_ui::value_drag::{SliderThumb, TrackFace}; use egui::{Color32, CornerRadius, Ui, Vec2}; /// How a channel's value steps and settles: a channel's or the alpha's. @@ -153,10 +155,14 @@ pub(crate) fn channel_slider<'a>( } } -/// One channel: the word label and number field on a line over the slider across the channel's colours. +/// One channel on one line, as Photoshop's Color panel draws it: the label at the start (the channel's short label +/// where one is given, "C"), which scrubs the value, the slider over the channel's colours with the pointer under its +/// track, and the number field with its unit at the end. #[derive(craft_ui::contract::Pattern)] pub(crate) struct ChannelRow<'a> { label: Label, + /// The text shown in place of the label: the channel's short label. + short: Option<&'static str>, value: Bind<'a, f64>, rule: ChannelRule, track: Option>, @@ -167,7 +173,13 @@ pub(crate) struct ChannelRow<'a> { impl<'a> ChannelRow<'a> { pub(crate) fn new(label: impl Into