mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-24 19:41:51 +01:00
stories: format the scripted binds
This commit is contained in:
1 parent
07bc5387be
commit
22835c7cf2
17 files changed
+44
-95
No files matched your search
@@ -39,10 +39,7 @@ fn color_ramp_web_safe(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn color_ramp_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let refuse_dark = |pick: &RampPick| if pick.color.b < 0.5 { Validity::Refuse(Message::new("Too dark")) } else { Validity::Ok };
|
||||
let dark = RampPick::new(Srgba::rgb(0.1, 0.1, 0.1), false);
|
||||
ColorRamp::new("Color ramp", RampKind::Spectrum, data.bind("pick", dark).check(refuse_dark))
|
||||
.kind_name("RGB Spectrum")
|
||||
.show(ui)
|
||||
.into()
|
||||
ColorRamp::new("Color ramp", RampKind::Spectrum, data.bind("pick", dark).check(refuse_dark)).kind_name("RGB Spectrum").show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorRamp<'static>, covers = [], drive = Drive::Never, title = "Disabled")]
|
||||
|
||||
@@ -18,8 +18,5 @@ fn path_field_filled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(PathField<'static>, covers = [], drive = Drive::Never)]
|
||||
fn path_field_missing_file(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
PathField::new("Open", data.bind("missing", "/photos/trip/missing.png".to_owned()), PickRequest::open("import"))
|
||||
.must_exist(true)
|
||||
.show(ui)
|
||||
.into()
|
||||
PathField::new("Open", data.bind("missing", "/photos/trip/missing.png".to_owned()), PickRequest::open("import")).must_exist(true).show(ui).into()
|
||||
}
|
||||
@@ -85,10 +85,7 @@ fn print_dialog(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(PrintDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn print_dialog_discovering(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let sheet = sheet(ui, false);
|
||||
PrintDialog::new(data.bind("settings", Settings::default()), &[], Bind::given(DialogFields::default()), &sheet)
|
||||
.discovering(true)
|
||||
.show(ui)
|
||||
.into()
|
||||
PrintDialog::new(data.bind("settings", Settings::default()), &[], Bind::given(DialogFields::default()), &sheet).discovering(true).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(PrintDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
|
||||
@@ -33,9 +33,7 @@ fn no_statistic_shown_is_refused(ui: &mut Ui, data: &mut StoryData) -> StoryOutp
|
||||
let refuse_none = |shown: &StatsShown| {
|
||||
if *shown == StatsShown::default() { Validity::Refuse(Message::new("Show at least one statistic")) } else { Validity::Ok }
|
||||
};
|
||||
SelectionStatsReadout::new("Selection statistics", &parts, data.bind("shown", StatsShown::default()).check(refuse_none))
|
||||
.show(ui)
|
||||
.into()
|
||||
SelectionStatsReadout::new("Selection statistics", &parts, data.bind("shown", StatsShown::default()).check(refuse_none)).show(ui).into()
|
||||
}
|
||||
|
||||
fn open_menu(fixture: &mut Fixture) {
|
||||
|
||||
@@ -41,8 +41,7 @@ fn section_caption(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(Section<'static>, covers = [], drive = Drive::Never)]
|
||||
fn section_with_menu_and_reorder(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let shown =
|
||||
Section::new("Layers").open(data.bind("open", true)).actions([HeaderAction::Menu]).reorder(true).show(ui, |ui, _| body(ui));
|
||||
let shown = Section::new("Layers").open(data.bind("open", true)).actions([HeaderAction::Menu]).reorder(true).show(ui, |ui, _| body(ui));
|
||||
shown.output.into()
|
||||
}
|
||||
|
||||
|
||||
@@ -54,9 +54,7 @@ static ENTRIES: LazyLock<Vec<HelpEntry>> = LazyLock::new(|| {
|
||||
fn palette(ui: &mut Ui, data: &mut StoryData, recents: Vec<CommandRef>) -> StoryOutput {
|
||||
// The palette binds two story values; it edits a copy of `open`, which goes back after the pass.
|
||||
let mut open = *data.value("open", true);
|
||||
let out = CommandPalette::new("Command palette", ENTRIES.as_slice(), Bind::bound(&mut open))
|
||||
.recents(data.bind("recents", recents))
|
||||
.show(ui);
|
||||
let out = CommandPalette::new("Command palette", ENTRIES.as_slice(), Bind::bound(&mut open)).recents(data.bind("recents", recents)).show(ui);
|
||||
*data.value("open", true) = open;
|
||||
let last = data.value("last", None::<String>);
|
||||
if let Some(picked) = &out.picked
|
||||
|
||||
@@ -36,8 +36,7 @@ fn with_readout(data: &mut StoryData, shown: SwatchTableOutput) -> StoryOutput {
|
||||
#[story(SwatchTable<'static>, covers = [Default, Many], drive = Drive::Never)]
|
||||
fn swatch_table(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let entries = table_entries();
|
||||
let shown =
|
||||
SwatchTable::new("Color Table", &entries).selection(data.bind("selected", Selection::single(5usize))).per_row(16).show_all(ui);
|
||||
let shown = SwatchTable::new("Color Table", &entries).selection(data.bind("selected", Selection::single(5usize))).per_row(16).show_all(ui);
|
||||
with_readout(data, shown)
|
||||
}
|
||||
|
||||
@@ -45,8 +44,7 @@ fn swatch_table(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn swatch_table_multiple(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let entries = table_entries();
|
||||
let start = Selection::new(vec![2usize, 3, 18], Some(18), Some(2));
|
||||
let shown =
|
||||
SwatchTable::new("Color Table", &entries).multiple(true).selection(data.bind("selected", start)).per_row(16).show_all(ui);
|
||||
let shown = SwatchTable::new("Color Table", &entries).multiple(true).selection(data.bind("selected", start)).per_row(16).show_all(ui);
|
||||
with_readout(data, shown)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,10 +17,7 @@ const SIZE: f64 = 12.0;
|
||||
|
||||
#[story(Field, covers = [Default], drive = Drive::Never)]
|
||||
fn field(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
Field::new("Size")
|
||||
.help(Help::Text("In points".into()))
|
||||
.show(ui, |ui, _| NumberField::new("Size", data.bind("size", Some(SIZE))).show(ui))
|
||||
.into()
|
||||
Field::new("Size").help(Help::Text("In points".into())).show(ui, |ui, _| NumberField::new("Size", data.bind("size", Some(SIZE))).show(ui)).into()
|
||||
}
|
||||
|
||||
#[story(Field, covers = [], drive = Drive::Never)]
|
||||
@@ -73,9 +70,10 @@ fn field_with_cross_field_error(ui: &mut Ui, data: &mut StoryData) -> StoryOutpu
|
||||
let mut out = None;
|
||||
FieldGroup::new("Period").show(ui, |ui, _| {
|
||||
Field::new("Start day").show(ui, |ui, _| NumberField::new("Start day", data.bind("start_day", Some(20.0))).show(ui));
|
||||
out = Some(Field::new("End day").show(ui, |ui, _| {
|
||||
NumberField::new("End day", data.bind("end_day", Some(5.0)).check_with(start, end_before_start)).show(ui)
|
||||
}));
|
||||
out = Some(
|
||||
Field::new("End day")
|
||||
.show(ui, |ui, _| NumberField::new("End day", data.bind("end_day", Some(5.0)).check_with(start, end_before_start)).show(ui)),
|
||||
);
|
||||
});
|
||||
out.map(StoryOutput::from).unwrap_or_default()
|
||||
}
|
||||
@@ -107,9 +105,7 @@ fn field_inspector_rows(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
}
|
||||
});
|
||||
for (label, key, value) in [("Opacity", "opacity", 100.0), ("Angle", "angle", 0.0)] {
|
||||
Field::new(label)
|
||||
.side(SideLabel::new().scrub(true))
|
||||
.show(ui, |ui, _| NumberField::new(label, data.bind(key, Some(value))).show(ui));
|
||||
Field::new(label).side(SideLabel::new().scrub(true)).show(ui, |ui, _| NumberField::new(label, data.bind(key, Some(value))).show(ui));
|
||||
}
|
||||
Field::new("Fill").show(ui, |ui, _| Swatch::new("Fill", FILL).show(ui));
|
||||
})
|
||||
|
||||
@@ -302,10 +302,10 @@ fn mask_thumb(cx: &ContentPainterCx, rect: Rect) {
|
||||
fn list_masks(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let linked = *data.value("linked", [true; 2]);
|
||||
let target = *data.value("target", ThumbTarget::Extra(0));
|
||||
let out = List::<usize>::new("Layers")
|
||||
.natural_height(true)
|
||||
.selection(data.bind("selection", Selection::single(0_usize)))
|
||||
.show_items(ui, &Labels(&MASK_ROWS), &mut |key, icx| {
|
||||
let out = List::<usize>::new("Layers").natural_height(true).selection(data.bind("selection", Selection::single(0_usize))).show_items(
|
||||
ui,
|
||||
&Labels(&MASK_ROWS),
|
||||
&mut |key, icx| {
|
||||
let row = ListRow::new(MASK_ROWS[*key]).state(icx.row.clone()).thumb(ThumbSize::Medium, layer_thumb);
|
||||
match *key {
|
||||
0 => row
|
||||
@@ -317,7 +317,8 @@ fn list_masks(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
1 => row.clipped(true),
|
||||
_ => row.italic(true),
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
for event in &out.events {
|
||||
match event {
|
||||
CollectionEvent::Item(0, RowEvent::LinkToggled { thumb, linked: on, .. }) => {
|
||||
@@ -420,11 +421,10 @@ impl ItemSource<usize> for TreeNodes<'_> {}
|
||||
fn list_tree_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let open = data.value("open", first_open()).clone();
|
||||
let shown = shown_nodes(&open);
|
||||
let out = List::<usize>::new("Layers")
|
||||
.tree(true)
|
||||
.natural_height(true)
|
||||
.selection(data.bind("selection", Selection::single(0_usize)))
|
||||
.show_items(ui, &TreeNodes { shown: &shown, open: &open }, &mut |key, _| {
|
||||
let out = List::<usize>::new("Layers").tree(true).natural_height(true).selection(data.bind("selection", Selection::single(0_usize))).show_items(
|
||||
ui,
|
||||
&TreeNodes { shown: &shown, open: &open },
|
||||
&mut |key, _| {
|
||||
let (name, depth) = TREE[*key];
|
||||
let row = ListRow::new(name).depth(depth);
|
||||
if is_group(*key) {
|
||||
@@ -432,7 +432,8 @@ fn list_tree_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
} else {
|
||||
row.icon(IconSpec::svg(IconId::new("check")))
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
let groups: Vec<usize> = (0..TREE.len()).filter(|&at| is_group(at)).collect();
|
||||
for event in &out.events {
|
||||
if let CollectionEvent::Open(change) = event {
|
||||
@@ -447,11 +448,11 @@ fn list_tree_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(List<'static, usize>, covers = [], drive = Drive::Never)]
|
||||
fn list_row_menu(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let names = names(4);
|
||||
let out = List::<usize>::new("Layers")
|
||||
.rename(true)
|
||||
.row_menu()
|
||||
.selection(data.bind("selection", Selection::single(1_usize)))
|
||||
.show_items(ui, &Names(&names), &mut |key, _| ListRow::new(names[*key].clone()));
|
||||
let out = List::<usize>::new("Layers").rename(true).row_menu().selection(data.bind("selection", Selection::single(1_usize))).show_items(
|
||||
ui,
|
||||
&Names(&names),
|
||||
&mut |key, _| ListRow::new(names[*key].clone()),
|
||||
);
|
||||
let menu_row = data.value("menu", None::<usize>);
|
||||
for event in &out.events {
|
||||
if let CollectionEvent::ContextMenu(request) = event {
|
||||
|
||||
@@ -110,10 +110,8 @@ fn panel_menu(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
};
|
||||
let opener = IconButton::new(IconId::new("menu")).popup(PopupKind::Menu).popup_mark(PopupMark::Menu).label("Panel menu").show(ui);
|
||||
let mut picked = None;
|
||||
let shown = Menu::new("Panel menu")
|
||||
.open(data.bind("open", false))
|
||||
.opened_by(&opener, Trigger::Click)
|
||||
.show(ui, |ui, _| picked = panel().show(ui).picked);
|
||||
let shown =
|
||||
Menu::new("Panel menu").open(data.bind("open", false)).opened_by(&opener, Trigger::Click).show(ui, |ui, _| picked = panel().show(ui).picked);
|
||||
let chosen = data.note("chosen", None::<GroupItem>);
|
||||
if picked.is_some() {
|
||||
*chosen = picked;
|
||||
|
||||
@@ -97,7 +97,8 @@ fn select_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(Select<'static, u8>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn select_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let entries = modes();
|
||||
let bind = data.bind("invalid", 2u8)
|
||||
let bind = data
|
||||
.bind("invalid", 2u8)
|
||||
.check(|mode| if *mode == 2 { Validity::Refuse(Message::new("Screen is not available here")) } else { Validity::Ok });
|
||||
Select::new("Blend mode", bind, &entries).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -50,7 +50,5 @@ fn linked_fields_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
Mixed::Same(Some(width)) if width > 500.0 => Validity::Refuse(Message::new("Too wide")),
|
||||
_ => Validity::Ok,
|
||||
};
|
||||
LinkedFields::new("Size", data.bind("wide", Mixed::each([Some(900.0), Some(50.0)])).check(too_wide), Bind::given(false))
|
||||
.show(ui)
|
||||
.into()
|
||||
LinkedFields::new("Size", data.bind("wide", Mixed::each([Some(900.0), Some(50.0)])).check(too_wide), Bind::given(false)).show(ui).into()
|
||||
}
|
||||
@@ -76,20 +76,10 @@ fn number_field(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
NumberField::new("Columns", data.bind("invalid", Some(7.0)).check(refuse_all)).range(COLUMNS).size(size).show(ui);
|
||||
});
|
||||
row("Pop-up slider").show(ui, |ui, _| {
|
||||
NumberField::new("Opacity", data.bind("opacity", Some(100.0)))
|
||||
.range(RANGE)
|
||||
.unit("%")
|
||||
.popup_slider(RANGE)
|
||||
.size(size)
|
||||
.show(ui);
|
||||
NumberField::new("Opacity", data.bind("opacity", Some(100.0))).range(RANGE).unit("%").popup_slider(RANGE).size(size).show(ui);
|
||||
});
|
||||
row("Zoom stops").show(ui, |ui, _| {
|
||||
NumberField::new("Zoom", data.bind("zoom", Some(100.0)))
|
||||
.range(0.1..=12_800.0)
|
||||
.unit("%")
|
||||
.stepper(zoom_step)
|
||||
.size(size)
|
||||
.show(ui);
|
||||
NumberField::new("Zoom", data.bind("zoom", Some(100.0))).range(0.1..=12_800.0).unit("%").stepper(zoom_step).size(size).show(ui);
|
||||
});
|
||||
row("Disabled").show(ui, |ui, _| {
|
||||
NumberField::new("Disabled", Bind::bound(&mut Some(64.0)))
|
||||
|
||||
@@ -26,9 +26,8 @@ fn text_field(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let size = *data.choice("size", ControlSize::Md, &SIZES);
|
||||
let placeholder = data.value("placeholder", String::from("Layer name")).clone();
|
||||
let out = FieldGroup::new("Text field states").labels(LabelScheme::Inspector).show(ui, |ui, _| {
|
||||
let first = row("Empty").show(ui, |ui, _| {
|
||||
TextField::new("Name", data.bind("name", String::new())).placeholder(placeholder.clone()).size(size).show(ui)
|
||||
});
|
||||
let first = row("Empty")
|
||||
.show(ui, |ui, _| TextField::new("Name", data.bind("name", String::new())).placeholder(placeholder.clone()).size(size).show(ui));
|
||||
row("Filled").show(ui, |ui, _| {
|
||||
TextField::new("Layer", Bind::bound(&mut String::from("Background"))).placeholder(placeholder.clone()).size(size).show(ui);
|
||||
});
|
||||
@@ -127,11 +126,7 @@ fn text_field_search_filled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(TextField<'static, PlainText>, covers = [], drive = Drive::Never)]
|
||||
fn text_field_adorned(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
TextField::new("Font", data.bind("font", "Inter".to_owned()))
|
||||
.leading(IconSpec::svg(IconId::new("search")))
|
||||
.trailing_arrow()
|
||||
.show(ui)
|
||||
.into()
|
||||
TextField::new("Font", data.bind("font", "Inter".to_owned())).leading(IconSpec::svg(IconId::new("search"))).trailing_arrow().show(ui).into()
|
||||
}
|
||||
|
||||
/// Completes spreadsheet functions: each candidate marked "ƒ", with what it does under the list.
|
||||
|
||||
@@ -52,9 +52,5 @@ fn range_slider_ticks(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(RangeSlider<'static>, covers = [], drive = Drive::Never)]
|
||||
fn range_slider_track_face(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
RangeSlider::new(data.bind("range", LEVEL), RANGE)
|
||||
.track_face(TrackFace::new(Progress::new(1.0).label("Track")))
|
||||
.label("Hue")
|
||||
.show(ui)
|
||||
.into()
|
||||
RangeSlider::new(data.bind("range", LEVEL), RANGE).track_face(TrackFace::new(Progress::new(1.0).label("Track"))).label("Hue").show(ui).into()
|
||||
}
|
||||
@@ -134,11 +134,7 @@ fn slider_value_text(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(Slider<'static>, covers = [], drive = Drive::Never, group = "Looks", title = "Track face")]
|
||||
fn slider_track_face(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
Slider::new(data.bind("value", 40.0), RANGE)
|
||||
.track_face(TrackFace::new(Progress::new(1.0).label("Track")))
|
||||
.label("Hue")
|
||||
.show(ui)
|
||||
.into()
|
||||
Slider::new(data.bind("value", 40.0), RANGE).track_face(TrackFace::new(Progress::new(1.0).label("Track"))).label("Hue").show(ui).into()
|
||||
}
|
||||
|
||||
/// A slider shown in a field: the story's subject is the slider, and its value changes through its own thumb.
|
||||
|
||||
@@ -49,13 +49,7 @@ fn thumb_row_wrapping(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
Thumb::new("Hue to").face(DataColor::new(Color32::from_rgb(60, 160, 220))),
|
||||
Thumb::new("Hue to").face(DataColor::new(Color32::from_rgb(160, 60, 220))),
|
||||
];
|
||||
ThumbRow::new(data.bind("hues", Mixed::each([330.0, 40.0, 120.0, 250.0])), HUES)
|
||||
.step(1.0)
|
||||
.wrap()
|
||||
.thumbs(thumbs)
|
||||
.label("Hues")
|
||||
.show(ui)
|
||||
.into()
|
||||
ThumbRow::new(data.bind("hues", Mixed::each([330.0, 40.0, 120.0, 250.0])), HUES).step(1.0).wrap().thumbs(thumbs).label("Hues").show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ThumbRow<'static, 4>, covers = [], drive = Drive::Never)]
|
||||
|
||||
Reference in new issue
Block a user