mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 01:44:25 +00:00
A type's stories from the package that registers it list before other packages' stories of it, so CropOverlay's first story is its own Upright (the old CropFrame card) ahead of draw's Crop tool stories; Crop rect takes the old title Upright
This commit is contained in:
@@ -69,7 +69,7 @@ fn drag_top_left(fixture: &mut Fixture) {
|
||||
}
|
||||
|
||||
#[story(CropOverlay<'static>, covers = [Default], drive = Drive::Custom(drag_top_left))]
|
||||
fn crop_rect(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
fn upright(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let rect = data.value("crop", crop());
|
||||
on_canvas(ui, |ui, at| CropOverlay::new("Crop", Bind::bound(&mut *rect)).show_at(ui, at))
|
||||
}
|
||||
|
||||
@@ -192,11 +192,22 @@ impl StoryRegistration {
|
||||
|
||||
inventory::collect!(StoryRegistration);
|
||||
|
||||
/// Every story linked into the running binary, by type name, then in the order they are declared in.
|
||||
/// Every story linked into the running binary, by type name; of each type, the stories of the package that registers
|
||||
/// it first, then those other packages declare; each in the order they are declared in.
|
||||
#[doc(hidden)]
|
||||
pub fn stories() -> Vec<&'static StoryRegistration> {
|
||||
let homes: HashMap<&str, &str> = crate::contract::registrations()
|
||||
.into_iter()
|
||||
.filter_map(|registration| {
|
||||
let name = registration.probe().map(|probe| probe.type_name()).or_else(|| registration.pattern_probe().map(|probe| probe.type_name()))?;
|
||||
Some((name, registration.crate_name()))
|
||||
})
|
||||
.collect();
|
||||
let mut all: Vec<_> = inventory::iter::<StoryRegistration>().collect();
|
||||
all.sort_by_key(|entry| ((entry.type_name)(), entry.file, entry.line));
|
||||
all.sort_by_key(|entry| {
|
||||
let name = (entry.type_name)();
|
||||
(name, homes.get(name) != Some(&entry.crate_name), entry.file, entry.line)
|
||||
});
|
||||
all
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
//! A package's stories of a type another package registers run that type's per-story cases in the package's suite;
|
||||
//! the cases about the type as a whole (its required states) stay with the package that registers it.
|
||||
//! the cases about the type as a whole (its required states) stay with the package that registers it. The type's own
|
||||
//! stories list before the visitor's.
|
||||
|
||||
use craft_ui::contract::{Common, Component, Cx, MeasureCx, Props as _, Role, Show as _};
|
||||
use craft_ui::style::StyleCx;
|
||||
use craft_ui::testing::{Story, StoryData, StoryOutput, StoryRegistration, trial};
|
||||
use craft_ui::testing::{Required, Story, StoryData, StoryOutput, StoryRegistration, trial};
|
||||
use craft_ui_test_kit::contract::PlainStyle;
|
||||
use egui::{Ui, Vec2};
|
||||
|
||||
@@ -39,9 +40,28 @@ fn plain_box(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
Visited { common: Common::new() }.label("Box").show(ui).into()
|
||||
}
|
||||
|
||||
// The visitor's story covers no state: a Default story is the registering package's to have.
|
||||
// The visitor's story covers no state: a Default story is the registering package's to have. Its file sorts before
|
||||
// the home story's.
|
||||
craft_ui::testing::__private::inventory::submit! {
|
||||
StoryRegistration::new(VISITOR, "craft_ui_visitor", std::any::type_name::<Visited>, Story::new("plain_box", plain_box))
|
||||
StoryRegistration::new(VISITOR, "craft_ui_visitor", std::any::type_name::<Visited>, Story::new("plain_box", plain_box)).at("a.rs", 1)
|
||||
}
|
||||
|
||||
craft_ui::testing::__private::inventory::submit! {
|
||||
StoryRegistration::new(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
"craft_ui_contract",
|
||||
std::any::type_name::<Visited>,
|
||||
Story::new("home_box", plain_box).covers(&[Required::Default]),
|
||||
)
|
||||
.at("z.rs", 1)
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_types_own_stories_list_before_another_packages() {
|
||||
let visited = std::any::type_name::<Visited>();
|
||||
let names: Vec<&str> =
|
||||
craft_ui::testing::stories().into_iter().filter(|entry| (entry.type_name)() == visited).map(|entry| entry.story.name).collect();
|
||||
assert_eq!(names, ["home_box", "plain_box"], "the registering package's story comes first");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
|
||||
Reference in New Issue
Block a user