mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Merge remote-tracking branch 'upstream/next' into ruler-look
# Conflicts: # crates/text/src/ui/ruler/stories.rs # crates/ui-canvas/src/canvas/rulers/stories.rs # crates/ui-gallery/src/chrome/card.rs # crates/ui-gallery/src/chrome/variants.rs # docs/contract-api.md
This commit is contained in:
@@ -111,6 +111,11 @@ jobs:
|
||||
# feature off, which an all-features build cannot reach.
|
||||
cargo nextest run --workspace --all-features --locked --profile ci --lib --bins --tests
|
||||
cargo nextest run -p craft-aep -p craft-video --all-features --locked --profile ci --example stubicc --example h264_h264enc_bench
|
||||
# The replay audit (craft-libs#2336), on Linux: the UI crates' tests again, from the same build, with every
|
||||
# memoized view that would replay also run for real and compared with its replay.
|
||||
if [ "$RUNNER_OS" = Linux ]; then
|
||||
CRAFT_UI_AUDIT_REPLAY=1 cargo nextest run --workspace --all-features --locked --profile ci --lib --bins --tests -E 'package(craft-ui-contract) | package(craft-ui-widgets) | package(craft-ui-panels) | package(craft-ui-patterns) | package(craft-ui-shell) | package(craft-ui-gallery) | package(craft-menu)'
|
||||
fi
|
||||
cargo test --workspace --doc --all-features --locked
|
||||
cargo nextest run -p craft-image-codecs -p craft-text --locked --profile ci --lib --bins --tests
|
||||
|
||||
|
||||
Generated
+9
@@ -2083,6 +2083,8 @@ dependencies = [
|
||||
"craft-host",
|
||||
"craft-keymap",
|
||||
"craft-theme",
|
||||
"craft-tracked",
|
||||
"craft-ui-macros",
|
||||
"emath",
|
||||
"kurbo",
|
||||
"serde",
|
||||
@@ -4316,6 +4318,7 @@ dependencies = [
|
||||
"smallvec",
|
||||
"syn 2.0.119",
|
||||
"toml",
|
||||
"typeid",
|
||||
"web-time",
|
||||
]
|
||||
|
||||
@@ -12923,6 +12926,12 @@ version = "0.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e"
|
||||
|
||||
[[package]]
|
||||
name = "typeid"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.20.1"
|
||||
|
||||
@@ -272,6 +272,7 @@ scoped-tls = "1"
|
||||
smallvec = "1"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
typeid = "1"
|
||||
proptest = "1"
|
||||
# Character sets of the WHATWG Encoding Standard (craft-mime). (Apache-2.0 OR MIT) AND BSD-3-Clause.
|
||||
encoding_rs = "0.8"
|
||||
|
||||
@@ -21,6 +21,9 @@ bitflags = "2"
|
||||
craft-host = { workspace = true }
|
||||
craft-keymap = { workspace = true }
|
||||
craft-theme = { workspace = true }
|
||||
# Value types readers hold in `Tracked` derive its `PlainData` marker.
|
||||
craft-tracked = { workspace = true }
|
||||
craft-ui-macros = { workspace = true }
|
||||
|
||||
# The dock layout is a persisted shape.
|
||||
serde = { workspace = true }
|
||||
|
||||
@@ -13,12 +13,14 @@ use kurbo::{Affine, Point, Rect, Vec2};
|
||||
/// [`aspect`](Self::aspect) stretches it along its x axis and before
|
||||
/// [`flip_x`](Self::flip_x) mirrors the result, PhotoCraft's `ViewXform`. DesignCraft's quarter
|
||||
/// turns are `rotation = 90 × q`; VectorCraft's radians are converted to degrees.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, craft_ui_macros::PlainData)]
|
||||
#[non_exhaustive]
|
||||
pub struct CanvasView {
|
||||
/// The canvas on screen, inside the rulers.
|
||||
#[plain_data(assume = "screen geometry: plain numbers, no interior mutability")]
|
||||
pub rect: ScreenRect,
|
||||
/// The document point drawn at `rect.center()`.
|
||||
#[plain_data(assume = "document geometry: plain numbers, no interior mutability")]
|
||||
pub center: Point,
|
||||
/// Screen points per document unit. In PhotoCraft's model this is the view zoom over the
|
||||
/// pixels per point, so 100 % shows one device pixel per document pixel.
|
||||
|
||||
@@ -68,7 +68,7 @@ impl From<Cow<'static, str>> for IconId {
|
||||
}
|
||||
|
||||
/// A mark beside a painted cursor.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum CursorBadge {
|
||||
/// A plus.
|
||||
@@ -100,7 +100,7 @@ pub enum CursorBadge {
|
||||
}
|
||||
|
||||
/// The kind of a [`CursorBadge::Count`] mark.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[non_exhaustive]
|
||||
pub enum CountMark {
|
||||
/// A point is added.
|
||||
|
||||
@@ -93,6 +93,47 @@ impl HitShape {
|
||||
}
|
||||
}
|
||||
|
||||
/// The shape moved by `by`.
|
||||
#[must_use]
|
||||
pub fn translated(&self, by: Vec2) -> Self {
|
||||
let points = |points: &[Pos2]| points.iter().map(|point| *point + by).collect();
|
||||
match self {
|
||||
HitShape::Rect(rect) => HitShape::Rect(rect.translate(by)),
|
||||
HitShape::Circle { center, radius } => HitShape::Circle { center: *center + by, radius: *radius },
|
||||
HitShape::Segment { a, b } => HitShape::Segment { a: *a + by, b: *b + by },
|
||||
HitShape::Polyline { points: line, closed, reach } => HitShape::Polyline { points: points(line), closed: *closed, reach: *reach },
|
||||
HitShape::Polygon(polygon) => HitShape::Polygon(points(polygon)),
|
||||
HitShape::OutsidePolygon { within, polygon } => HitShape::OutsidePolygon { within: within.translate(by), polygon: points(polygon) },
|
||||
}
|
||||
}
|
||||
|
||||
/// The shape with each coordinate taken from `to`'s where the two lie within `within` points, when both are the
|
||||
/// same kind of shape with as many points: two shapes `==` finds equal after it differ by no more than `within`.
|
||||
#[must_use]
|
||||
pub fn snapped(&self, to: &HitShape, within: f32) -> Self {
|
||||
let near = |value: f32, to: f32| if (value - to).abs() <= within { to } else { value };
|
||||
let pos = |value: Pos2, to: Pos2| Pos2::new(near(value.x, to.x), near(value.y, to.y));
|
||||
let rect = |value: Rect, to: Rect| Rect::from_min_max(pos(value.min, to.min), pos(value.max, to.max));
|
||||
let points = |values: &[Pos2], to: &[Pos2]| {
|
||||
if values.len() == to.len() { values.iter().zip(to).map(|(value, to)| pos(*value, *to)).collect() } else { values.to_vec() }
|
||||
};
|
||||
match (self, to) {
|
||||
(HitShape::Rect(value), HitShape::Rect(to)) => HitShape::Rect(rect(*value, *to)),
|
||||
(HitShape::Circle { center, radius }, HitShape::Circle { center: to_center, radius: to_radius }) => {
|
||||
HitShape::Circle { center: pos(*center, *to_center), radius: near(*radius, *to_radius) }
|
||||
}
|
||||
(HitShape::Segment { a, b }, HitShape::Segment { a: to_a, b: to_b }) => HitShape::Segment { a: pos(*a, *to_a), b: pos(*b, *to_b) },
|
||||
(HitShape::Polyline { points: line, closed, reach }, HitShape::Polyline { points: to_line, reach: to_reach, .. }) => {
|
||||
HitShape::Polyline { points: points(line, to_line), closed: *closed, reach: near(*reach, *to_reach) }
|
||||
}
|
||||
(HitShape::Polygon(polygon), HitShape::Polygon(to_polygon)) => HitShape::Polygon(points(polygon, to_polygon)),
|
||||
(HitShape::OutsidePolygon { within: area, polygon }, HitShape::OutsidePolygon { within: to_area, polygon: to_polygon }) => {
|
||||
HitShape::OutsidePolygon { within: rect(*area, *to_area), polygon: points(polygon, to_polygon) }
|
||||
}
|
||||
_ => self.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `point` hits the shape grown to be at least `across` wide and high: the hit area of a part is never
|
||||
/// smaller than the pointer's target size.
|
||||
fn hit_across(&self, point: Pos2, across: f32) -> bool {
|
||||
@@ -232,6 +273,22 @@ pub struct Shape<O> {
|
||||
pub min_across: f32,
|
||||
}
|
||||
|
||||
impl<O: Clone> Shape<O> {
|
||||
/// The shape moved by `by`.
|
||||
#[must_use]
|
||||
pub fn translated(&self, by: Vec2) -> Self {
|
||||
Shape { shape: self.shape.translated(by), owner: self.owner.clone(), ..*self }
|
||||
}
|
||||
|
||||
/// The shape with its geometry and least size across taken from `to`'s where they lie within `within` points
|
||||
/// ([`HitShape::snapped`]).
|
||||
#[must_use]
|
||||
pub fn snapped(&self, to: &Shape<O>, within: f32) -> Self {
|
||||
let min_across = if (self.min_across - to.min_across).abs() <= within { to.min_across } else { self.min_across };
|
||||
Shape { shape: self.shape.snapped(&to.shape, within), owner: self.owner.clone(), min_across, ..*self }
|
||||
}
|
||||
}
|
||||
|
||||
impl<O> Shape<O> {
|
||||
/// A shape of `owner` at stack `position`.
|
||||
pub const fn new(shape: HitShape, sense: Sense, owner: O, part: Option<PartRef>, priority: HitPriority, position: u32) -> Self {
|
||||
|
||||
@@ -193,7 +193,7 @@ pub trait SelectionModel<K>: Value + Default {
|
||||
}
|
||||
|
||||
/// A set of keys with a lead and an anchor.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, craft_ui_macros::PlainData)]
|
||||
#[non_exhaustive]
|
||||
pub struct Selection<K> {
|
||||
/// The selected keys.
|
||||
|
||||
@@ -4,7 +4,7 @@ use std::collections::HashMap;
|
||||
use std::sync::{Mutex, PoisonError};
|
||||
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::{Bind, Show as _, ShowContainer as _};
|
||||
use craft_ui::contract::{Show as _, ShowContainer as _};
|
||||
use craft_ui::display::Divider;
|
||||
use craft_ui::layout_components::Row;
|
||||
use craft_ui::patterns::form_dialogs::PreviewView;
|
||||
@@ -71,16 +71,16 @@ fn compare_pair(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let labels = ["Select", "Candidate"];
|
||||
let output = filling(ui, |ui, area| {
|
||||
let mut active = *data.value("active", 0usize);
|
||||
let view = data.value("view", PreviewView::fitting());
|
||||
let (view, view_at) = data.value_at("view", PreviewView::fitting());
|
||||
let pair = ComparePair::new(space).rtl(rtl);
|
||||
let [left, right] = pair.rects(area);
|
||||
Divider::vertical().show_at(ui, pair.divider(area));
|
||||
let select =
|
||||
CompareTile::new(labels[0], Bind::bound(view), image(1)).caption(caption(labels[0], "IMG_0001.jpg")).active(active == 0).place(ui, left);
|
||||
CompareTile::new(labels[0], view_at.bind(view), image(1)).caption(caption(labels[0], "IMG_0001.jpg")).active(active == 0).place(ui, left);
|
||||
if select.clicked {
|
||||
active = 0;
|
||||
}
|
||||
let candidate = CompareTile::new(labels[1], Bind::bound(view), image(2))
|
||||
let candidate = CompareTile::new(labels[1], view_at.bind(view), image(2))
|
||||
.caption(caption(labels[1], "IMG_0002.jpg"))
|
||||
.active(active == 1)
|
||||
.rejected(true)
|
||||
@@ -98,9 +98,9 @@ fn compare_pair(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(CompareTile<'static>, covers = [LongText], drive = Drive::Never)]
|
||||
fn compare_tile_narrow(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
filling(ui, |ui, area| {
|
||||
let view = data.value("view", PreviewView::fitting());
|
||||
let (view, view_at) = data.value_at("view", PreviewView::fitting());
|
||||
let rect = Rect::from_min_size(area.min, Vec2::splat(area.width() * NARROW_SHARE));
|
||||
CompareTile::new("Select", Bind::bound(view), image(1))
|
||||
CompareTile::new("Select", view_at.bind(view), image(1))
|
||||
.caption(caption("Select", "A_file_name_much_longer_than_the_tile.jpeg"))
|
||||
.place(ui, rect)
|
||||
.into()
|
||||
@@ -110,8 +110,8 @@ fn compare_tile_narrow(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(CompareTile<'static>, covers = [], drive = Drive::Never)]
|
||||
fn compare_tile_pending(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
filling(ui, |ui, area| {
|
||||
let view = data.value("view", PreviewView::fitting());
|
||||
CompareTile::new("Candidate", Bind::bound(view), image(2))
|
||||
let (view, view_at) = data.value_at("view", PreviewView::fitting());
|
||||
CompareTile::new("Candidate", view_at.bind(view), image(2))
|
||||
.caption(caption("Candidate", "IMG_0002.jpg"))
|
||||
.state(RenderState::Pending(true))
|
||||
.place(ui, area)
|
||||
@@ -122,8 +122,8 @@ fn compare_tile_pending(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(CompareTile<'static>, covers = [], drive = Drive::Never)]
|
||||
fn compare_tile_failed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
filling(ui, |ui, area| {
|
||||
let view = data.value("view", PreviewView::fitting());
|
||||
CompareTile::new("Candidate", Bind::bound(view), CompareImage::None)
|
||||
let (view, view_at) = data.value_at("view", PreviewView::fitting());
|
||||
CompareTile::new("Candidate", view_at.bind(view), CompareImage::None)
|
||||
.caption(CompareCaption::new("Candidate", "IMG_0002.jpg"))
|
||||
.state(RenderState::Failed("The renderer stopped".into()))
|
||||
.place(ui, area)
|
||||
@@ -138,12 +138,12 @@ fn compare_survey(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
const ASPECT: f32 = 1.5;
|
||||
let rtl = Env::of(ui).view().direction().is_rtl();
|
||||
filling(ui, |ui, area| {
|
||||
let view = data.value("view", PreviewView::fitting());
|
||||
let (view, view_at) = data.value_at("view", PreviewView::fitting());
|
||||
let mut outs = Vec::new();
|
||||
for at in 0..COUNT {
|
||||
let rect = survey_cell(COUNT, at, area, ASPECT, rtl);
|
||||
let name = format!("IMG_{at:04}.jpg");
|
||||
let out = CompareTile::new(name.clone(), Bind::bound(view), image(at as u64))
|
||||
let out = CompareTile::new(name.clone(), view_at.bind(view), image(at as u64))
|
||||
.caption(CompareCaption::new("", name))
|
||||
.survey(true)
|
||||
.place(ui, rect);
|
||||
|
||||
@@ -162,8 +162,9 @@ fn show_places(ui: &mut Ui, data: &mut StoryData, setup: Setup) -> StoryOutput {
|
||||
})
|
||||
.clone();
|
||||
let mut demo = demo.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
// The framework's repaint runs the story's view again, where the next jobs run.
|
||||
if !setup.slow && demo.jobs.run_all() > 0 {
|
||||
ctx.request_repaint();
|
||||
craft_ui::runtime::frame::request_repaint(&ctx);
|
||||
}
|
||||
let current = demo.current.clone();
|
||||
let places = {
|
||||
|
||||
@@ -22,7 +22,7 @@ const BANG_DROP: f32 = 0.09375;
|
||||
const BAN_RING: f32 = 0.55;
|
||||
|
||||
/// A status badge drawn from the theme: a solid shape in the status colour with its mark in `text.on_status`.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, craft_ui::contract::MemoProps)]
|
||||
enum StatusGlyph {
|
||||
/// A `status.bad.solid` disc with `?`.
|
||||
Missing,
|
||||
|
||||
@@ -13,7 +13,7 @@ use craft_behavior::Selection;
|
||||
use craft_docpath::Refused;
|
||||
use craft_docpath::links::{FakeLinkFiles, Link, LinkIdentity, LinkStatus, identity_of};
|
||||
use craft_host::{Jobs, ManualJobs};
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::dialog::{DialogStack, StackDialog as _};
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::list::ThumbSize;
|
||||
@@ -68,7 +68,7 @@ fn links() -> (Vec<Link<u32>>, HashMap<u32, LinkStatus>) {
|
||||
}
|
||||
|
||||
fn list_story(ui: &mut Ui, data: &mut StoryData, links: &[Link<u32>], statuses: &HashMap<u32, LinkStatus>) -> StoryOutput {
|
||||
let state = data.value(
|
||||
let (state, state_at) = data.value_at(
|
||||
"state",
|
||||
LinkListState {
|
||||
selection: Selection::single(2),
|
||||
@@ -80,7 +80,7 @@ fn list_story(ui: &mut Ui, data: &mut StoryData, links: &[Link<u32>], statuses:
|
||||
let info = lead.map_or_else(|| words.info_none.as_str().to_owned(), |link| words.info_path.fill(&[("path", &link.stored)]));
|
||||
let thumbs = Thumbnails::<u32>::in_context(ui.ctx(), "craft-browse-link-list-story", ThumbnailOptions::new());
|
||||
let pictures = FakeThumbSource::<u32>::new().aspect(4, 3);
|
||||
LinkList::new("Links", links, statuses, Bind::bound(state))
|
||||
LinkList::new("Links", links, statuses, state_at.bind(state))
|
||||
.thumbnails(&thumbs, &pictures)
|
||||
.info(move |ui| {
|
||||
Text::new(info.clone()).show(ui);
|
||||
@@ -156,10 +156,11 @@ fn dialog_story(ui: &mut Ui, data: &mut StoryData, search: bool, finish: bool) -
|
||||
if search && !*started {
|
||||
*started = true;
|
||||
dialog.begin_search();
|
||||
ui.ctx().request_repaint();
|
||||
craft_ui::runtime::frame::request_repaint(ui.ctx());
|
||||
}
|
||||
// The framework's repaint runs the story's view again, where the next jobs run.
|
||||
if finish && demo.jobs.run_all() > 0 {
|
||||
ui.ctx().request_repaint();
|
||||
craft_ui::runtime::frame::request_repaint(ui.ctx());
|
||||
}
|
||||
StoryOutput::default()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use super::{AreaShape, ColorArea};
|
||||
use crate::AreaMode;
|
||||
use craft_theme::{ColorModel, HsbModel, Srgba};
|
||||
use craft_ui::contract::{Bind, Props as _, Show as _, Validity};
|
||||
use craft_ui::contract::{Props as _, Show as _, Validity};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, story};
|
||||
use craft_ui::value_drag::PointPicker;
|
||||
@@ -13,33 +13,33 @@ use egui::Ui;
|
||||
/// shows inside itself.
|
||||
#[story(ColorArea<'static>, covers = [Default], drive = Drive::DragChild(Grip::new(PointPicker::WELL)))]
|
||||
fn color_area(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, Bind::bound(values)).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, values_at.bind(values)).show(ui).into()
|
||||
}
|
||||
|
||||
/// The Color Picker dialog's field: a square, `size.plot.width` on a side.
|
||||
#[story(ColorArea<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_area_square(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, Bind::bound(values)).shape(AreaShape::Square).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, values_at.bind(values)).shape(AreaShape::Square).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorArea<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_area_web_safe(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.6, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, Bind::bound(values)).quantize(6).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.6, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, values_at.bind(values)).quantize(6).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorArea<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn color_area_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let refuse_dim =
|
||||
|values: &craft_theme::ModelValues| if values.values[2] < 50.0 { Validity::Refuse(Message::new("Too dim")) } else { Validity::Ok };
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.1, 0.2, 0.3)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, Bind::bound(values).check(refuse_dim)).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.1, 0.2, 0.3)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, values_at.bind(values).check(refuse_dim)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorArea<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_area_disabled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, Bind::bound(values)).enabled(false).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, values_at.bind(values)).enabled(false).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::{ColorDisc, DiscMove, MARKER};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::{Bind, Props as _, Show as _, Validity};
|
||||
use craft_ui::contract::{Props as _, Show as _, Validity};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -11,19 +11,19 @@ const MARKERS: [Srgba; 3] = [Srgba::rgb(0.9, 0.2, 0.2), Srgba::rgb(0.2, 0.7, 0.4
|
||||
|
||||
#[story(ColorDisc<'static>, covers = [Default], drive = Drive::Drag(Grip::part(MARKER.at(1))))]
|
||||
fn color_disc(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let moved = data.value("move", DiscMove::new(0, 0.0, 0.7));
|
||||
ColorDisc::new("Harmony", &MARKERS, Bind::bound(moved)).chosen(1).show(ui).into()
|
||||
let (moved, moved_at) = data.value_at("move", DiscMove::new(0, 0.0, 0.7));
|
||||
ColorDisc::new("Harmony", &MARKERS, moved_at.bind(moved)).chosen(1).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorDisc<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn color_disc_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let refuse_pale = |moved: &DiscMove| if moved.saturation < 0.5 { Validity::Refuse(Message::new("Too pale")) } else { Validity::Ok };
|
||||
let moved = Bind::bound(data.value("pale", DiscMove::new(1, 0.0, 0.2))).check(refuse_pale);
|
||||
let moved = data.bind("pale", DiscMove::new(1, 0.0, 0.2)).check(refuse_pale);
|
||||
ColorDisc::new("Harmony", &MARKERS, moved).chosen(1).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorDisc<'static>, covers = [], drive = Drive::Never, title = "Disabled")]
|
||||
fn color_disc_disabled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let moved = data.value("move", DiscMove::new(0, 0.0, 0.7));
|
||||
ColorDisc::new("Harmony", &MARKERS, Bind::bound(moved)).chosen(1).enabled(false).show(ui).into()
|
||||
let (moved, moved_at) = data.value_at("move", DiscMove::new(0, 0.0, 0.7));
|
||||
ColorDisc::new("Harmony", &MARKERS, moved_at.bind(moved)).chosen(1).enabled(false).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
//! Stories of `DropperButton`.
|
||||
|
||||
use super::{DropperButton, DropperKind};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
fn button(ui: &mut Ui, data: &mut StoryData, kind: DropperKind, armed: bool) -> StoryOutput {
|
||||
let armed = data.value("armed", armed);
|
||||
StoryOutput::from(DropperButton::new("Sample in image", Bind::bound(armed)).kind(kind).show(ui))
|
||||
let (armed, armed_at) = data.value_at("armed", armed);
|
||||
StoryOutput::from(DropperButton::new("Sample in image", armed_at.bind(armed)).kind(kind).show(ui))
|
||||
}
|
||||
|
||||
#[story(DropperButton<'static>, covers = [], drive = Drive::Never)]
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
use super::{EyedropperBar, EyedropperOptions, SampleSize, SampleSizeSelect};
|
||||
use craft_ui::bars::{Bar, BarKind};
|
||||
use craft_ui::contract::{Bind, ShowContainer as _};
|
||||
use craft_ui::contract::ShowContainer as _;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
#[story(SampleSizeSelect<'static>, covers = [], drive = Drive::Never)]
|
||||
fn sample_size_select(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let size = data.value("size", SampleSize::Point);
|
||||
StoryOutput::from(SampleSizeSelect::new(Bind::bound(size)).show(ui))
|
||||
let (size, size_at) = data.value_at("size", SampleSize::Point);
|
||||
StoryOutput::from(SampleSizeSelect::new(size_at.bind(size)).show(ui))
|
||||
}
|
||||
|
||||
#[story(EyedropperBar<'static>, covers = [], drive = Drive::Never)]
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
use super::{GradientEditor, GradientEditorOutput};
|
||||
use crate::ui::gradient::{ColorStop, GradientStops, OpacityStop, StopRef, StopRows, StopRules};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -56,34 +55,34 @@ fn combined() -> GradientStops {
|
||||
|
||||
#[story(GradientEditor<'static, u8>, covers = [Default], drive = Drive::Never)]
|
||||
fn gradient_editor(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let stops = data.value("stops", split());
|
||||
let output = GradientEditor::new("Gradient", Bind::bound(stops)).show(ui);
|
||||
let (stops, stops_at) = data.value_at("stops", split());
|
||||
let output = GradientEditor::new("Gradient", stops_at.bind(stops)).show(ui);
|
||||
hinted(ui, data, output)
|
||||
}
|
||||
|
||||
#[story(GradientEditor<'static, u8>, covers = [], drive = Drive::Never)]
|
||||
fn gradient_editor_combined(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let stops = data.value("stops", combined());
|
||||
let output = GradientEditor::new("Gradient", Bind::bound(stops)).rules(StopRules::new(StopRows::Combined)).show(ui);
|
||||
let (stops, stops_at) = data.value_at("stops", combined());
|
||||
let output = GradientEditor::new("Gradient", stops_at.bind(stops)).rules(StopRules::new(StopRows::Combined)).show(ui);
|
||||
hinted(ui, data, output)
|
||||
}
|
||||
|
||||
#[story(GradientEditor<'static, u8>, covers = [], drive = Drive::Never)]
|
||||
fn gradient_editor_color_only(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let stops = data.value("stops", GradientStops::new(vec![color(0.0, [0.0, 0.0, 0.0]), color(1.0, [1.0, 1.0, 1.0])]));
|
||||
GradientEditor::new("Gradient map", Bind::bound(stops)).rules(StopRules::new(StopRows::ColorOnly).stops(2, 64)).show(ui).into()
|
||||
let (stops, stops_at) = data.value_at("stops", GradientStops::new(vec![color(0.0, [0.0, 0.0, 0.0]), color(1.0, [1.0, 1.0, 1.0])]));
|
||||
GradientEditor::new("Gradient map", stops_at.bind(stops)).rules(StopRules::new(StopRows::ColorOnly).stops(2, 64)).show(ui).into()
|
||||
}
|
||||
|
||||
/// The colour popover on, a colour stop selected.
|
||||
#[story(GradientEditor<'static, u8>, covers = [], drive = Drive::Never)]
|
||||
fn gradient_editor_popover(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let (stops, selected) = data.value("state", (split(), Some(StopRef::Color(0))));
|
||||
let output = GradientEditor::new("Gradient", Bind::bound(stops)).color_popover(true).shared_selection(Bind::bound(selected)).show(ui);
|
||||
let ((stops, selected), state_at) = data.value_at("state", (split(), Some(StopRef::Color(0))));
|
||||
let output = GradientEditor::new("Gradient", state_at.bind(stops)).color_popover(true).shared_selection(state_at.bind(selected)).show(ui);
|
||||
hinted(ui, data, output)
|
||||
}
|
||||
|
||||
#[story(GradientEditor<'static, u8>, covers = [], drive = Drive::Never, title = "Disabled")]
|
||||
fn gradient_editor_disabled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let stops = data.value("stops", split());
|
||||
GradientEditor::new("Gradient", Bind::bound(stops)).enabled(false).show(ui).into()
|
||||
let (stops, stops_at) = data.value_at("stops", split());
|
||||
GradientEditor::new("Gradient", stops_at.bind(stops)).enabled(false).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use super::{HarmonyPanel, HarmonyPanelState, HarmonyPicked, HarmonyWheel};
|
||||
use crate::harmony::Harmony;
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::{Bind, ShowContainer as _};
|
||||
use craft_ui::contract::ShowContainer as _;
|
||||
use craft_ui::layout_components::Stack;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -12,13 +12,13 @@ const BASE: Srgba = Srgba::rgb(0.86, 0.24, 0.16);
|
||||
|
||||
#[story(HarmonyPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
fn harmony_panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let (state, picked) = data.value("guide", (triad(), HarmonyPicked::default()));
|
||||
let ((state, picked), guide_at) = data.value_at("guide", (triad(), HarmonyPicked::default()));
|
||||
let colors = state.rule.apply(BASE);
|
||||
// The wheel above the panel shows the panel's rule on the base colour, as a Color Guide works with the wheel.
|
||||
Stack::new()
|
||||
.show(ui, |ui, _| {
|
||||
let _ = HarmonyWheel::new("Harmony", &colors).selected_marker(Some(0)).show(ui);
|
||||
StoryOutput::from(HarmonyPanel::new(Bind::bound(&mut *state), Bind::bound(&mut *picked), BASE).show(ui))
|
||||
StoryOutput::from(HarmonyPanel::new(guide_at.bind(&mut *state), guide_at.bind(&mut *picked), BASE).show(ui))
|
||||
})
|
||||
.inner
|
||||
.unwrap_or_default()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Stories of the LUT picker.
|
||||
|
||||
use super::{LutChoice, LutPicker};
|
||||
use craft_ui::contract::{Bind, Props as _, Role, Show as _, Validity};
|
||||
use craft_ui::contract::{Props as _, Role, Show as _, Validity};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, story};
|
||||
use egui::{Key, Modifiers, Ui};
|
||||
@@ -19,14 +19,14 @@ fn pick_second(fixture: &mut Fixture) {
|
||||
|
||||
#[story(LutPicker<'static>, covers = [Default], drive = Drive::Custom(pick_second))]
|
||||
fn lut_picker(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let shown = LutPicker::new(Bind::bound(data.value("lut", LutChoice::Builtin("warm")))).label("3D LUT File").show(ui);
|
||||
let shown = LutPicker::new(data.bind("lut", LutChoice::Builtin("warm"))).label("3D LUT File").show(ui);
|
||||
let chosen = format!("Chosen: {:?}", data.value("lut", LutChoice::Builtin("warm")));
|
||||
StoryOutput::from(shown).readout(chosen)
|
||||
}
|
||||
|
||||
#[story(LutPicker<'static>, covers = [], drive = Drive::Never)]
|
||||
fn lut_picker_loaded(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let shown = LutPicker::new(Bind::bound(data.value("lut", LutChoice::loaded("Film", 33)))).label("3D LUT File").show(ui);
|
||||
let shown = LutPicker::new(data.bind("lut", LutChoice::loaded("Film", 33))).label("3D LUT File").show(ui);
|
||||
let chosen = format!("Chosen: {:?}", data.value("lut", LutChoice::loaded("Film", 33)));
|
||||
StoryOutput::from(shown).readout(chosen)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ fn lut_picker_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
LutChoice::Builtin(_) => Validity::Refuse(Message::new("Load a file")),
|
||||
_ => Validity::Ok,
|
||||
};
|
||||
let shown = LutPicker::new(Bind::bound(data.value("lut", LutChoice::Builtin("warm"))).check(refuse_builtin)).label("3D LUT File").show(ui);
|
||||
let shown = LutPicker::new(data.bind("lut", LutChoice::Builtin("warm")).check(refuse_builtin)).label("3D LUT File").show(ui);
|
||||
let chosen = format!("Chosen: {:?}", data.value("lut", LutChoice::Builtin("warm")));
|
||||
StoryOutput::from(shown).readout(chosen)
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ const BLUE: Srgba = Srgba::rgb(0.2, 0.4, 0.8);
|
||||
|
||||
fn chip(ui: &mut Ui, data: &mut StoryData, paint: Paint) -> StoryOutput {
|
||||
let stops = vec![(0.0, BLUE), (1.0, Srgba::rgb(1.0, 1.0, 1.0))];
|
||||
let held = data.value("paint", paint);
|
||||
PaintChip::new("Fill", Bind::bound(held), BLUE).gradient_editor(GradientPreview::new(stops), |_: &mut Ui| None).show(ui).into()
|
||||
let (held, held_at) = data.value_at("paint", paint);
|
||||
PaintChip::new("Fill", held_at.bind(held), BLUE).gradient_editor(GradientPreview::new(stops), |_: &mut Ui| None).show(ui).into()
|
||||
}
|
||||
|
||||
/// A fill, a gradient fill and a stroke with no colour, in one column; the drives use the first.
|
||||
@@ -60,8 +60,8 @@ fn paint_chip(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(PaintChip<'static>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn paint_chip_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let held = data.value("mixed", Mixed::<Paint>::Mixed);
|
||||
PaintChip::new("Fill", Bind::bound_mixed(held), BLUE).show(ui).into()
|
||||
let (held, held_at) = data.value_at("mixed", Mixed::<Paint>::Mixed);
|
||||
PaintChip::new("Fill", held_at.bind_mixed(held), BLUE).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(PaintChip<'static>, covers = [Open], drive = Drive::Custom(open_popover))]
|
||||
@@ -81,8 +81,8 @@ fn paint_chip_open_with_recents_and_swatches(ui: &mut Ui, data: &mut StoryData)
|
||||
SwatchGroup { name: "Pastels".to_owned(), entries: vec![entry("Rose", [1.0, 0.8, 0.85]), entry("Mint", [0.75, 1.0, 0.85])] },
|
||||
];
|
||||
let recent = [BLUE, Srgba::rgb(0.9, 0.5, 0.1), Srgba::rgb(0.1, 0.6, 0.3)];
|
||||
let (held, folders) = data.value("state", (Paint::Solid(BLUE), PresetState::<SwatchKey>::new()));
|
||||
PaintChip::new("Fill", Bind::bound(held), BLUE).recent(&recent).swatches(&groups, Bind::bound(folders)).full_picker(true).show(ui).into()
|
||||
let ((held, folders), state_at) = data.value_at("state", (Paint::Solid(BLUE), PresetState::<SwatchKey>::new()));
|
||||
PaintChip::new("Fill", state_at.bind(held), BLUE).recent(&recent).swatches(&groups, state_at.bind(folders)).full_picker(true).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(PaintChip<'static>, covers = [], drive = Drive::Never)]
|
||||
@@ -102,8 +102,8 @@ fn paint_chip_pattern(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(PaintChip<'static>, covers = [], drive = Drive::Never)]
|
||||
fn paint_chip_disabled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let held = data.value("paint", Paint::Solid(Srgba { r: 0.9, g: 0.2, b: 0.2, a: 0.6 }));
|
||||
PaintChip::new("Fill", Bind::bound(held), BLUE).enabled(false).show(ui).into()
|
||||
let (held, held_at) = data.value_at("paint", Paint::Solid(Srgba { r: 0.9, g: 0.2, b: 0.2, a: 0.6 }));
|
||||
PaintChip::new("Fill", held_at.bind(held), BLUE).enabled(false).show(ui).into()
|
||||
}
|
||||
|
||||
fn paints() -> Vec<(String, Paint)> {
|
||||
@@ -118,14 +118,14 @@ fn paints() -> Vec<(String, Paint)> {
|
||||
#[story(PaintList<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn paint_list(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paints = paints();
|
||||
PaintList::new("Paints", &paints, Bind::bound(data.value("selected", None::<usize>))).show(ui).into()
|
||||
PaintList::new("Paints", &paints, data.bind("selected", None::<usize>)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(PaintList<'static>, covers = [], drive = Drive::Never)]
|
||||
fn paint_list_selection_colors(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paints = paints();
|
||||
let rows = [PaintRow::linked(PaintLink::new("Primary / Blue", PaintLinkKind::Style))];
|
||||
PaintList::new("Selection colors", &paints, Bind::bound(data.value("selected", Some(0usize))))
|
||||
PaintList::new("Selection colors", &paints, data.bind("selected", Some(0usize)))
|
||||
.options(PaintListOptions { select_users: true, bind: true, remove: true, add: true, ..PaintListOptions::SELECTION_COLORS })
|
||||
.rows(&rows)
|
||||
.show(ui)
|
||||
@@ -135,6 +135,6 @@ fn paint_list_selection_colors(ui: &mut Ui, data: &mut StoryData) -> StoryOutput
|
||||
#[story(PaintChip<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn paint_chip_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let refuse_none = |paint: &Paint| if matches!(paint, Paint::None) { Validity::Refuse(Message::new("A fill is required")) } else { Validity::Ok };
|
||||
let held = Bind::bound(data.value("paint", Paint::None)).check(refuse_none);
|
||||
let held = data.bind("paint", Paint::None).check(refuse_none);
|
||||
PaintChip::new("Fill", held, BLUE).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -564,7 +564,7 @@ fn outline(at: Rect, style: &SwatchPairStyle) -> PaintShape {
|
||||
|
||||
/// The glyphs of the pair's buttons, drawn on a square grid of `GRID` units; they picture the pair, so they mirror
|
||||
/// with it.
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, craft_ui::contract::MemoProps)]
|
||||
enum PairGlyph {
|
||||
/// Default colours: a black square over a white one, as the wells stand.
|
||||
Defaults,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use super::{PairWell, SwatchPair, Well};
|
||||
use craft_behavior::Mixed;
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::{Bind, Show as _, Validity};
|
||||
use craft_ui::contract::{Show as _, Validity};
|
||||
use craft_ui::rails::{LastUsed, ToolRail, ToolSlot};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, story};
|
||||
@@ -34,10 +34,10 @@ struct Colors {
|
||||
/// popup's picker edits the well it opened on. With `ring` the secondary well is a ring, as DesignCraft's stroke.
|
||||
fn editing(ui: &mut Ui, data: &mut StoryData, names: [&'static str; 2], start: [Srgba; 2], ring: bool) -> StoryOutput {
|
||||
let defaults = [Srgba::rgb(0.0, 0.0, 0.0), Srgba::rgb(1.0, 1.0, 1.0)];
|
||||
let state = data.value("colors", Colors { active: Well::Primary, colors: start });
|
||||
let (state, state_at) = data.value_at("colors", Colors { active: Well::Primary, colors: start });
|
||||
let wells = [PairWell::new(names[0], state.colors[0]), PairWell::new(names[1], state.colors[1]).ring(ring)];
|
||||
let shown =
|
||||
SwatchPair::new("Colours", wells, Bind::bound(&mut state.active)).swap_button("Swap colours").default_button("Default colours").show(ui);
|
||||
SwatchPair::new("Colours", wells, state_at.bind(&mut state.active)).swap_button("Swap colours").default_button("Default colours").show(ui);
|
||||
if shown.swap {
|
||||
state.colors.swap(0, 1);
|
||||
}
|
||||
@@ -69,13 +69,13 @@ fn swatch_pair_ring(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(SwatchPair<'static>, covers = [], drive = Drive::Never)]
|
||||
fn swatch_pair_host_picker(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
SwatchPair::new("Colours", wells(false), Bind::bound(data.value("active", Well::Primary))).popover(false).click_activates(false).show(ui).into()
|
||||
SwatchPair::new("Colours", wells(false), data.bind("active", Well::Primary)).popover(false).click_activates(false).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(SwatchPair<'static>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn swatch_pair_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let wells = [PairWell::new("Fill", Mixed::<Srgba>::Mixed), PairWell::new("Stroke", Srgba::rgb(0.1, 0.3, 0.8)).ring(true)];
|
||||
SwatchPair::new("Fill and stroke", wells, Bind::bound(data.value("active", Well::Primary))).show(ui).into()
|
||||
SwatchPair::new("Fill and stroke", wells, data.bind("active", Well::Primary)).show(ui).into()
|
||||
}
|
||||
|
||||
/// Opens the picker of the focused well with Enter.
|
||||
@@ -87,26 +87,26 @@ fn open_picker(fixture: &mut Fixture) {
|
||||
|
||||
#[story(SwatchPair<'static>, covers = [Open], drive = Drive::Custom(open_picker))]
|
||||
fn swatch_pair_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
SwatchPair::new("Colours", wells(false), Bind::bound(data.value("active", Well::Primary))).show(ui).into()
|
||||
SwatchPair::new("Colours", wells(false), data.bind("active", Well::Primary)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(SwatchPair<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn swatch_pair_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let refuse_secondary =
|
||||
|well: &Well| if *well == Well::Secondary { Validity::Refuse(Message::new("Only the foreground can be edited")) } else { Validity::Ok };
|
||||
SwatchPair::new("Colours", wells(false), Bind::bound(data.value("active", Well::Secondary)).check(refuse_secondary)).show(ui).into()
|
||||
SwatchPair::new("Colours", wells(false), data.bind("active", Well::Secondary).check(refuse_secondary)).show(ui).into()
|
||||
}
|
||||
|
||||
/// The pair in a tool rail's footer, as PhotoCraft's colour chips: the gap round the front well takes the rail's chrome.
|
||||
#[story(SwatchPair<'static>, covers = [], drive = Drive::Never)]
|
||||
fn swatch_pair_tool_rail(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let active = data.value("active", Well::Primary);
|
||||
let (active, active_at) = data.value_at("active", Well::Primary);
|
||||
let (slots, last): (Vec<ToolSlot<u8>>, LastUsed<u8>) = (Vec::new(), LastUsed::default());
|
||||
let wells = [PairWell::new("Foreground colour", Srgba::rgb(0.0, 0.0, 0.0)), PairWell::new("Background colour", Srgba::rgb(1.0, 1.0, 1.0))];
|
||||
let mut shown = None;
|
||||
ToolRail::new("Tools", &slots, &0, &last).show_rail(ui, |ui, _| {
|
||||
shown = Some(
|
||||
SwatchPair::new("Colours", wells.clone(), Bind::bound(&mut *active))
|
||||
SwatchPair::new("Colours", wells.clone(), active_at.bind(&mut *active))
|
||||
.popover(false)
|
||||
.swap_button("Swap colours")
|
||||
.default_button("Default colours")
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use super::SwatchPalette;
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::runtime::env::Label;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -30,7 +29,7 @@ fn named(entries: impl IntoIterator<Item = (String, Srgba)>) -> Vec<(Label, Srgb
|
||||
#[story(SwatchPalette<'static>, covers = [], drive = Drive::Never)]
|
||||
fn swatch_palette(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let swatches = named(PALETTE.iter().map(|(name, color)| ((*name).to_owned(), *color)));
|
||||
let shown = SwatchPalette::new("Swatches", Bind::bound(data.value("color", PALETTE[8].1)), &swatches).show(ui);
|
||||
let shown = SwatchPalette::new("Swatches", data.bind("color", PALETTE[8].1), &swatches).show(ui);
|
||||
let last = data.note("last", String::new());
|
||||
if let Some(event) = &shown.edit {
|
||||
*last = format!("{event:?}");
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use super::{ColorPanel, ColorPanelMode, ColorPanelRamp, ColorPanelState};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
@@ -10,7 +9,7 @@ use egui::Ui;
|
||||
const COLORS: [Srgba; 2] = [Srgba::rgb(0.07, 0.65, 0.58), Srgba::rgb(1.0, 1.0, 1.0)];
|
||||
|
||||
fn panel(ui: &mut Ui, data: &mut StoryData, state: ColorPanelState) -> StoryOutput {
|
||||
ColorPanel::new(Bind::bound(data.value("state", state)), COLORS).show(ui).into()
|
||||
ColorPanel::new(data.bind("state", state), COLORS).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
|
||||
@@ -114,16 +114,16 @@ fn start() -> PickedColor {
|
||||
/// The compact popup's picker: the default models and the screen-pick button.
|
||||
#[story(ColorPicker<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn color_picker_compact(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let color = data.value("color", start());
|
||||
let shown = ColorPicker::new("Foreground color", Bind::bound(color)).eyedropper(true).show(ui);
|
||||
let (color, color_at) = data.value_at("color", start());
|
||||
let shown = ColorPicker::new("Foreground color", color_at.bind(color)).eyedropper(true).show(ui);
|
||||
with_readout(data, shown)
|
||||
}
|
||||
|
||||
/// The compact picker with the opacity row.
|
||||
#[story(ColorPicker<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_picker_compact_alpha(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let color = data.value("color", start());
|
||||
let shown = ColorPicker::new("Foreground color", Bind::bound(color)).alpha(true).eyedropper(true).show(ui);
|
||||
let (color, color_at) = data.value_at("color", start());
|
||||
let shown = ColorPicker::new("Foreground color", color_at.bind(color)).alpha(true).eyedropper(true).show(ui);
|
||||
with_readout(data, shown)
|
||||
}
|
||||
|
||||
@@ -132,8 +132,8 @@ fn color_picker_compact_alpha(ui: &mut Ui, data: &mut StoryData) -> StoryOutput
|
||||
fn color_picker_web_colors(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let web = *data.value("web", true);
|
||||
let mut web = web;
|
||||
let color = data.value("color", start());
|
||||
let shown = ColorPicker::new("Foreground color", Bind::bound(color)).web_colors(Bind::bound(&mut web)).show(ui);
|
||||
let (color, color_at) = data.value_at("color", start());
|
||||
let shown = ColorPicker::new("Foreground color", color_at.bind(color)).web_colors(Bind::bound(&mut web)).show(ui);
|
||||
with_readout(data, shown)
|
||||
}
|
||||
|
||||
@@ -143,9 +143,9 @@ fn color_picker_web_colors(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn color_picker_full(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut mode = *data.value("mode", AreaMode::default());
|
||||
let current = Srgba::rgb(0.9, 0.2, 0.1);
|
||||
let color = data.value("color", PickedColor::rgb(Srgba::rgb(1.0, 0.0, 1.0)));
|
||||
let (color, color_at) = data.value_at("color", PickedColor::rgb(Srgba::rgb(1.0, 0.0, 1.0)));
|
||||
let models: [&'static dyn ColorModel; 4] = [&HsbModel, &RgbModel, &LabModel, &CMYK_MODEL];
|
||||
let shown = ColorPicker::new("Foreground color", Bind::bound(color))
|
||||
let shown = ColorPicker::new("Foreground color", color_at.bind(color))
|
||||
.layout(ColorPickerLayout::Full)
|
||||
.models(models)
|
||||
.mode(Bind::bound(&mut mode))
|
||||
@@ -162,9 +162,9 @@ fn color_picker_full(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// An InDesign-like model set: RGB in the first group; Lab, OKLCH (with its radios) and the host's CMYK in the second.
|
||||
#[story(ColorPicker<'static>, covers = [Many], drive = Drive::Never)]
|
||||
fn color_picker_full_models(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let color = data.value("color", start());
|
||||
let (color, color_at) = data.value_at("color", start());
|
||||
let models: [&'static dyn ColorModel; 4] = [&RgbModel, &LabModel, &OklchModel, &CMYK_MODEL];
|
||||
let shown = ColorPicker::new("Foreground color", Bind::bound(color)).layout(ColorPickerLayout::Full).models(models).show(ui);
|
||||
let shown = ColorPicker::new("Foreground color", color_at.bind(color)).layout(ColorPickerLayout::Full).models(models).show(ui);
|
||||
with_readout(data, shown)
|
||||
}
|
||||
|
||||
@@ -187,9 +187,9 @@ fn track_ramp(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(ChannelRow<'static>, covers = [], drive = Drive::Never)]
|
||||
fn channel_row(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("value", 40.0_f64);
|
||||
let (value, value_at) = data.value_at("value", 40.0_f64);
|
||||
let channel = HsbModel.channels()[1];
|
||||
let row = ChannelRow::new("Saturation", Bind::bound(value), ChannelRule::of(&channel))
|
||||
let row = ChannelRow::new("Saturation", value_at.bind(value), ChannelRule::of(&channel))
|
||||
.track(vec![Srgba::rgb(1.0, 1.0, 1.0), Srgba::rgb(1.0, 0.0, 0.0)]);
|
||||
match row.show(ui) {
|
||||
Some(edit) => StoryOutput::from(edit),
|
||||
|
||||
@@ -16,15 +16,15 @@ fn picked() -> PickedColor {
|
||||
|
||||
#[story(ColorPopover<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn closed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
StoryOutput::from(ColorPopover::new("Fill colour", Bind::bound(data.value("color", picked()))).show(ui))
|
||||
StoryOutput::from(ColorPopover::new("Fill colour", data.bind("color", picked())).show(ui))
|
||||
}
|
||||
|
||||
#[story(ColorPopover<'static>, covers = [], drive = Drive::Never)]
|
||||
fn open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let color = data.value("color", picked());
|
||||
let (color, color_at) = data.value_at("color", picked());
|
||||
let shown = Stack::new().show(ui, |ui, _| {
|
||||
let opener = Button::new("Stop").show(ui);
|
||||
ColorPopover::new("Stop colour", Bind::bound(&mut *color)).anchor(&opener, Bind::given(true)).show(ui)
|
||||
ColorPopover::new("Stop colour", color_at.bind(&mut *color)).anchor(&opener, Bind::given(true)).show(ui)
|
||||
});
|
||||
match shown.inner {
|
||||
Some(output) => StoryOutput::from(output),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use super::{ColorRamp, RampKind, RampPick};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::{Bind, Props as _, Show as _, Validity};
|
||||
use craft_ui::contract::{Props as _, Show as _, Validity};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -13,17 +13,17 @@ fn pick() -> RampPick {
|
||||
|
||||
#[story(ColorRamp<'static>, covers = [Default], drive = Drive::Drag(Grip::new(super::BAR)))]
|
||||
fn color_ramp(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
ColorRamp::new("Color ramp", RampKind::Spectrum, Bind::bound(data.value("pick", pick()))).kind_name("RGB Spectrum").show(ui).into()
|
||||
ColorRamp::new("Color ramp", RampKind::Spectrum, data.bind("pick", pick())).kind_name("RGB Spectrum").show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorRamp<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_ramp_grayscale(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
ColorRamp::new("Color ramp", RampKind::Grayscale, Bind::bound(data.value("pick", pick()))).kind_name("Grayscale").show(ui).into()
|
||||
ColorRamp::new("Color ramp", RampKind::Grayscale, data.bind("pick", pick())).kind_name("Grayscale").show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorRamp<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_ramp_between(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
ColorRamp::new("Color ramp", RampKind::Between, Bind::bound(data.value("pick", pick())))
|
||||
ColorRamp::new("Color ramp", RampKind::Between, data.bind("pick", pick()))
|
||||
.ends([Srgba::rgb(0.9, 0.2, 0.1), Srgba::rgb(0.1, 0.3, 0.9)])
|
||||
.kind_name("Foreground to background")
|
||||
.show(ui)
|
||||
@@ -32,20 +32,17 @@ fn color_ramp_between(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(ColorRamp<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_ramp_web_safe(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
ColorRamp::new("Color ramp", RampKind::Spectrum, Bind::bound(data.value("pick", pick()))).web_safe(true).kind_name("Web colors").show(ui).into()
|
||||
ColorRamp::new("Color ramp", RampKind::Spectrum, data.bind("pick", pick())).web_safe(true).kind_name("Web colors").show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorRamp<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
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, Bind::bound(data.value("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")]
|
||||
fn color_ramp_disabled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
ColorRamp::new("Color ramp", RampKind::Spectrum, Bind::bound(data.value("pick", pick()))).kind_name("RGB Spectrum").enabled(false).show(ui).into()
|
||||
ColorRamp::new("Color ramp", RampKind::Spectrum, data.bind("pick", pick())).kind_name("RGB Spectrum").enabled(false).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use craft_behavior::Mixed;
|
||||
use craft_theme::Rgba;
|
||||
use craft_ui::contract::{Bind, Validity};
|
||||
use craft_ui::contract::Validity;
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -11,19 +11,19 @@ use super::ColorReadout;
|
||||
|
||||
#[story(ColorReadout<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn color_readout(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let color = data.value("color", Rgba::rgb(0x33, 0x66, 0x99));
|
||||
ColorReadout::new("Color", Bind::bound(color)).show(ui).into()
|
||||
let (color, color_at) = data.value_at("color", Rgba::rgb(0x33, 0x66, 0x99));
|
||||
ColorReadout::new("Color", color_at.bind(color)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorReadout<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_readout_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let color = data.value("mixed", Mixed::<Rgba>::Mixed);
|
||||
ColorReadout::new("Color", Bind::bound_mixed(color)).show(ui).into()
|
||||
let (color, color_at) = data.value_at("mixed", Mixed::<Rgba>::Mixed);
|
||||
ColorReadout::new("Color", color_at.bind_mixed(color)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorReadout<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn color_readout_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let refuse_dark = |color: &Rgba| if color.0[2] < 0x80 { Validity::Refuse(Message::new("Too dark")) } else { Validity::Ok };
|
||||
let color = data.value("dark", Rgba::rgb(0x33, 0x33, 0x33));
|
||||
ColorReadout::new("Color", Bind::bound(color).check(refuse_dark)).show(ui).into()
|
||||
let (color, color_at) = data.value_at("dark", Rgba::rgb(0x33, 0x33, 0x33));
|
||||
ColorReadout::new("Color", color_at.bind(color).check(refuse_dark)).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -97,9 +97,8 @@ fn sample_points_carrying_a_new_point(ui: &mut Ui, _: &mut StoryData) -> StoryOu
|
||||
|
||||
#[story(SamplerOptions<'static>, covers = [], drive = Drive::Never)]
|
||||
fn options(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let size = data.value("size", crate::ui::SampleSize::Point);
|
||||
let shown =
|
||||
Bar::new("Color sampler options", BarKind::Options).show(ui, |ui, _| SamplerOptions::new(3, craft_ui::contract::Bind::bound(size)).show(ui));
|
||||
let (size, size_at) = data.value_at("size", crate::ui::SampleSize::Point);
|
||||
let shown = Bar::new("Color sampler options", BarKind::Options).show(ui, |ui, _| SamplerOptions::new(3, size_at.bind(size)).show(ui));
|
||||
match shown.inner {
|
||||
Some(output) => StoryOutput::from(output),
|
||||
None => StoryOutput::from(shown.output),
|
||||
|
||||
@@ -3,33 +3,33 @@
|
||||
use super::ColorStrip;
|
||||
use crate::AreaMode;
|
||||
use craft_theme::{ColorModel, HsbModel, Srgba};
|
||||
use craft_ui::contract::{Bind, Props as _, Show as _, Validity};
|
||||
use craft_ui::contract::{Props as _, Show as _, Validity};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
#[story(ColorStrip<'static>, covers = [Default], drive = Drive::Step)]
|
||||
fn color_strip(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorStrip::new("Hue", AreaMode::Hue, Bind::bound(values)).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorStrip::new("Hue", AreaMode::Hue, values_at.bind(values)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorStrip<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_strip_web_safe(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.6, 0.8)));
|
||||
ColorStrip::new("Hue", AreaMode::Hue, Bind::bound(values)).quantize(6).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.6, 0.8)));
|
||||
ColorStrip::new("Hue", AreaMode::Hue, values_at.bind(values)).quantize(6).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorStrip<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn color_strip_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let refuse_dim =
|
||||
|values: &craft_theme::ModelValues| if values.values[2] < 50.0 { Validity::Refuse(Message::new("Too dim")) } else { Validity::Ok };
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.1, 0.2, 0.3)));
|
||||
ColorStrip::new("Hue", AreaMode::Hue, Bind::bound(values).check(refuse_dim)).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.1, 0.2, 0.3)));
|
||||
ColorStrip::new("Hue", AreaMode::Hue, values_at.bind(values).check(refuse_dim)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorStrip<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_strip_disabled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorStrip::new("Hue", AreaMode::Hue, Bind::bound(values)).enabled(false).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorStrip::new("Hue", AreaMode::Hue, values_at.bind(values)).enabled(false).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
//! Stories of `SwatchesPanel`.
|
||||
|
||||
use super::{SwatchLibrary, SwatchesPanel, SwatchesState};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
/// The panel over a library and state kept in the story's data; the reported edits run on the library, so the story stays
|
||||
/// interactive.
|
||||
fn interactive(ui: &mut Ui, data: &mut StoryData, name: &'static str, start: SwatchLibrary) -> StoryOutput {
|
||||
let (library, state) = data.value(name, (start, SwatchesState::default()));
|
||||
let out = SwatchesPanel::new(&library.groups, Bind::bound(state), craft_theme::Srgba::rgb(0.2, 0.4, 0.6)).show(ui);
|
||||
let ((library, state), library_state_at) = data.value_at(name, (start, SwatchesState::default()));
|
||||
let out = SwatchesPanel::new(&library.groups, library_state_at.bind(state), craft_theme::Srgba::rgb(0.2, 0.4, 0.6)).show(ui);
|
||||
for edit in &out.edits {
|
||||
library.apply(edit);
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@
|
||||
|
||||
use super::ColorWheel;
|
||||
use craft_theme::{ColorModel, HsbModel, Srgba};
|
||||
use craft_ui::contract::{Bind, Props as _, Show as _, Validity};
|
||||
use craft_ui::contract::{Props as _, Show as _, Validity};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
#[story(ColorWheel<'static>, covers = [Default], drive = Drive::Drag(Grip::new(super::RING)))]
|
||||
fn color_wheel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
let shown = ColorWheel::new("Color wheel", Bind::bound(values)).show(ui);
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
let shown = ColorWheel::new("Color wheel", values_at.bind(values)).show(ui);
|
||||
let last = data.note("last", String::new());
|
||||
if let Some(event) = shown.events.last() {
|
||||
*last = format!("{event:?}");
|
||||
@@ -23,12 +23,12 @@ fn color_wheel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn color_wheel_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let refuse_dim =
|
||||
|values: &craft_theme::ModelValues| if values.values[2] < 50.0 { Validity::Refuse(Message::new("Too dim")) } else { Validity::Ok };
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.1, 0.2, 0.3)));
|
||||
ColorWheel::new("Color wheel", Bind::bound(values).check(refuse_dim)).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.1, 0.2, 0.3)));
|
||||
ColorWheel::new("Color wheel", values_at.bind(values).check(refuse_dim)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ColorWheel<'static>, covers = [], drive = Drive::Never, title = "Disabled")]
|
||||
fn color_wheel_disabled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorWheel::new("Color wheel", Bind::bound(values)).enabled(false).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.2, 0.5, 0.8)));
|
||||
ColorWheel::new("Color wheel", values_at.bind(values)).enabled(false).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ fn the_wheel_geometry_round_trips() {
|
||||
}
|
||||
|
||||
fn web_safe_area(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", HsbModel.from_srgb(Srgba::rgb(0.4, 0.6, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, Bind::bound(values)).quantize(6).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", HsbModel.from_srgb(Srgba::rgb(0.4, 0.6, 0.8)));
|
||||
ColorArea::new("Saturation and brightness", AreaMode::Hue, values_at.bind(values)).quantize(6).show(ui).into()
|
||||
}
|
||||
|
||||
/// A key on a quantising area steps by the channel's step and goes on until the colour is a different one, so each
|
||||
|
||||
@@ -141,11 +141,22 @@ const NO_GLOBAL_STATE_PREFIXES: &[&str] = &[
|
||||
/// a `static` or `thread_local!` item or [`FS`] for `std::fs`. Each group names the settled fact or environment key that
|
||||
/// covers it, or the later task of craft-libs#2336 that removes the state. A new item in these files is flagged.
|
||||
const NO_GLOBAL_STATE: &[(&str, &str)] = &[
|
||||
// The trait's home crate: it implements `MemoProps` by hand for std and framework value types.
|
||||
// The trait's home crate: it implements `MemoProps` by hand for std and framework value types, and for the
|
||||
// framework's own keys the derive cannot write: a binding by its source's address, its check and the check's `fn`
|
||||
// (values.rs), an icon's glyph by the type of its `dyn Glyph` (icon.rs), and the write-only `Outbox` (memo_view.rs).
|
||||
("crates/ui-contract/src/contract/memo.rs", "MemoProps"),
|
||||
// Settled fact: `ModalRules` holds a closure the derive cannot take; it keys on its plain fields and the revision
|
||||
// the app moves with every rule change, which stands for the closure.
|
||||
("crates/menu/src/modal.rs", "MemoProps"),
|
||||
("crates/ui-contract/src/contract/values.rs", "MemoProps"),
|
||||
("crates/ui-contract/src/contract/memo_view.rs", "MemoProps"),
|
||||
("crates/ui-contract/src/primitives/icon.rs", "MemoProps"),
|
||||
// Settled fact: a card's view of a story's state keys by the story value's revision, whether the start is taken, the
|
||||
// dialog's flags and the reset count; the view of every shown story's state is one fixed-size digest of those keys.
|
||||
// Both are props held as `&mut`, which the derive does not take.
|
||||
("crates/ui-gallery/src/viewer/picks.rs", "MemoProps"),
|
||||
// Settled fact: the names of a preset group key by a walk over the group and its folders (`dyn EachName`), which
|
||||
// the derive cannot see through.
|
||||
("crates/ui-patterns/src/patterns/presets/model/library.rs", "MemoProps"),
|
||||
// Settled fact: a name check keys by its inputs and its `fn` behind `dyn NameChecker`, as `Bind::check_with` does.
|
||||
("crates/ui-patterns/src/patterns/presets/named.rs", "MemoProps"),
|
||||
// Settled fact: constant font bytes, decompressed once from compile-time input and immutable after init.
|
||||
("crates/ui-contract/src/fonts/defaults.rs", "HACK"),
|
||||
("crates/ui-contract/src/fonts/defaults.rs", "EGUI_ICONS"),
|
||||
|
||||
@@ -72,10 +72,10 @@ impl<'a> PathField<'a> {
|
||||
let before = held.read(cx).unwrap_or_default();
|
||||
let looks = must_exist && cx.env.shell().caps.contains(Caps::FILE_SYSTEM);
|
||||
let not_found = words.not_found.clone();
|
||||
let check = move |path: &String| {
|
||||
if looks && path_is_missing(path) { Validity::Warn(Message::new(not_found.clone())) } else { Validity::Ok }
|
||||
};
|
||||
let row = PathRow::new(label.clone(), Bind::given(before.clone()).check(check)).pick(request.clone()).show(ui);
|
||||
let value = Bind::given(before.clone()).check_with((looks, not_found), |(looks, not_found), path| {
|
||||
if *looks && path_is_missing(path) { Validity::Warn(Message::new(not_found.clone())) } else { Validity::Ok }
|
||||
});
|
||||
let row = PathRow::new(label.clone(), value).pick(request.clone()).show(ui);
|
||||
browsing = row.browsing;
|
||||
let answered = row.picked;
|
||||
let typed = row
|
||||
|
||||
@@ -5,27 +5,23 @@ use std::sync::Arc;
|
||||
use super::{FileChooser, PathField};
|
||||
use craft_browse::places::{FakeDirectories, FolderCache, StandardFolder};
|
||||
use craft_host::{ManualJobs, PickRequest, Wake};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::dialog::stories::hosted_with;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
#[story(PathField<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn path_field_empty(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
PathField::new("Save to", Bind::bound(data.value("empty", String::new())), PickRequest::save("export")).show(ui).into()
|
||||
PathField::new("Save to", data.bind("empty", String::new()), PickRequest::save("export")).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(PathField<'static>, covers = [], drive = Drive::Never)]
|
||||
fn path_field_filled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
PathField::new("Save to", Bind::bound(data.value("filled", "/photos/trip/sunrise.png".to_owned())), PickRequest::save("export")).show(ui).into()
|
||||
PathField::new("Save to", data.bind("filled", "/photos/trip/sunrise.png".to_owned()), PickRequest::save("export")).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(PathField<'static>, covers = [], drive = Drive::Never)]
|
||||
fn path_field_missing_file(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
PathField::new("Open", Bind::bound(data.value("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()
|
||||
}
|
||||
|
||||
/// The folders the chooser stories browse: a home with documents, pictures, a hidden folder and an empty folder.
|
||||
|
||||
@@ -32,6 +32,7 @@ const HEART_POINTS: usize = 32;
|
||||
|
||||
/// One entry of the shape menu.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "ui", derive(craft_ui::contract::MemoProps))]
|
||||
#[non_exhaustive]
|
||||
pub enum ShapePreset {
|
||||
/// A rectangle.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! Stories of the Brush Preset picker.
|
||||
|
||||
use craft_behavior::Mixed;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::patterns::presets::PresetRow;
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::testing::pictures::{SampleTip, paint_tip, paint_wave};
|
||||
@@ -39,10 +38,10 @@ fn rows(env: &Env, parts: BrushCardParts) -> Vec<PresetRow<u32>> {
|
||||
#[story(BrushPresetPicker<'static, u32>, covers = [Default], drive = Drive::Never)]
|
||||
fn picker(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let env = Env::of(ui);
|
||||
let (current, state) = data.value("brush", (Some(SOFT), BrushPickerState::<u32>::new()));
|
||||
let ((current, state), brush_at) = data.value_at("brush", (Some(SOFT), BrushPickerState::<u32>::new()));
|
||||
let rows = rows(&env, state.parts);
|
||||
let values = BrushPickerValues::new(SOFT_SIZE, Some(0.8));
|
||||
BrushPresetPicker::new("Brush Preset picker", Bind::bound(current), &rows, Bind::bound(state), values)
|
||||
BrushPresetPicker::new("Brush Preset picker", brush_at.bind(current), &rows, brush_at.bind(state), values)
|
||||
.max_diameter(MAX_SIZE)
|
||||
.import()
|
||||
.show(ui)
|
||||
@@ -55,13 +54,13 @@ fn picker(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn picker_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let env = Env::of(ui);
|
||||
let at = ui.max_rect().min;
|
||||
let (current, state, open) = data.value("open", (Some(SOFT), BrushPickerState::<u32>::new(), true));
|
||||
let ((current, state, open), open_at2) = data.value_at("open", (Some(SOFT), BrushPickerState::<u32>::new(), true));
|
||||
let rows = rows(&env, state.parts);
|
||||
let values = BrushPickerValues::new(SOFT_SIZE, Some(0.8)).with_tip(TipAngle::new(30.0, 0.6));
|
||||
BrushPresetPicker::new("Brush Preset picker", Bind::bound(current), &rows, Bind::bound(state), values)
|
||||
BrushPresetPicker::new("Brush Preset picker", open_at2.bind(current), &rows, open_at2.bind(state), values)
|
||||
.max_diameter(MAX_SIZE)
|
||||
.import()
|
||||
.open_at(at, Bind::bound(open))
|
||||
.open_at(at, open_at2.bind(open))
|
||||
.show(ui)
|
||||
.into()
|
||||
}
|
||||
@@ -69,34 +68,34 @@ fn picker_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(BrushesPanel<'static, u32>, covers = [Default], drive = Drive::Never)]
|
||||
fn panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let env = Env::of(ui);
|
||||
let (state, diameter) = data.value("panel", (PresetState::<u32>::new(), SOFT_SIZE));
|
||||
let ((state, diameter), panel_at) = data.value_at("panel", (PresetState::<u32>::new(), SOFT_SIZE));
|
||||
let rows = rows(&env, BrushCardParts::ALL);
|
||||
BrushesPanel::new("Brushes", &rows, Bind::bound(state), Bind::bound(diameter), MAX_SIZE).selected(SOFT).import(true).show(ui).into()
|
||||
BrushesPanel::new("Brushes", &rows, panel_at.bind(state), panel_at.bind(diameter), MAX_SIZE).selected(SOFT).import(true).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(BrushPresetPicker<'static, u32>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn picker_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let env = Env::of(ui);
|
||||
let (current, state) = data.value("mixed", (Mixed::<Option<u32>>::Mixed, BrushPickerState::<u32>::new()));
|
||||
let ((current, state), mixed_at) = data.value_at("mixed", (Mixed::<Option<u32>>::Mixed, BrushPickerState::<u32>::new()));
|
||||
let rows = rows(&env, state.parts);
|
||||
let values = BrushPickerValues::new(HARD_SIZE, None);
|
||||
BrushPresetPicker::new("Brush Preset picker", Bind::bound_mixed(current), &rows, Bind::bound(state), values).show(ui).into()
|
||||
BrushPresetPicker::new("Brush Preset picker", mixed_at.bind_mixed(current), &rows, mixed_at.bind(state), values).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(BrushPresetPicker<'static, u32>, covers = [], drive = Drive::Never)]
|
||||
fn picker_sampled(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let env = Env::of(ui);
|
||||
let (current, state) = data.value("sampled", (Some(HARD), BrushPickerState::<u32>::new()));
|
||||
let ((current, state), sampled_at) = data.value_at("sampled", (Some(HARD), BrushPickerState::<u32>::new()));
|
||||
let rows = rows(&env, state.parts);
|
||||
BrushPresetPicker::new("Brush Preset picker", Bind::bound(current), &rows, Bind::bound(state), BrushPickerValues::new(HARD_SIZE, None))
|
||||
BrushPresetPicker::new("Brush Preset picker", sampled_at.bind(current), &rows, sampled_at.bind(state), BrushPickerValues::new(HARD_SIZE, None))
|
||||
.show(ui)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[story(BrushPresetPicker<'static, u32>, covers = [], drive = Drive::Never)]
|
||||
fn picker_empty(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let (current, state) = data.value("empty", (None::<u32>, BrushPickerState::<u32>::new()));
|
||||
BrushPresetPicker::new("Brush Preset picker", Bind::bound(current), &[], Bind::bound(state), BrushPickerValues::new(SOFT_SIZE, Some(1.0)))
|
||||
let ((current, state), empty_at) = data.value_at("empty", (None::<u32>, BrushPickerState::<u32>::new()));
|
||||
BrushPresetPicker::new("Brush Preset picker", empty_at.bind(current), &[], empty_at.bind(state), BrushPickerValues::new(SOFT_SIZE, Some(1.0)))
|
||||
.show(ui)
|
||||
.into()
|
||||
}
|
||||
|
||||
@@ -223,8 +223,8 @@ fn panel_off(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(BrushSectionList<'static, u8>, covers = [Default], drive = Drive::Never)]
|
||||
fn section_list(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let brush = data.value("brush", Brush::new(true));
|
||||
let output = BrushSectionList::new("Brush settings sections", &brush.sections, Bind::bound(&mut brush.shown)).link_row().show(ui);
|
||||
let (brush, brush_at) = data.value_at("brush", Brush::new(true));
|
||||
let output = BrushSectionList::new("Brush settings sections", &brush.sections, brush_at.bind(&mut brush.shown)).link_row().show(ui);
|
||||
let events = output.events.clone();
|
||||
let facts = StoryOutput::from(output);
|
||||
for event in events {
|
||||
@@ -240,20 +240,20 @@ fn angle_note(angle: TipAngle) -> String {
|
||||
|
||||
#[story(TipEllipse<'static>, covers = [Default], drive = Drive::Drag(Grip::new(super::ellipse::ARROW)))]
|
||||
fn tip_ellipse(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let shown = TipEllipse::new("Tip angle and roundness", Bind::bound(data.value("angle", ANGLE))).show(ui);
|
||||
let shown = TipEllipse::new("Tip angle and roundness", data.bind("angle", ANGLE)).show(ui);
|
||||
let note = angle_note(*data.value("angle", ANGLE));
|
||||
StoryOutput::from(shown).readout(note)
|
||||
}
|
||||
|
||||
#[story(TipEllipse<'static>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn tip_ellipse_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
TipEllipse::new("Tip angle and roundness", Bind::bound_mixed(data.value("mixed", Mixed::<TipAngle>::Mixed))).show(ui).into()
|
||||
TipEllipse::new("Tip angle and roundness", data.bind_mixed("mixed", Mixed::<TipAngle>::Mixed)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(TipEllipse<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn tip_ellipse_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let refuse_flat = |angle: &TipAngle| if angle.roundness < 0.5 { Validity::Refuse(Message::new("Too flat")) } else { Validity::Ok };
|
||||
let shown = TipEllipse::new("Tip angle and roundness", Bind::bound(data.value("flat", ANGLE)).check(refuse_flat)).show(ui);
|
||||
let shown = TipEllipse::new("Tip angle and roundness", data.bind("flat", ANGLE).check(refuse_flat)).show(ui);
|
||||
let note = angle_note(*data.value("flat", ANGLE));
|
||||
StoryOutput::from(shown).readout(note)
|
||||
}
|
||||
@@ -263,12 +263,12 @@ fn tip_ellipse_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn dynamic_control_row(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let words = Env::of(ui).words::<BrushSettingsStoryWords>();
|
||||
let controls = controls();
|
||||
let (rows, size) = data.value("rows", ((ControlRow::new(Control::Fade), ControlRow::new(Control::PenPressure)), SIZE));
|
||||
let ((rows, size), rows_at) = data.value_at("rows", ((ControlRow::new(Control::Fade), ControlRow::new(Control::PenPressure)), SIZE));
|
||||
let (fade, curve) = rows;
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
fade.show(ui, &controls);
|
||||
curve.show(ui, &controls);
|
||||
let _ = BrushSizeField::new("Size", Bind::bound(&mut *size), MAX_SIZE).restore(ORIGINAL).show(ui);
|
||||
let _ = BrushSizeField::new("Size", rows_at.bind(&mut *size), MAX_SIZE).restore(ORIGINAL).show(ui);
|
||||
});
|
||||
let output = StoryOutput::default();
|
||||
if curve.curve_open { output.readout(words.curve_open.as_str().to_owned()) } else { output }
|
||||
@@ -281,5 +281,5 @@ fn stroke_strip(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(BrushSizeField<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn size_field(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
BrushSizeField::new("Size", Bind::bound(data.value("size", SIZE)), MAX_SIZE).restore(ORIGINAL).show(ui).into()
|
||||
BrushSizeField::new("Size", data.bind("size", SIZE), MAX_SIZE).restore(ORIGINAL).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ fn on_canvas<R: Into<StoryOutput>>(ui: &mut Ui, targets: &[ConnectionTarget], mu
|
||||
#[story(ConnectorHandles<'static>, covers = [Default], drive = Drive::Drag(Grip::part(super::handles::END.at(0)).toward(vec2(0.0, 1.0))))]
|
||||
fn connector_glued_at_both_ends(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let targets = targets();
|
||||
let item = data.value(
|
||||
let (item, item_at) = data.value_at(
|
||||
"item",
|
||||
ConnectorItem {
|
||||
id: 9,
|
||||
@@ -81,7 +81,7 @@ fn connector_glued_at_both_ends(ui: &mut Ui, data: &mut StoryData) -> StoryOutpu
|
||||
path: None,
|
||||
},
|
||||
);
|
||||
on_canvas(ui, &targets, |ui, at| ConnectorHandles::new("Connector", Bind::bound(&mut *item), &targets).show_at(ui, at))
|
||||
on_canvas(ui, &targets, |ui, at| ConnectorHandles::new("Connector", item_at.bind(&mut *item), &targets).show_at(ui, at))
|
||||
}
|
||||
|
||||
/// The arrowhead previews of the cap choices, at the line's start or end.
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::hash::{DefaultHasher, Hash as _, Hasher as _};
|
||||
use crate::geometry::fillet::fillet;
|
||||
use craft_behavior::kurbo::{BezPath, Point, Vec2};
|
||||
use craft_ui::canvas::RasterSource as _;
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::testing::canvas_story::{OUTLINE, StoryDocument, StoryPicture, StoryShape, accent, on_picture, paint_shapes};
|
||||
use craft_ui::testing::{Drive, EditKind, Grip, StoryData, StoryOutput, story};
|
||||
@@ -144,12 +144,12 @@ fn edit(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let hide_above = *data.ranged("hide above", 177.0, 90.0..=180.0);
|
||||
let individual = *data.value("individual", true);
|
||||
let mut last = data.note::<Option<String>>("last", None).clone();
|
||||
let targets = data.value("targets", edited(individual));
|
||||
let (targets, targets_at) = data.value_at("targets", edited(individual));
|
||||
if let Some(path) = targets.iter_mut().find(|target| target.key == 3) {
|
||||
path.individual = individual;
|
||||
}
|
||||
let output = on_canvas(ui, targets, |ui, at, targets| {
|
||||
let shown = CornerWidgets::new("Corner radius", Bind::bound(&mut *targets)).kinds(kinds).hide_above(hide_above).show_at(ui, at);
|
||||
let shown = CornerWidgets::new("Corner radius", targets_at.bind(&mut *targets)).kinds(kinds).hide_above(hide_above).show_at(ui, at);
|
||||
let kind = shown.edit.events.iter().filter_map(EditKind::of).next_back().and_then(|kind| match kind {
|
||||
EditKind::Begin => Some(&words.began),
|
||||
EditKind::Update => Some(&words.updated),
|
||||
@@ -181,6 +181,8 @@ fn edit(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(CornerWidgets<'static>, covers = [], drive = Drive::Never)]
|
||||
fn cycling_kinds_and_a_wide_angle_limit(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let targets = data.value("kinds", targets());
|
||||
on_canvas(ui, targets, |ui, at, targets| CornerWidgets::new("Corner radius", Bind::bound(targets)).kinds(true).hide_above(120.0).show_at(ui, at))
|
||||
let (targets, targets_at) = data.value_at("kinds", targets());
|
||||
on_canvas(ui, targets, |ui, at, targets| {
|
||||
CornerWidgets::new("Corner radius", targets_at.bind(targets)).kinds(true).hide_above(120.0).show_at(ui, at)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::super::options::{CropLength, CropSizeFields};
|
||||
use super::super::session::{CropDocKey, CropDocument};
|
||||
use super::PerspectiveCropBar;
|
||||
use craft_ui::bars::{Bar, BarKind};
|
||||
use craft_ui::contract::{Bind, ShowContainer as _};
|
||||
use craft_ui::contract::ShowContainer as _;
|
||||
use craft_ui::runtime::env::UnitKind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -19,10 +19,10 @@ fn perspective_crop_bar(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
resolution: "300".into(),
|
||||
..CropSizeFields::default()
|
||||
};
|
||||
let (size, grid) = data.value("bar", (fields, true));
|
||||
let ((size, grid), bar_at) = data.value_at("bar", (fields, true));
|
||||
let mut output = None;
|
||||
Bar::new("Options", BarKind::Options).show(ui, |ui, _| {
|
||||
output = Some(PerspectiveCropBar::new(&mut *size, &document, Bind::bound(&mut *grid)).show(ui));
|
||||
output = Some(PerspectiveCropBar::new(&mut *size, &document, bar_at.bind(&mut *grid)).show(ui));
|
||||
});
|
||||
output.map(StoryOutput::from).unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::{CORNER, PerspectiveCropQuad, PerspectiveQuad};
|
||||
use craft_behavior::CanvasView;
|
||||
use craft_behavior::kurbo::{BezPath, Point};
|
||||
use craft_ui::canvas::{CropShield, RasterSource as _};
|
||||
use craft_ui::contract::{Bind, Show as _, Validity};
|
||||
use craft_ui::contract::{Show as _, Validity};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::canvas_story::{OUTLINE, StoryDocument, StoryPicture, StoryShape, on_picture, paint_shapes};
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryHost, StoryOutput, ToolStory, story, tool_story};
|
||||
@@ -38,15 +38,17 @@ fn on_canvas<R: Into<StoryOutput>>(ui: &mut Ui, mut quad: impl FnMut(&mut Ui, eg
|
||||
|
||||
#[story(PerspectiveCropQuad<'static>, covers = [Default], drive = Drive::Drag(Grip::part(CORNER.at(0))))]
|
||||
fn skewed_page(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let quad = data.value("quad", Some(PAGE));
|
||||
on_canvas(ui, |ui, at| PerspectiveCropQuad::new("Perspective crop", Bind::bound(&mut *quad)).shield(CropShield::PERSPECTIVE).show_at(ui, at).edit)
|
||||
let (quad, quad_at) = data.value_at("quad", Some(PAGE));
|
||||
on_canvas(ui, |ui, at| {
|
||||
PerspectiveCropQuad::new("Perspective crop", quad_at.bind(&mut *quad)).shield(CropShield::PERSPECTIVE).show_at(ui, at).edit
|
||||
})
|
||||
}
|
||||
|
||||
#[story(PerspectiveCropQuad<'static>, covers = [Invalid], drive = Drive::Drag(Grip::part(CORNER.at(0))))]
|
||||
fn bent_page(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let quad = data.value("quad", Some(BENT));
|
||||
let (quad, quad_at) = data.value_at("quad", Some(BENT));
|
||||
on_canvas(ui, |ui, at| {
|
||||
let bind = Bind::bound(&mut *quad).check(|quad: &PerspectiveQuad| match quad {
|
||||
let bind = quad_at.bind(&mut *quad).check(|quad: &PerspectiveQuad| match quad {
|
||||
Some(quad) if !super::is_valid(quad) => Validity::Refuse(Message::new("The corners do not make a convex quad")),
|
||||
_ => Validity::Ok,
|
||||
});
|
||||
|
||||
@@ -83,25 +83,27 @@ fn gradient_overlay(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(GradientOverlay<'static>, covers = [Default], drive = Drive::Drag(Grip::new(END).toward(vec2(0.0, 1.0))))]
|
||||
fn gradient_overlay_extent(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("gradient", gradient());
|
||||
let (value, value_at) = data.value_at("gradient", gradient());
|
||||
let picture = ramp(value, true);
|
||||
on_canvas(ui, &picture, |ui, at| {
|
||||
GradientOverlay::new("Gradient", Bind::bound(&mut *value)).style(GradientStyle::Radial).reverse().show_at(ui, at).edit
|
||||
GradientOverlay::new("Gradient", value_at.bind(&mut *value)).style(GradientStyle::Radial).reverse().show_at(ui, at).edit
|
||||
})
|
||||
}
|
||||
|
||||
#[story(GradientOverlay<'static>, covers = [Default], drive = Drive::Drag(Grip::new(END).toward(vec2(0.0, 1.0))))]
|
||||
fn gradient_overlay_mirror(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("gradient", gradient());
|
||||
let (value, value_at) = data.value_at("gradient", gradient());
|
||||
let picture = ramp(value, false);
|
||||
on_canvas(ui, &picture, |ui, at| GradientOverlay::new("Gradient", Bind::bound(&mut *value)).style(GradientStyle::Reflected).show_at(ui, at).edit)
|
||||
on_canvas(ui, &picture, |ui, at| {
|
||||
GradientOverlay::new("Gradient", value_at.bind(&mut *value)).style(GradientStyle::Reflected).show_at(ui, at).edit
|
||||
})
|
||||
}
|
||||
|
||||
#[story(GradientOverlay<'static>, covers = [Default], drive = Drive::Drag(Grip::new(END).toward(vec2(0.0, 1.0))))]
|
||||
fn gradient_overlay_diamond(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("gradient", gradient());
|
||||
let (value, value_at) = data.value_at("gradient", gradient());
|
||||
let picture = ramp(value, false);
|
||||
on_canvas(ui, &picture, |ui, at| GradientOverlay::new("Gradient", Bind::bound(&mut *value)).style(GradientStyle::Diamond).show_at(ui, at).edit)
|
||||
on_canvas(ui, &picture, |ui, at| GradientOverlay::new("Gradient", value_at.bind(&mut *value)).style(GradientStyle::Diamond).show_at(ui, at).edit)
|
||||
}
|
||||
|
||||
#[story(GradientOverlay<'static>, covers = [Default], drive = Drive::Drag(Grip::new(END).toward(vec2(0.0, 1.0))))]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! Stories of the gradient palette.
|
||||
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::patterns::presets::{PresetState, PresetView};
|
||||
use craft_ui::testing::{StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -31,8 +30,8 @@ fn palette(ui: &mut Ui, data: &mut StoryData, view: PresetView) -> StoryOutput {
|
||||
let recent = [pair([0.2, 0.8, 0.4], [0.1, 0.2, 0.6])];
|
||||
let mut initial = PresetState::new();
|
||||
initial.view = view;
|
||||
let state = data.value("state", initial);
|
||||
let shown = GradientPalette::new("Gradients", &groups, Bind::bound(&mut *state))
|
||||
let (state, state_at) = data.value_at("state", initial);
|
||||
let shown = GradientPalette::new("Gradients", &groups, state_at.bind(&mut *state))
|
||||
.recent(&recent)
|
||||
.selected(GradientRef::Item { group: 0, item: 1 })
|
||||
.show(ui);
|
||||
@@ -62,8 +61,8 @@ fn gradient_palette_tiles(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
items.push(GradientItem::new("Focus, rectangle", stops.clone()).tile(GradientTile::Focus { outline: FocusOutline::Rect, focus }));
|
||||
items.push(GradientItem::new("Ramp", stops));
|
||||
let groups = [GradientGroup::new("Tiles", items)];
|
||||
let state = data.value("state", PresetState::<GradientRef>::new());
|
||||
let shown = GradientPalette::new("Gradient tiles", &groups, Bind::bound(&mut *state)).show(ui);
|
||||
let (state, state_at) = data.value_at("state", PresetState::<GradientRef>::new());
|
||||
let shown = GradientPalette::new("Gradient tiles", &groups, state_at.bind(&mut *state)).show(ui);
|
||||
StoryOutput::from(shown)
|
||||
}
|
||||
|
||||
|
||||
@@ -62,16 +62,16 @@ fn ruler_overlay_with_a_protractor_arm(ui: &mut Ui, data: &mut StoryData) -> Sto
|
||||
|
||||
#[story(RulerBar<'static>, covers = [], drive = Drive::Never)]
|
||||
fn ruler_bar_with_a_line(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let use_scale = data.value("scale", false);
|
||||
let (use_scale, use_scale_at) = data.value_at("scale", false);
|
||||
let mut output = None;
|
||||
Bar::new("Options", BarKind::Options).show(ui, |ui, _| output = Some(RulerBar::new(Some(line()), Bind::bound(&mut *use_scale)).show(ui)));
|
||||
Bar::new("Options", BarKind::Options).show(ui, |ui, _| output = Some(RulerBar::new(Some(line()), use_scale_at.bind(&mut *use_scale)).show(ui)));
|
||||
output.map(StoryOutput::from).unwrap_or_default()
|
||||
}
|
||||
|
||||
#[story(RulerBar<'static>, covers = [], drive = Drive::Never)]
|
||||
fn ruler_bar_without_a_line(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let use_scale = data.value("none", false);
|
||||
let (use_scale, use_scale_at) = data.value_at("none", false);
|
||||
let mut output = None;
|
||||
Bar::new("Options", BarKind::Options).show(ui, |ui, _| output = Some(RulerBar::new(None, Bind::bound(&mut *use_scale)).show(ui)));
|
||||
Bar::new("Options", BarKind::Options).show(ui, |ui, _| output = Some(RulerBar::new(None, use_scale_at.bind(&mut *use_scale)).show(ui)));
|
||||
output.map(StoryOutput::from).unwrap_or_default()
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ fn tile(cx: &ContentPainterCx<'_>, rect: Rect, _: &PatternSwatch) {
|
||||
}
|
||||
|
||||
fn editor(ui: &mut Ui, data: &mut StoryData, start: PatternFillOptions, library: &[PatternSwatch]) -> StoryOutput {
|
||||
let options = data.value("options", start);
|
||||
let out = PatternFillEditor::new("Pattern fill", Bind::bound(options), library).thumbnails(tile).show(ui);
|
||||
let (options, options_at) = data.value_at("options", start);
|
||||
let out = PatternFillEditor::new("Pattern fill", options_at.bind(options), library).thumbnails(tile).show(ui);
|
||||
StoryOutput::from(out)
|
||||
}
|
||||
|
||||
@@ -38,13 +38,10 @@ fn pattern_fill_preset(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(PatternFillEditor<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn pattern_fill_dialog(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let library = swatches();
|
||||
let mut options = data.value("options", PatternFillOptions::bitmap("bubbles")).clone();
|
||||
let mut open = *data.value("open", true);
|
||||
FormDialog::new("Pattern Fill", Bind::bound(&mut options)).opened(Bind::bound(&mut open)).show(ui, |ui, _, value| {
|
||||
let ((options, options_at), (open, open_at)) = data.pair_at(("options", PatternFillOptions::bitmap("bubbles")), ("open", true));
|
||||
FormDialog::new("Pattern Fill", options_at.bind(options)).opened(open_at.bind(open)).show(ui, |ui, _, value| {
|
||||
PatternFillEditor::new("Pattern fill", Bind::bound(value), &library).thumbnails(tile).show(ui);
|
||||
true
|
||||
});
|
||||
*data.value("options", PatternFillOptions::bitmap("bubbles")) = options;
|
||||
*data.value("open", true) = open;
|
||||
StoryOutput::default()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::{
|
||||
};
|
||||
use craft_behavior::kurbo::Point;
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, story};
|
||||
use egui::{Ui, Vec2};
|
||||
|
||||
@@ -30,52 +30,54 @@ fn selected() -> PathSelection {
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [Default], drive = Drive::Drag(Grip::part(ANCHOR.at(index(0, KnotRef { subpath: 0, knot: 0 }))).toward(Vec2::X)))]
|
||||
fn direct_selection_with_a_selected_anchor(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", Bind::bound(&mut *paths), &selected()).show_at(ui, at))
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &selected()).show_at(ui, at))
|
||||
}
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [Default], drive = Drive::Drag(Grip::part(ANCHOR.at(index(0, KnotRef { subpath: 0, knot: 0 }))).toward(Vec2::X)))]
|
||||
fn all_handles_shown(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| {
|
||||
BezierOverlay::new("Paths", Bind::bound(&mut *paths), &PathSelection::default()).handles(HandlesShown::All).show_at(ui, at)
|
||||
BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &PathSelection::default()).handles(HandlesShown::All).show_at(ui, at)
|
||||
})
|
||||
}
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [Default], drive = Drive::Drag(Grip::part(ANCHOR.at(index(0, KnotRef { subpath: 0, knot: 0 }))).toward(Vec2::X)))]
|
||||
fn curvature_tool(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", Bind::bound(&mut *paths), &selected()).tool(BezierTool::Curvature).show_at(ui, at))
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &selected()).tool(BezierTool::Curvature).show_at(ui, at))
|
||||
}
|
||||
|
||||
/// Add Anchor takes a press on an anchor and moves nothing: the drag is `add_anchor_tool_dragged`'s, on a segment.
|
||||
#[story(BezierOverlay<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn add_anchor_tool(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| {
|
||||
BezierOverlay::new("Paths", Bind::bound(&mut *paths), &PathSelection::default()).tool(BezierTool::AddAnchor).show_at(ui, at)
|
||||
BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &PathSelection::default()).tool(BezierTool::AddAnchor).show_at(ui, at)
|
||||
})
|
||||
}
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [Default], drive = Drive::Drag(Grip::part(SEGMENT.at(index(0, KnotRef { subpath: 0, knot: 0 }))).toward(Vec2::Y)))]
|
||||
fn add_anchor_tool_dragged(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| {
|
||||
BezierOverlay::new("Paths", Bind::bound(&mut *paths), &PathSelection::default()).tool(BezierTool::AddAnchor).show_at(ui, at)
|
||||
BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &PathSelection::default()).tool(BezierTool::AddAnchor).show_at(ui, at)
|
||||
})
|
||||
}
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [Default], drive = Drive::Drag(Grip::part(SEGMENT.at(index(0, KnotRef { subpath: 0, knot: 0 }))).toward(Vec2::Y)))]
|
||||
fn convert_tool_straight_segment(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", Bind::bound(&mut *paths), &PathSelection::default()).tool(BezierTool::Convert).show_at(ui, at))
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| {
|
||||
BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &PathSelection::default()).tool(BezierTool::Convert).show_at(ui, at)
|
||||
})
|
||||
}
|
||||
|
||||
#[story(BezierOverlay<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn outlines_only(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let paths = data.value("paths", paths());
|
||||
let (paths, paths_at) = data.value_at("paths", paths());
|
||||
on_canvas(ui, |ui, at| {
|
||||
BezierOverlay::new("Paths", Bind::bound(&mut *paths), &PathSelection::default())
|
||||
BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &PathSelection::default())
|
||||
.tool(BezierTool::Anchors)
|
||||
.anchors(AnchorsShown::Hidden)
|
||||
.show_at(ui, at)
|
||||
@@ -89,6 +91,6 @@ fn a_path_in_its_own_colour(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
paths[0].color = Some(Srgba::rgb(0.9, 0.43, 0.08));
|
||||
paths
|
||||
};
|
||||
let paths = data.value("paths", coloured());
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", Bind::bound(&mut *paths), &selected()).show_at(ui, at))
|
||||
let (paths, paths_at) = data.value_at("paths", coloured());
|
||||
on_canvas(ui, |ui, at| BezierOverlay::new("Paths", paths_at.bind(&mut *paths), &selected()).show_at(ui, at))
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use super::{PathOptionsPopover, PathOptionsSettings};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
@@ -14,8 +13,8 @@ fn line_color() -> Srgba {
|
||||
#[story(PathOptionsPopover<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn path_options_defaults(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut open = *data.value("open", false);
|
||||
let settings = data.value("defaults", PathOptionsSettings::default());
|
||||
let shown = PathOptionsPopover::new("Path Options", Bind::bound(&mut *settings)).default_color(line_color()).show(ui, &mut open);
|
||||
let (settings, settings_at) = data.value_at("defaults", PathOptionsSettings::default());
|
||||
let shown = PathOptionsPopover::new("Path Options", settings_at.bind(&mut *settings)).default_color(line_color()).show(ui, &mut open);
|
||||
*data.value("open", false) = open;
|
||||
shown.into()
|
||||
}
|
||||
@@ -23,8 +22,8 @@ fn path_options_defaults(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(PathOptionsPopover<'static>, covers = [], drive = Drive::Never)]
|
||||
fn path_options_with_a_color(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut open = *data.value("open-set", false);
|
||||
let settings = data.value("set", PathOptionsSettings { rubber_band: true, color: Some([200, 40, 40]), thickness: Some(2.0) });
|
||||
let shown = PathOptionsPopover::new("Path Options", Bind::bound(&mut *settings)).show(ui, &mut open);
|
||||
let (settings, settings_at) = data.value_at("set", PathOptionsSettings { rubber_band: true, color: Some([200, 40, 40]), thickness: Some(2.0) });
|
||||
let shown = PathOptionsPopover::new("Path Options", settings_at.bind(&mut *settings)).show(ui, &mut open);
|
||||
*data.value("open-set", false) = open;
|
||||
shown.into()
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
//! Stories of the picture fill editor: Stretch and Tile.
|
||||
|
||||
use super::{PictureFill, PictureFillEditor, PictureMode, TileAlignment, TileMirror};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
#[story(PictureFillEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn picture_fill_stretch(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let fill = data.value("stretch", PictureFill::new("sunrise.png"));
|
||||
PictureFillEditor::new("Picture", Bind::bound(fill)).show(ui).into()
|
||||
let (fill, fill_at) = data.value_at("stretch", PictureFill::new("sunrise.png"));
|
||||
PictureFillEditor::new("Picture", fill_at.bind(fill)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(PictureFillEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn picture_fill_tile(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut start = PictureFill::new("sunrise.png");
|
||||
start.mode = PictureMode::Tile { offset: [12.0, 0.0], scale: [50.0, 50.0], alignment: TileAlignment::Center, mirror: TileMirror::Horizontal };
|
||||
let fill = data.value("tile", start);
|
||||
PictureFillEditor::new("Picture", Bind::bound(fill)).show(ui).into()
|
||||
let (fill, fill_at) = data.value_at("tile", start);
|
||||
PictureFillEditor::new("Picture", fill_at.bind(fill)).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -54,51 +54,51 @@ fn with_readout(data: &mut StoryData, output: impl Into<StoryOutput>, latest: Op
|
||||
|
||||
#[story(StrokeEditor<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn stroke_editor_panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let style = data.value("panel", StrokeStyle::default());
|
||||
let out = StrokeEditor::new("Stroke", Bind::bound(style)).sections(StrokeSections::PANEL | StrokeSections::DASH_ALIGN).show(ui);
|
||||
let (style, style_at) = data.value_at("panel", StrokeStyle::default());
|
||||
let out = StrokeEditor::new("Stroke", style_at.bind(style)).sections(StrokeSections::PANEL | StrokeSections::DASH_ALIGN).show(ui);
|
||||
let latest = out.events.last().map(|event| format!("{event:?}"));
|
||||
with_readout(data, out, latest)
|
||||
}
|
||||
|
||||
#[story(StrokeEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn stroke_editor_popover_dash_align(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let style = data.value("popover-align", StrokeStyle::default().with_line_style(super::LineStyle::Dashed));
|
||||
let out = StrokeEditor::new("Stroke", Bind::bound(style)).sections(StrokeSections::POPOVER | StrokeSections::DASH_ALIGN).show(ui);
|
||||
let (style, style_at) = data.value_at("popover-align", StrokeStyle::default().with_line_style(super::LineStyle::Dashed));
|
||||
let out = StrokeEditor::new("Stroke", style_at.bind(style)).sections(StrokeSections::POPOVER | StrokeSections::DASH_ALIGN).show(ui);
|
||||
let latest = out.events.last().map(|event| format!("{event:?}"));
|
||||
with_readout(data, out, latest)
|
||||
}
|
||||
|
||||
#[story(StrokeEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn stroke_editor_popover(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let style = data.value("popover", StrokeStyle::default());
|
||||
let out = StrokeEditor::new("Stroke", Bind::bound(style)).sections(StrokeSections::POPOVER).show(ui);
|
||||
let (style, style_at) = data.value_at("popover", StrokeStyle::default());
|
||||
let out = StrokeEditor::new("Stroke", style_at.bind(style)).sections(StrokeSections::POPOVER).show(ui);
|
||||
let latest = out.events.last().map(|event| format!("{event:?}"));
|
||||
with_readout(data, out, latest)
|
||||
}
|
||||
|
||||
#[story(StrokeEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn stroke_editor_open_path(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let style = data.value("open", StrokeStyle::default());
|
||||
let out = StrokeEditor::new("Stroke", Bind::bound(style)).sections(StrokeSections::POPOVER).closed(false).show(ui);
|
||||
let (style, style_at) = data.value_at("open", StrokeStyle::default());
|
||||
let out = StrokeEditor::new("Stroke", style_at.bind(style)).sections(StrokeSections::POPOVER).closed(false).show(ui);
|
||||
let latest = out.events.last().map(|event| format!("{event:?}"));
|
||||
with_readout(data, out, latest)
|
||||
}
|
||||
|
||||
#[story(StrokeEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn stroke_editor_dashed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let style = data.value("dashed", StrokeStyle::default().with_line_style(super::LineStyle::Dashed));
|
||||
let out = StrokeEditor::new("Stroke", Bind::bound(style)).sections(StrokeSections::POPOVER).show(ui);
|
||||
let (style, style_at) = data.value_at("dashed", StrokeStyle::default().with_line_style(super::LineStyle::Dashed));
|
||||
let out = StrokeEditor::new("Stroke", style_at.bind(style)).sections(StrokeSections::POPOVER).show(ui);
|
||||
let latest = out.events.last().map(|event| format!("{event:?}"));
|
||||
with_readout(data, out, latest)
|
||||
}
|
||||
|
||||
#[story(StrokeEditor<'static>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn stroke_editor_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let (style, mixed) = data.value("mixed", {
|
||||
let ((style, mixed), mixed_at) = data.value_at("mixed", {
|
||||
let base = StrokeStyle::default();
|
||||
StrokeMixed::of([&base, &other_than(&base)]).expect("two styles")
|
||||
});
|
||||
let out = StrokeEditor::new("Stroke", Bind::bound(style)).sections(StrokeSections::POPOVER | StrokeSections::DASH_ALIGN).mixed(mixed).show(ui);
|
||||
let out = StrokeEditor::new("Stroke", mixed_at.bind(style)).sections(StrokeSections::POPOVER | StrokeSections::DASH_ALIGN).mixed(mixed).show(ui);
|
||||
let latest = out.events.last().map(|event| format!("{event:?}"));
|
||||
with_readout(data, out, latest)
|
||||
}
|
||||
@@ -158,8 +158,8 @@ struct Picks {
|
||||
|
||||
#[story(StrokeEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn stroke_editor_choice_rows(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let picks =
|
||||
data.value("rows", Picks { style: StrokeStyle::default(), start: "none".into(), end: "arrow".into(), profile: "uniform".into(), last: None });
|
||||
let (picks, picks_at) = data
|
||||
.value_at("rows", Picks { style: StrokeStyle::default(), start: "none".into(), end: "arrow".into(), profile: "uniform".into(), last: None });
|
||||
let heads = [
|
||||
StrokeChoice::new("none", "None"),
|
||||
StrokeChoice::new("arrow", "Arrow"),
|
||||
@@ -179,7 +179,7 @@ fn stroke_editor_choice_rows(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
.selected(Mixed::Same(picks.profile.as_str()))
|
||||
.paint(ChoicePainter::new(|cx, rect, choice| paint_profile(cx, rect, &choice.id))),
|
||||
];
|
||||
let out = StrokeEditor::new("Stroke", Bind::bound(&mut picks.style)).rows(&rows).show(ui);
|
||||
let out = StrokeEditor::new("Stroke", picks_at.bind(&mut picks.style)).rows(&rows).show(ui);
|
||||
let picked = out.choice.clone();
|
||||
let story: StoryOutput = out.into();
|
||||
if let Some((row, choice)) = &picked {
|
||||
@@ -206,25 +206,25 @@ fn stroke_editor_choice_rows(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(StrokeButton<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn stroke_button(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let (style, open) = data.value("button", (StrokeStyle::default(), false));
|
||||
let out = StrokeButton::new("Stroke Options", Bind::bound(style), Bind::bound(open)).show(ui);
|
||||
let ((style, open), button_at) = data.value_at("button", (StrokeStyle::default(), false));
|
||||
let out = StrokeButton::new("Stroke Options", button_at.bind(style), button_at.bind(open)).show(ui);
|
||||
let latest = out.events.last().map(|event| format!("{event:?}"));
|
||||
with_readout(data, out, latest)
|
||||
}
|
||||
|
||||
#[story(StrokeButton<'static>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn stroke_button_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let (style, open) = data.value("button mixed", (Mixed::<StrokeStyle>::Mixed, false));
|
||||
let out = StrokeButton::new("Stroke Options", Bind::bound_mixed(style), Bind::bound(open)).show(ui);
|
||||
let ((style, open), style_open_at) = data.value_at("button mixed", (Mixed::<StrokeStyle>::Mixed, false));
|
||||
let out = StrokeButton::new("Stroke Options", style_open_at.bind_mixed(style), style_open_at.bind(open)).show(ui);
|
||||
let latest = out.events.last().map(|event| format!("{event:?}"));
|
||||
with_readout(data, out, latest)
|
||||
}
|
||||
|
||||
#[story(StrokeButton<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn stroke_button_refused(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let (style, open) = data.value("button refused", (StrokeStyle::default().with_line_style(super::LineStyle::Dashed), false));
|
||||
let ((style, open), style_open_at) = data.value_at("button refused", (StrokeStyle::default().with_line_style(super::LineStyle::Dashed), false));
|
||||
let refuse_dashes = |style: &StrokeStyle| if style.dashes.is_empty() { Validity::Ok } else { Validity::Refuse(Message::new("Solid lines only")) };
|
||||
let out = StrokeButton::new("Stroke Options", Bind::bound(style).check(refuse_dashes), Bind::bound(open)).show(ui);
|
||||
let out = StrokeButton::new("Stroke Options", style_open_at.bind(style).check(refuse_dashes), style_open_at.bind(open)).show(ui);
|
||||
let latest = out.events.last().map(|event| format!("{event:?}"));
|
||||
with_readout(data, out, latest)
|
||||
}
|
||||
@@ -243,8 +243,8 @@ fn pick_dashed(fixture: &mut Fixture) {
|
||||
|
||||
#[story(StrokeButton<'static>, covers = [Open], drive = Drive::Custom(pick_dashed))]
|
||||
fn stroke_button_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let style = data.value("button open", StrokeStyle::default());
|
||||
let out = StrokeButton::new("Stroke Options", Bind::bound(style), Bind::given(false)).show(ui);
|
||||
let (style, style_at) = data.value_at("button open", StrokeStyle::default());
|
||||
let out = StrokeButton::new("Stroke Options", style_at.bind(style), Bind::given(false)).show(ui);
|
||||
let latest = out.events.last().map(|event| format!("{event:?}"));
|
||||
with_readout(data, out, latest)
|
||||
}
|
||||
|
||||
@@ -98,14 +98,14 @@ fn editing_guides(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(SymmetryHandles<'static>, covers = [Default], drive = Drive::Drag(Grip::part(SYMMETRY.at(CENTRE))))]
|
||||
fn handles_on_a_canvas(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let symmetry = data.value("symmetry", sample(SymmetryMode::Vertical));
|
||||
let (symmetry, symmetry_at) = data.value_at("symmetry", sample(SymmetryMode::Vertical));
|
||||
let room = craft_ui::testing::stage(ui);
|
||||
let view = view(ui, room);
|
||||
let shown = Canvas::new("Document").view(view).show_at(ui, room, |ui, body| {
|
||||
craft_ui::testing::canvas_story::show_document(ui, body.rect, &SHOWN);
|
||||
let drawn = *symmetry;
|
||||
SymmetryOverlay::new("Symmetry", &drawn, PAGE).editing(true).show_at(ui, body.rect);
|
||||
SymmetryHandles::new("Symmetry", Bind::bound(&mut *symmetry), PAGE).show_at(ui, body.rect)
|
||||
SymmetryHandles::new("Symmetry", symmetry_at.bind(&mut *symmetry), PAGE).show_at(ui, body.rect)
|
||||
});
|
||||
let output = shown.inner.map(|output| StoryOutput::from(output.edit)).unwrap_or_default();
|
||||
output.readout(axes(symmetry))
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use super::{BarSlot, TransformBar};
|
||||
use super::{TransformEdit, TransformSession, TransformSettings};
|
||||
use craft_behavior::kurbo::Rect;
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -13,18 +13,18 @@ const START: Rect = Rect::new(0.0, 0.0, 200.0, 100.0);
|
||||
|
||||
#[story(TransformBar<'static, ()>, covers = [], drive = Drive::Never)]
|
||||
fn box_phase(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let settings = data.value("settings", TransformSettings::default());
|
||||
let (settings, settings_at) = data.value_at("settings", TransformSettings::default());
|
||||
let session = TransformSession::<()>::new(START);
|
||||
TransformBar::new("Free Transform", &session, Bind::bound(settings)).show(ui).into()
|
||||
TransformBar::new("Free Transform", &session, settings_at.bind(settings)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(TransformBar<'static, ()>, covers = [], drive = Drive::Never)]
|
||||
fn warp_phase(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let settings = data.value("settings", TransformSettings::default());
|
||||
let (settings, settings_at) = data.value_at("settings", TransformSettings::default());
|
||||
let mut session = TransformSession::<()>::new(START);
|
||||
let _ = session.apply(TransformEdit::Warp(()), 0.0);
|
||||
let fields = BarSlot::new(|ui: &mut Ui| {
|
||||
Text::new("Warp fields").show(ui);
|
||||
});
|
||||
TransformBar::new("Warp", &session, Bind::bound(settings)).warp_fields(fields).show(ui).into()
|
||||
TransformBar::new("Warp", &session, settings_at.bind(settings)).warp_fields(fields).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use craft_behavior::CanvasView;
|
||||
use craft_behavior::geometry::quad::BoxState;
|
||||
use craft_behavior::kurbo::{Line, Rect as DocRect};
|
||||
use craft_ui::canvas::RasterSource as _;
|
||||
use craft_ui::contract::{Bind, Entry};
|
||||
use craft_ui::contract::Entry;
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::runtime::pointer;
|
||||
use craft_ui::testing::canvas_story::{OUTLINE, StoryDocument, StoryPicture, StoryShape, accent, paint_shapes};
|
||||
@@ -100,9 +100,9 @@ fn run_session(ui: &mut Ui, data: &mut StoryData, with_rows: bool) -> StoryOutpu
|
||||
let rows = if with_rows { app_rows(&words) } else { Vec::new() };
|
||||
let first = data.value("settings", sample_settings()).clone();
|
||||
let kept = story_tool(data, || TransformKept::new(&first));
|
||||
let settings = data.value("settings", sample_settings());
|
||||
let (settings, settings_at) = data.value_at("settings", sample_settings());
|
||||
// The bar shows before the canvas, as the app's options bar does: its edits reach the session on this pass.
|
||||
let bar = TransformBar::new("Free Transform", &kept.borrow().session, Bind::bound(settings)).show(ui);
|
||||
let bar = TransformBar::new("Free Transform", &kept.borrow().session, settings_at.bind(settings)).show(ui);
|
||||
let settings = settings.clone();
|
||||
let document = StoryDocument::STANDARD;
|
||||
let line = accent(ui, 1.0);
|
||||
|
||||
@@ -33,14 +33,14 @@ fn on_canvas(ui: &mut Ui, data: &mut StoryData, make: impl for<'a> Fn(Bind<'a, B
|
||||
|
||||
/// [`on_canvas`] with the box's whole output.
|
||||
fn shown_on_canvas(ui: &mut Ui, data: &mut StoryData, make: impl for<'a> Fn(Bind<'a, BoxState>) -> TransformBox<'a>) -> Option<TransformBoxOutput> {
|
||||
let state = data.value("box", BoxState::from_rect(PICTURE));
|
||||
let (state, state_at) = data.value_at("box", BoxState::from_rect(PICTURE));
|
||||
let room = craft_ui::testing::stage(ui);
|
||||
let view = craft_ui::testing::canvas_story::story_view(room, ui.pixels_per_point(), PICTURE.center(), 100.0);
|
||||
let layer = layer();
|
||||
let shown = Canvas::new("Document").view(view).show_at(ui, room, |ui, body| {
|
||||
show_document(ui, body.rect, &StoryDocument::STANDARD);
|
||||
show_quad(ui, body.rect, "Layer", state.quad, &layer);
|
||||
make(Bind::bound(&mut *state)).show_at(ui, body.rect)
|
||||
make(state_at.bind(&mut *state)).show_at(ui, body.rect)
|
||||
});
|
||||
shown.inner
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use craft_behavior::kurbo::{Rect, Size};
|
||||
use craft_behavior::{RulerUnits, Ticks};
|
||||
use craft_ui::bars::{Bar, BarKind};
|
||||
use craft_ui::canvas::RulerText;
|
||||
use craft_ui::contract::{Bind, Entry, ShowContainer as _};
|
||||
use craft_ui::contract::{Entry, ShowContainer as _};
|
||||
use craft_ui::runtime::env::UnitKind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -35,19 +35,19 @@ fn inches() -> RulerText {
|
||||
|
||||
#[story(TransformFields<'static>, covers = [], drive = Drive::Never)]
|
||||
fn panel_form(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let state = data.value("state", sample());
|
||||
TransformFields::new("Transform", Bind::bound(&mut state.0), START, Bind::bound(&mut state.1)).show(ui).into()
|
||||
let (state, state_at) = data.value_at("state", sample());
|
||||
TransformFields::new("Transform", state_at.bind(&mut state.0), START, state_at.bind(&mut state.1)).show(ui).into()
|
||||
}
|
||||
|
||||
/// The panel form of a layer's properties: position and size only, percentages read against the document.
|
||||
#[story(TransformFields<'static>, covers = [], drive = Drive::Never)]
|
||||
fn panel_form_with_document(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let state = data.value("state", sample());
|
||||
let (state, state_at) = data.value_at("state", sample());
|
||||
let mut groups = TransformGroups::NONE;
|
||||
groups.reference = true;
|
||||
groups.position = true;
|
||||
groups.size = true;
|
||||
TransformFields::new("Transform", Bind::bound(&mut state.0), START, Bind::bound(&mut state.1))
|
||||
TransformFields::new("Transform", state_at.bind(&mut state.0), START, state_at.bind(&mut state.1))
|
||||
.groups(groups)
|
||||
.document(Size::new(1000.0, 400.0))
|
||||
.show(ui)
|
||||
@@ -57,12 +57,12 @@ fn panel_form_with_document(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// The bar form with the Δ toggle on: X and Y show the reference point's offset.
|
||||
#[story(TransformFields<'static>, covers = [], drive = Drive::Never)]
|
||||
fn bar_form_relative(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let state = data.value("state", (sample().0, true, true));
|
||||
let (state, state_at) = data.value_at("state", (sample().0, true, true));
|
||||
Bar::new("Options", BarKind::Options)
|
||||
.show(ui, |ui, _| {
|
||||
TransformFields::new("Transform", Bind::bound(&mut state.0), START, Bind::bound(&mut state.1))
|
||||
TransformFields::new("Transform", state_at.bind(&mut state.0), START, state_at.bind(&mut state.1))
|
||||
.bar()
|
||||
.relative(Bind::bound(&mut state.2))
|
||||
.relative(state_at.bind(&mut state.2))
|
||||
.show(ui);
|
||||
})
|
||||
.output
|
||||
@@ -71,10 +71,10 @@ fn bar_form_relative(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(TransformFields<'static>, covers = [], drive = Drive::Never)]
|
||||
fn bar_form_in_percent(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let state = data.value("state", sample());
|
||||
let (state, state_at) = data.value_at("state", sample());
|
||||
Bar::new("Options", BarKind::Options)
|
||||
.show(ui, |ui, _| {
|
||||
TransformFields::new("Transform", Bind::bound(&mut state.0), START, Bind::bound(&mut state.1)).bar().show(ui);
|
||||
TransformFields::new("Transform", state_at.bind(&mut state.0), START, state_at.bind(&mut state.1)).bar().show(ui);
|
||||
})
|
||||
.output
|
||||
.into()
|
||||
@@ -82,11 +82,11 @@ fn bar_form_in_percent(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(TransformFields<'static>, covers = [], drive = Drive::Never)]
|
||||
fn bar_form_in_a_length_unit(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let state = data.value("state", sample());
|
||||
let (state, state_at) = data.value_at("state", sample());
|
||||
let units = [Entry::new(UnitKind::Percent, "Percent"), Entry::new(UnitKind::Pixels, "Pixels"), Entry::new(UnitKind::Inches, "Inches")];
|
||||
Bar::new("Options", BarKind::Options)
|
||||
.show(ui, |ui, _| {
|
||||
TransformFields::new("Transform", Bind::bound(&mut state.0), START, Bind::bound(&mut state.1))
|
||||
TransformFields::new("Transform", state_at.bind(&mut state.0), START, state_at.bind(&mut state.1))
|
||||
.bar()
|
||||
.units(inches(), inches())
|
||||
.size_unit(size_unit_of(UnitKind::Inches, inches(), UnitKind::POINTS_PER_INCH))
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! Stories of `AxisSliders`: the Weight and Width axes of a variable face with three named instances.
|
||||
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, ValueAt, story};
|
||||
use egui::Ui;
|
||||
|
||||
use super::{AxisSliders, AxisValues};
|
||||
@@ -18,6 +17,6 @@ fn axis_sliders(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
];
|
||||
let instance = |name: &str, weight: f32, width: f32| NamedInstance { name: name.to_owned(), coordinates: vec![(WGHT, weight), (WDTH, width)] };
|
||||
let instances = [instance("Light", 300.0, 100.0), instance("Regular", 400.0, 100.0), instance("Bold Condensed", 700.0, 75.0)];
|
||||
let values: &mut AxisValues = data.value("values", vec![(WGHT, 400.0), (WDTH, 100.0)]);
|
||||
AxisSliders::new("Axes", &axes, Bind::bound(values)).instances(&instances).show(ui).into()
|
||||
let (values, values_at): (&mut AxisValues, ValueAt<'_>) = data.value_at("values", vec![(WGHT, 400.0), (WDTH, 100.0)]);
|
||||
AxisSliders::new("Axes", &axes, values_at.bind(values)).instances(&instances).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -212,23 +212,23 @@ fn font_picker_plain_missing(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(FontPicker<'static>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn font_picker_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let catalog = catalog();
|
||||
FontPicker::new("Font family", Bind::bound_mixed(data.value("family", Mixed::<String>::Mixed)), &catalog).show(ui).into()
|
||||
FontPicker::new("Font family", data.bind_mixed("family", Mixed::<String>::Mixed), &catalog).show(ui).into()
|
||||
}
|
||||
|
||||
/// A family the catalog does not hold, which the check refuses.
|
||||
#[story(FontPicker<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn font_picker_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let catalog = catalog();
|
||||
let known = catalog.clone();
|
||||
let check = move |family: &String| {
|
||||
if known.styles(family).is_empty() { Validity::Refuse(Message::new("No such font is installed")) } else { Validity::Ok }
|
||||
};
|
||||
FontPicker::new("Font family", Bind::bound(data.value("family", "Gotham".to_owned())).check(check), &catalog).show(ui).into()
|
||||
// The story's catalog is built once for the process, so the check reads it rather than taking it as an input.
|
||||
let family = data.bind("family", "Gotham".to_owned()).check(|family| {
|
||||
if self::catalog().styles(family).is_empty() { Validity::Refuse(Message::new("No such font is installed")) } else { Validity::Ok }
|
||||
});
|
||||
FontPicker::new("Font family", family, &catalog).show(ui).into()
|
||||
}
|
||||
|
||||
/// A family name far longer than the field.
|
||||
#[story(FontPicker<'static>, covers = [LongText], drive = Drive::Never)]
|
||||
fn font_picker_long(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let catalog = catalog();
|
||||
FontPicker::new("Font family", Bind::bound(data.value("family", LONG_FAMILY.to_owned())), &catalog).show(ui).into()
|
||||
FontPicker::new("Font family", data.bind("family", LONG_FAMILY.to_owned()), &catalog).show(ui).into()
|
||||
}
|
||||
|
||||
+18
-2
@@ -30,6 +30,14 @@ pub struct Host {
|
||||
commands: Arc<dyn Commands>,
|
||||
jobs: Arc<dyn Jobs>,
|
||||
files: Arc<dyn Files>,
|
||||
/// Unique per host built (`generation`).
|
||||
generation: u64,
|
||||
}
|
||||
|
||||
/// A generation no host built before has.
|
||||
fn next_generation() -> u64 {
|
||||
static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
|
||||
NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Collects a [`Host`]'s services; each one defaults when not set.
|
||||
@@ -49,6 +57,13 @@ impl Host {
|
||||
HostBuilder { app, i18n: None, lang: None, settings: None, commands: None, jobs: None, files: None }
|
||||
}
|
||||
|
||||
/// Which host this is: a host and its clones hold the same services and language, and one built anew
|
||||
/// ([`HostBuilder::build`], [`Host::with_lang`], [`Host::with_files`]) gets a new generation. What the services
|
||||
/// hold (settings sections, catalogs) changes inside them without changing the generation.
|
||||
pub fn generation(&self) -> u64 {
|
||||
self.generation
|
||||
}
|
||||
|
||||
/// The app's name and version.
|
||||
pub fn app(&self) -> &AppInfo {
|
||||
&self.app
|
||||
@@ -97,12 +112,12 @@ impl Host {
|
||||
|
||||
/// A copy in another language; install it to switch the interface.
|
||||
pub fn with_lang(&self, lang: Lang) -> Host {
|
||||
Host { lang, ..self.clone() }
|
||||
Host { lang, generation: next_generation(), ..self.clone() }
|
||||
}
|
||||
|
||||
/// A copy with another file service; install it to switch the pickers.
|
||||
pub fn with_files(&self, files: Arc<dyn Files>) -> Host {
|
||||
Host { files, ..self.clone() }
|
||||
Host { files, generation: next_generation(), ..self.clone() }
|
||||
}
|
||||
|
||||
/// The stored value of section `S`, or `S::default()` when it is missing or does not fit `S`.
|
||||
@@ -166,6 +181,7 @@ impl HostBuilder {
|
||||
commands: self.commands.unwrap_or_else(|| Arc::new(NoCommands)),
|
||||
jobs: self.jobs.unwrap_or_else(default_jobs),
|
||||
files: self.files.unwrap_or_else(|| Arc::new(NoPickFiles::default())),
|
||||
generation: next_generation(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+16
-2
@@ -276,6 +276,8 @@ pub struct DateFormat {
|
||||
latin_digits: bool,
|
||||
/// Formatters and names, built on first use and shared by clones.
|
||||
cache: Arc<Cache>,
|
||||
/// Unique per format built; a clone keeps it (`generation`).
|
||||
generation: u64,
|
||||
}
|
||||
|
||||
/// One ICU formatter per field set the styles need.
|
||||
@@ -374,13 +376,25 @@ impl PartsWrite for Spliced {
|
||||
impl DateFormat {
|
||||
/// The format for `region`'s time locale and clock.
|
||||
pub fn new(region: &Region) -> DateFormat {
|
||||
Self { locale: region.time.clone(), hour_cycle: region.hour_cycle, latin_digits: false, cache: Arc::default() }
|
||||
Self {
|
||||
locale: region.time.clone(),
|
||||
hour_cycle: region.hour_cycle,
|
||||
latin_digits: false,
|
||||
cache: Arc::default(),
|
||||
generation: crate::words::next_generation(),
|
||||
}
|
||||
}
|
||||
|
||||
/// This format writing `0`–`9` for [`Digits::Latin`], else the locale's own digits. Formatters
|
||||
/// are rebuilt on first use.
|
||||
pub fn with_digits(self, digits: Digits) -> DateFormat {
|
||||
DateFormat { latin_digits: digits == Digits::Latin, cache: Arc::default(), ..self }
|
||||
DateFormat { latin_digits: digits == Digits::Latin, cache: Arc::default(), generation: crate::words::next_generation(), ..self }
|
||||
}
|
||||
|
||||
/// Which format this is: a format and its clones write every date the same, and one built anew gets a new
|
||||
/// generation. What keys on the dates a format writes keys on this.
|
||||
pub fn generation(&self) -> u64 {
|
||||
self.generation
|
||||
}
|
||||
|
||||
/// The format for a locale tag (`de-CH`), with the locale's clock.
|
||||
|
||||
@@ -38,6 +38,8 @@ pub struct Format {
|
||||
pub(crate) marks: Marks,
|
||||
/// The decimal and group marks of the written form, read once from a number that shows both.
|
||||
separators: (char, Option<char>),
|
||||
/// Unique per format built (`generation`).
|
||||
generation: u64,
|
||||
}
|
||||
|
||||
impl Format {
|
||||
@@ -50,7 +52,15 @@ impl Format {
|
||||
}
|
||||
let decimal = data::provider()
|
||||
.and_then(|p| DecimalFormatter::try_new_with_buffer_provider(p, (&locale).into(), DecimalFormatterOptions::default()).ok());
|
||||
let mut format = Format { decimal, group: None, point: None, percent: ("", "%"), marks: Marks::default(), separators: ('.', None) };
|
||||
let mut format = Format {
|
||||
decimal,
|
||||
group: None,
|
||||
point: None,
|
||||
percent: ("", "%"),
|
||||
marks: Marks::default(),
|
||||
separators: ('.', None),
|
||||
generation: crate::words::next_generation(),
|
||||
};
|
||||
// The locale's own separators and digits, read from a number that shows them all.
|
||||
let probe = format.parts(&Decimal::try_from_str("-1234567.5").unwrap_or_default());
|
||||
let latin = probe.integer.starts_with(|c: char| c.is_ascii_digit());
|
||||
@@ -84,6 +94,12 @@ impl Format {
|
||||
format
|
||||
}
|
||||
|
||||
/// Which format this is: a format writes every number the same for its whole life, and one built anew gets a new
|
||||
/// generation. What keys on the numbers a format writes keys on this.
|
||||
pub fn generation(&self) -> u64 {
|
||||
self.generation
|
||||
}
|
||||
|
||||
/// The decimal and group marks numbers are written with, in the digits of the format. The group mark is
|
||||
/// `None` where the format writes none.
|
||||
pub fn separators(&self) -> (char, Option<char>) {
|
||||
|
||||
@@ -107,8 +107,8 @@ pub struct Words {
|
||||
generation: u64,
|
||||
}
|
||||
|
||||
/// A generation no `Words` built before has; English (the default) is 0.
|
||||
fn next_generation() -> u64 {
|
||||
/// A generation no `Words`, `Format` or `DateFormat` built before has; English (the default) is 0.
|
||||
pub(crate) fn next_generation() -> u64 {
|
||||
static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
|
||||
NEXT.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ use egui::Ui;
|
||||
|
||||
#[story(BrightnessContrastEditor<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn brightness_contrast(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("value", BrightnessContrast { brightness: 20.0, contrast: -10.0, legacy: false });
|
||||
BrightnessContrastEditor::new("Brightness/Contrast", Bind::bound(value)).show(ui).into()
|
||||
let (value, value_at) = data.value_at("value", BrightnessContrast { brightness: 20.0, contrast: -10.0, legacy: false });
|
||||
BrightnessContrastEditor::new("Brightness/Contrast", value_at.bind(value)).show(ui).into()
|
||||
}
|
||||
|
||||
/// The editor in its Image › Adjustments dialog, opened from a button.
|
||||
@@ -35,16 +35,16 @@ fn brightness_contrast_dialog(ui: &mut Ui, data: &mut StoryData) -> StoryOutput
|
||||
#[story(ThresholdEditor<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn threshold(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let histogram = HistogramData::tone(&story_bins(0.0), ChannelColor::Neutral);
|
||||
let level = data.value("level", 90.0);
|
||||
ThresholdEditor::new("Threshold", Bind::bound(level)).histogram(&histogram).show(ui).into()
|
||||
let (level, level_at) = data.value_at("level", 90.0);
|
||||
ThresholdEditor::new("Threshold", level_at.bind(level)).histogram(&histogram).show(ui).into()
|
||||
}
|
||||
|
||||
fn color_balance(ui: &mut Ui, data: &mut StoryData, start: ColorBalanceTone) -> StoryOutput {
|
||||
let shifts =
|
||||
ColorBalance { shadows: [-20.0, 0.0, 30.0], midtones: [10.0, -15.0, 0.0], highlights: [25.0, 10.0, -20.0], ..ColorBalance::default() };
|
||||
// The host keeps the value and the tone shown.
|
||||
let (value, tone) = data.value("value", (shifts, start));
|
||||
let shown = ColorBalanceEditor::new("Color Balance", Bind::bound(value)).tone(*tone).show(ui);
|
||||
let ((value, tone), value_at) = data.value_at("value", (shifts, start));
|
||||
let shown = ColorBalanceEditor::new("Color Balance", value_at.bind(value)).tone(*tone).show(ui);
|
||||
*tone = shown.tone;
|
||||
shown.into()
|
||||
}
|
||||
@@ -67,13 +67,14 @@ fn color_balance_highlights(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// A filter preset: the Filter row is on.
|
||||
#[story(PhotoFilterEditor<'static>, covers = [Default], drive = Drive::Never, group = "Sources", title = "A filter preset")]
|
||||
fn photo_filter_preset(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("preset", PhotoFilter { color: PhotoFilterPreset::Cooling80.color(), density: 25.0, preserve_luminosity: true });
|
||||
PhotoFilterEditor::new("Photo Filter", Bind::bound(value)).show(ui).into()
|
||||
let (value, value_at) =
|
||||
data.value_at("preset", PhotoFilter { color: PhotoFilterPreset::Cooling80.color(), density: 25.0, preserve_luminosity: true });
|
||||
PhotoFilterEditor::new("Photo Filter", value_at.bind(value)).show(ui).into()
|
||||
}
|
||||
|
||||
/// A colour of no preset: the Color row is on, and the select offers Custom.
|
||||
#[story(PhotoFilterEditor<'static>, covers = [], drive = Drive::Never, group = "Sources", title = "A custom color")]
|
||||
fn photo_filter_color(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("color", PhotoFilter { color: Srgba::rgb(0.4, 0.2, 0.6), density: 60.0, preserve_luminosity: false });
|
||||
PhotoFilterEditor::new("Photo Filter", Bind::bound(value)).show(ui).into()
|
||||
let (value, value_at) = data.value_at("color", PhotoFilter { color: Srgba::rgb(0.4, 0.2, 0.6), density: 60.0, preserve_luminosity: false });
|
||||
PhotoFilterEditor::new("Photo Filter", value_at.bind(value)).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ use crate::ui::adjust::{ToneChannel, ToneChannels, TonePicker, ToneSpace};
|
||||
use crate::ui::curve::Curve;
|
||||
use crate::ui::curve::stories::story_bins;
|
||||
use crate::ui::histogram::ChannelColor;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
@@ -36,22 +35,22 @@ fn curves_panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut curves = ToneCurves::identity(&channels);
|
||||
curves.curves[0] = Curve::smooth(vec![[0.0, 0.0], [64.0, 80.0], [192.0, 170.0], [255.0, 255.0]]);
|
||||
curves.curves[1] = Curve::smooth(vec![[0.0, 10.0], [255.0, 245.0]]);
|
||||
let rig = data.value("rig", Rig { curves, armed: None });
|
||||
let (rig, rig_at) = data.value_at("rig", Rig { curves, armed: None });
|
||||
let histograms = [counts(0.0), counts(0.0), counts(12.0), counts(-12.0)];
|
||||
CurvesPanel::new("Curves", Bind::bound(&mut rig.curves), channels).histograms(&histograms).pickers(Bind::bound(&mut rig.armed)).show(ui).into()
|
||||
CurvesPanel::new("Curves", rig_at.bind(&mut rig.curves), channels).histograms(&histograms).pickers(rig_at.bind(&mut rig.armed)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(CurvesPanel<'static>, covers = [], drive = Drive::Never, group = "Modes", title = "Pencil, with Smooth")]
|
||||
fn curves_panel_pencil(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let channels = ToneChannels::of(ToneSpace::Rgb, false);
|
||||
let drawn = ToneCurves { curves: vec![Curve::Map(bumpy_map()); channels.len()], mode: CurvesMode::Pencil };
|
||||
let curves = data.value("drawn", drawn);
|
||||
CurvesPanel::new("Curves", Bind::bound(curves), channels).histograms(&[counts(0.0), counts(0.0), counts(0.0), counts(0.0)]).show(ui).into()
|
||||
let (curves, curves_at) = data.value_at("drawn", drawn);
|
||||
CurvesPanel::new("Curves", curves_at.bind(curves), channels).histograms(&[counts(0.0), counts(0.0), counts(0.0), counts(0.0)]).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(CurvesPanel<'static>, covers = [], drive = Drive::Never, group = "Modes", title = "One isolated mask channel")]
|
||||
fn curves_panel_isolated_mask(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let channels = ToneChannels::isolated(ToneChannel::Named { name: "Layer mask".to_owned(), color: ChannelColor::Neutral });
|
||||
let curves = data.value("mask", ToneCurves::identity(&channels));
|
||||
CurvesPanel::new("Curves", Bind::bound(curves), channels).histograms(&[counts(0.0)]).show(ui).into()
|
||||
let (curves, curves_at) = data.value_at("mask", ToneCurves::identity(&channels));
|
||||
CurvesPanel::new("Curves", curves_at.bind(curves), channels).histograms(&[counts(0.0)]).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
use super::{HueRangeValue, HueSaturation, HueSaturationEditor};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
@@ -22,8 +21,8 @@ fn shifted(degrees: f64) -> Srgba {
|
||||
|
||||
#[story(HueSaturationEditor<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn hue_saturation_master(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("master", HueSaturation { hue: 40.0, saturation: 20.0, ..HueSaturation::default() });
|
||||
HueSaturationEditor::new("Hue/Saturation", Bind::bound(value)).adjusted_spectrum(&shifted).show(ui).into()
|
||||
let (value, value_at) = data.value_at("master", HueSaturation { hue: 40.0, saturation: 20.0, ..HueSaturation::default() });
|
||||
HueSaturationEditor::new("Hue/Saturation", value_at.bind(value)).adjusted_spectrum(&shifted).show(ui).into()
|
||||
}
|
||||
|
||||
/// The Reds range with its four thumbs and the readout.
|
||||
@@ -31,13 +30,13 @@ fn hue_saturation_master(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn hue_saturation_range(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut start = HueSaturation::default();
|
||||
start.ranges[0] = HueRangeValue { hue: 15.0, ..HueRangeValue::neutral(0) };
|
||||
let value = data.value("range", start);
|
||||
HueSaturationEditor::new("Hue/Saturation", Bind::bound(value)).range(Some(0)).adjusted_spectrum(&shifted).show(ui).into()
|
||||
let (value, value_at) = data.value_at("range", start);
|
||||
HueSaturationEditor::new("Hue/Saturation", value_at.bind(value)).range(Some(0)).adjusted_spectrum(&shifted).show(ui).into()
|
||||
}
|
||||
|
||||
/// Colorize on: the range select is off and the Hue runs 0 to 360.
|
||||
#[story(HueSaturationEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn hue_saturation_colorize(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("colorize", HueSaturation { hue: 210.0, saturation: 40.0, colorize: true, ..HueSaturation::default() });
|
||||
HueSaturationEditor::new("Hue/Saturation", Bind::bound(value)).show(ui).into()
|
||||
let (value, value_at) = data.value_at("colorize", HueSaturation { hue: 210.0, saturation: 40.0, colorize: true, ..HueSaturation::default() });
|
||||
HueSaturationEditor::new("Hue/Saturation", value_at.bind(value)).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::{Levels, LevelsEditor};
|
||||
use crate::ui::curve::stories::story_bins;
|
||||
use crate::ui::histogram::{ChannelColor, HistogramData};
|
||||
use craft_behavior::Mixed;
|
||||
use craft_ui::contract::{Bind, Show as _, Validity};
|
||||
use craft_ui::contract::{Show as _, Validity};
|
||||
use craft_ui::display::{Shade, Text};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, story};
|
||||
@@ -19,8 +19,8 @@ fn identity() -> Levels {
|
||||
fn levels_editor(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let bins = story_bins(0.0);
|
||||
let histogram = HistogramData::tone(&bins, ChannelColor::Neutral);
|
||||
let levels = data.value("levels", identity());
|
||||
let output = LevelsEditor::new("Levels", Bind::bound(&mut *levels)).histogram(&histogram).value("RGB channel").show(ui);
|
||||
let (levels, levels_at) = data.value_at("levels", identity());
|
||||
let output = LevelsEditor::new("Levels", levels_at.bind(&mut *levels)).histogram(&histogram).value("RGB channel").show(ui);
|
||||
let facts = output.into();
|
||||
let l = *levels;
|
||||
let readout = format!("Input {:.3} / {:.2} / {:.3}, output {:.3} / {:.3}", l.in_black, l.gamma, l.in_white, l.out_black, l.out_white);
|
||||
@@ -32,7 +32,7 @@ fn levels_editor(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn levels_editor_stale(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let bins = story_bins(12.0);
|
||||
let histogram = HistogramData::tone(&bins, ChannelColor::Red);
|
||||
LevelsEditor::new("Levels", Bind::bound(data.value("stale", identity())))
|
||||
LevelsEditor::new("Levels", data.bind("stale", identity()))
|
||||
.channel(ChannelColor::Red)
|
||||
.histogram(&histogram)
|
||||
.stale(true)
|
||||
@@ -43,7 +43,7 @@ fn levels_editor_stale(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(LevelsEditor<'static>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn levels_editor_mixed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
LevelsEditor::new("Levels", Bind::bound_mixed(data.value("mixed", Mixed::<Levels>::Mixed))).show(ui).into()
|
||||
LevelsEditor::new("Levels", data.bind_mixed("mixed", Mixed::<Levels>::Mixed)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(LevelsEditor<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
@@ -51,5 +51,5 @@ fn levels_editor_invalid(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let refuse = |levels: &Levels| {
|
||||
if levels.in_black > 100.0 { Validity::Refuse(Message::new("Input black is above the limit")) } else { Validity::Ok }
|
||||
};
|
||||
LevelsEditor::new("Levels", Bind::bound(data.value("over", Levels::new(150.0, 1.0, 255.0, 0.0, 255.0))).check(refuse)).show(ui).into()
|
||||
LevelsEditor::new("Levels", data.bind("over", Levels::new(150.0, 1.0, 255.0, 0.0, 255.0)).check(refuse)).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ use super::LevelsPanel;
|
||||
use crate::ui::adjust::{AdjustContext, Levels, ToneChannel, ToneChannels, TonePicker, ToneSpace};
|
||||
use crate::ui::curve::stories::story_bins;
|
||||
use crate::ui::histogram::ChannelColor;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
@@ -26,10 +25,10 @@ fn counts(shift: f32) -> [u32; 256] {
|
||||
|
||||
/// The panel over `channels` with the point pickers, in `context`.
|
||||
fn panel(ui: &mut Ui, data: &mut StoryData, channels: ToneChannels, context: AdjustContext, histograms: &[[u32; 256]], start: Rig) -> StoryOutput {
|
||||
let rig = data.value("rig", start);
|
||||
LevelsPanel::new("Levels", Bind::bound(&mut rig.levels), channels)
|
||||
let (rig, rig_at) = data.value_at("rig", start);
|
||||
LevelsPanel::new("Levels", rig_at.bind(&mut rig.levels), channels)
|
||||
.histograms(histograms)
|
||||
.pickers(Bind::bound(&mut rig.armed))
|
||||
.pickers(rig_at.bind(&mut rig.armed))
|
||||
.context(context)
|
||||
.show(ui)
|
||||
.into()
|
||||
@@ -65,7 +64,7 @@ fn levels_panel_gray(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(LevelsPanel<'static>, covers = [], drive = Drive::Never, group = "Channels", title = "One isolated mask channel")]
|
||||
fn levels_panel_isolated_mask(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let levels = data.value("mask", vec![Levels::identity(0.0..=255.0)]);
|
||||
let (levels, levels_at) = data.value_at("mask", vec![Levels::identity(0.0..=255.0)]);
|
||||
let channels = ToneChannels::isolated(ToneChannel::Named { name: "Layer mask".to_owned(), color: ChannelColor::Neutral });
|
||||
LevelsPanel::new("Levels", Bind::bound(levels), channels).histograms(&[counts(0.0)]).show(ui).into()
|
||||
LevelsPanel::new("Levels", levels_at.bind(levels), channels).histograms(&[counts(0.0)]).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
//! Stories of Black & White, Channel Mixer and Selective Color: each editor's cases in one card.
|
||||
|
||||
use super::{BlackWhite, BlackWhiteEditor, ChannelMixer, ChannelMixerEditor, SelectiveColor, SelectiveColorEditor, SelectiveMethod};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
fn black_white(ui: &mut Ui, data: &mut StoryData, start: BlackWhite) -> StoryOutput {
|
||||
let value = data.value("value", start);
|
||||
BlackWhiteEditor::new("Black & White", Bind::bound(value)).show(ui).into()
|
||||
let (value, value_at) = data.value_at("value", start);
|
||||
BlackWhiteEditor::new("Black & White", value_at.bind(value)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(BlackWhiteEditor<'static>, covers = [Default], drive = Drive::Never, group = "Tint", title = "Default")]
|
||||
@@ -22,8 +21,8 @@ fn black_white_tinted(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
}
|
||||
|
||||
fn channel_mixer(ui: &mut Ui, data: &mut StoryData, start: ChannelMixer) -> StoryOutput {
|
||||
let value = data.value("value", start);
|
||||
ChannelMixerEditor::new("Channel Mixer", Bind::bound(value)).show(ui).into()
|
||||
let (value, value_at) = data.value_at("value", start);
|
||||
ChannelMixerEditor::new("Channel Mixer", value_at.bind(value)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ChannelMixerEditor<'static>, covers = [Default], drive = Drive::Never, group = "Outputs", title = "Color")]
|
||||
@@ -44,8 +43,8 @@ fn channel_mixer_over(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
}
|
||||
|
||||
fn selective_color(ui: &mut Ui, data: &mut StoryData, start: SelectiveColor) -> StoryOutput {
|
||||
let value = data.value("value", start);
|
||||
SelectiveColorEditor::new("Selective Color", Bind::bound(value)).show(ui).into()
|
||||
let (value, value_at) = data.value_at("value", start);
|
||||
SelectiveColorEditor::new("Selective Color", value_at.bind(value)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(SelectiveColorEditor<'static>, covers = [Default], drive = Drive::Never, group = "Methods", title = "Relative")]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use crate::ui::adjust::{AdjustContext, AdjustSession, ColorBalance, ColorBalanceEditor, ColorBalanceTone};
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Bind, Show as _, clicked};
|
||||
use craft_ui::contract::{Show as _, clicked};
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
@@ -21,10 +21,11 @@ struct Panel {
|
||||
/// Reset returns to the settings the panel found while edited, and to the defaults the next time.
|
||||
#[story(ColorBalanceEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_balance_properties(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let panel = data.value("panel", Panel { value: ColorBalance { shadows: [10.0, 0.0, -10.0], ..ColorBalance::default() }, ..Panel::default() });
|
||||
let (panel, panel_at) =
|
||||
data.value_at("panel", Panel { value: ColorBalance { shadows: [10.0, 0.0, -10.0], ..ColorBalance::default() }, ..Panel::default() });
|
||||
panel.pass += 1;
|
||||
panel.session.track(TARGET, panel.pass, &panel.value);
|
||||
let mut editor = ColorBalanceEditor::new("Color Balance", Bind::bound(&mut panel.value)).context(AdjustContext::properties(true));
|
||||
let mut editor = ColorBalanceEditor::new("Color Balance", panel_at.bind(&mut panel.value)).context(AdjustContext::properties(true));
|
||||
if let Some(tone) = panel.tone.take() {
|
||||
editor = editor.tone(tone);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
use super::{AdjustField, AdjustSliders, AdjustTrack};
|
||||
use crate::ui::adjust::AdjustWords;
|
||||
use crate::ui::adjust::style::{balance, mix, tones};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::runtime::env::UnitKind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -12,8 +11,8 @@ use egui::Ui;
|
||||
#[story(AdjustSliders<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn adjust_sliders(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let fields = AdjustField::exposure(&AdjustWords::default());
|
||||
let values = data.value("values", vec![0.0, 0.0, 1.0]);
|
||||
AdjustSliders::new("Exposure", &fields, Bind::bound(values)).show(ui).into()
|
||||
let (values, values_at) = data.value_at("values", vec![0.0, 0.0, 1.0]);
|
||||
AdjustSliders::new("Exposure", &fields, values_at.bind(values)).show(ui).into()
|
||||
}
|
||||
|
||||
/// A table with two-colour tracks.
|
||||
@@ -27,6 +26,6 @@ fn adjust_sliders_color_tracks(ui: &mut Ui, data: &mut StoryData) -> StoryOutput
|
||||
.unit_kind(UnitKind::Percent)
|
||||
.track(AdjustTrack::Colors(vec![tones::BLACK, mix::RANGES[0]])),
|
||||
];
|
||||
let values = data.value("colors", vec![0.0, 40.0]);
|
||||
AdjustSliders::new("Colors", &fields, Bind::bound(values)).show(ui).into()
|
||||
let (values, values_at) = data.value_at("colors", vec![0.0, 40.0]);
|
||||
AdjustSliders::new("Colors", &fields, values_at.bind(values)).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -1,18 +1,17 @@
|
||||
//! Stories of the point picker row: one picker armed, and the row in a colour mode without pickers.
|
||||
|
||||
use super::{TonePicker, TonePickerRow};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
#[story(TonePickerRow<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn tone_picker_row(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let armed = data.value("armed", Some(TonePicker::Gray));
|
||||
TonePickerRow::new(Bind::bound(armed)).show(ui).into()
|
||||
let (armed, armed_at) = data.value_at("armed", Some(TonePicker::Gray));
|
||||
TonePickerRow::new(armed_at.bind(armed)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(TonePickerRow<'static>, covers = [], drive = Drive::Never)]
|
||||
fn tone_picker_row_unavailable(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let armed = data.value("armed", None::<TonePicker>);
|
||||
TonePickerRow::new(Bind::bound(armed)).unavailable().show(ui).into()
|
||||
let (armed, armed_at) = data.value_at("armed", None::<TonePicker>);
|
||||
TonePickerRow::new(armed_at.bind(armed)).unavailable().show(ui).into()
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! Stories of the Blur Gallery's pins and the panel of the selected pin.
|
||||
|
||||
use craft_ui::canvas::RasterSource as _;
|
||||
use craft_ui::contract::{Bind, Show as _, Validity};
|
||||
use craft_ui::contract::{Show as _, Validity};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, story};
|
||||
use egui::{Ui, vec2};
|
||||
@@ -28,9 +28,9 @@ fn pin(x: f64, y: f64, amount: f64) -> BlurPin {
|
||||
/// The picture with the pins over it.
|
||||
fn on_picture(ui: &mut Ui, data: &mut StoryData, build: impl FnOnce(&MockImage) -> BlurPins) -> StoryOutput {
|
||||
let image = MockImage::default();
|
||||
let pins = data.value(PINS, build(&image));
|
||||
let (pins, pins_at) = data.value_at(PINS, build(&image));
|
||||
story_canvas(ui, Some(&image), StoryView::Fit, |ui, at| {
|
||||
StoryOutput::from(BlurPinsOverlay::new("Blur pins", Bind::bound(&mut *pins)).show_at(ui, at))
|
||||
StoryOutput::from(BlurPinsOverlay::new("Blur pins", pins_at.bind(&mut *pins)).show_at(ui, at))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ fn field(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(BlurPinsOverlay<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn too_many_pins(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let image = MockImage::default();
|
||||
let pins = data.value(PINS, {
|
||||
let (pins, pins_at) = data.value_at(PINS, {
|
||||
let mut pins = BlurPins::new(BlurKind::Field, bounds(&image), pin(0.5, 0.5, 30.0));
|
||||
pins.pins = vec![pin(0.22, 0.55, 8.0), pin(0.5, 0.4, 30.0), pin(0.78, 0.62, 30.0)];
|
||||
pins.selected = Some(1);
|
||||
@@ -57,7 +57,7 @@ fn too_many_pins(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
});
|
||||
let few = |pins: &BlurPins| if pins.pins.len() > MOST_PINS { Validity::Refuse(Message::new("There are too many pins")) } else { Validity::Ok };
|
||||
story_canvas(ui, Some(&image), StoryView::Fit, |ui, at| {
|
||||
StoryOutput::from(BlurPinsOverlay::new("Blur pins", Bind::bound(&mut *pins).check(few)).show_at(ui, at))
|
||||
StoryOutput::from(BlurPinsOverlay::new("Blur pins", pins_at.bind(&mut *pins).check(few)).show_at(ui, at))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::dialog::stories::hosted;
|
||||
use craft_ui::runtime::env::Label;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
@@ -29,22 +28,34 @@ fn document() -> [u32; 2] {
|
||||
|
||||
#[story(ColorRangeDialog<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn color_range_dialog(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("value", sampled());
|
||||
let (value, value_at) = data.value_at("value", sampled());
|
||||
let picture = MockImage::new(PROXY);
|
||||
ColorRangeDialog::new("Color Range", Bind::bound(value)).mask(&picture).image(&picture).picture_scale(SCALE).document(document()).show(ui).into()
|
||||
ColorRangeDialog::new("Color Range", value_at.bind(value))
|
||||
.mask(&picture)
|
||||
.image(&picture)
|
||||
.picture_scale(SCALE)
|
||||
.document(document())
|
||||
.show(ui)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[story(ColorRangeDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_range_dialog_midtones(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("value", ColorRangeValue { select: ColorRangeSelect::Midtones, ..ColorRangeValue::default() });
|
||||
let (value, value_at) = data.value_at("value", ColorRangeValue { select: ColorRangeSelect::Midtones, ..ColorRangeValue::default() });
|
||||
let picture = MockImage::new(PROXY);
|
||||
ColorRangeDialog::new("Color Range", Bind::bound(value)).mask(&picture).image(&picture).picture_scale(SCALE).document(document()).show(ui).into()
|
||||
ColorRangeDialog::new("Color Range", value_at.bind(value))
|
||||
.mask(&picture)
|
||||
.image(&picture)
|
||||
.picture_scale(SCALE)
|
||||
.document(document())
|
||||
.show(ui)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[story(ColorRangeDialog<'static>, covers = [], drive = Drive::Never)]
|
||||
fn color_range_dialog_failed(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let value = data.value("value", ColorRangeValue::default());
|
||||
ColorRangeDialog::new("Color Range", Bind::bound(value))
|
||||
let (value, value_at) = data.value_at("value", ColorRangeValue::default());
|
||||
ColorRangeDialog::new("Color Range", value_at.bind(value))
|
||||
.picture_scale(SCALE)
|
||||
.document(document())
|
||||
.error(Label::from("The preview could not be rendered."))
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::graph::{CurveGraph, PLOT};
|
||||
use super::{Curve, CurveChannel, CurveEditor, CurvePreview, ToneRamp};
|
||||
use crate::ui::histogram::{ChannelColor, HistogramData};
|
||||
use craft_behavior::Mixed;
|
||||
use craft_ui::contract::{Bind, Show as _, Validity};
|
||||
use craft_ui::contract::{Show as _, Validity};
|
||||
use craft_ui::runtime::env::Message;
|
||||
use craft_ui::style::DataColor;
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, story};
|
||||
@@ -44,8 +44,8 @@ fn curve_editor(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
)
|
||||
.clone();
|
||||
let histogram = HistogramData::tone(&story_bins(0.0), ChannelColor::Neutral);
|
||||
let curve = data.value("curve", bent());
|
||||
let output = CurveEditor::new("Curve", Bind::bound(curve))
|
||||
let (curve, curve_at) = data.value_at("curve", bent());
|
||||
let output = CurveEditor::new("Curve", curve_at.bind(curve))
|
||||
.channels(&channels())
|
||||
.overlays(&overlays)
|
||||
.histogram(&histogram)
|
||||
@@ -57,24 +57,24 @@ fn curve_editor(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// Pencil mode: a drag draws one output per input level.
|
||||
#[story(CurveEditor<'static>, covers = [], drive = Drive::Drag(Grip::new(PLOT)))]
|
||||
fn curve_editor_pencil(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let curve = data.value("drawn", Curve::Map((0..=255).map(|k| k as f32).collect()));
|
||||
CurveEditor::new("Curve", Bind::bound(curve)).pencil().show(ui).into()
|
||||
let (curve, curve_at) = data.value_at("drawn", Curve::Map((0..=255).map(|k| k as f32).collect()));
|
||||
CurveEditor::new("Curve", curve_at.bind(curve)).pencil().show(ui).into()
|
||||
}
|
||||
|
||||
/// A contour: corner points and fields in percent; the Corner check box toggles the selected point.
|
||||
#[story(CurveEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn curve_editor_corners(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let points = vec![[0.0, 0.0], [64.0, 160.0], [128.0, 96.0], [192.0, 224.0], [255.0, 255.0]];
|
||||
let curve = data.value("contour", Curve::from_parts(points, vec![false, false, true, false, false]));
|
||||
CurveEditor::new("Contour", Bind::bound(curve)).corners().percent().show(ui).into()
|
||||
let (curve, curve_at) = data.value_at("contour", Curve::from_parts(points, vec![false, false, true, false, false]));
|
||||
CurveEditor::new("Contour", curve_at.bind(curve)).corners().percent().show(ui).into()
|
||||
}
|
||||
|
||||
/// Fields in percent of the levels, with the selection kept by the host.
|
||||
#[story(CurveEditor<'static>, covers = [], drive = Drive::Never)]
|
||||
fn curve_editor_percent(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let selected = *data.value("selected", Some(1usize));
|
||||
let curve = data.value("percent", bent());
|
||||
let output = CurveEditor::new("Curve", Bind::bound(curve)).percent().selection(selected).show(ui);
|
||||
let (curve, curve_at) = data.value_at("percent", bent());
|
||||
let output = CurveEditor::new("Curve", curve_at.bind(curve)).percent().selection(selected).show(ui);
|
||||
*data.value("selected", Some(1usize)) = output.selected;
|
||||
output.into()
|
||||
}
|
||||
@@ -82,12 +82,12 @@ fn curve_editor_percent(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// The plot of the curve editor alone.
|
||||
#[story(CurveGraph<'static>, covers = [Default], drive = Drive::Drag(Grip::new(PLOT)))]
|
||||
fn curve_graph(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
CurveGraph::new("Curve", Bind::bound(data.value("curve", bent()))).show(ui).into()
|
||||
CurveGraph::new("Curve", data.bind("curve", bent())).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(CurveGraph<'static>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn curve_graph_that_differs(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
CurveGraph::new("Curve", Bind::bound_mixed(data.value("mixed", Mixed::<Curve>::Mixed))).show(ui).into()
|
||||
CurveGraph::new("Curve", data.bind_mixed("mixed", Mixed::<Curve>::Mixed)).show(ui).into()
|
||||
}
|
||||
|
||||
/// A graph that refuses a curve of more than two points.
|
||||
@@ -96,7 +96,7 @@ fn curve_graph_that_is_refused(ui: &mut Ui, data: &mut StoryData) -> StoryOutput
|
||||
let refuse = |curve: &Curve| {
|
||||
if curve.points().is_some_and(|points| points.len() > 2) { Validity::Refuse(Message::new("Too many points")) } else { Validity::Ok }
|
||||
};
|
||||
CurveGraph::new("Curve", Bind::bound(data.value("refused", bent())).check(refuse)).show(ui).into()
|
||||
CurveGraph::new("Curve", data.bind("refused", bent()).check(refuse)).show(ui).into()
|
||||
}
|
||||
|
||||
/// One curve, read-only.
|
||||
|
||||
@@ -12,7 +12,6 @@ use egui::Ui;
|
||||
|
||||
use craft_behavior::kurbo::Rect;
|
||||
use craft_ui::canvas::RasterSource;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::dialog::stories::hosted;
|
||||
use craft_ui::dialog::{FullWindowView, HostedWorkspace};
|
||||
use craft_ui::runtime::pending::{Job, Pending};
|
||||
@@ -150,14 +149,14 @@ fn workspace_with_the_preview_failed(ui: &mut Ui, data: &mut StoryData) -> Story
|
||||
|
||||
#[story(FillPanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let settings = data.value("settings", FillSettings::default());
|
||||
FillPanel::new(Bind::bound(settings), SamplingMode::Auto).show(ui).into()
|
||||
let (settings, settings_at) = data.value_at("settings", FillSettings::default());
|
||||
FillPanel::new(settings_at.bind(settings), SamplingMode::Auto).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(FillPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
fn panel_with_an_error(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let settings = data.value("settings", FillSettings::default());
|
||||
FillPanel::new(Bind::bound(settings), SamplingMode::Custom)
|
||||
let (settings, settings_at) = data.value_at("settings", FillSettings::default());
|
||||
FillPanel::new(settings_at.bind(settings), SamplingMode::Custom)
|
||||
.error(Some("at most 1000 sampling strokes: undo some, or reset the sampling area"))
|
||||
.show(ui)
|
||||
.into()
|
||||
|
||||
@@ -18,7 +18,7 @@ use super::session::{FillLimit, FillLimits, FillSession, FillStrokeEvent, Sampli
|
||||
use crate::ui::select_mask::EditMode;
|
||||
|
||||
/// The tools of Content-Aware Fill's strip: Sampling Brush (B), Lasso (L), Hand (H), Zoom (Z).
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub enum FillTool {
|
||||
/// The Sampling Brush.
|
||||
|
||||
@@ -8,7 +8,7 @@ use std::time::Duration;
|
||||
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::canvas::{PixelRect, RasterSource};
|
||||
use craft_ui::contract::{Bind, Job};
|
||||
use craft_ui::contract::Job;
|
||||
use craft_ui::dialog::{FullWindowWorkspace as _, WorkspaceCx};
|
||||
use craft_ui::patterns::form_dialogs::{Param, ParamKind};
|
||||
use craft_ui::primitives::textures::{FakeThumbSource, ThumbSource, ThumbnailOptions, Thumbnails};
|
||||
@@ -153,7 +153,7 @@ fn workspace(ui: &mut Ui, data: &mut StoryData, rendering: bool) -> StoryOutput
|
||||
let session = data.value("session", start()).clone();
|
||||
let mut workspace = FilterGalleryWorkspace::new(FilterGalleryOpen::new(image.size(), "Photo", session));
|
||||
let source: &dyn FilterGallerySource = &MockSource { image, rendering, thumbs: FakeThumbSource::new() };
|
||||
let pass = workspace.show(ui, WorkspaceCx::new(source, Bind::bound(data.value("open", true))));
|
||||
let pass = workspace.show(ui, WorkspaceCx::new(source, data.bind("open", true)));
|
||||
// A swatch press asks the app for a color; the story has no picker.
|
||||
for event in &pass.events {
|
||||
if let FilterGalleryEvent::PickColor(request) = event {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Stories of `BlendIfBar`: halves together (one triangle per pair) and halves apart (split handles).
|
||||
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::display::{Shade, Text};
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
@@ -12,12 +12,12 @@ use crate::layer_style::BlendIfRange;
|
||||
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([30, 30, 220, 220]));
|
||||
BlendIfBar::new("Underlying Layer", Bind::bound(range)).show(ui).into()
|
||||
let (range, range_at) = data.value_at("range", BlendIfRange([30, 30, 220, 220]));
|
||||
BlendIfBar::new("Underlying Layer", range_at.bind(range)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(BlendIfBar<'static>, covers = [Default], drive = Drive::Never, group = "Handles", title = "Split pairs (Alt-drag splits a pair)")]
|
||||
fn blend_if_bar_split(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let range = data.value("range", BlendIfRange([10, 60, 190, 240]));
|
||||
BlendIfBar::new("This Layer", Bind::bound(range)).show(ui).into()
|
||||
let (range, range_at) = data.value_at("range", BlendIfRange([10, 60, 190, 240]));
|
||||
BlendIfBar::new("This Layer", range_at.bind(range)).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Stories of the contour field: the built-in contours and a user's, under the host's "Contour" caption.
|
||||
|
||||
use craft_ui::contract::{Bind, ShowContainer as _};
|
||||
use craft_ui::contract::ShowContainer as _;
|
||||
use craft_ui::form::Field;
|
||||
use craft_ui::patterns::presets::PresetState;
|
||||
use craft_ui::runtime::env::Env;
|
||||
@@ -21,11 +21,11 @@ fn field(ui: &mut Ui, data: &mut StoryData, start: Contour, anti_alias: bool) ->
|
||||
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", (start, PresetState::<ContourKey>::new(), Some(anti_alias)));
|
||||
let ((contour, state, anti_alias), field_at) = data.value_at("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))
|
||||
ContourField::new("Contour", field_at.bind(&mut *contour), &rows, field_at.bind(&mut *state))
|
||||
.user(&user)
|
||||
.anti_alias(Bind::bound(&mut *anti_alias))
|
||||
.anti_alias(field_at.bind(&mut *anti_alias))
|
||||
.show(ui)
|
||||
});
|
||||
let output = shown.inner.map(StoryOutput::from).unwrap_or_default();
|
||||
|
||||
@@ -12,7 +12,6 @@ use egui::{Color32, ColorImage, Ui};
|
||||
use craft_behavior::PixelSize;
|
||||
use craft_behavior::kurbo::Point;
|
||||
use craft_ui::canvas::{PixelRect, RasterSource};
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::dialog::HostedWorkspace;
|
||||
use craft_ui::dialog::stories::hosted;
|
||||
use craft_ui::primitives::Revision;
|
||||
@@ -181,8 +180,8 @@ fn workspace_with_the_mesh_shown(ui: &mut Ui, data: &mut StoryData) -> StoryOutp
|
||||
|
||||
#[story(LiquifyPanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let settings = data.value("settings", LiquifySettings::default());
|
||||
LiquifyPanel::new(Bind::bound(settings)).show(ui).into()
|
||||
let (settings, settings_at) = data.value_at("settings", LiquifySettings::default());
|
||||
LiquifyPanel::new(settings_at.bind(settings)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(LiquifyPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
@@ -194,7 +193,7 @@ fn panel_with_the_backdrop_shown(ui: &mut Ui, data: &mut StoryData) -> StoryOutp
|
||||
backdrop_opacity: BACKDROP_OPACITY,
|
||||
..LiquifySettings::default()
|
||||
};
|
||||
let settings = data.value("settings", shown);
|
||||
let (settings, settings_at) = data.value_at("settings", shown);
|
||||
let layers = [(LAYER_SKY, "Sky".to_owned()), (LAYER_HOUSE, "House".to_owned())];
|
||||
LiquifyPanel::new(Bind::bound(settings)).layers(&layers).show(ui).into()
|
||||
LiquifyPanel::new(settings_at.bind(settings)).layers(&layers).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ use super::session::{LiquifyStroke, StrokeEvent};
|
||||
/// The tools of Liquify's strip, in strip order, with Photoshop's letters. Serialised with the
|
||||
/// engine's names (`forwardWarp`, `twirlCw`, `lassoMask`, …) so a [`LiquifyStroke`] passes to
|
||||
/// PhotoCraft's engine unchanged.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize, craft_ui::contract::MemoProps)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[non_exhaustive]
|
||||
pub enum LiquifyTool {
|
||||
|
||||
@@ -164,14 +164,14 @@ fn floating_scope(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(RawDevelopPanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let settings = data.value("settings", RawDevelopSettings::default());
|
||||
RawDevelopPanel::new(Bind::bound(settings)).show(ui).into()
|
||||
let (settings, settings_at) = data.value_at("settings", RawDevelopSettings::default());
|
||||
RawDevelopPanel::new(settings_at.bind(settings)).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(RawDevelopPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
fn panel_with_demosaic(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let settings = data.value("settings", RawDevelopSettings::default());
|
||||
RawDevelopPanel::new(Bind::bound(settings)).demosaic(Demosaic::Ahd).show(ui).into()
|
||||
let (settings, settings_at) = data.value_at("settings", RawDevelopSettings::default());
|
||||
RawDevelopPanel::new(settings_at.bind(settings)).demosaic(Demosaic::Ahd).show(ui).into()
|
||||
}
|
||||
|
||||
/// A click on the Color Mixer's Saturation tab, the second of its three.
|
||||
@@ -183,8 +183,8 @@ fn saturation_tab(fixture: &mut Fixture) {
|
||||
|
||||
#[story(RawDevelopPanel<'static>, covers = [], drive = Drive::Custom(saturation_tab))]
|
||||
fn panel_with_color_mixer_saturation(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let settings = data.value("settings", RawDevelopSettings::default());
|
||||
RawDevelopPanel::new(Bind::bound(settings)).show(ui).into()
|
||||
let (settings, settings_at) = data.value_at("settings", RawDevelopSettings::default());
|
||||
RawDevelopPanel::new(settings_at.bind(settings)).show(ui).into()
|
||||
}
|
||||
|
||||
/// The scope state of the strip stories: Expanded, so the zone values and statistics show.
|
||||
@@ -225,7 +225,7 @@ fn floating_scope_window(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(RawFilmstrip<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn filmstrip(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let items = raws();
|
||||
let current = data.value("current", 1_usize);
|
||||
RawFilmstrip::new(&items, Bind::bound(current)).show(ui);
|
||||
let (current, current_at) = data.value_at("current", 1_usize);
|
||||
RawFilmstrip::new(&items, current_at.bind(current)).show(ui);
|
||||
StoryOutput::default()
|
||||
}
|
||||
|
||||
@@ -208,12 +208,12 @@ fn first_values() -> ZoneValues {
|
||||
#[story(ScopePanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn tone_zones(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let start = (ScopePanelState { settings: view(ScopeView::Expanded), ..ScopePanelState::default() }, first_values());
|
||||
let (state, values) = data.value("zones", start);
|
||||
let ((state, values), zones_at) = data.value_at("zones", start);
|
||||
let curves = curves(Mode::Rgb, 0.0);
|
||||
let channels = scope_channels(&curves);
|
||||
let frame = ScopeFrame::histogram(HistogramSet::new(&channels));
|
||||
let (zones, scales, texts) = (ToneZone::CAMERA_RAW, zone_scales(), zone_texts(Some(&*values)));
|
||||
ScopePanel::new(state).frame(&frame).zones(&zones, &scales, &texts, Bind::bound(values)).show(ui).into()
|
||||
ScopePanel::new(state).frame(&frame).zones(&zones, &scales, &texts, zones_at.bind(values)).show(ui).into()
|
||||
}
|
||||
|
||||
/// Generated pixels in a skin cluster, a sky and some foliage, with a few saturated ones.
|
||||
@@ -315,21 +315,21 @@ fn clipping_warnings_on(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
|
||||
#[story(ClipWarning<'static>, covers = [Default], drive = Drive::Activate)]
|
||||
fn clip_warning(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let on = data.value("on", true);
|
||||
ClipWarning::new("Highlight Clipping Warning (O)", Bind::bound(on), ChannelMask::R).show(ui).into()
|
||||
let (on, on_at) = data.value_at("on", true);
|
||||
ClipWarning::new("Highlight Clipping Warning (O)", on_at.bind(on), ChannelMask::R).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ClipWarning<'static>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn clip_warning_that_differs(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let on = data.value("mixed", Mixed::<bool>::Mixed);
|
||||
ClipWarning::new("Highlight Clipping Warning (O)", Bind::bound_mixed(on), ChannelMask::R).show(ui).into()
|
||||
let (on, on_at) = data.value_at("mixed", Mixed::<bool>::Mixed);
|
||||
ClipWarning::new("Highlight Clipping Warning (O)", on_at.bind_mixed(on), ChannelMask::R).show(ui).into()
|
||||
}
|
||||
|
||||
#[story(ClipWarning<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn clip_warning_that_is_refused(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let on = data.value("refused", false);
|
||||
let (on, on_at) = data.value_at("refused", false);
|
||||
let refuse = |_: &bool| Validity::Refuse(Message::new("Not available"));
|
||||
ClipWarning::new("Highlight Clipping Warning (O)", Bind::bound(on).check(refuse), ChannelMask::R).show(ui).into()
|
||||
ClipWarning::new("Highlight Clipping Warning (O)", on_at.bind(on).check(refuse), ChannelMask::R).show(ui).into()
|
||||
}
|
||||
|
||||
/// The zones of a story over a picture, with each zone's scale and value text, and the story's canvas.
|
||||
@@ -343,23 +343,23 @@ fn zones_story(ui: &mut Ui, mut value: Bind<'_, ZoneValues>, texts: &[Label]) ->
|
||||
|
||||
#[story(ToneZones<'static>, covers = [Default], drive = Drive::Drag(Grip::part(ZONE.at(1)).toward(vec2(1.0, 0.0))))]
|
||||
fn zones_over_a_plot(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("values", first_values());
|
||||
let (values, values_at) = data.value_at("values", first_values());
|
||||
let texts = zone_texts(Some(&*values));
|
||||
zones_story(ui, Bind::bound(values), &texts)
|
||||
zones_story(ui, values_at.bind(values), &texts)
|
||||
}
|
||||
|
||||
#[story(ToneZones<'static>, covers = [Mixed], drive = Drive::Never)]
|
||||
fn zones_that_differ(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("mixed", Mixed::<ZoneValues>::Mixed);
|
||||
zones_story(ui, Bind::bound_mixed(values), &zone_texts(None))
|
||||
let (values, values_at) = data.value_at("mixed", Mixed::<ZoneValues>::Mixed);
|
||||
zones_story(ui, values_at.bind_mixed(values), &zone_texts(None))
|
||||
}
|
||||
|
||||
#[story(ToneZones<'static>, covers = [Invalid], drive = Drive::Never)]
|
||||
fn zones_that_are_refused(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let values = data.value("refused", first_values());
|
||||
let (values, values_at) = data.value_at("refused", first_values());
|
||||
let texts = zone_texts(Some(&*values));
|
||||
let refuse = |_: &ZoneValues| Validity::Refuse(Message::new("Not available"));
|
||||
zones_story(ui, Bind::bound(values).check(refuse), &texts)
|
||||
zones_story(ui, values_at.bind(values).check(refuse), &texts)
|
||||
}
|
||||
|
||||
#[story(ClippingOverlay<'static>, covers = [Default], drive = Drive::Never)]
|
||||
|
||||
@@ -84,7 +84,7 @@ impl<T> EditPhase<T> {
|
||||
|
||||
/// The tools of Select and Mask's strip, with Photoshop's letters. Quick Selection and Object
|
||||
/// Selection share the W slot, Lasso and Polygonal Lasso the L slot.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub enum SelectMaskTool {
|
||||
/// W.
|
||||
|
||||
@@ -47,7 +47,7 @@ pub enum VanishingPointStripTool {
|
||||
}
|
||||
|
||||
/// A slot of the strip.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
pub(super) enum Pick {
|
||||
EditPlane,
|
||||
CreatePlane,
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
use craft_behavior::geometry::quad::Homography;
|
||||
use craft_behavior::kurbo::Point;
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, story};
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, ValueAt, story};
|
||||
use egui::{Ui, vec2};
|
||||
|
||||
use super::overlay::CORNER;
|
||||
@@ -54,27 +54,27 @@ fn warped_by(planes: &[Plane]) -> impl Fn(Point) -> Point + use<> {
|
||||
|
||||
/// Shows `planes` over the transform preview stage: the layer's picture drawn through the planes (in Layout the
|
||||
/// planes' targets are their sources, so it stays), the planes over it.
|
||||
fn on_canvas(ui: &mut Ui, planes: &mut Vec<Plane>, mode: PlaneMode) -> StoryOutput {
|
||||
fn on_canvas(ui: &mut Ui, planes: &mut Vec<Plane>, planes_at: ValueAt<'_>, mode: PlaneMode) -> StoryOutput {
|
||||
let doc = Document::standard();
|
||||
let textures = doc.textures();
|
||||
let layer = doc.layer();
|
||||
doc.canvas(ui, Zoom::Fit, None, |ui, at| {
|
||||
let map = warped_by(planes);
|
||||
draw(ui, at, &doc, &textures, PreviewMap::function(layer, PreviewQuality::PLANE_CELLS, &map), 1.0, false);
|
||||
StoryOutput::from(PerspectiveWarp::new("Planes", Bind::bound(&mut *planes), mode, 0).show_at(ui, at))
|
||||
StoryOutput::from(PerspectiveWarp::new("Planes", planes_at.bind(&mut *planes), mode, 0).show_at(ui, at))
|
||||
})
|
||||
}
|
||||
|
||||
#[story(PerspectiveWarp<'static>, covers = [Default], drive = Drive::Drag(Grip::part(CORNER.at(1)).toward(vec2(1.0, -1.0))), group = "Planes", title = "Layout, two linked planes")]
|
||||
fn two_linked_planes_in_layout(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let planes = data.value("planes", two_linked_planes(0.0));
|
||||
on_canvas(ui, planes, PlaneMode::Layout)
|
||||
let (planes, planes_at) = data.value_at("planes", two_linked_planes(0.0));
|
||||
on_canvas(ui, planes, planes_at, PlaneMode::Layout)
|
||||
}
|
||||
|
||||
#[story(PerspectiveWarp<'static>, covers = [Default], drive = Drive::Drag(Grip::part(CORNER.at(1)).toward(vec2(1.0, -1.0))), group = "Planes", title = "Warp, the picture follows")]
|
||||
fn two_linked_planes_in_warp(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let planes = data.value("warped", two_linked_planes(PULL));
|
||||
on_canvas(ui, planes, PlaneMode::Warp)
|
||||
let (planes, planes_at) = data.value_at("warped", two_linked_planes(PULL));
|
||||
on_canvas(ui, planes, planes_at, PlaneMode::Warp)
|
||||
}
|
||||
|
||||
/// A session over two linked planes, in `mode`.
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
//! deformation of a grid), and the options bar.
|
||||
|
||||
use craft_behavior::kurbo::{Point, Rect as DocRect, Vec2};
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, story};
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::testing::{Drive, Grip, StoryData, StoryOutput, ValueAt, story};
|
||||
use egui::{Ui, vec2};
|
||||
|
||||
use super::{Pin, PinDensity, PinEdit, PinMeshView, PinSolver, PinWarp, PinWarpBar, PinWarpOptions, PinWarpSession, PinWarpSettings};
|
||||
@@ -107,9 +107,8 @@ pub(crate) fn sample_pins(layer: DocRect) -> Vec<Pin> {
|
||||
}
|
||||
|
||||
/// Shows `pins` over the transform preview stage: the layer's picture drawn by the real `TransformPreview` through
|
||||
/// the solver's mesh as the pins deform it, the pins over it; the selection the pins report is kept.
|
||||
fn on_canvas(ui: &mut Ui, data: &mut StoryData, pins: &mut Vec<Pin>, show_mesh: bool) -> StoryOutput {
|
||||
let selected = data.value("selected", vec![1usize]).clone();
|
||||
/// the solver's mesh as the pins deform it, the pins over it; the selection the pins report is kept in `selected`.
|
||||
fn on_canvas(ui: &mut Ui, pins: &mut Vec<Pin>, pins_at: ValueAt<'_>, selected: &mut Vec<usize>, show_mesh: bool) -> StoryOutput {
|
||||
let doc = Document::standard();
|
||||
let textures = doc.textures();
|
||||
let layer = layer();
|
||||
@@ -117,12 +116,12 @@ fn on_canvas(ui: &mut Ui, data: &mut StoryData, pins: &mut Vec<Pin>, show_mesh:
|
||||
let shown = doc.canvas(ui, Zoom::Fit, None, |ui, at| {
|
||||
let solver = IdwSolver::solved(layer, pins);
|
||||
draw(ui, at, &doc, &textures, PreviewMap::pins(solver.view(), layer), 1.0, false);
|
||||
let output = PinWarp::new("Pins", Bind::bound(&mut *pins), solver.view()).selected_pins(&selected).show_mesh(show_mesh).show_at(ui, at);
|
||||
let output = PinWarp::new("Pins", pins_at.bind(&mut *pins), solver.view()).selected_pins(selected).show_mesh(show_mesh).show_at(ui, at);
|
||||
reported = output.select.clone();
|
||||
StoryOutput::from(output)
|
||||
});
|
||||
if let Some(select) = reported {
|
||||
*data.value("selected", vec![1usize]) = select;
|
||||
*selected = select;
|
||||
}
|
||||
shown
|
||||
}
|
||||
@@ -135,10 +134,8 @@ fn pins_with_a_fixed_turn() -> Vec<Pin> {
|
||||
|
||||
#[story(PinWarp<'static>, covers = [Default], drive = Drive::Drag(Grip::part(super::overlay::PIN.at(1)).toward(vec2(1.0, 0.0))))]
|
||||
fn pins_with_a_fixed_rotation(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut pins = data.value("pins", pins_with_a_fixed_turn()).clone();
|
||||
let output = on_canvas(ui, data, &mut pins, true);
|
||||
*data.value("pins", pins_with_a_fixed_turn()) = pins;
|
||||
output
|
||||
let ((pins, pins_at), (selected, _)) = data.pair_at(("pins", pins_with_a_fixed_turn()), ("selected", vec![1usize]));
|
||||
on_canvas(ui, pins, pins_at, selected, true)
|
||||
}
|
||||
|
||||
/// A session on the sample pins with pin 1 selected and, when `fixed`, its rotation fixed.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use craft_behavior::kurbo::{Point, Rect as DocRect};
|
||||
use craft_ui::bars::{Bar, BarKind};
|
||||
use craft_ui::contract::{Bind, Show as _, ShowContainer as _};
|
||||
use craft_ui::contract::{Show as _, ShowContainer as _};
|
||||
use craft_ui::testing::{Drive, Fixture, Grip, StoryData, StoryOutput, pointer, story};
|
||||
use egui::{Ui, vec2};
|
||||
|
||||
@@ -38,26 +38,26 @@ fn hover_middle(fixture: &mut Fixture) {
|
||||
|
||||
#[story(WarpGrid<'static>, covers = [Default])]
|
||||
fn one_patch_with_thirds(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mesh = data.value("mesh", WarpMesh::identity(picture(), 1, 1));
|
||||
on_canvas(ui, mesh, |ui, rect, mesh| WarpGrid::new("Warp", Bind::bound(mesh), picture()).show_at(ui, rect))
|
||||
let (mesh, mesh_at) = data.value_at("mesh", WarpMesh::identity(picture(), 1, 1));
|
||||
on_canvas(ui, mesh, |ui, rect, mesh| WarpGrid::new("Warp", mesh_at.bind(mesh), picture()).show_at(ui, rect))
|
||||
}
|
||||
|
||||
#[story(WarpGrid<'static>, covers = [Default], drive = Drive::Drag(Grip::part(POINT.at(0)).toward(vec2(24.0, 16.0))))]
|
||||
fn three_by_three_after_a_drag(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mesh = data.value("mesh", WarpMesh::identity(picture(), 3, 3));
|
||||
on_canvas(ui, mesh, |ui, rect, mesh| WarpGrid::new("Warp", Bind::bound(mesh), picture()).show_at(ui, rect))
|
||||
let (mesh, mesh_at) = data.value_at("mesh", WarpMesh::identity(picture(), 3, 3));
|
||||
on_canvas(ui, mesh, |ui, rect, mesh| WarpGrid::new("Warp", mesh_at.bind(mesh), picture()).show_at(ui, rect))
|
||||
}
|
||||
|
||||
#[story(WarpGrid<'static>, covers = [Default], drive = Drive::Custom(hover_middle))]
|
||||
fn cross_split_over_a_patch(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mesh = data.value("mesh", WarpMesh::identity(picture(), 3, 3));
|
||||
on_canvas(ui, mesh, |ui, rect, mesh| WarpGrid::new("Warp", Bind::bound(mesh), picture()).split(WarpSplit::Cross).show_at(ui, rect))
|
||||
let (mesh, mesh_at) = data.value_at("mesh", WarpMesh::identity(picture(), 3, 3));
|
||||
on_canvas(ui, mesh, |ui, rect, mesh| WarpGrid::new("Warp", mesh_at.bind(mesh), picture()).split(WarpSplit::Cross).show_at(ui, rect))
|
||||
}
|
||||
|
||||
#[story(WarpGrid<'static>, covers = [Default])]
|
||||
fn lines_only(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mesh = data.value("mesh", WarpMesh::identity(picture(), 3, 3));
|
||||
on_canvas(ui, mesh, |ui, rect, mesh| WarpGrid::new("Warp", Bind::bound(mesh), picture()).lines_only().show_at(ui, rect))
|
||||
let (mesh, mesh_at) = data.value_at("mesh", WarpMesh::identity(picture(), 3, 3));
|
||||
on_canvas(ui, mesh, |ui, rect, mesh| WarpGrid::new("Warp", mesh_at.bind(mesh), picture()).lines_only().show_at(ui, rect))
|
||||
}
|
||||
|
||||
/// The app's style list: None, four presets, Custom and Cylinder.
|
||||
|
||||
@@ -58,7 +58,7 @@ use serde_json::Value;
|
||||
use crate::ui::live_preview::settings_hash;
|
||||
|
||||
/// The tools of the strip.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub enum WideAngleTool {
|
||||
/// A.
|
||||
|
||||
@@ -9,7 +9,7 @@ use std::time::Duration;
|
||||
use craft_behavior::PixelSize;
|
||||
use craft_behavior::kurbo::Point;
|
||||
use craft_ui::canvas::RasterSource;
|
||||
use craft_ui::contract::{Bind, Show as _};
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::dialog::stories::hosted;
|
||||
use craft_ui::dialog::{FullWindowCanvas, FullWindowView, HostedWorkspace};
|
||||
use craft_ui::runtime::pending::Job;
|
||||
@@ -119,9 +119,9 @@ fn workspace_corrected(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn lines(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let session = session();
|
||||
let pictures = pictures();
|
||||
let view = data.value("view", FullWindowView::new());
|
||||
let (view, view_at) = data.value_at("view", FullWindowView::new());
|
||||
let mut seen = None;
|
||||
let canvas = FullWindowCanvas::new(Bind::bound(view), pictures.source()).controls(|ui, rect| {
|
||||
let canvas = FullWindowCanvas::new(view_at.bind(view), pictures.source()).controls(|ui, rect| {
|
||||
seen = Some(
|
||||
ConstraintLines::new("Constraint lines", &session, &Bowed)
|
||||
.picture([IMAGE.width, IMAGE.height], [IMAGE.width, IMAGE.height])
|
||||
@@ -135,6 +135,6 @@ fn lines(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(WideAnglePanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn panel(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let session = session();
|
||||
let preview = data.value("preview", true);
|
||||
WideAnglePanel::new(&session, Bind::bound(preview)).show(ui).into()
|
||||
let (preview, preview_at) = data.value_at("preview", true);
|
||||
WideAnglePanel::new(&session, preview_at.bind(preview)).show(ui).into()
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use craft_imaging::ui::transform_preview::{
|
||||
};
|
||||
use craft_imaging::ui::warp::WarpMesh;
|
||||
use craft_ui::canvas::{Canvas, PixelRect};
|
||||
use craft_ui::contract::{Lazy, Show as _, ShowContainer as _};
|
||||
use craft_ui::contract::{MemoProps, MemoView, PlainData, Show as _, ShowContainer as _, Tracked};
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use egui::{Color32, ColorImage, Shape};
|
||||
|
||||
@@ -385,15 +385,38 @@ type PaintedPreview = (Rc<PreviewTextures>, f32);
|
||||
/// The texture and size a painted preview showed.
|
||||
type ShownPreview = (egui::TextureId, [f32; 2]);
|
||||
|
||||
/// What the next frames paint: the previews, each at its scale, and the display every one is converted for.
|
||||
#[derive(Default, PlainData)]
|
||||
struct Painting {
|
||||
#[plain_data(assume = "the previews' textures are a cache: what they show follows their pixels, which do not change")]
|
||||
previews: Vec<PaintedPreview>,
|
||||
#[plain_data(assume = "a display is replaced, never changed: its key follows its conversion")]
|
||||
display: Option<PreviewDisplay>,
|
||||
}
|
||||
|
||||
/// What each painted preview shows: the texture and uv extent `PreviewTextures::pick` gives.
|
||||
fn picks(ui: &egui::Ui, painting: &Painting) -> Vec<Option<ShownPreview>> {
|
||||
let display = painting.display.as_ref();
|
||||
painting.previews.iter().map(|(textures, scale)| textures.pick(ui.ctx(), PreviewTextures::choose(1.0, *scale, false), display)).collect()
|
||||
}
|
||||
|
||||
/// A memoized view of the painting.
|
||||
#[derive(MemoProps)]
|
||||
struct Previews<'a> {
|
||||
painting: &'a Tracked<Painting>,
|
||||
}
|
||||
|
||||
fn previews(props: &mut Previews<'_>, ui: &mut egui::Ui) -> Vec<Option<ShownPreview>> {
|
||||
picks(ui, props.painting)
|
||||
}
|
||||
|
||||
/// Previews painted every frame of a fixture whose host runs jobs only when a trial says (upstream's 5 × 3 white
|
||||
/// image).
|
||||
struct Mips {
|
||||
fixture: Fixture,
|
||||
jobs: Arc<ManualJobs>,
|
||||
/// The previews the next frames paint, each at its scale.
|
||||
painted: Rc<RefCell<Vec<PaintedPreview>>>,
|
||||
/// The display every painted preview is converted for.
|
||||
display: Rc<RefCell<Option<PreviewDisplay>>>,
|
||||
/// What the next frames paint.
|
||||
painting: Rc<RefCell<Tracked<Painting>>>,
|
||||
/// What each painted preview showed in the last frame.
|
||||
shown: Rc<RefCell<Vec<Option<ShownPreview>>>>,
|
||||
/// The previews' uploads in the last frame, read in the frame.
|
||||
@@ -409,51 +432,50 @@ impl Mips {
|
||||
Self::with(false)
|
||||
}
|
||||
|
||||
/// The previews painted inside a settling region (`Lazy::settles`), which replays its last run while nothing the
|
||||
/// framework tracks changed for it.
|
||||
fn settling() -> Self {
|
||||
/// The previews painted inside a memoized view, which replays its last run while its painting is unchanged and no
|
||||
/// texture it shows is loading.
|
||||
fn memoized() -> Self {
|
||||
Self::with(true)
|
||||
}
|
||||
|
||||
fn with(settles: bool) -> Self {
|
||||
fn with(memoized: bool) -> Self {
|
||||
let jobs = Arc::new(ManualJobs::new());
|
||||
let painted = Rc::new(RefCell::new(Vec::<(Rc<PreviewTextures>, f32)>::new()));
|
||||
let display = Rc::new(RefCell::new(None::<PreviewDisplay>));
|
||||
let painting = Rc::new(RefCell::new(Tracked::new(Painting::default())));
|
||||
let shown = Rc::new(RefCell::new(Vec::new()));
|
||||
let uploads = Rc::new(Cell::new(0));
|
||||
let (paint, converted, seen, counted) = (Rc::clone(&painted), Rc::clone(&display), Rc::clone(&shown), Rc::clone(&uploads));
|
||||
let (paint, seen, counted) = (Rc::clone(&painting), Rc::clone(&shown), Rc::clone(&uploads));
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let run = |ui: &mut egui::Ui| {
|
||||
let display = converted.borrow();
|
||||
let picks = paint
|
||||
.borrow()
|
||||
.iter()
|
||||
.map(|(textures, scale)| textures.pick(ui.ctx(), PreviewTextures::choose(1.0, *scale, false), display.as_ref()))
|
||||
.collect();
|
||||
*seen.borrow_mut() = picks;
|
||||
};
|
||||
if settles {
|
||||
Lazy::new("previews", 0.0).settles(true).show(ui, run);
|
||||
let painting = paint.borrow();
|
||||
let shows = if memoized {
|
||||
MemoView::new("previews", Previews { painting: &painting }, previews).show(ui).unwrap_or_default()
|
||||
} else {
|
||||
run(ui);
|
||||
}
|
||||
picks(ui, &painting)
|
||||
};
|
||||
*seen.borrow_mut() = shows;
|
||||
counted.set(PreviewTextures::statistics(ui.ctx()).uploads);
|
||||
});
|
||||
fixture.host(Arc::new(Host::builder(AppInfo { id: "trial", name: "Trial", version: "0" }).jobs(jobs.clone()).build()));
|
||||
fixture.settle();
|
||||
Mips { fixture, jobs, painted, display, shown, uploads }
|
||||
Mips { fixture, jobs, painting, shown, uploads }
|
||||
}
|
||||
|
||||
/// One frame painting `previews`.
|
||||
/// A change of the previews or their scales arrives with input, as a drag's does.
|
||||
/// One frame painting `previews`; a change of the previews or their scales is an edit of the painting.
|
||||
fn paint(&mut self, previews: &[(&Rc<PreviewTextures>, f32)]) {
|
||||
let next: Vec<_> = previews.iter().map(|(textures, scale)| (Rc::clone(textures), *scale)).collect();
|
||||
let changed = {
|
||||
let painted = self.painted.borrow();
|
||||
let painting = self.painting.borrow();
|
||||
let painted = &painting.previews;
|
||||
painted.len() != next.len() || painted.iter().zip(&next).any(|(a, b)| !Rc::ptr_eq(&a.0, &b.0) || a.1 != b.1)
|
||||
};
|
||||
*self.painted.borrow_mut() = next;
|
||||
self.fixture.frame(if changed { vec![egui::Event::WindowFocused(true)] } else { Vec::new() });
|
||||
if changed {
|
||||
self.painting.borrow_mut().edit(|painting| painting.previews = next);
|
||||
}
|
||||
self.fixture.frame(Vec::new());
|
||||
}
|
||||
|
||||
/// Converts every painted preview for `display` from the next frame on.
|
||||
fn display(&mut self, display: PreviewDisplay) {
|
||||
self.painting.borrow_mut().edit(|painting| painting.display = Some(display));
|
||||
}
|
||||
|
||||
/// The texture and uv extent the `at`th preview showed.
|
||||
@@ -471,12 +493,12 @@ fn near_uv(uv: [f32; 2], want: [f32; 2]) -> bool {
|
||||
}
|
||||
|
||||
/// P91 (#13382): the frame that first needs a mip level builds none on the UI thread; level 0 stands in, the frames
|
||||
/// while its job waits do no work for it, and the landing frame uploads it once. In a settling region the frame
|
||||
/// after the job lands runs the region again with no other input and shows the level.
|
||||
/// while its job waits do no work for it, and the landing frame uploads it once. In a memoized view the frame after
|
||||
/// the job lands runs the view again with no other input and shows the level.
|
||||
#[trial]
|
||||
fn a_mip_level_first_needed_mid_drag_is_built_off_the_ui_thread() {
|
||||
for settles in [false, true] {
|
||||
mips_first_needed_mid_drag(if settles { Mips::settling() } else { Mips::new() });
|
||||
for memoized in [false, true] {
|
||||
mips_first_needed_mid_drag(if memoized { Mips::memoized() } else { Mips::new() });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -531,7 +553,7 @@ fn a_level_with_nothing_finer_uploaded_for_the_display_is_built_at_once() {
|
||||
assert_eq!(mips.jobs.waiting(), 0, "a first frame at level 1 builds it in the frame");
|
||||
assert!(near_uv(mips.shown(0).1, [5.0 / 6.0, 3.0 / 4.0]), "level 1 shows at once");
|
||||
mips.paint(&[(&t, 1.0)]);
|
||||
*mips.display.borrow_mut() = Some(PreviewDisplay::new(7, ColorImage::clone));
|
||||
mips.display(PreviewDisplay::new(7, ColorImage::clone));
|
||||
mips.paint(&[(&t, 0.3)]);
|
||||
assert_eq!(mips.jobs.waiting(), 0, "nothing is uploaded for the new display, so level 1 is built in the frame");
|
||||
assert!(near_uv(mips.shown(0).1, [5.0 / 6.0, 3.0 / 4.0]));
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
//! Stories of `LayerCompsPanel`: no comps, two comps with one applied, a comp with a warning.
|
||||
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
@@ -8,8 +7,8 @@ use super::{LayerCompRow, LayerCompsPanel};
|
||||
|
||||
#[story(LayerCompsPanel<'static>, covers = [Default], drive = Drive::Never)]
|
||||
fn layer_comps_panel_no_comps(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let selected = data.value("selected", None::<u64>);
|
||||
StoryOutput::from(LayerCompsPanel::new("Layer Comps", &[], Bind::bound(selected)).last_state_applied(true).show(ui))
|
||||
let (selected, selected_at) = data.value_at("selected", None::<u64>);
|
||||
StoryOutput::from(LayerCompsPanel::new("Layer Comps", &[], selected_at.bind(selected)).last_state_applied(true).show(ui))
|
||||
}
|
||||
|
||||
#[story(LayerCompsPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
@@ -18,13 +17,13 @@ fn layer_comps_panel_two_comps(ui: &mut Ui, data: &mut StoryData) -> StoryOutput
|
||||
LayerCompRow::new(1, "Daylight").applied(true).visibility(true).position(true).appearance(true),
|
||||
LayerCompRow::new(2, "Night").comment("The scene with the lamps on").visibility(true),
|
||||
];
|
||||
let selected = data.value("selected", Some(1_u64));
|
||||
StoryOutput::from(LayerCompsPanel::new("Layer Comps", &rows, Bind::bound(selected)).show(ui))
|
||||
let (selected, selected_at) = data.value_at("selected", Some(1_u64));
|
||||
StoryOutput::from(LayerCompsPanel::new("Layer Comps", &rows, selected_at.bind(selected)).show(ui))
|
||||
}
|
||||
|
||||
#[story(LayerCompsPanel<'static>, covers = [], drive = Drive::Never)]
|
||||
fn layer_comps_panel_warning(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let rows = vec![LayerCompRow::new(1, "Draft").missing(3).visibility(true), LayerCompRow::new(2, "Final").missing(1).position(true)];
|
||||
let selected = data.value("selected", None::<u64>);
|
||||
StoryOutput::from(LayerCompsPanel::new("Layer Comps", &rows, Bind::bound(selected)).show(ui))
|
||||
let (selected, selected_at) = data.value_at("selected", None::<u64>);
|
||||
StoryOutput::from(LayerCompsPanel::new("Layer Comps", &rows, selected_at.bind(selected)).show(ui))
|
||||
}
|
||||
|
||||
@@ -4,84 +4,85 @@ use super::{EffectKind, FilterBy, FilterKind, LayerAttribute, LayerFilter, Layer
|
||||
use crate::ui::mock::FakeLayers;
|
||||
use crate::ui::tree::LayerTree as _;
|
||||
use craft_theme::LabelColor;
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, ValueAt, story};
|
||||
use egui::Ui;
|
||||
|
||||
/// The bar over `filter`, with the count of `tree`'s layers the filter lists.
|
||||
fn show_over(ui: &mut Ui, filter: &mut LayerFilter, tree: &FakeLayers) -> StoryOutput {
|
||||
fn show_over(ui: &mut Ui, filter: &mut LayerFilter, filter_at: ValueAt<'_>, tree: &FakeLayers) -> StoryOutput {
|
||||
let modes = tree.blend_modes(false, "normal");
|
||||
let output = StoryOutput::from(LayerFilterBar::new(Bind::bound(&mut *filter)).blend_modes(&modes).show(ui));
|
||||
let output = StoryOutput::from(LayerFilterBar::new(filter_at.bind(&mut *filter)).blend_modes(&modes).show(ui));
|
||||
let filter: &LayerFilter = filter;
|
||||
let shown = tree.layers.iter().filter(|layer| !filter.active() || tree.listed(&layer.id, filter)).count();
|
||||
output.readout(format!("{shown} of {} layers match", tree.layers.len()))
|
||||
}
|
||||
|
||||
/// The bar over `filter`, counted over the fifty-layer tree.
|
||||
fn show(ui: &mut Ui, filter: &mut LayerFilter) -> StoryOutput {
|
||||
show_over(ui, filter, &FakeLayers::fifty())
|
||||
fn show(ui: &mut Ui, filter: &mut LayerFilter, filter_at: ValueAt<'_>) -> StoryOutput {
|
||||
show_over(ui, filter, filter_at, &FakeLayers::fifty())
|
||||
}
|
||||
|
||||
#[story(LayerFilterBar<'static>, covers = [Default], drive = Drive::Never, group = "Types", title = "Filter by Kind")]
|
||||
fn by_kind(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let filter = data.value("filter", LayerFilter { kinds: vec![FilterKind::Pixel], ..LayerFilter::default() });
|
||||
show(ui, filter)
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { kinds: vec![FilterKind::Pixel], ..LayerFilter::default() });
|
||||
show(ui, filter, filter_at)
|
||||
}
|
||||
|
||||
#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Filter by Name")]
|
||||
fn by_name(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Name, name: String::from("mask"), ..LayerFilter::default() });
|
||||
show(ui, filter)
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Name, name: String::from("mask"), ..LayerFilter::default() });
|
||||
show(ui, filter, filter_at)
|
||||
}
|
||||
|
||||
/// An app that offers three of the nine types.
|
||||
#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Offering Kind, Name and Mode")]
|
||||
fn offered_types(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Mode, mode: String::from("multiply"), ..LayerFilter::default() });
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Mode, mode: String::from("multiply"), ..LayerFilter::default() });
|
||||
let tree = FakeLayers::fifty();
|
||||
let modes = tree.blend_modes(false, "normal");
|
||||
let bar = LayerFilterBar::new(Bind::bound(filter)).filter_types([FilterBy::Kind, FilterBy::Name, FilterBy::Mode]).blend_modes(&modes);
|
||||
let bar = LayerFilterBar::new(filter_at.bind(filter)).filter_types([FilterBy::Kind, FilterBy::Name, FilterBy::Mode]).blend_modes(&modes);
|
||||
StoryOutput::from(bar.show(ui))
|
||||
}
|
||||
|
||||
#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Filter by Effect")]
|
||||
fn by_effect(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Effect, effect: EffectKind::Stroke, ..LayerFilter::default() });
|
||||
show(ui, filter)
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Effect, effect: EffectKind::Stroke, ..LayerFilter::default() });
|
||||
show(ui, filter, filter_at)
|
||||
}
|
||||
|
||||
#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Filter by Mode")]
|
||||
fn by_mode(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Mode, mode: String::from("multiply"), ..LayerFilter::default() });
|
||||
show(ui, filter)
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Mode, mode: String::from("multiply"), ..LayerFilter::default() });
|
||||
show(ui, filter, filter_at)
|
||||
}
|
||||
|
||||
#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Filter by Attribute")]
|
||||
fn by_attribute(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Attribute, attribute: LayerAttribute::Clipped, ..LayerFilter::default() });
|
||||
show(ui, filter)
|
||||
let (filter, filter_at) =
|
||||
data.value_at("filter", LayerFilter { by: FilterBy::Attribute, attribute: LayerAttribute::Clipped, ..LayerFilter::default() });
|
||||
show(ui, filter, filter_at)
|
||||
}
|
||||
|
||||
#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Filter by Color")]
|
||||
fn by_color(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Color, color: Some(LabelColor::Blue), ..LayerFilter::default() });
|
||||
show(ui, filter)
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Color, color: Some(LabelColor::Blue), ..LayerFilter::default() });
|
||||
show(ui, filter, filter_at)
|
||||
}
|
||||
|
||||
#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Filter by Smart Object")]
|
||||
fn by_smart_object(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::SmartObject, smart: vec![SmartKind::Missing], ..LayerFilter::default() });
|
||||
show_over(ui, filter, &FakeLayers::boards())
|
||||
let (filter, filter_at) =
|
||||
data.value_at("filter", LayerFilter { by: FilterBy::SmartObject, smart: vec![SmartKind::Missing], ..LayerFilter::default() });
|
||||
show_over(ui, filter, filter_at, &FakeLayers::boards())
|
||||
}
|
||||
|
||||
#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Filter by Artboard")]
|
||||
fn by_artboard(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Artboard, ..LayerFilter::default() });
|
||||
show_over(ui, filter, &FakeLayers::boards())
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Artboard, ..LayerFilter::default() });
|
||||
show_over(ui, filter, filter_at, &FakeLayers::boards())
|
||||
}
|
||||
|
||||
#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Filter by Group")]
|
||||
fn by_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Group, ..LayerFilter::default() });
|
||||
show(ui, filter)
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Group, ..LayerFilter::default() });
|
||||
show(ui, filter, filter_at)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
//! tree; extra columns; effects and Smart Filters open; filtered by Artboard and by Group, which keep each group open or
|
||||
//! closed.
|
||||
|
||||
use craft_ui::contract::Bind;
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
@@ -50,8 +49,8 @@ fn layers_panel_no_active_layer(ui: &mut Ui, data: &mut StoryData) -> StoryOutpu
|
||||
#[story(LayersPanel<'static, FakeLayers>, covers = [], drive = Drive::Never)]
|
||||
fn layers_panel_filtered(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let tree = selected();
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Name, name: String::from("o"), ..LayerFilter::default() });
|
||||
let shown = LayersPanel::new(&tree).filter(Bind::bound(filter)).show(ui);
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Name, name: String::from("o"), ..LayerFilter::default() });
|
||||
let shown = LayersPanel::new(&tree).filter(filter_at.bind(filter)).show(ui);
|
||||
with_readout(data, shown)
|
||||
}
|
||||
|
||||
@@ -105,8 +104,8 @@ fn layers_panel_effects_open(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(LayersPanel<'static, FakeLayers>, covers = [], drive = Drive::Never)]
|
||||
fn layers_panel_by_artboard(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let tree = FakeLayers::boards();
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Artboard, ..LayerFilter::default() });
|
||||
let shown = LayersPanel::new(&tree).filter(Bind::bound(filter)).show(ui);
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Artboard, ..LayerFilter::default() });
|
||||
let shown = LayersPanel::new(&tree).filter(filter_at.bind(filter)).show(ui);
|
||||
with_readout(data, shown)
|
||||
}
|
||||
|
||||
@@ -114,7 +113,7 @@ fn layers_panel_by_artboard(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
#[story(LayersPanel<'static, FakeLayers>, covers = [], drive = Drive::Never)]
|
||||
fn layers_panel_by_group(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let tree = FakeLayers::fifty();
|
||||
let filter = data.value("filter", LayerFilter { by: FilterBy::Group, ..LayerFilter::default() });
|
||||
let shown = LayersPanel::new(&tree).filter(Bind::bound(filter)).show(ui);
|
||||
let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Group, ..LayerFilter::default() });
|
||||
let shown = LayersPanel::new(&tree).filter(filter_at.bind(filter)).show(ui);
|
||||
with_readout(data, shown)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use craft_behavior::{EditEvent, EditHistory, Mixed, SelectionChange};
|
||||
use craft_layers::ui::mock::FakeLayers;
|
||||
use craft_layers::ui::panel::{LayerColumn, LayerDrop, LayerPosition, LayerToggle, LayersEvent, LayersPanel};
|
||||
use craft_layers::ui::tree::{LayerKind, LayerPart, LayerSelection};
|
||||
use craft_ui::contract::Lazy;
|
||||
use craft_ui::contract::{MemoProps, MemoView, Outbox, PlainData, Tracked};
|
||||
use craft_ui::testing::access::focused_key;
|
||||
use craft_ui::testing::focus::AccessActionKind;
|
||||
use craft_ui::testing::{Fixture, Target, pointer, trial};
|
||||
@@ -246,22 +246,44 @@ fn shift_right_and_left_open_and_close_the_active_layers_effects() {
|
||||
assert_eq!(fx(take(&app)), [(7, false)], "Shift+Left closes them");
|
||||
}
|
||||
|
||||
/// The tree a memoized view of the panel shows, as the app's model.
|
||||
#[derive(PlainData)]
|
||||
struct Model {
|
||||
#[plain_data(assume = "a mock tree: its only interior mutability is call counters, which no view shows")]
|
||||
tree: FakeLayers,
|
||||
}
|
||||
|
||||
/// A memoized view of the panel over the app's model; it applies what the panel reports to the model and sends it on.
|
||||
#[derive(MemoProps)]
|
||||
struct PanelView<'a> {
|
||||
model: &'a mut Tracked<Model>,
|
||||
events: Outbox<'a, LayersEvent<u32>>,
|
||||
}
|
||||
|
||||
fn panel_view(props: &mut PanelView<'_>, ui: &mut Ui) {
|
||||
let out = LayersPanel::new(&props.model.tree).show(ui);
|
||||
for event in out.events {
|
||||
props.model.edit(|model| apply(&mut model.tree, &event));
|
||||
props.events.send(event);
|
||||
}
|
||||
}
|
||||
|
||||
/// A row's access focus action, as a screen reader or a test driver gives it, puts key focus in the rows with the
|
||||
/// lead on that row: the access focus lands on the row's node.
|
||||
/// So does it while the panel is a settled region that replays its last run.
|
||||
/// So does it while the panel is a settled memoized view that replays its last run.
|
||||
#[trial]
|
||||
fn a_rows_access_focus_action_leads_the_focused_rows_to_it() {
|
||||
let settled = || {
|
||||
let app = Rc::new(RefCell::new(App { tree: FakeLayers::sample(), events: Vec::new() }));
|
||||
let shared = Rc::clone(&app);
|
||||
let mut model = Tracked::new(Model { tree: FakeLayers::sample() });
|
||||
let mut events = Vec::new();
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
Lazy::new("layers", 0.0).settles(true).show(ui, |ui| show(ui, &mut shared.borrow_mut()));
|
||||
MemoView::new("layers", PanelView { model: &mut model, events: Outbox::new(&mut events) }, panel_view).show(ui);
|
||||
});
|
||||
fixture.room(PANEL);
|
||||
fixture.settle();
|
||||
(fixture, app)
|
||||
fixture
|
||||
};
|
||||
for (mut fixture, _app) in [rig(FakeLayers::sample()), settled()] {
|
||||
for mut fixture in [rig(FakeLayers::sample()).0, settled()] {
|
||||
let styled = row(&fixture, "Styled");
|
||||
fixture.access(AccessActionKind::Focus, &styled).idle(2);
|
||||
assert!(fixture.focused_stop().is_some(), "the rows hold key focus");
|
||||
|
||||
@@ -106,14 +106,21 @@ impl Rig {
|
||||
self.fixture.by_label(name).expect("the row is drawn").rect
|
||||
}
|
||||
|
||||
/// One frame that reveals `id`, with what it reported; asserts that the frame ran once and measured no row twice.
|
||||
/// One frame that reveals `id`, with what it reported; asserts that the frame ran once and measured no row twice but
|
||||
/// the rows the lead moves between.
|
||||
fn reveal(&mut self, id: u32, groups: Groups) -> Vec<LayersEvent<u32>> {
|
||||
self.seen.borrow_mut().clear();
|
||||
self.reveal.set(Some((id, groups)));
|
||||
self.fixture.idle(1);
|
||||
assert_eq!(self.fixture.passes(), 1, "a reveal runs its frame once");
|
||||
let measures = craft_ui::runtime::measure::row_measures(self.fixture.ctx());
|
||||
assert!(measures.iter().all(|(_, count)| *count == 1), "a reveal measures no row twice: {measures:?}");
|
||||
// The lead moves to the revealed row: the row it leaves, measured before the move, is measured again with its
|
||||
// new state, as is the revealed row when the pass measured it before the move.
|
||||
let again = measures.iter().filter(|(_, count)| *count == 2).count();
|
||||
assert!(
|
||||
measures.iter().all(|(_, count)| *count <= 2) && again <= 2,
|
||||
"a reveal measures again only the rows the lead moves between: {measures:?}"
|
||||
);
|
||||
self.seen.borrow_mut().drain(..).collect()
|
||||
}
|
||||
|
||||
|
||||
+79
-27
@@ -12,9 +12,9 @@
|
||||
mod stories;
|
||||
|
||||
use craft_keymap::{CommandRef, Platform};
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::contract::{MemoProps, MemoView, Show as _, Stateless};
|
||||
use craft_ui::menu::{MenuBar as Bar, MenuHelp, MenuTitle};
|
||||
use craft_ui::runtime::env::Env;
|
||||
use craft_ui::runtime::env::{Env, Label};
|
||||
use egui::{Rect, Ui};
|
||||
|
||||
use crate::context::Rows;
|
||||
@@ -56,8 +56,19 @@ pub(crate) fn keymap_platform(target: Target, os: Platform) -> Platform {
|
||||
}
|
||||
}
|
||||
|
||||
/// A replay at another place moves the titles' rect with the bar.
|
||||
impl craft_ui::runtime::Shift for MenuBarOutput {
|
||||
fn shifted(&self, by: &egui::RecordShift) -> Self {
|
||||
MenuBarOutput { titles: by.rect(self.titles) }
|
||||
}
|
||||
|
||||
fn snapped(&self, to: &Self, within: f32) -> Self {
|
||||
MenuBarOutput { titles: craft_ui::runtime::Shift::snapped(&self.titles, &to.titles, within) }
|
||||
}
|
||||
}
|
||||
|
||||
/// What the bar did in a frame, from [`MenuBarUi::show`].
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[non_exhaustive]
|
||||
pub struct MenuBarOutput {
|
||||
/// The menu titles alone, without the room the bar leaves after them
|
||||
@@ -65,36 +76,57 @@ pub struct MenuBarOutput {
|
||||
pub titles: Rect,
|
||||
}
|
||||
|
||||
/// The English-label hook a bar takes by default: none is set, so this type only names the slot.
|
||||
pub type EnglishFn = fn(Labeled<'_>) -> Option<String>;
|
||||
|
||||
/// The bar for one frame: `MenuBarUi::new(&bar).show(ui)`. Draw it at the top of the window, in a top panel.
|
||||
/// The commands chosen come back through the command queue, not from `show`.
|
||||
///
|
||||
/// The bar is a memoized view: while its model, options, place and environment are those of its last run and nothing
|
||||
/// reaches it (pointer, focus, keys, an open menu), it adds that run again in place of running.
|
||||
#[derive(craft_ui::contract::Pattern)]
|
||||
pub struct MenuBarUi<'a> {
|
||||
#[pattern(probe(MenuBarUi<'static, EnglishFn>))]
|
||||
pub struct MenuBarUi<'a, E = EnglishFn> {
|
||||
bar: &'a MenuBar,
|
||||
/// The platform set with [`target`](Self::target); the shell's when none is.
|
||||
target: Option<Target>,
|
||||
english: Option<&'a EnglishHook<'a>>,
|
||||
english: Option<Stateless<E>>,
|
||||
preferred: &'a [(&'a str, char)],
|
||||
keyboard: Option<bool>,
|
||||
help_search: bool,
|
||||
}
|
||||
|
||||
/// Every input of the bar's view.
|
||||
#[derive(MemoProps)]
|
||||
struct BarProps<'a, #[memo_props(stateless)] E> {
|
||||
bar: &'a MenuBar,
|
||||
target: Target,
|
||||
english: Option<Stateless<E>>,
|
||||
preferred: &'a [(&'a str, char)],
|
||||
keyboard: bool,
|
||||
help: Option<usize>,
|
||||
label: Label,
|
||||
}
|
||||
|
||||
impl<'a> MenuBarUi<'a> {
|
||||
/// The bar for `bar`, already laid out ([`crate::layout`]), on the shell's platform ([`Target::of_shell`]).
|
||||
pub fn new(bar: &'a MenuBar) -> MenuBarUi<'a> {
|
||||
MenuBarUi { bar, target: None, english: None, preferred: &[], keyboard: None, help_search: false }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, E: Fn(Labeled<'_>) -> Option<String> + Copy + 'static> MenuBarUi<'a, E> {
|
||||
/// The platform the bar is on, for the shortcut column ([`craft_keymap::Chord::display`]): ⌘ glyphs on
|
||||
/// [`Target::Mac`] and in a browser on a Mac, Ctrl names everywhere else. On [`Target::Mac`] the native bar
|
||||
/// has the keys, and this one takes none unless [`keyboard`](Self::keyboard) says so.
|
||||
pub fn target(mut self, target: Target) -> MenuBarUi<'a> {
|
||||
pub fn target(mut self, target: Target) -> MenuBarUi<'a, E> {
|
||||
self.target = Some(target);
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether the bar takes F10, Alt and Alt with a letter. By default it does, except on [`Target::Mac`]. The
|
||||
/// app turns it off while a modal dialog or the shortcut recorder has the keys.
|
||||
pub fn keyboard(mut self, on: bool) -> MenuBarUi<'a> {
|
||||
pub fn keyboard(mut self, on: bool) -> MenuBarUi<'a, E> {
|
||||
self.keyboard = Some(on);
|
||||
self
|
||||
}
|
||||
@@ -102,23 +134,24 @@ impl<'a> MenuBarUi<'a> {
|
||||
/// The English label of a row or title, for labels the keyboard can't type a letter of (Chinese, Japanese,
|
||||
/// Korean…): such a label shows its English label's mnemonic after it, "文件(F)", before a trailing ellipsis
|
||||
/// ("開く(O)…"), as Windows menus do. Without this hook (or when it returns `None`) such a label has no
|
||||
/// mnemonic. The Help menu's search also matches the English labels, on every target.
|
||||
pub fn english(mut self, english: &'a dyn Fn(Labeled<'_>) -> Option<String>) -> MenuBarUi<'a> {
|
||||
self.english = Some(english);
|
||||
self
|
||||
/// mnemonic. The Help menu's search also matches the English labels, on every target. The hook is a fn item or a
|
||||
/// closure that captures nothing ([`Stateless`]): the bar's key follows its type.
|
||||
pub fn english<F: Fn(Labeled<'_>) -> Option<String> + Copy + 'static>(self, english: F) -> MenuBarUi<'a, F> {
|
||||
let MenuBarUi { bar, target, english: _, preferred, keyboard, help_search } = self;
|
||||
MenuBarUi { bar, target, english: Some(Stateless::new(english)), preferred, keyboard, help_search }
|
||||
}
|
||||
|
||||
/// Preferred mnemonics, each for a menu or submenu by its title as shown or for an item by its command id:
|
||||
/// the row takes that letter when its label has it and no row before it in its menu took it. Every other row
|
||||
/// takes the first unused letter of its label, word starts first.
|
||||
pub fn mnemonics(mut self, preferred: &'a [(&'a str, char)]) -> MenuBarUi<'a> {
|
||||
pub fn mnemonics(mut self, preferred: &'a [(&'a str, char)]) -> MenuBarUi<'a, E> {
|
||||
self.preferred = preferred;
|
||||
self
|
||||
}
|
||||
|
||||
/// Start the [`MenuRole::Help`] menu with a search field over every command of the bar
|
||||
/// ([`MenuBar::help_entries`]). A bar with no Help menu has no field.
|
||||
pub fn help_search(mut self, on: bool) -> MenuBarUi<'a> {
|
||||
pub fn help_search(mut self, on: bool) -> MenuBarUi<'a, E> {
|
||||
self.help_search = on;
|
||||
self
|
||||
}
|
||||
@@ -129,20 +162,39 @@ impl<'a> MenuBarUi<'a> {
|
||||
pub fn show(self, ui: &mut Ui) -> MenuBarOutput {
|
||||
let env = Env::of(ui);
|
||||
let target = self.target.unwrap_or_else(|| Target::of_shell(env.view().shell()));
|
||||
let rows = Rows::new(target).english(self.english).preferred(self.preferred);
|
||||
let labels =
|
||||
rows.labels(&self.bar.menus, |menu| menu.title.as_str(), |menu| menu.title.as_str(), |menu| rows.english_of(Labeled::Title(&menu.title)));
|
||||
let shared = &rows;
|
||||
let titles: Vec<MenuTitle<'_>> =
|
||||
self.bar.menus.iter().zip(labels).map(|(menu, label)| MenuTitle::new(label, move |ui| shared.show(ui, &menu.children))).collect();
|
||||
let help = self.help_search.then(|| self.bar.menus.iter().position(|menu| menu.role == MenuRole::Help)).flatten();
|
||||
// Collecting the search's commands walks every row of every menu: the bar does it only while Help is open.
|
||||
let (bar_model, english) = (self.bar, self.english);
|
||||
let entries = move || entries_of(bar_model, english);
|
||||
let mut bar = Bar::new(env.words::<BarWords>().label.clone(), titles).keyboard(self.keyboard.unwrap_or(target != Target::Mac));
|
||||
if let Some(menu) = help {
|
||||
bar = bar.help(MenuHelp::new(menu, &entries));
|
||||
}
|
||||
MenuBarOutput { titles: bar.show(ui).titles }
|
||||
let props = BarProps {
|
||||
bar: self.bar,
|
||||
target,
|
||||
english: self.english,
|
||||
preferred: self.preferred,
|
||||
keyboard: self.keyboard.unwrap_or(target != Target::Mac),
|
||||
help,
|
||||
label: env.words::<BarWords>().label.clone(),
|
||||
};
|
||||
MemoView::new("menu-bar", props, show_bar::<E>).show(ui).unwrap_or(MenuBarOutput { titles: Rect::NOTHING })
|
||||
}
|
||||
}
|
||||
|
||||
/// The bar's view: the titles through [`craft_ui::menu::MenuBar`], each menu's rows as command rows.
|
||||
fn show_bar<E: Fn(Labeled<'_>) -> Option<String> + Copy + 'static>(props: &mut BarProps<'_, E>, ui: &mut Ui) -> MenuBarOutput {
|
||||
let hook = props.english.map(|english| {
|
||||
let english = english.get();
|
||||
move |labeled: Labeled<'_>| english(labeled)
|
||||
});
|
||||
let english: Option<&EnglishHook<'_>> = hook.as_ref().map(|hook| hook as &EnglishHook<'_>);
|
||||
let rows = Rows::new(props.target).english(english).preferred(props.preferred);
|
||||
let labels =
|
||||
rows.labels(&props.bar.menus, |menu| menu.title.as_str(), |menu| menu.title.as_str(), |menu| rows.english_of(Labeled::Title(&menu.title)));
|
||||
let shared = &rows;
|
||||
let titles: Vec<MenuTitle<'_>> =
|
||||
props.bar.menus.iter().zip(labels).map(|(menu, label)| MenuTitle::new(label, move |ui| shared.show(ui, &menu.children))).collect();
|
||||
// Collecting the search's commands walks every row of every menu: the bar does it only while Help is open.
|
||||
let bar_model = props.bar;
|
||||
let entries = move || entries_of(bar_model, english);
|
||||
let mut bar = Bar::new(props.label.clone(), titles).keyboard(props.keyboard);
|
||||
if let Some(menu) = props.help {
|
||||
bar = bar.help(MenuHelp::new(menu, &entries));
|
||||
}
|
||||
MenuBarOutput { titles: bar.show(ui).titles }
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ const CTRL_CMD_M: Chord = Chord::new(CTRL_CMD, Key::M);
|
||||
const CMD_COMMA: Chord = Chord::new(Mods::CMD, Key::Comma);
|
||||
|
||||
/// The platform a layout is for.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub enum Target {
|
||||
#[allow(missing_docs)]
|
||||
|
||||
@@ -12,7 +12,7 @@ use std::fmt;
|
||||
use std::sync::Arc;
|
||||
|
||||
use craft_keymap::CommandRef;
|
||||
use craft_ui::contract::{MemoKey, MemoProps};
|
||||
use craft_ui::contract::MemoProps;
|
||||
|
||||
use crate::driver::Gate;
|
||||
use crate::model::{Builtin, Item};
|
||||
@@ -37,7 +37,7 @@ pub type PendingRule = Arc<dyn Fn(&CommandRef) -> bool + Send + Sync>;
|
||||
/// assert!(gate.allows_under(&rules, &"view.zoomIn".into()));
|
||||
/// assert!(!gate.allows_under(&rules, &"image.crop".into()));
|
||||
/// ```
|
||||
#[derive(Clone, Default)]
|
||||
#[derive(Clone, Default, MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub struct ModalRules {
|
||||
/// Commands that still run while [`Gate::modal`] is set (a dialog or prompt is open), by
|
||||
@@ -48,6 +48,7 @@ pub struct ModalRules {
|
||||
pub workspace: bool,
|
||||
/// A pending operation is open (an uncommitted crop): only the commands this returns true for
|
||||
/// run. `None`: no pending operation.
|
||||
#[memo_props(covered_by = "revision", reason = "the caller moves the revision with every rule change")]
|
||||
pub pending: Option<PendingRule>,
|
||||
/// The caller's count of rule changes. A rule holds a closure and cannot be compared, so the
|
||||
/// caller says when the rules changed; the menu skips the resync, and the runtime's command gate keeps its answers,
|
||||
@@ -88,18 +89,6 @@ impl ModalRules {
|
||||
}
|
||||
}
|
||||
|
||||
/// As props of the runtime's command gate: the plain fields and [`ModalRules::revision`], which stands for the
|
||||
/// [`ModalRules::pending`] closure. The derive cannot take the closure, and the revision is the caller's count of rule
|
||||
/// changes, so equal keys mean equal rules as long as the caller moves it with every change.
|
||||
impl MemoProps for ModalRules {
|
||||
fn key(&self, key: &mut MemoKey) {
|
||||
let ModalRules { in_dialogs, workspace, pending: _, revision } = self;
|
||||
in_dialogs.key(key);
|
||||
workspace.key(key);
|
||||
revision.key(key);
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ModalRules {
|
||||
// new: `PendingRule` is a closure; print whether one is set.
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
|
||||
+12
-12
@@ -8,7 +8,7 @@ use craft_keymap::{Chord, CommandRef, Mods};
|
||||
use craft_theme::Srgba;
|
||||
|
||||
/// The app's menus, in order, and its open documents.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
#[derive(Clone, Debug, Default, PartialEq, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub struct MenuBar {
|
||||
/// The top-level menus, left to right.
|
||||
@@ -18,7 +18,7 @@ pub struct MenuBar {
|
||||
}
|
||||
|
||||
/// An open document, listed in the Window menu.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub struct Document {
|
||||
/// What choosing it runs (bring the document to the front).
|
||||
@@ -51,7 +51,7 @@ impl Document {
|
||||
}
|
||||
|
||||
/// A top-level menu.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub struct Menu {
|
||||
/// The title in the bar.
|
||||
@@ -64,7 +64,7 @@ pub struct Menu {
|
||||
|
||||
/// What a top-level menu is for, set by the app. macOS treats the app, Window and Help menus
|
||||
/// specially; File is where the system Close Window item goes.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub enum MenuRole {
|
||||
/// Any menu without a fixed place.
|
||||
@@ -85,7 +85,7 @@ pub enum MenuRole {
|
||||
}
|
||||
|
||||
/// The platforms an item or submenu is shown on. All of them by default.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
pub struct Platforms(u8);
|
||||
|
||||
impl Platforms {
|
||||
@@ -132,7 +132,7 @@ impl BitOr for Platforms {
|
||||
}
|
||||
|
||||
/// One entry of a menu.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub enum Node {
|
||||
/// An item the user can choose.
|
||||
@@ -162,7 +162,7 @@ pub enum Node {
|
||||
}
|
||||
|
||||
/// One menu item: a command with its label, shortcut and state.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub struct Item {
|
||||
/// What the item runs: the app's command (`file.open`), with its parameters
|
||||
@@ -198,7 +198,7 @@ pub struct Item {
|
||||
|
||||
/// The command a row runs while `mods` are held as it is chosen (Alt on Merge Visible runs Stamp
|
||||
/// Visible).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub struct Alternate {
|
||||
/// The modifiers that select the alternate.
|
||||
@@ -222,7 +222,7 @@ impl Alternate {
|
||||
}
|
||||
|
||||
/// A plain item, or one with a checked state.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub enum ItemKind {
|
||||
/// An ordinary item.
|
||||
@@ -247,7 +247,7 @@ impl ItemKind {
|
||||
|
||||
/// Items the layouts put in fixed places. The app tags its own About, Settings, Quit, Appearance
|
||||
/// and Language items; the Mac layout adds Hide and Minimize.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub enum ItemRole {
|
||||
/// The About item.
|
||||
@@ -268,7 +268,7 @@ pub enum ItemRole {
|
||||
}
|
||||
|
||||
/// The items AppKit provides.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub enum Standard {
|
||||
#[allow(missing_docs)]
|
||||
@@ -307,7 +307,7 @@ pub(crate) fn label_or_system(label: &str, english: &str, system: impl FnOnce(&s
|
||||
|
||||
/// The commands of the items the crate adds itself. The crate runs them; an app sees them only
|
||||
/// in a layout's result.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, craft_ui::contract::MemoProps)]
|
||||
#[non_exhaustive]
|
||||
pub enum Builtin {
|
||||
/// Hide the app: a custom item, because AppKit's own always takes ⌘H, which apps often bind.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user