diff --git a/crates/ui-egui/src/dialogs/revolve.rs b/crates/ui-egui/src/dialogs/revolve.rs index 1128715764..2d9c252ef3 100644 --- a/crates/ui-egui/src/dialogs/revolve.rs +++ b/crates/ui-egui/src/dialogs/revolve.rs @@ -8,6 +8,7 @@ use std::sync::{Arc, RwLock}; use craft::behavior::{DisplayOrder, ItemSource, SelectionChange}; use craft::theme::Srgba; use craft::ui::buttons::Button; +use craft::ui::choice::Swatch; use craft::ui::contract::Entry; use craft::ui::contract::{Bind, CollectionEvent, Gap, Props as _, Show as _, ShowCollection as _, ShowContainer as _, clicked}; use craft::ui::layout_components::{Row, Stack}; @@ -684,15 +685,12 @@ pub(super) fn set_light_value(fields: &mut DialogFields, key: &str, value: Value /// The light's colour: a swatch that asks the host's picker; the answer arrives in `__lightPick`. fn light_color_row() -> Param { Param::custom("lightColor", tl!("Color"), |ui, fields, cx| { - let hex = fields.text("lightColor").unwrap_or("#ffffff").to_owned(); - let color = Srgba::from_hex(&hex).unwrap_or(Srgba::rgb(1.0, 1.0, 1.0)); - // The row's body may run more than once in a pass: the picker opens after it. - let mut ask = false; - let row = Row::new().show(ui, |ui, _| ask = pressed(ui, &hex.to_uppercase(), true, Some(tl!("Color")))); - if ask { + let color = fields.text("lightColor").and_then(Srgba::from_hex).unwrap_or(Srgba::rgb(1.0, 1.0, 1.0)); + let swatch = Swatch::new(tl!("Color"), color).tooltip(tl!("Color")).show(ui); + if swatch.clicked { cx.pick_color("__lightPick", color); } - row.output + swatch.response }) .opens_with("#ffffff") } diff --git a/crates/ui-egui/src/dialogs/revolve/tests.rs b/crates/ui-egui/src/dialogs/revolve/tests.rs index f0529ee590..839b14a6c1 100644 --- a/crates/ui-egui/src/dialogs/revolve/tests.rs +++ b/crates/ui-egui/src/dialogs/revolve/tests.rs @@ -546,3 +546,30 @@ fn lighting_presets_cancel_restores_an_existing_custom_light_rig() { h.cancel(); assert_eq!(doc(&h), before); } + +/// The color well named Color, with the color it shows. +fn color_well(h: &ThreeD) -> Option { + use craft::ui::contract::Role; + let tree = h.fixture.tree(); + let well = h.fixture.by_role(Role::COLOR_WELL).into_iter().find(|t| tree.name_of(t.node) == Some("Color")); + well.and_then(|t| tree.value_of(t.node).map(str::to_owned)) +} + +/// The light color of 3D and Materials and the custom shading color of 3D (Classic) show as color wells with the +/// stored color. +#[test] +fn the_light_color_and_the_custom_shading_color_are_color_wells() { + let mut h = drawn(SQUARE, REVOLVE); + h.set("__page", json!("lighting")); + h.set("lightColor", json!("#ff8040")); + assert_eq!(color_well(&h).as_deref(), Some("#ff8040"), "the light color is a well that shows the light's color"); + h.cancel(); + + let mut h = drawn(SQUARE, CLASSIC_EXTRUDE); + h.set("__page", json!("lighting")); + h.set("surface", json!("plastic")); + h.set("shadingColor", json!("custom")); + h.set("shadingCustom", json!("#336699")); + assert_eq!(color_well(&h).as_deref(), Some("#336699"), "the custom shading color is a well that shows the color"); + h.cancel(); +} diff --git a/crates/ui-egui/src/dialogs/three_d_classic.rs b/crates/ui-egui/src/dialogs/three_d_classic.rs index 577ece6fb1..626e5f3d3f 100644 --- a/crates/ui-egui/src/dialogs/three_d_classic.rs +++ b/crates/ui-egui/src/dialogs/three_d_classic.rs @@ -12,6 +12,7 @@ use craft::ui::buttons::{Button, IconButton}; use craft::ui::canvas::Canvas; use craft::ui::canvas::{CanvasSpace, canvas_space}; use craft::ui::canvas_controls::SelectionOutline; +use craft::ui::choice::Swatch; use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _}; use craft::ui::display::{Picture, Text}; use craft::ui::layout_components::Row; @@ -195,11 +196,11 @@ fn shading_custom() -> Param { fields.set(SHADING_CUSTOM, Srgba::from_rgb_array(rgb).to_hex()); } let color = shading_color(fields); - let button = Button::new(color.to_hex().to_uppercase()).show(ui); // PLAN: assumed a swatch icon via IconSpec::Swatch - if button.clicked() { + let swatch = Swatch::new(tl!("Color"), color).show(ui); + if swatch.clicked { cx.pick_color(SHADING_CUSTOM, color); } - button.response + swatch.response }) .opens_with("#000000") }