From 0b823cd7b0632dafadee48814bf5cfa046d4fb5d Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 15 Nov 2026 21:30:32 +0000 Subject: [PATCH] tfix4-f6: value controls that step by the wheel declare it, so a Free scope frees them --- crates/font-manager/src/picker.rs | 3 +- .../ui-contract/src/contract/steps/sense.rs | 13 ++-- crates/ui-widgets/src/pickers/combo_box.rs | 3 +- crates/ui-widgets/src/pickers/select.rs | 5 ++ crates/ui-widgets/src/text/number.rs | 4 +- crates/ui-widgets/tests/it/value_drag.rs | 61 +++++++++++++------ 6 files changed, 62 insertions(+), 27 deletions(-) diff --git a/crates/font-manager/src/picker.rs b/crates/font-manager/src/picker.rs index b618ab17a..46f9f6180 100644 --- a/crates/font-manager/src/picker.rs +++ b/crates/font-manager/src/picker.rs @@ -507,8 +507,9 @@ impl Component for FontPicker<'_> { craft_ui::text::FieldStyle::at(cx) } + /// The wheel steps the family through the list. fn sense(&self) -> Sense { - Sense::CLICK | Sense::FOCUS | Sense::TAKE_FOCUS + Sense::CLICK | Sense::FOCUS | Sense::TAKE_FOCUS | Sense::WHEEL_Y } /// The width of the longest family names in common use, so the field keeps its size whichever family is picked. diff --git a/crates/ui-contract/src/contract/steps/sense.rs b/crates/ui-contract/src/contract/steps/sense.rs index 5a342acc3..7e659ea03 100644 --- a/crates/ui-contract/src/contract/steps/sense.rs +++ b/crates/ui-contract/src/contract/steps/sense.rs @@ -7,12 +7,13 @@ use craft_theme::{State, StateMix}; use egui::{Context, Id, Rect}; /// Registers a wheel taker for next pass's split (8.6): `sensed`, the taker the wheel bits of the component's sense -/// make (`WheelTaker::for_sense`). Every value control is a `WheelTaker::value` taker, in any scope: a wheel gesture -/// it owns ends with a `WheelPhase::End` share. A value control with a text part is a field (`WheelTaker::field`). A -/// value control takes the wheel only while focused or armed, on the axes it senses (the vertical one when it senses -/// none); inside a `WheelScope::Free` scope one that senses the wheel takes it without focus. Inside a -/// `WheelScope::Gated` scope every taker waits for focus or arming. A zoom zone that takes no axis itself waits only -/// for a gated scope: its wheel goes to the view around it. +/// make (`WheelTaker::for_sense`). Every value control is a `WheelTaker::value` taker, in any scope: a wheel gesture it +/// owns ends with a `WheelPhase::End` share. A value control with a text part is a field (`WheelTaker::field`). A value +/// control takes the wheel only while focused or armed, on the axes it senses (the vertical one when it senses none); +/// inside a `WheelScope::Free` scope one that senses the wheel takes it without focus. A value control that steps by +/// the wheel declares the axis it steps in its sense, so a free scope frees it; one that does not step keeps the +/// fallback and stays gated. Inside a `WheelScope::Gated` scope every taker waits for focus or arming. A zoom zone that +/// takes no axis itself waits only for a gated scope: its wheel goes to the view around it. pub(crate) fn register_wheel( ctx: &Context, id: Id, diff --git a/crates/ui-widgets/src/pickers/combo_box.rs b/crates/ui-widgets/src/pickers/combo_box.rs index f69eac27f..0f9eb9247 100644 --- a/crates/ui-widgets/src/pickers/combo_box.rs +++ b/crates/ui-widgets/src/pickers/combo_box.rs @@ -111,8 +111,9 @@ impl Component for ComboBox<'_> { crate::text::FieldStyle::at(cx) } + /// The wheel steps the text through the options. fn sense(&self) -> Sense { - Sense::CLICK | Sense::FOCUS | Sense::TAKE_FOCUS + Sense::CLICK | Sense::FOCUS | Sense::TAKE_FOCUS | Sense::WHEEL_Y } /// The widest of the current text, the placeholder and the options, and the room of the chevron: the field keeps diff --git a/crates/ui-widgets/src/pickers/select.rs b/crates/ui-widgets/src/pickers/select.rs index 0d665f620..206ce7dc2 100644 --- a/crates/ui-widgets/src/pickers/select.rs +++ b/crates/ui-widgets/src/pickers/select.rs @@ -185,6 +185,11 @@ impl Component for Select<'_, T> { } } + /// The face senses the pointer; the wheel steps the pick. + fn sense(&self) -> Sense { + Sense::CLICK | Sense::FOCUS | Sense::WHEEL_Y + } + /// The widest face of an entry (its closed label, or its picture), the placeholder and the mixed word, so the field /// keeps its size whichever is shown. fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { diff --git a/crates/ui-widgets/src/text/number.rs b/crates/ui-widgets/src/text/number.rs index af759a050..4cdbb89ea 100644 --- a/crates/ui-widgets/src/text/number.rs +++ b/crates/ui-widgets/src/text/number.rs @@ -398,9 +398,9 @@ impl Component for NumberField<'_, V> { } } - /// A drag on the body scrubs a field that is not in edit. + /// A drag on the body scrubs a field that is not in edit; the wheel steps the value. fn sense(&self) -> Sense { - Sense::CLICK | Sense::DRAG | Sense::FOCUS | Sense::TAKE_FOCUS + Sense::CLICK | Sense::DRAG | Sense::FOCUS | Sense::TAKE_FOCUS | Sense::WHEEL_Y } fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { diff --git a/crates/ui-widgets/tests/it/value_drag.rs b/crates/ui-widgets/tests/it/value_drag.rs index 88c70c4cf..73bb7bdc3 100644 --- a/crates/ui-widgets/tests/it/value_drag.rs +++ b/crates/ui-widgets/tests/it/value_drag.rs @@ -145,21 +145,31 @@ fn a_leaf_at_a_degenerate_rect_neither_panics_nor_changes_its_value() { } } -/// The wheel over a slider in a scrolling panel scrolls the panel while the slider has no focus; it steps the slider -/// once the slider has focus, or without focus inside a `WheelScope::Free` scope (an adjustment dialog). An outer -/// `WheelScope::Gated` scope (a card in the Overview) wins over a free one inside it. +/// The wheel over a value control in a scrolling panel (a slider, a number field, a select) scrolls the panel while the +/// control has no focus; it steps the control once the control has focus, or without focus inside a `WheelScope::Free` +/// scope (an adjustment dialog, an options bar). An outer `WheelScope::Gated` scope (a card in the Overview) wins over a +/// free one inside it. #[trial] -fn the_wheel_steps_a_slider_when_focused_or_freed_and_otherwise_scrolls_the_panel() { - use craft_ui::contract::{ContainerProps, Scroll, ShowContainer as _}; +fn the_wheel_steps_a_value_control_when_focused_or_freed_and_otherwise_scrolls_the_panel() { + use craft_ui::contract::{ContainerProps, Entry, Scroll, ShowContainer as _}; + use craft_ui::pickers::Select; + use craft_ui::text::NumberField; use craft_ui::runtime::env::{WheelScope, with_env}; use craft_ui::runtime::focus::{FocusTarget, request}; use craft_ui::testing::layout::{Block, in_region}; use craft_ui_test_kit::body::Slab; use std::cell::Cell; - /// How far the value and the panel moved after one wheel turn over the slider, shown in the scopes `scopes` + #[derive(Clone, Copy, Debug)] + enum Control { + Slider, + Number, + Select, + } + + /// How far the value and the panel moved after one wheel turn over `control`, shown in the scopes `scopes` /// (outer first) inside the panel. - fn turned(scopes: &[WheelScope], focused: bool) -> (f64, f32) { + fn turned(control: Control, scopes: &[WheelScope], focused: bool) -> (f64, f32) { fn nested(ui: &mut Ui, scopes: &[WheelScope], body: &mut dyn FnMut(&mut Ui)) { match scopes.split_first() { Some((scope, inner)) => with_env(ui, |set| set.wheel = Some(*scope), |ui| nested(ui, inner, body)), @@ -174,8 +184,23 @@ fn the_wheel_steps_a_slider_when_focused_or_freed_and_otherwise_scrolls_the_pane top.set(ui.next_widget_position().y); nested(ui, scopes, &mut |ui| { let mut value = value.borrow_mut(); - let shown = Slider::new(Bind::bound(&mut *value), 0.0..=100.0).label("Opacity").show(ui); - slider.set(Some((shown.response.id, shown.response.rect))); + let response = match control { + Control::Slider => Slider::new(Bind::bound(&mut *value), 0.0..=100.0).label("Opacity").show(ui).response, + Control::Number => { + let mut number = Some(*value); + let response = NumberField::new("Opacity", Bind::bound(&mut number)).show(ui).edit.response; + *value = number.unwrap_or(*value); + response + } + Control::Select => { + let entries: Vec> = (40..=60).map(|n| Entry::new(n, format!("{n} %"))).collect(); + let mut pick = *value as u8; + let response = Select::new("Opacity", Bind::bound(&mut pick), &entries).show(ui).response; + *value = f64::from(pick); + response + } + }; + slider.set(Some((response.id, response.rect))); }); Block::new(Vec2::new(100.0, 1000.0)).show(ui); }); @@ -195,14 +220,16 @@ fn the_wheel_steps_a_slider_when_focused_or_freed_and_otherwise_scrolls_the_pane (*value.borrow() - value_before, top_before - top.get()) } - let (value, panel) = turned(&[], false); - assert!(value == 0.0 && panel > 0.0, "unfocused: the panel scrolls and the value stays ({value}, {panel})"); - let (value, panel) = turned(&[], true); - assert!(value != 0.0 && panel == 0.0, "focused: the slider steps and the panel stays ({value}, {panel})"); - let (value, panel) = turned(&[WheelScope::Free], false); - assert!(value != 0.0 && panel == 0.0, "free scope: the unfocused slider steps ({value}, {panel})"); - let (value, panel) = turned(&[WheelScope::Gated, WheelScope::Free], false); - assert!(value == 0.0 && panel > 0.0, "a gated scope wins over a free one inside it ({value}, {panel})"); + for control in [Control::Slider, Control::Number, Control::Select] { + let (value, panel) = turned(control, &[], false); + assert!(value == 0.0 && panel > 0.0, "{control:?} unfocused: the panel scrolls and the value stays ({value}, {panel})"); + let (value, panel) = turned(control, &[], true); + assert!(value != 0.0 && panel == 0.0, "{control:?} focused: it steps and the panel stays ({value}, {panel})"); + let (value, panel) = turned(control, &[WheelScope::Free], false); + assert!(value != 0.0 && panel == 0.0, "{control:?} in a free scope: it steps unfocused ({value}, {panel})"); + let (value, panel) = turned(control, &[WheelScope::Gated, WheelScope::Free], false); + assert!(value == 0.0 && panel > 0.0, "{control:?}: a gated scope wins over a free one inside it ({value}, {panel})"); + } } #[trial]