framework-01-w1: net change of 4 commits

- framework-01-w1: written from its sheet
- framework-01-w1: review fixes (review-1)
- framework-01-w1: review fixes (review-1, files the rulings name)
- Integration: Cargo.lock line for w1's craft-settings dependency
This commit is contained in:
aiongg
2026-11-15 04:46:05 +00:00
parent 38d3342ad0
commit db4828eaca
10 changed files with 71 additions and 16 deletions
Generated
+1
View File
@@ -3073,6 +3073,7 @@ dependencies = [
"craft-keymap",
"craft-platform",
"craft-quit",
"craft-settings",
"craft-theme",
"craft-ui-contract",
"craft-ui-macros",
+12 -4
View File
@@ -3,7 +3,7 @@
//! `cargo run -p story-render --features <crate> -- --only <Name> --out <dir>` writes, into `<dir>`:
//! `new-<Name>--<story>.png` for every story of the component, `new-<Name>.png` for the story its Overview card
//! shows (its first), `stories.tsv` and `components.tsv`. Each story runs in a card's story body (`StoryBody`) in a
//! fresh context, in ArtCraft Dark (`--theme`, `--mode`) at 2 pixels per point (`--scale`) with the interface fonts, and its image is cropped to the
//! fresh context, in ArtCraft Dark (`--theme`, `--mode`, `--density`, `--contrast`) at 2 pixels per point (`--scale`) with the interface fonts, and its image is cropped to the
//! story's surface and the layers it opened. A story runs in an embedded shell, over which its dialogs open, and a story
//! whose dialog the card holds behind its button is shown with the dialog open.
//!
@@ -20,17 +20,19 @@
//! renders the story (with `--card`, the group) of that name only; `--threads N` (default: the cores, at most 8);
//! `--width W` and `--room H` set the card's story width (with `--card`, the card's width) and the height a filling
//! story gets, in points; `--scale S` the images' pixels per point (1 matches the old gallery's shots, so a canvas
//! document shows at the same size on both sides); `--theme ID` and `--mode light|dark` the theme and mode (ArtCraft
//! Dark without them). `stories.tsv` lists the scale of every image.
//! document shows at the same size on both sides); `--theme ID`, `--mode light|dark`, `--density compact|comfortable`
//! and `--contrast standard|high` the theme, mode, density and contrast (ArtCraft Dark and the gallery's density and
//! contrast without them). A value that is not one of these is refused. `stories.tsv` lists the scale of every image.
use craft_behavior::ColumnWidth;
use craft_ui::contract::{Pad, Scroll, ShowContainer as _, Surface};
use craft_ui::fonts::{I18nScripts, UiFonts};
use craft_ui::layout_components::{Grid, Stack};
use craft_ui::runtime::commands::CommandInput;
use craft_ui::runtime::env::{RootEnv, WindowKey};
use craft_ui::shell::AppShell;
use craft_ui::testing::snapshot::{Renderer, RgbaImage, layer_rects, modal_open};
use craft_ui::testing::{Frames, StoryRegistration};
use craft_ui::testing::{Frames, Story, StoryRegistration};
use craft_ui_gallery::WINDOW;
use craft_ui_gallery::chrome::{Spec, StoryBody, overview_card};
use craft_ui_gallery::viewer::{CONTRASTS, CardState, Catalog, Cells, DENSITIES, GallerySettings, MODES, entry_of, theme_named};
@@ -307,6 +309,12 @@ fn render(job: &Job, renderer: &mut Renderer, env: &RootEnv, options: &Options)
frames.screen(Vec2::from(WINDOW));
frames.pixels_per_point(options.scale);
frames.record_paint();
// The command states of the story shown, as the gallery gives them, before the first frame. The Overview gives its
// cards none, so a card is rendered under none.
frames.commands(match &job.shown {
Shown::Story(registration) => Story::command_input([&registration.story]),
Shown::Card(_) => CommandInput::new(),
});
let (shown, dialog) = match &job.shown {
Shown::Story(registration) => (story(&mut frames, registration, job, options), false),
Shown::Card(spec) => card(&mut frames, spec, options),
+2
View File
@@ -34,6 +34,8 @@ accesskit = "0.25"
craft-keymap = { workspace = true, features = ["egui"] }
craft-theme = { workspace = true }
craft-ui-macros = { workspace = true }
craft-settings = { workspace = true }
toml = { version = "1.1", default-features = false, features = ["std", "parse", "serde"] }
egui = { workspace = true }
libtest-mimic = { version = "0.8", optional = true }
craft-host = { workspace = true }
@@ -200,6 +200,8 @@ impl Fixture {
fixture.data = data;
fixture.outputs = outputs;
fixture.root_id = root_id;
fixture.commands = Story::command_input([story]);
fixture.frames.commands(fixture.commands.clone());
fixture
}
+9 -1
View File
@@ -24,6 +24,8 @@ pub struct Frames {
repaint_delay: Duration,
host: Option<Arc<Host>>,
commands: CommandInput,
/// The modifiers the app holds down for the user in every following frame.
latched: craft_keymap::Mods,
tree: Option<AccessTree>,
ime: Option<fixture::ImeSeen>,
copied: Vec<String>,
@@ -94,6 +96,7 @@ impl Frames {
repaint_delay: Duration::MAX,
host: None,
commands: CommandInput::new(),
latched: craft_keymap::Mods::NONE,
tree: None,
ime: None,
copied: Vec::new(),
@@ -122,7 +125,7 @@ impl Frames {
}
fn input(&self) -> FrameInput {
let input = FrameInput::new(self.root.clone()).commands(self.commands.clone());
let input = FrameInput::new(self.root.clone()).commands(self.commands.clone()).latched(self.latched);
match &self.host {
Some(host) => input.host(host.clone()),
None => input,
@@ -134,6 +137,11 @@ impl Frames {
self.root = root;
}
/// The modifiers the app holds down for the user in every following frame.
pub fn latched(&mut self, mods: craft_keymap::Mods) {
self.latched = mods;
}
/// The command input every following frame is given.
pub fn commands(&mut self, commands: CommandInput) {
self.commands = commands;
+6
View File
@@ -124,6 +124,12 @@ impl Story {
self
}
/// The command input of `stories` shown together: each story's command function applied in order over an empty
/// input, so a later story's state for a command replaces an earlier one's. Runners call this before the first frame.
pub fn command_input<'a>(stories: impl IntoIterator<Item = &'a Story>) -> CommandInput {
stories.into_iter().filter_map(|story| story.commands).fold(CommandInput::new(), |input, add| add(input))
}
/// The caption a viewer shows over the story.
pub const fn title(mut self, title: &'static str) -> Self {
self.title = Some(title);
+17 -5
View File
@@ -75,18 +75,24 @@ fn read_dropped(file: &OsFile) -> Result<AppSizes, String> {
parse_sizes(&file.name, &bytes)
}
/// The registered name of the component whose tab is in front and selected in the shown workspace's dock.
fn front_component(viewer: &Viewer) -> Option<&'static str> {
let dock = if viewer.workspace == Workspace::Theme { &viewer.theme_dock } else { &viewer.browser.dock };
viewer.browser.selection.items.iter().rev().find_map(|key| match key {
TreeKey::Component(type_name) => Some(*type_name),
_ => None,
}).filter(|type_name| dock.layout.panel_state(&PanelId::Component(type_name)) == PanelState::Front)
}
/// The dock of the shown workspace over the viewer's state.
fn body(ui: &mut Ui, _: &mut BodyCx<'_>, viewer: &mut Viewer) {
let selected = front_component(viewer).map(PanelId::Component);
let Viewer { env, workspace, preview, browser, themes, theme_dock, mock, variants, variants_tab, inspect_layers, .. } = viewer;
let subject = ThemeSubject::new(theme_of(env.theme_id()), env.appearance(ui.ctx()));
let in_theme = *workspace == Workspace::Theme;
let Browser { catalog, filter, selection, open, dock, story_of, generation, cells, open_request, followed, tree_seen, level, .. } = browser;
let dock: &mut Dock<_> = if in_theme { theme_dock } else { dock };
let front = |panel: PanelId| dock.layout.panel_state(&panel) == PanelState::Front;
let selected = selection.items.iter().rev().find_map(|key| match key {
TreeKey::Component(type_name) => Some(PanelId::Component(type_name)),
_ => None,
});
let inspect = Inspect {
on: !in_theme && variants.is_none() && front(PanelId::Inspect),
front: [Some(PanelId::Overview), selected].into_iter().flatten().filter(|panel| front(*panel)).collect(),
@@ -127,7 +133,13 @@ fn body(ui: &mut Ui, _: &mut BodyCx<'_>, viewer: &mut Viewer) {
impl ShellApp for Gallery {
fn frame_input(&mut self) -> FrameInput {
FrameInput::new(self.viewer.env.clone())
// App-scope command states are one input per frame, so only the stories of the component shown reach it; the
// Overview, the Theme dock and a frame with no such tab give none.
let browser = &self.viewer.browser;
let stories = front_component(&self.viewer)
.into_iter()
.flat_map(|type_name| browser.catalog.stories_of(type_name).iter().map(|&at| &browser.catalog.entries[at].registration.story));
FrameInput::new(self.viewer.env.clone()).commands(craft_ui::testing::Story::command_input(stories))
}
fn output(&mut self, output: FrameOutput) {
@@ -3,7 +3,7 @@
use super::CommandPalette;
use crate::contract::Bind;
use crate::menu::search::HelpEntry;
use crate::runtime::commands::{CommandRef, EditCommands};
use crate::runtime::commands::{CommandInput, CommandRef, CommandState, EditCommands};
use crate::testing::{Drive, StoryData, StoryOutput, story};
use egui::Ui;
use std::sync::LazyLock;
@@ -68,12 +68,17 @@ fn palette(ui: &mut Ui, data: &mut StoryData, recents: Vec<CommandRef>) -> Story
StoryOutput::from(out).readout(readout)
}
#[story(CommandPalette<'static>, covers = [], drive = Drive::Never, title = "PhotoCraft")]
/// The command states the stories run under: Redo is disabled, as the entries list it.
fn commands(input: CommandInput) -> CommandInput {
input.state(EditCommands::Redo, CommandState::new().enabled(false))
}
#[story(CommandPalette<'static>, covers = [], drive = Drive::Never, title = "PhotoCraft", commands = commands)]
fn command_palette(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
palette(ui, data, Vec::new())
}
#[story(CommandPalette<'static>, covers = [], drive = Drive::Never, title = "Recent commands")]
#[story(CommandPalette<'static>, covers = [], drive = Drive::Never, title = "Recent commands", commands = commands)]
fn command_palette_recents(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
let recents = [PhotoCraftCommand::Levels, PhotoCraftCommand::Brush, PhotoCraftCommand::Search].map(CommandRef::from).to_vec();
palette(ui, data, recents)
+12 -1
View File
@@ -8,7 +8,7 @@ use craft_ui::patterns::panels::CommandPalette;
use craft_ui::popover::Popover;
use craft_ui::runtime::commands::{CommandRef, CommandState, EditCommands, FireSource};
use craft_ui::runtime::frame::take_output;
use craft_ui::testing::{Fixture, trial};
use craft_ui::testing::{Fixture, stories, trial};
use egui::{Key, Modifiers, Ui};
use std::cell::{Cell, RefCell};
use std::rc::Rc;
@@ -95,6 +95,17 @@ fn a_picked_command_runs_from_the_palette_and_comes_first_when_it_opens_again()
assert!(rows(&fixture)[0].0.starts_with("Flip"), "the command just run leads the empty query");
}
/// The palette story's `commands` function reaches its first frame: Redo lists disabled, a command it does not name
/// lists enabled.
#[trial]
fn the_palette_story_runs_under_its_command_states() {
let entry = stories().into_iter().find(|entry| entry.story.name == "command_palette").expect("the palette story");
let mut fixture = Fixture::story(&entry.story);
fixture.settle();
assert!(disabled(&fixture, "Redo"), "the story's Redo lists disabled");
assert!(!disabled(&fixture, "Search"), "a command the story does not name lists enabled");
}
#[trial]
fn a_command_the_app_disables_lists_disabled_and_does_not_run_even_after_typing_into_the_field() {
let entries = vec![HelpEntry::new(TrialCommand::Rotate, "Rotate"), HelpEntry::new(EditCommands::Undo, "Undo").with_path(["Edit"])];
+2 -2
View File
@@ -5,7 +5,7 @@
cl test <crate> [cargo args] [-- test args] build the crate's tests (cargo test --no-run), then run each test binary
cl build gallery [cargo args] the debug gallery binary (target/debug/craft-ui-gallery)
cl build <crate> [cargo args] cargo build of the crate's lib and bins
cl render <crate|ui> <Component> [--card] [--story <name>] [--out <dir>] [--threads N] [--theme <id>] [--mode light|dark]
cl render <crate|ui> <Component> [--card] [--story <name>] [--out <dir>] [--threads N] [--theme <id>] [--mode light|dark] [--density compact|comfortable] [--contrast standard|high]
the component's stories (--card: its Overview cards) as PNGs through the story-render bin
cl features <crate> print the --features value cl adds for <crate>
cl doctor check the manifests for drift from the one feature resolution
@@ -382,7 +382,7 @@ def main():
run(top, with_features(["build"] + selected(pkg) + own_targets(packages[pkg]), features) + args)
if command == "render":
if len(rest) < 2:
fail("cl render <crate|ui> <Component> [--card] [--story <name>] [--out <dir>] [--threads N] [--theme <id>] [--mode light|dark]")
fail("cl render <crate|ui> <Component> [--card] [--story <name>] [--out <dir>] [--threads N] [--theme <id>] [--mode light|dark] [--density compact|comfortable] [--contrast standard|high]")
crate, component, options = rest[0], rest[1], rest[2:]
short = crate.removeprefix("craft-")
features = []