tfix4-f6: value controls that step by the wheel declare it, so a Free scope frees them

This commit is contained in:
aiongg
2026-11-15 21:30:32 +00:00
parent a83b8e9ce7
commit 0b823cd7b0
6 changed files with 62 additions and 27 deletions
+2 -1
View File
@@ -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.
@@ -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,
+2 -1
View File
@@ -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
+5
View File
@@ -185,6 +185,11 @@ impl<T: Value + 'static> 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 {
+2 -2
View File
@@ -398,9 +398,9 @@ impl<V: NumberValue + 'static> 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 {
+44 -17
View File
@@ -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<Entry<u8>> = (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]