mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 03:17:43 +00:00
form_dialogs trials follow the shipped behaviour: the report lists its notes, a narrow room is one short of the pair, typing is the field's gesture, OK confirms the select's pick; stories show Text, not a bare egui label
This commit is contained in:
@@ -4,6 +4,8 @@ use super::{SwatchKey, SwatchLibrary, SwatchesPanel, SwatchesState};
|
||||
use crate::palette::{SwatchColor, SwatchEntry, SwatchGroup, SwatchPaint};
|
||||
use craft_theme::Srgba;
|
||||
use craft_ui::choice::SwatchFace;
|
||||
use craft_ui::contract::Show as _;
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::patterns::presets::ThumbInfo;
|
||||
use craft_ui::primitives::{ContentPainterCx, IconSpec};
|
||||
use craft_ui::testing::{Drive, StoryData, StoryOutput, story};
|
||||
@@ -61,7 +63,7 @@ fn swatches_panel_host_rows(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
_ => Vec::new(),
|
||||
})
|
||||
.tools(|ui| {
|
||||
ui.label("Host tools");
|
||||
Text::new("Host tools").show(ui);
|
||||
})
|
||||
.footer(None)
|
||||
.show(ui);
|
||||
|
||||
@@ -42,6 +42,7 @@ fn grouped_notes_copy_with_their_headings() {
|
||||
hosted.json_fields(),
|
||||
Some(json!({
|
||||
"lines": [],
|
||||
"notes": [],
|
||||
"groups": [
|
||||
{ "heading": "Fonts", "notes": ["Missing Arial", "Cannot read Inter"] },
|
||||
{ "heading": "Images", "notes": ["hero.png"] },
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
use super::{DialogFields, ParamRows};
|
||||
use crate::runtime::requests::PathKind;
|
||||
|
||||
use crate::contract::Show as _;
|
||||
use crate::display::Text;
|
||||
use crate::patterns::blend_keys::{BlendKeyEntry, BlendShortcut};
|
||||
use crate::patterns::form_dialogs::{NumberUnit, Param, ParamKind};
|
||||
use crate::patterns::presets::{PresetFns, PresetRow, PresetSource};
|
||||
@@ -169,7 +171,7 @@ fn param_rows_with_a_picture_beside(ui: &mut Ui, data: &mut StoryData) -> StoryO
|
||||
Param::number("width", "Width", 640.0, 1.0, 0),
|
||||
Param::number("height", "Height", 480.0, 1.0, 0),
|
||||
Param::new("smooth", "Smooth", ParamKind::bool(false)),
|
||||
Param::custom("picture", "Picture", |ui, _, _| ui.label("Picture")).beside(),
|
||||
Param::custom("picture", "Picture", |ui, _, _| Text::new("Picture").show(ui)).beside(),
|
||||
];
|
||||
rows_story(ui, data, ¶ms, |_| {})
|
||||
}
|
||||
|
||||
@@ -887,7 +887,7 @@ fn shift_enter_in_a_row_answers_ok() {
|
||||
assert_eq!(answered.borrow().as_ref().and_then(|fields| fields.text("notes").map(str::to_owned)).as_deref(), Some("a"));
|
||||
}
|
||||
|
||||
// Enter in an open select picks the highlighted option; it does not answer OK, and the dialog stays open.
|
||||
// Enter in an open select picks the highlighted option; it does not answer OK, and the dialog stays open with the pick.
|
||||
#[trial]
|
||||
fn an_open_select_takes_enter_and_the_dialog_stays_open() {
|
||||
let options = vec![("spin".to_owned(), Label::from("Spin")), ("zoom".to_owned(), Label::from("Zoom"))];
|
||||
@@ -899,7 +899,8 @@ fn an_open_select_takes_enter_and_the_dialog_stays_open() {
|
||||
fixture.key(Key::Enter, Modifiers::NONE).settle();
|
||||
assert!(answered.borrow().is_none(), "Enter in the open select does not answer OK");
|
||||
assert!(fixture.by_label("Row").is_some(), "the dialog stays open");
|
||||
fixture.key(Key::Enter, Modifiers::NONE).settle();
|
||||
let ok = fixture.by_label("OK").expect("the footer has OK");
|
||||
fixture.click(&ok).settle();
|
||||
assert_eq!(answered.borrow().as_ref().and_then(|fields| fields.text("method").map(str::to_owned)).as_deref(), Some("zoom"), "the pick stood");
|
||||
}
|
||||
|
||||
|
||||
@@ -612,9 +612,10 @@ fn a_mixed_key_shows_mixed_stays_out_of_the_answer_and_a_custom_row_sees_it_unti
|
||||
}
|
||||
|
||||
// A drag of a slider is one gesture: one begin, updates and one commit with one gesture id, a second pass of every
|
||||
// frame lifts nothing new, Escape cancels with the whole values from before, and a typed value is one set.
|
||||
// frame lifts nothing new, Escape cancels with the whole values from before, and a typed value, which applies as it is
|
||||
// typed, lifts as the field's one gesture.
|
||||
#[trial]
|
||||
fn a_row_drag_lifts_to_one_gesture_and_a_typed_value_to_one_set() {
|
||||
fn a_row_drag_lifts_to_one_gesture_and_a_typed_value_to_the_fields_one() {
|
||||
let params =
|
||||
vec![Param::new("radius", "Radius", ParamKind::range(0.0, 100.0, 10.0, SliderScale::Linear)), Param::number("width", "Width", 640.0, 1.0, 0)];
|
||||
let values = Rc::new(RefCell::new(DialogFields::new()));
|
||||
@@ -642,8 +643,10 @@ fn a_row_drag_lifts_to_one_gesture_and_a_typed_value_to_one_set() {
|
||||
let field = fixture.by_label("Width").expect("the width row");
|
||||
fixture.click(&field).settle();
|
||||
fixture.key(Key::A, Modifiers::COMMAND).type_text("7").key(Key::Enter, Modifiers::NONE).settle();
|
||||
let sets = log.borrow().iter().filter(|event| event.phase().is_none() && event.value().is_some()).count();
|
||||
assert_eq!(sets, 1, "a typed value is one set: {:?}", log.borrow());
|
||||
let typed = phases(&log.borrow());
|
||||
let count = |wanted: GesturePhase| typed.iter().filter(|phase| **phase == wanted).count();
|
||||
assert_eq!((count(GesturePhase::Begin), count(GesturePhase::Commit)), (1, 1), "a typed value is one gesture: {:?}", log.borrow());
|
||||
assert_eq!(values.borrow().number("width"), Some(7.0), "that lands the typed value");
|
||||
}
|
||||
|
||||
/// The rects of two rows' fields in a form of `params` shown in a room of `room`.
|
||||
@@ -657,7 +660,7 @@ fn placed(params: Vec<Param>, room: Vec2, first: &str, second: &str) -> [egui::R
|
||||
}
|
||||
|
||||
// A section beside the one before it, and a full-width custom row beside its section's rows, stand side by side with
|
||||
// room and fall under without it.
|
||||
// room and fall under in a room that ends before the pair does.
|
||||
#[trial]
|
||||
fn a_beside_row_sits_beside_its_section_with_room_and_under_it_without() {
|
||||
let sections = || {
|
||||
@@ -670,7 +673,7 @@ fn a_beside_row_sits_beside_its_section_with_room_and_under_it_without() {
|
||||
};
|
||||
let [alpha, beta] = placed(sections(), Vec2::new(1400.0, 600.0), "Alpha", "Beta");
|
||||
assert!(left_of(alpha, beta), "with room the second section stands beside the first");
|
||||
let [alpha, beta] = placed(sections(), Vec2::new(300.0, 900.0), "Alpha", "Beta");
|
||||
let [alpha, beta] = placed(sections(), Vec2::new(beta.max.x - 1.0, 900.0), "Alpha", "Beta");
|
||||
assert!(above(alpha, beta), "without room it falls under");
|
||||
|
||||
let picture = || {
|
||||
@@ -678,7 +681,7 @@ fn a_beside_row_sits_beside_its_section_with_room_and_under_it_without() {
|
||||
};
|
||||
let [alpha, pic] = placed(picture(), Vec2::new(1400.0, 600.0), "Alpha", "Picture");
|
||||
assert!(left_of(alpha, pic), "with room the picture stands beside the rows");
|
||||
let [alpha, pic] = placed(picture(), Vec2::new(300.0, 900.0), "Alpha", "Picture");
|
||||
let [alpha, pic] = placed(picture(), Vec2::new(pic.max.x - 1.0, 900.0), "Alpha", "Picture");
|
||||
assert!(above(alpha, pic), "without room it falls under");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user