Stories bind story values through data.bind, as upstream's do

This commit is contained in:
bflatastic
2026-11-22 01:33:52 +07:00
parent 70d1d2ee1c
commit b9ac6ab349
8 changed files with 10 additions and 10 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ fn fill_stroke(
shown: ColorPanelShown,
tweak: impl FnOnce(ColorPanel<'_>) -> ColorPanel<'_>,
) -> StoryOutput {
let panel = ColorPanel::new(Bind::bound(data.value("state", state)), COLORS).layout(ColorPanelLayout::FillStroke).shown(shown);
let panel = ColorPanel::new(data.bind("state", state), COLORS).layout(ColorPanelLayout::FillStroke).shown(shown);
tweak(panel).show(ui).into()
}
+1 -1
View File
@@ -37,7 +37,7 @@ fn color_ramp_web_safe(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
#[story(ColorRamp<'static>, covers = [], drive = Drive::Never)]
fn color_ramp_recolor_clicks(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let shown = ColorRamp::new("Color ramp", RampKind::Spectrum, Bind::bound(data.value("pick", pick()))).recolor_clicks(true).kind_name("RGB Spectrum").show(ui);
let shown = ColorRamp::new("Color ramp", RampKind::Spectrum, data.bind("pick", pick())).recolor_clicks(true).kind_name("RGB Spectrum").show(ui);
let last = data.note("last", String::new());
if let Some(recolor) = shown.recolor {
*last = format!("{recolor:?}");
+1 -1
View File
@@ -248,7 +248,7 @@ fn tip_ellipse(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
#[story(TipEllipse<'static>, covers = [], drive = Drive::Never)]
fn tip_ellipse_flat(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let flat = TipAngle::new(0.0, 0.0);
let shown = TipEllipse::new("Tip angle and roundness", Bind::bound(data.value("flat_tip", flat))).least_roundness(0.0).show(ui);
let shown = TipEllipse::new("Tip angle and roundness", data.bind("flat_tip", flat)).least_roundness(0.0).show(ui);
let note = angle_note(*data.value("flat_tip", flat));
StoryOutput::from(shown).readout(note)
}
@@ -159,7 +159,7 @@ const MOST_ARTBOARDS: u32 = 4;
#[story(NewDocumentDialog<'static>, covers = [], drive = Drive::Never)]
fn new_document_dialog_with_host_details(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let mut settings = data.value("settings", StorySettings::default()).clone();
let output = NewDocumentDialog::over(Bind::bound(&mut settings)).opened(Bind::bound(data.value("open", true))).show(ui);
let output = NewDocumentDialog::over(Bind::bound(&mut settings)).opened(data.bind("open", true)).show(ui);
*data.value("settings", StorySettings::default()) = settings;
output.into()
}
@@ -180,7 +180,7 @@ fn new_document_dialog_saving_host_details(ui: &mut Ui, data: &mut StoryData) ->
let output = NewDocumentDialog::over(Bind::bound(&mut settings))
.saved(Bind::bound(&mut library))
.tab(Bind::bound(&mut tab))
.opened(Bind::bound(data.value("open", true)))
.opened(data.bind("open", true))
.show(ui);
*data.value("settings", StorySettings::default()) = settings;
*data.value("library", seeded_library()) = library;
@@ -20,7 +20,7 @@ fn slider_field(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
/// Words at the two ends of the track, as a softness or a contrast control names its extremes.
#[story(SliderField<'static>, covers = [], drive = Drive::Never)]
fn slider_field_end_words(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
SliderField::new("Softness", Bind::bound(data.value("softness", 50.0)), PERCENT)
SliderField::new("Softness", data.bind("softness", 50.0), PERCENT)
.marks_labelled([(0.0, "Soft"), (100.0, "Hard")])
.show(ui)
.into()
+1 -1
View File
@@ -42,7 +42,7 @@ fn field_long_text(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
fn field_link_label(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
Field::new("Opacity")
.side(SideLabel::new().link().scrub(true))
.show(ui, |ui, _| NumberField::new("Opacity", Bind::bound(data.value("link", Some(100.0)))).scrub_by_label().show(ui))
.show(ui, |ui, _| NumberField::new("Opacity", data.bind("link", Some(100.0))).scrub_by_label().show(ui))
.into()
}
@@ -43,7 +43,7 @@ fn combo_box_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
#[story(ComboBox<'static>, covers = [], drive = Drive::Never, group = "States", title = "No options")]
fn combo_box_no_options(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
ComboBox::new("Font", Bind::bound(data.value("none", String::new())), &[]).show(ui).into()
ComboBox::new("Font", data.bind("none", String::new()), &[]).show(ui).into()
}
/// Focuses the field and opens the list on every option with Alt+Down.
+2 -2
View File
@@ -36,7 +36,7 @@ fn linked_fields_equal_columns(ui: &mut Ui, data: &mut StoryData) -> StoryOutput
#[story(LinkedFields<'static, 2>, covers = [], drive = Drive::Never)]
fn linked_fields_percent(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let linked = *data.value("linked", true);
LinkedFields::new("Scale", Bind::bound(data.value("scale", Mixed::each([Some(100.0); 2]))), Bind::given(linked))
LinkedFields::new("Scale", data.bind("scale", Mixed::each([Some(100.0); 2])), Bind::given(linked))
.captions(["W", "H"])
.range(1.0..=1000.0)
.unit_kind(UnitKind::Percent)
@@ -47,7 +47,7 @@ fn linked_fields_percent(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
#[story(LinkedFields<'static, 2>, covers = [], drive = Drive::Never)]
fn linked_fields_link_caption(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let linked = *data.value("linked", true);
LinkedFields::new("Margins", Bind::bound(data.value("link caption", Mixed::each([Some(12.0); 2]))), Bind::given(linked))
LinkedFields::new("Margins", data.bind("link caption", Mixed::each([Some(12.0); 2])), Bind::given(linked))
.captions(["Inside", "Outside"])
.caption_with(1, SideLabel::new().link())
.layout(LinkedLayout::Column)