Layer style stories: the Blend If hint, ContourField under its Contour label with a readout, LayerStyleDialog in its form dialog starting closed

This commit is contained in:
aiongg
2026-11-12 14:32:49 +00:00
parent 0c30c66140
commit 092334d352
3 changed files with 60 additions and 26 deletions
@@ -1,6 +1,7 @@
//! Stories of `BlendIfBar`: halves together (one triangle per pair) and halves apart (split handles).
use craft_ui::contract::Bind;
use craft_ui::contract::{Bind, Show as _};
use craft_ui::display::{Shade, Text};
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
use egui::Ui;
@@ -9,6 +10,8 @@ use crate::layer_style::BlendIfRange;
#[story(BlendIfBar<'static>, covers = [], drive = Drive::Never, group = "Handles", title = "Unsplit pairs")]
fn blend_if_bar_unsplit(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
// The card's hint over both bars: the first case shows it.
Text::new("Tab to a handle. Arrows move one level, Shift ten, Alt one half.").shade(Shade::Muted).show(ui);
let range = data.value("range", BlendIfRange([20, 20, 240, 240]));
BlendIfBar::new("Underlying Layer", Bind::bound(range)).show(ui).into()
}
@@ -1,6 +1,7 @@
//! Stories of the contour field: the built-in contours and a user's.
//! Stories of the contour field: the built-in contours and a user's, under the host's "Contour" caption.
use craft_ui::contract::Bind;
use craft_ui::contract::{Bind, ShowContainer as _};
use craft_ui::form::Field;
use craft_ui::patterns::presets::PresetState;
use craft_ui::runtime::env::Env;
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
@@ -14,20 +15,30 @@ fn user_contours() -> Vec<Contour> {
vec![Contour { name: String::from("Soft Step"), points: vec![point(0.0, 0.0), point(0.4, 0.1), point(1.0, 1.0)] }]
}
#[story(ContourField<'static>, covers = [Default], drive = Drive::Never)]
fn contour_field(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
/// The field over `start` with its Anti-aliased check box, in the host's Field, and the contour it holds as the
/// readout.
fn field(ui: &mut Ui, data: &mut StoryData, start: Contour, anti_alias: bool) -> StoryOutput {
let words = Env::of(ui).words::<ContourWords>();
let user = user_contours();
let rows = contour_rows(&Contour::presets(), &user, &words, None);
let (contour, state) = data.value("field", (Contour::linear(), PresetState::<ContourKey>::new()));
ContourField::new("Contour", Bind::bound(contour), &rows, Bind::bound(state)).user(&user).show(ui).into()
let (contour, state, anti_alias) = data.value("field", (start, PresetState::<ContourKey>::new(), Some(anti_alias)));
let shown = Field::new("Contour").show(ui, |ui, _| {
ContourField::new("Contour", Bind::bound(&mut *contour), &rows, Bind::bound(&mut *state))
.user(&user)
.anti_alias(Bind::bound(&mut *anti_alias))
.show(ui)
});
let output = shown.inner.map(StoryOutput::from).unwrap_or_default();
output.readout(format!("Contour: {}, {} points.", contour.name, contour.points.len()))
}
#[story(ContourField<'static>, covers = [Default], drive = Drive::Never)]
fn contour_field(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let cone = Contour::preset("Cone").unwrap_or_else(Contour::linear);
field(ui, data, cone, false)
}
#[story(ContourField<'static>, covers = [], drive = Drive::Never)]
fn contour_field_with_user_contour(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let words = Env::of(ui).words::<ContourWords>();
let user = user_contours();
let rows = contour_rows(&Contour::presets(), &user, &words, None);
let (contour, state, anti_alias) = data.value("field", (user[0].clone(), PresetState::<ContourKey>::new(), Some(true)));
ContourField::new("Contour", Bind::bound(contour), &rows, Bind::bound(state)).user(&user).anti_alias(Bind::bound(anti_alias)).show(ui).into()
field(ui, data, user_contours().remove(0), true)
}
+34 -14
View File
@@ -1,15 +1,17 @@
//! Stories of the Layer Style dialog: the dialog on an effect page, the Blending Options page in an RGB and a CMYK
//! document, one story per effect page and the Styles page. The story is the host: it keeps one
//! [`LayerStyleDraft`] per story instance, applies the dialog's edit and view state, and answers the Styles page with
//! fake thumbnails.
//! document, one story per effect page and the Styles page. The story is the host: it frames the body in its form
//! dialog, keeps one [`LayerStyleDraft`] per story instance, applies the dialog's edit and view state, and answers the
//! Styles page with fake thumbnails.
use craft_ui::contract::Entry;
use craft_ui::choice::Checkbox;
use craft_ui::contract::{Bind, Entry, Props as _, Show as _};
use craft_ui::patterns::form_dialogs::FormDialog;
use craft_ui::patterns::presets::PresetRow;
use craft_ui::runtime::env::{Env, Label};
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
use egui::Ui;
use super::{LayerStyleDialog, StylePresets};
use super::{LayerStyleDialog, LayerStyleWords, StylePresets};
use crate::layer_style::{BlendIf, Blending, EffectId, EffectInstance, EffectKind, EffectSpec, LayerStyle, LayerStyleDraft, LayerStylePage};
craft_ui::words! {
@@ -79,19 +81,37 @@ fn style_of(kinds: &[EffectKind]) -> LayerStyle {
LayerStyle { effects, ..LayerStyle::default() }
}
/// The dialog over the story's draft; the host applies the view state and the style edit.
/// The dialog over the story's draft, in the host's frame: a form dialog with its buttons beside the body and the
/// Preview check box under OK and Cancel. It starts closed behind the card's button; the host applies the view state
/// and the style edit.
fn host(ui: &mut Ui, data: &mut StoryData, start: impl FnOnce() -> LayerStyleDraft, channels: &[Label]) -> StoryOutput {
let words = Env::of(ui).words::<LayerStyleStoryWords>();
let env = Env::of(ui);
let (words, preview) = (env.words::<LayerStyleStoryWords>(), env.words::<LayerStyleWords>().preview.clone());
let mut open = *data.value("open", true);
let draft = data.value("draft", start());
let names: Vec<String> = channels.iter().map(|name| name.as_str().to_owned()).collect();
let (modes, patterns, rows) = (blend_modes(&words), patterns(&words), style_rows(&words));
let presets = StylePresets::new(&rows, |cx, rect, _| cx.checker(rect));
let out = LayerStyleDialog::new("Layer Style", draft, &names).blend_modes(&modes).patterns(&patterns).style_presets(presets).show(ui);
out.apply_view(draft);
if let Some(value) = out.edit.value() {
draft.style = value.clone();
}
out.into()
let mut output = None;
FormDialog::new("Layer Style", Bind::bound(draft))
.opened(Bind::bound(&mut open))
.shaped(|dialog| dialog.side_buttons(true))
.footer_value(move |ui, draft| {
if let Some(on) = Checkbox::new(Bind::given(draft.preview)).label(preview.clone()).show(ui).value().copied() {
draft.preview = on;
}
})
.show(ui, |ui, _, draft| {
let presets = StylePresets::new(&rows, |cx, rect, _| cx.checker(rect));
let out = LayerStyleDialog::new("Layer Style", draft, &names).blend_modes(&modes).patterns(&patterns).style_presets(presets).show(ui);
out.apply_view(draft);
if let Some(value) = out.edit.value() {
draft.style = value.clone();
}
output = Some(StoryOutput::from(out));
true
});
*data.value("open", true) = open;
output.unwrap_or_default()
}
fn rgb(words: &LayerStyleStoryWords) -> [Label; 3] {