PointPicker: the well takes the room its row leaves; the story shows the X and Y fields beside it

The well fills its row's width after its siblings (Component::fills) instead of measuring the whole room, so fields
beside it stay in view (ParamRows' point row showed them past the edge). The cross is size.icon.md long. The Default
story shows the picker with its X and Y fields, as a dialog's point row does.
This commit is contained in:
aiongg
2026-11-12 14:52:13 +00:00
parent c3b581de4d
commit 0115deeb45
2 changed files with 28 additions and 4 deletions
@@ -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<craft_behavior::Axis> {
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 {
@@ -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)))]