PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Color panel: the field and hue strip fill the panel height, like Photoshop (#2455)
Jeremy7e46557283c1
diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rsindex bd7f61754..18de2c575 100644--- a/crates/ui-egui/src/dock.rs+++ b/crates/ui-egui/src/dock.rs@@ -419,6 +419,10 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, shown: &[Group], mut bodui.set_min_height(inner);body(app, ui, g, tab);} else {+ // The pro Color field stretches to the group's height instead of a fixed 120 pt.+ if t.pro && g == Group::Color && tab == 0 {+ ui.data_mut(|d| d.insert_temp(crate::panels::color_field_fill_id(), inner));+ }egui::ScrollArea::vertical().id_salt(("dock-scroll", g.key(), tab)).max_height(inner)diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex ccebc5a81..20665ce66 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -2829,6 +2829,18 @@ fn field_chips(app: &mut PhotocraftApp, ui: &mut egui::Ui, chips: Rect) {}}+/// Where the dock tells the Color field how tall its group body is.+pub(crate) fn color_field_fill_id() -> egui::Id {+ egui::Id::new("color-field-fill-height")+}++/// Height of the Color field: the group body's height (when docked) less the hex/RGB readout,+/// which folds onto a second line in a narrow dock. 120 pt when nothing sets a height.+fn color_field_height(avail: Option<f32>, width: f32) -> f32 {+ let reserve = 32.0 + if width < 280.0 { 26.0 } else { 0.0 };+ avail.filter(|a| a.is_finite()).map_or(120.0, |a| (a - reserve).clamp(120.0, 2000.0))+}+/// Photoshop Color panel: saturation/brightness field + hue strip, drawn as shaded meshes.fn color_field(app: &mut PhotocraftApp, ui: &mut egui::Ui) {let t = Tokens::get(ui.ctx());@@ -2842,7 +2854,9 @@ fn color_field(app: &mut PhotocraftApp, ui: &mut egui::Ui) {}let w = ui.available_width();let strip_w = 14.0;- let h = 120.0;+ // Photoshop's Color panel field fills the panel: take the height the dock offers, less the+ // hex/RGB readout (which folds onto a second line in a narrow dock). Without a dock, 120 pt.+ let h = color_field_height(ui.data(|d| d.get_temp::<f32>(color_field_fill_id())), w);ui.horizontal(|ui| {ui.spacing_mut().item_spacing.x = 8.0;let (chips, _) = ui.allocate_exact_size(vec2(38.0, h), Sense::hover());@@ -3461,6 +3475,17 @@ mod color_tests {assert_eq!(srgb_bytes(h.state().session.tools.foreground), [0, 255, 0]);}+ /// The Color field fills the dock group, never shrinks below 120 pt, and ignores a bad height.+ #[test]+ fn color_field_height_fills_the_group() {+ assert_eq!(color_field_height(None, 300.0), 120.0);+ assert_eq!(color_field_height(Some(500.0), 300.0), 468.0);+ assert_eq!(color_field_height(Some(500.0), 200.0), 442.0);+ assert_eq!(color_field_height(Some(60.0), 300.0), 120.0);+ assert_eq!(color_field_height(Some(f32::NAN), 300.0), 120.0);+ assert_eq!(color_field_height(Some(1.0e9), 300.0), 2000.0);+ }+fn field_harness(app: PhotocraftApp) -> egui_kittest::Harness<'static, PhotocraftApp> {// 60 fps steps, so two clicks a frame apart are a double-click.let mut h = egui_kittest::Harness::builder().with_size(vec2(300.0, 200.0)).with_step_dt(1.0 / 60.0).build_ui_state(