mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 20:14:31 +01:00
Memoized views stay the one change mechanism: next's settling-path additions (modifier reads as bind keys, given-edit and keymap unsettling, settle counters) give way to the tracked inputs that cover them, and request_own_repaint calls become request_repaint. next's command board, node facts after the node check, the guide drag out of a ruler and the CommandStates input are taken; the trials next wrote on Lazy::settles run on memoized views. The ruler guide env value keys a view under the canvas in every pass of a drag. The replay audit's run in the gate takes next's target selection.
33 lines
1.5 KiB
Rust
33 lines
1.5 KiB
Rust
//! A step that cannot move a value is not offered: a value at the end of its range declares no step past it, and a
|
|
//! value that wraps declares both steps at either end.
|
|
|
|
use craft_ui::choice::Rating;
|
|
use craft_ui::contract::{Props as _, Role, Show as _};
|
|
use craft_ui::testing::access::Declared;
|
|
use craft_ui::testing::{Fixture, Story, StoryData, StoryOutput, trial};
|
|
use craft_ui::value_drag::AngleDial;
|
|
use egui::Ui;
|
|
|
|
fn top_rating(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
|
Rating::new(data.bind("stars", 5u8), 5).label("Rating").show(ui).into()
|
|
}
|
|
|
|
fn dial_at_start(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
|
AngleDial::new(data.bind("angle", 0.0)).range(0.0..=360.0).label("Angle").show(ui).into()
|
|
}
|
|
|
|
/// Whether the one node of `role` declares Increment and Decrement.
|
|
fn steps(show: fn(&mut Ui, &mut StoryData) -> StoryOutput, role: Role) -> (bool, bool) {
|
|
let mut fixture = Fixture::story(&Story::new("steps", show));
|
|
fixture.settle();
|
|
let node = fixture.by_role(role).first().expect("the node").node;
|
|
let tree = fixture.tree();
|
|
(tree.declares_key(node, Declared::Increment), tree.declares_key(node, Declared::Decrement))
|
|
}
|
|
|
|
#[trial]
|
|
fn a_value_at_its_range_end_offers_no_step_past_it_unless_it_wraps() {
|
|
assert_eq!(steps(top_rating, Role::RADIO_GROUP), (false, true), "a full rating offers Decrement only");
|
|
assert_eq!(steps(dial_at_start, Role::SLIDER), (true, true), "a one-turn dial at its start wraps, so it offers both");
|
|
}
|