mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 03:17:43 +00:00
appearance-w3: net change of 1 commits
- appearance-w3: written from its sheet
This commit is contained in:
@@ -19,8 +19,8 @@ impl<'a> NumberStepper<'a> {
|
||||
NumberStepper(Box::new(next))
|
||||
}
|
||||
|
||||
pub(super) fn next(&self, from: f64, direction: i32) -> f64 {
|
||||
(self.0)(from, direction, 1.0) // P3(appearance-w3): ap.AP15
|
||||
pub(super) fn next(&self, from: f64, direction: i32, scale: f64) -> f64 {
|
||||
(self.0)(from, direction, scale)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
//! Popups: the dismissal rules.
|
||||
|
||||
use crate::overlay::kit::{Leaf, Opened, Opener, Seen};
|
||||
use craft_ui::contract::{Overlay, Props as _, Show as _, Trigger};
|
||||
use craft_ui::contract::{Bind, Overlay, Props as _, Role, Show as _, Trigger};
|
||||
use craft_ui::popover::Popover;
|
||||
use craft_ui::testing::pointer::{click, moved, press, release};
|
||||
use craft_ui::testing::{Frames, trial};
|
||||
use egui::{Pos2, Rect, Ui, Vec2};
|
||||
use std::cell::RefCell;
|
||||
use craft_ui::testing::{Fixture, Frames, trial};
|
||||
use craft_ui::text::NumberField;
|
||||
use egui::{Key, Modifiers, Pos2, Rect, Ui, Vec2};
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::rc::Rc;
|
||||
|
||||
const OPENER: Rect = Rect { min: Pos2::new(100.0, 100.0), max: Pos2::new(180.0, 120.0) };
|
||||
const BELOW: Rect = Rect { min: Pos2::new(300.0, 300.0), max: Pos2::new(360.0, 330.0) };
|
||||
@@ -70,3 +73,32 @@ fn a_click_on_the_opener_closes_its_open_menu() {
|
||||
frames.idle(30, &mut show);
|
||||
assert!(!opened.shown.get(), "the press on the opener reaches it, and its toggle closes the menu");
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn a_number_draft_in_a_popover_commits_when_an_outside_press_closes_it() {
|
||||
let (open, value) = (Rc::new(Cell::new(true)), Rc::new(Cell::new(Some(10.0f64))));
|
||||
let (shown_open, shown_value) = (open.clone(), value.clone());
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
let opener = craft_ui::buttons::Button::new("Stroke").show(ui);
|
||||
let mut is_open = shown_open.get();
|
||||
Popover::new("Stroke options", Bind::bound(&mut is_open)).opened_by(&opener).show(ui, |ui, _| {
|
||||
let mut number = shown_value.get();
|
||||
NumberField::new("Weight", Bind::bound(&mut number)).show(ui);
|
||||
shown_value.set(number);
|
||||
});
|
||||
shown_open.set(is_open);
|
||||
});
|
||||
fixture.settle();
|
||||
let field = fixture.by_label("Weight").expect("the field shows in the popover");
|
||||
fixture.click(&field);
|
||||
fixture.key(Key::A, Modifiers::COMMAND);
|
||||
// An expression applies on commit only, so it stays a draft until the popover closes.
|
||||
fixture.type_text("3+4");
|
||||
fixture.idle(2);
|
||||
assert_eq!(value.get(), Some(10.0), "the expression is a draft before the press");
|
||||
let dialog = fixture.by_role(Role::DIALOG).first().cloned().expect("the popover shows");
|
||||
fixture.click_at(dialog.rect.right_bottom() + Vec2::splat(40.0));
|
||||
fixture.idle(30);
|
||||
assert_eq!(value.get(), Some(7.0), "the draft commits when the outside press closes the popover");
|
||||
assert!(!open.get(), "the outside press closes the popover");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user