diff --git a/crates/ui-widgets/src/value_drag/point_picker.rs b/crates/ui-widgets/src/value_drag/point_picker.rs index 2a151eaa4..f89967e95 100644 --- a/crates/ui-widgets/src/value_drag/point_picker.rs +++ b/crates/ui-widgets/src/value_drag/point_picker.rs @@ -343,14 +343,19 @@ impl Component for PointPicker<'_> { PointPickerStyle { metrics: Metrics::new().min_size(Vec2::new(cx.tokens.size.plot.width, cx.tokens.size.plot.height)), focus: cx.focus_look(), - thumb: cx.tokens.size.handle.md, + thumb: cx.tokens.size.icon.md, marker: cx.marker(), hit: cx.tokens.size.hit.target, } } + /// The well takes the width its row leaves after the fields beside it, and all the room where it is alone. + fn fills(&self) -> Option { + Some(craft_behavior::Axis::X) + } + fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { - Vec2::new(cx.picture_width(cx.tokens.size.plot.width, f32::INFINITY), 0.0) + Vec2::new(cx.tokens.size.plot.width, 0.0) } fn sense(&self) -> Sense { diff --git a/crates/ui-widgets/src/value_drag/point_picker/stories.rs b/crates/ui-widgets/src/value_drag/point_picker/stories.rs index 89a038c9e..9f0a8fdfd 100644 --- a/crates/ui-widgets/src/value_drag/point_picker/stories.rs +++ b/crates/ui-widgets/src/value_drag/point_picker/stories.rs @@ -1,9 +1,12 @@ //! Stories of `PointPicker`. use super::PointPicker; -use crate::contract::{Bind, Props as _, Show as _, Validity}; +use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _, Validity}; +use crate::form::Field; +use crate::layout_components::{Row, Stack}; use crate::runtime::env::Message; use crate::testing::{Drive, Grip, StoryData, StoryOutput, story}; +use crate::text::NumberField; use craft_behavior::Mixed; use egui::Ui; @@ -12,9 +15,25 @@ const CENTER: [f64; 2] = [50.0, 50.0]; const RIGHT: [f64; 2] = [90.0, 50.0]; const CAP: f64 = 80.0; +/// The picker with the X and Y fields its caller shows beside it, bound to the same point (a dialog's point row). #[story(PointPicker<'static>, covers = [Default], drive = Drive::Step)] fn point_picker(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { - PointPicker::new(Bind::bound(data.value("point", Mixed::each(CENTER))), RANGE, RANGE).label("Blur center").show(ui).into() + let mut point = *data.value("point", Mixed::each(CENTER)); + let shown = Row::new().show(ui, |ui, _| { + let picked = PointPicker::new(Bind::bound(&mut point), RANGE, RANGE).label("Blur center").show(ui); + Stack::new().show(ui, |ui, _| { + for (axis, name) in ["X", "Y"].into_iter().enumerate() { + let value = point[axis].same().copied(); + let field = Field::new(name).show(ui, |ui, _| NumberField::new(name, Bind::given(value)).range(RANGE).unit("%").show(ui)); + if let Some(typed) = field.inner.and_then(|out| out.edit.value().cloned().flatten()) { + point[axis] = Mixed::Same(typed); + } + } + }); + picked + }); + *data.value("point", Mixed::each(CENTER)) = point; + shown.inner.map(Into::into).unwrap_or_default() } #[story(PointPicker<'static>, covers = [], drive = Drive::Drag(Grip::new(PointPicker::WELL)))]