mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-22 18:41:27 +01:00
ui-widgets: NumberField::STEP_UP and STEP_DOWN name the step arrows' parts publicly; the step-arrow trial and story use them
This commit is contained in:
1 parent
ae8bffc192
commit
70bb11ab70
3 files changed
+11
-13
No files matched your search
@@ -92,10 +92,6 @@ fn content_sized<C: Component>(cx: &MeasureCx<'_, C>) -> bool {
|
||||
const PRESETS: PartKey = PartKey::new("presets");
|
||||
/// The chevron that opens the popup slider.
|
||||
const SLIDER: PartKey = PartKey::new("slider");
|
||||
/// The up half of the step arrows.
|
||||
const STEP_UP: PartKey = PartKey::new("step_up");
|
||||
/// The down half of the step arrows.
|
||||
const STEP_DOWN: PartKey = PartKey::new("step_down");
|
||||
|
||||
/// The style of a number field: the field look, which the chevrons are laid out by, and the unit's text.
|
||||
#[derive(Clone, Debug, PartialEq, ComponentStyle)]
|
||||
@@ -200,6 +196,11 @@ pub struct NumberField<'a, V: NumberValue + 'static = Option<f64>> {
|
||||
}
|
||||
|
||||
impl<'a> NumberField<'a, Option<f64>> {
|
||||
/// The up half of the step arrows ([`step_arrows`](Self::step_arrows)): a press steps the value up once.
|
||||
pub const STEP_UP: PartKey = PartKey::new("step_up");
|
||||
/// The down half of the step arrows: a press steps the value down once.
|
||||
pub const STEP_DOWN: PartKey = PartKey::new("step_down");
|
||||
|
||||
/// A number field named `label`; empty text is `None`.
|
||||
pub fn new(label: impl Into<Label>, value: Bind<'a, Option<f64>>) -> Self {
|
||||
Self::of(label, value)
|
||||
@@ -426,7 +427,7 @@ impl<'a, V: NumberValue + 'static> NumberField<'a, V> {
|
||||
fn before_text(cx: &MeasureCx<'_, Self>, arrows: StepArrows) -> Vec<Adornment> {
|
||||
let mut before = Vec::new();
|
||||
if arrows == StepArrows::Leading {
|
||||
before.push(Adornment::steps(STEP_UP, STEP_DOWN));
|
||||
before.push(Adornment::steps(NumberField::STEP_UP, NumberField::STEP_DOWN));
|
||||
}
|
||||
if let Some(inside) = cx.env.inside_label() {
|
||||
match (inside.icon(), inside.text()) {
|
||||
@@ -654,7 +655,7 @@ impl<V: NumberValue + 'static> Component for NumberField<'_, V> {
|
||||
let fine_shows = self.decimals() >= decimals_for_step(rule.step / LARGE_STEPS);
|
||||
// A press on a half steps in the pass it goes down; while it is held the steps due since the last pass
|
||||
// repeat, from the press's own start time and the pass's time, so a rerun pass (no time elapsed) steps none.
|
||||
for (key, notches) in [(STEP_UP, 1), (STEP_DOWN, -1)] {
|
||||
for (key, notches) in [(NumberField::STEP_UP, 1), (NumberField::STEP_DOWN, -1)] {
|
||||
let Some(press) = cx.part_if_declared(key).map(|part| part.press) else { continue };
|
||||
let (start, first) = match press.phase {
|
||||
PressPhase::Down { start, .. } => (start, true),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Stories of `NumberField`.
|
||||
|
||||
use super::{NamedOr, NumberField, NumberName, NumberPick, STEP_UP, StepArrows, UnitPlacement};
|
||||
use super::{NamedOr, NumberField, NumberName, NumberPick, StepArrows, UnitPlacement};
|
||||
use crate::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _, Validity};
|
||||
use crate::display::Text;
|
||||
use crate::form::{Field, FieldGroup};
|
||||
@@ -147,7 +147,7 @@ fn number_field_step_arrows(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
/// the step-arrow trial's: every repeated step is an edit of its own, and a drive ends its edit once.
|
||||
fn hold_up(fixture: &mut Fixture) {
|
||||
fixture.settle();
|
||||
let at = fixture.root_id().and_then(|root| fixture.part_rect(root, STEP_UP)).map(|rect| rect.center());
|
||||
let at = fixture.root_id().and_then(|root| fixture.part_rect(root, NumberField::STEP_UP)).map(|rect| rect.center());
|
||||
if let Some(at) = at {
|
||||
fixture.frame(vec![pointer::moved(at)]);
|
||||
fixture.frame(vec![pointer::press(at)]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//! The step arrows of a number field: one press steps once, a held press repeats by the pass time, and a field that
|
||||
//! takes no input takes no press.
|
||||
|
||||
use craft_behavior::{HoldRepeat, PartKey};
|
||||
use craft_behavior::HoldRepeat;
|
||||
use craft_ui::contract::{Bind, Props as _, Show as _};
|
||||
use craft_ui::testing::{Fixture, pointer, trial};
|
||||
use craft_ui::text::{NumberField, StepArrows};
|
||||
@@ -15,9 +15,6 @@ const START: f64 = 50.0;
|
||||
/// The field's label.
|
||||
const LABEL: &str = "Size";
|
||||
|
||||
/// The up half's part, as the field declares it.
|
||||
const UP: PartKey = PartKey::new("step_up");
|
||||
|
||||
/// A field with leading step arrows, `enabled` and `read_only` as given, and the number it reports.
|
||||
fn field(enabled: bool, read_only: bool) -> (Fixture, Rc<Cell<f64>>) {
|
||||
let value = Rc::new(Cell::new(START));
|
||||
@@ -38,7 +35,7 @@ fn field(enabled: bool, read_only: bool) -> (Fixture, Rc<Cell<f64>>) {
|
||||
/// The middle of the up half.
|
||||
fn up(fixture: &Fixture) -> Pos2 {
|
||||
let root = fixture.root_id().expect("the field is shown");
|
||||
fixture.part_rect(root, UP).expect("the field declares its up half").center()
|
||||
fixture.part_rect(root, NumberField::STEP_UP).expect("the field declares its up half").center()
|
||||
}
|
||||
|
||||
/// Presses the up half and leaves the button down.
|
||||
|
||||
Reference in new issue
Block a user