Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Color panel field fills its group in a custom workspace too

aionggfa99e183b6a8
diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs
index deaea4e78..0412c4fc6 100644
--- a/crates/ui-egui/src/dock.rs
+++ b/crates/ui-egui/src/dock.rs
@@ -521,10 +521,7 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui, shown: &[Group], mut bod
ui.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));
- }
+ crate::panels::offer_color_field_fill(ui, t.pro, g, tab);
// No scroll fade: it darkens real colours, swatches and previews at the edge
// (#2726); the scroll bar already shows there is more.
ui.spacing_mut().scroll.fade.strength = 0.0;
diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs
index a62ecafff..f68c3e46e 100644
--- a/crates/ui-egui/src/panel_docking.rs
+++ b/crates/ui-egui/src/panel_docking.rs
@@ -547,6 +547,7 @@ fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: &str) {
if group.scrolls_itself(tab) {
crate::panels::dock_body(app, ui, *group, tab);
} else {
+ crate::panels::offer_color_field_fill(ui, pro, *group, tab);
egui::ScrollArea::vertical()
.id_salt(("shared-panel-body", id))
.auto_shrink([false, false])
diff --git a/crates/ui-egui/src/panel_docking_tests.rs b/crates/ui-egui/src/panel_docking_tests.rs
index a4ae378ed..193ff2e6b 100644
--- a/crates/ui-egui/src/panel_docking_tests.rs
+++ b/crates/ui-egui/src/panel_docking_tests.rs
@@ -585,6 +585,23 @@ fn explicit_reveal_activates_existing_tab_and_expands_custom_group() {
assert_eq!(app.ui.docking, before);
}
+// #2455 in a custom workspace: the pro Color field fills a tall floating group, not 120 pt.
+#[test]
+fn pro_color_field_fills_a_tall_custom_group() {
+ let mut app = app();
+ app.run("window.panel.float", json!({"panel":"color","x":40,"y":60,"width":320,"height":560})).unwrap();
+ assert!(app.ui.docking.is_some());
+ let h = harness(app, vec2(1280.0, 800.0));
+ // The SV field and the 14 pt hue strip beside it are draggable, equally tall and 8 pt apart.
+ let drags: Vec<egui::Rect> =
+ h.ctx.viewport(|v| v.this_pass.widgets.layers().flat_map(|(_, w)| w).filter(|w| w.sense.senses_drag()).map(|w| w.rect).collect());
+ let field = drags
+ .iter()
+ .find(|f| drags.iter().any(|s| s.width() == 14.0 && s.top() == f.top() && s.height() == f.height() && (s.left() - f.right() - 8.0).abs() < 0.5))
+ .expect("Color field with its hue strip");
+ assert!(field.height() > 300.0, "field stays short in a 560 pt group: {field:?}");
+}
+
// #4028: in a custom workspace too, a new adjustment layer brings Properties to the front.
#[test]
fn a_new_adjustment_layer_activates_properties_in_a_custom_workspace() {
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index 10476013e..f2961fd7b 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -3794,10 +3794,19 @@ 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 {
+fn color_field_fill_id() -> egui::Id {
egui::Id::new("color-field-fill-height")
}
+/// The pro Color field stretches to its dock group's height instead of a fixed 120 pt: a dock
+/// calls this with the group body's `ui` before drawing the tab.
+pub(crate) fn offer_color_field_fill(ui: &egui::Ui, pro: bool, group: crate::dock::Group, tab: usize) {
+ if pro && group == crate::dock::Group::Color && tab == 0 {
+ let inner = ui.available_height().max(0.0);
+ ui.data_mut(|d| d.insert_temp(color_field_fill_id(), inner));
+ }
+}
+
/// 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 {