Value controls take the wheel only while focused or armed

A value control takes the wheel only while focused or armed, on the axes
it senses. WheelScope replaces the wheel_gated scope: Free lets the
sliders of an adjustment dialog take the wheel without focus, and Gated
(the Overview card) gates every taker and wins over a Free inside it.
Slider senses the vertical wheel only; RangeSlider and ThumbRow sense no
wheel bits; PointPicker and AngleDial sense both scroll axes.
This commit is contained in:
aiongg
2026-11-12 14:32:39 +00:00
parent 264ad8cc53
commit 306fef9a38
25 changed files with 160 additions and 67 deletions
+2 -2
View File
@@ -83,8 +83,8 @@ pub struct WheelTaker<O> {
pub vertical: bool,
/// It takes zoom.
pub zoom: bool,
/// It takes any axis (scroll or zoom) only while focused or armed: a value control without wheel bits, or any
/// taker inside a wheel-gated scope.
/// It takes any axis (scroll or zoom) only while focused or armed: a value control, unless its scope frees it,
/// or any taker inside a gated scope.
pub gated: bool,
/// A scroll region (a scrolling body or collection): Shift turns the vertical wheel sideways over it.
pub scrolls: bool,
@@ -1,12 +1,11 @@
//! Brightness/Contrast: its value and editor.
use craft_ui::choice::Checkbox;
use craft_ui::contract::{Bind, EditResponse, Pattern, Props as _, Remember as _, Show as _, ShowContainer as _};
use craft_ui::form::FieldGroup;
use craft_ui::contract::{Bind, EditResponse, Pattern, Props as _, Remember as _, Show as _};
use craft_ui::runtime::env::Label;
use egui::Ui;
use crate::ui::adjust::sliders::{Run, lifted, read, words};
use crate::ui::adjust::sliders::{Run, editor_group, lifted, read, words};
use crate::ui::adjust::{AdjustContext, AdjustField};
/// Contrast's lowest value, and with Use Legacy.
@@ -68,7 +67,7 @@ impl<'a> BrightnessContrastEditor<'a> {
let BrightnessContrastEditor { label, mut value, context } = self;
let words = words(ui);
let mut edit = None;
let shown = FieldGroup::new(label).show(ui, |ui, cx| {
let shown = editor_group(ui, label, context, |ui, cx| {
let now = read(&mut value, cx).unwrap_or_default();
let lowest = if now.legacy { LEGACY_CONTRAST_MIN } else { CONTRAST_MIN };
let brightness = AdjustField::new("brightness", words.brightness.clone(), -150.0..=150.0, 0.0);
@@ -2,12 +2,12 @@
use craft_ui::choice::{Checkbox, Radio, RadioGroup};
use craft_ui::contract::{Bind, EditResponse, Outcome, Pattern, Props as _, Remember as _, Show as _, ShowContainer as _};
use craft_ui::form::{Field, FieldGroup};
use craft_ui::form::Field;
use craft_ui::layout_components::Row;
use craft_ui::runtime::env::Label;
use egui::Ui;
use crate::ui::adjust::sliders::{Run, lifted, read, words};
use crate::ui::adjust::sliders::{Run, editor_group, lifted, read, words};
use crate::ui::adjust::{AdjustContext, AdjustField};
/// The tone Color Balance shows.
@@ -156,7 +156,7 @@ impl<'a> ColorBalanceEditor<'a> {
let ColorBalanceEditor { label, mut value, tone: host_tone, context } = self;
let words = words(ui);
let mut out = None;
let shown = FieldGroup::new(label).show(ui, |ui, cx| {
let shown = editor_group(ui, label, context, |ui, cx| {
let now = read(&mut value, cx).unwrap_or_default();
let tone = host_tone.or(cx.memory::<BalanceMemory>().tone).unwrap_or_default();
let mut picked = None;
@@ -5,14 +5,14 @@ use craft_ui::choice::{Checkbox, Radio, RadioGroup, Swatch};
use craft_ui::contract::{
Bind, EditResponse, Entry, LabelKind, Outcome, Pattern, Props as _, Remember as _, Show as _, ShowContainer as _, SideLabel,
};
use craft_ui::form::{Field, FieldGroup};
use craft_ui::form::Field;
use craft_ui::layout_components::Row;
use craft_ui::pickers::Select;
use craft_ui::runtime::env::{Label, UnitKind};
use craft_ui::runtime::requests::ColorRequest;
use egui::Ui;
use crate::ui::adjust::sliders::{Run, lifted, read, words};
use crate::ui::adjust::sliders::{Run, editor_group, lifted, read, words};
use crate::ui::adjust::{AdjustContext, AdjustField, AdjustWords};
/// An opaque colour from 8-bit sRGB channels.
@@ -255,7 +255,7 @@ impl<'a> PhotoFilterEditor<'a> {
let PhotoFilterEditor { label, mut value, context } = self;
let words = words(ui);
let mut out = None;
let shown = FieldGroup::new(label).show(ui, |ui, cx| {
let shown = editor_group(ui, label, context, |ui, cx| {
let now = read(&mut value, cx).unwrap_or_default();
let preset = PhotoFilterPreset::of(now.color);
let use_color = cx.memory::<FilterMemory>().use_color.unwrap_or(preset.is_none());
@@ -1,11 +1,10 @@
//! Threshold: its editor.
use craft_ui::contract::{Bind, EditResponse, Pattern, Remember as _, Show as _, ShowContainer as _};
use craft_ui::form::FieldGroup;
use craft_ui::contract::{Bind, EditResponse, Pattern, Remember as _, Show as _};
use craft_ui::runtime::env::Label;
use egui::Ui;
use crate::ui::adjust::sliders::{Run, lifted, read, words};
use crate::ui::adjust::sliders::{Run, editor_group, lifted, read, words};
use crate::ui::adjust::{AdjustContext, AdjustField};
use crate::ui::histogram::{ChannelColor, Histogram, HistogramData};
@@ -59,7 +58,7 @@ impl<'a> ThresholdEditor<'a> {
let ThresholdEditor { label, mut level, histogram, context } = self;
let words = words(ui);
let mut edit = None;
let shown = FieldGroup::new(label).show(ui, |ui, cx| {
let shown = editor_group(ui, label, context, |ui, cx| {
let now = read(&mut level, cx).unwrap_or(THRESHOLD_DEFAULT).clamp(THRESHOLD_MIN, THRESHOLD_MAX);
let empty = HistogramData::tone(&[0u32; THRESHOLD_BINS][..], ChannelColor::Neutral);
let data = histogram.unwrap_or(&empty);
+4 -4
View File
@@ -28,14 +28,14 @@ pub struct AdjustContext {
}
impl AdjustContext {
/// An editor in an Image › Adjustments dialog. `dynamic` is Preferences › Interface › Dynamic
/// Color Sliders: colour tracks on the colour sliders, the plain track when off.
/// An editor in an Image › Adjustments dialog: the wheel over a slider steps it without focus. `dynamic` is
/// Preferences › Interface › Dynamic Color Sliders: colour tracks on the colour sliders, the plain track when off.
pub fn dialog(dynamic: bool) -> Self {
Self { dialog: true, dynamic_color_sliders: dynamic, gray: false }
}
/// An editor in the Properties panel (an adjustment layer). `dynamic` as in
/// [`dialog`](Self::dialog).
/// An editor in the Properties panel (an adjustment layer): the wheel steps only a focused or armed slider and
/// scrolls the panel over the others. `dynamic` as in [`dialog`](Self::dialog).
pub fn properties(dynamic: bool) -> Self {
Self { dialog: false, dynamic_color_sliders: dynamic, gray: false }
}
@@ -9,14 +9,14 @@ use craft_theme::{Hsb, Srgba};
use craft_ui::choice::Checkbox;
use craft_ui::contract::{Bind, EditResponse, Entry, Outcome, Pattern, Props as _, Remember as _, Show as _, ShowContainer as _};
use craft_ui::display::{Shade, Text};
use craft_ui::form::{Field, FieldGroup};
use craft_ui::form::Field;
use craft_ui::pickers::Select;
use craft_ui::runtime::env::{Env, Label, UnitKind};
use craft_ui::style::{DataColor, TypeRole};
use craft_ui::value_drag::{Anchor, Thumb, ThumbRow, TrackFace};
use egui::{Color32, Ui};
use super::sliders::{Run, lifted, read, words};
use super::sliders::{Run, editor_group, lifted, read, words};
use super::style::tones;
use super::{AdjustContext, AdjustField, AdjustTrack};
use crate::ui::curve::ToneRamp;
@@ -295,7 +295,7 @@ impl<'a> HueSaturationEditor<'a> {
let words = words(ui);
let units = Env::of(ui).units();
let mut out = None;
let shown = FieldGroup::new(label).show(ui, |ui, cx| {
let shown = editor_group(ui, label, context, |ui, cx| {
let now = read(&mut value, cx).unwrap_or_default();
let memory = cx.memory::<HueMemory>().clone();
// Colorize works on the master only.
@@ -4,13 +4,12 @@ use craft_theme::Srgba;
use craft_ui::buttons::Button;
use craft_ui::choice::{Checkbox, Swatch};
use craft_ui::contract::{Bind, EditResponse, Outcome, Pattern, Props as _, Remember as _, Show as _, ShowContainer as _, clicked};
use craft_ui::form::FieldGroup;
use craft_ui::layout_components::Row;
use craft_ui::runtime::env::{Label, UnitKind};
use craft_ui::runtime::requests::ColorRequest;
use egui::Ui;
use crate::ui::adjust::sliders::{Run, lifted, read, words};
use crate::ui::adjust::sliders::{Run, editor_group, lifted, read, words};
use crate::ui::adjust::style::{mix, tones};
use crate::ui::adjust::{AdjustContext, AdjustField, AdjustTrack};
@@ -117,7 +116,7 @@ impl<'a> BlackWhiteEditor<'a> {
let BlackWhiteEditor { label, mut value, context } = self;
let words = words(ui);
let mut out = None;
let shown = FieldGroup::new(label).show(ui, |ui, cx| {
let shown = editor_group(ui, label, context, |ui, cx| {
let now = read(&mut value, cx).unwrap_or_default();
let names = [&words.reds, &words.yellows, &words.greens, &words.cyans, &words.blues, &words.magentas];
let keys = ["reds", "yellows", "greens", "cyans", "blues", "magentas"];
@@ -4,13 +4,13 @@ use craft_theme::variant::Tone;
use craft_ui::choice::Checkbox;
use craft_ui::contract::{Bind, EditResponse, Entry, Pattern, Props as _, Remember as _, Show as _, ShowContainer as _};
use craft_ui::display::Text;
use craft_ui::form::{Field, FieldGroup, Help};
use craft_ui::form::{Field, Help};
use craft_ui::runtime::env::{Env, Label, UnitKind, Units};
use craft_ui::style::TypeRole;
use egui::Ui;
use super::Tables;
use crate::ui::adjust::sliders::{Run, lifted, read, words};
use crate::ui::adjust::sliders::{Run, editor_group, lifted, read, words};
use crate::ui::adjust::style::{mix, tones};
use crate::ui::adjust::{AdjustContext, AdjustField, AdjustTrack, AdjustWords};
@@ -127,7 +127,7 @@ impl<'a> ChannelMixerEditor<'a> {
let words = words(ui);
let units = Env::of(ui).units();
let mut edit = None;
let shown = FieldGroup::new(label.clone()).show(ui, |ui, cx| {
let shown = editor_group(ui, label.clone(), context, |ui, cx| {
let now = read(&mut value, cx).unwrap_or_default();
let mono = now.gray.is_some();
// Monochrome has the one output, Gray.
@@ -2,13 +2,13 @@
use craft_ui::choice::{Radio, RadioGroup};
use craft_ui::contract::{Bind, EditResponse, Entry, Outcome, Pattern, Props as _, Remember as _, Show as _, ShowContainer as _};
use craft_ui::form::{Field, FieldGroup};
use craft_ui::form::Field;
use craft_ui::layout_components::Row;
use craft_ui::runtime::env::{Label, UnitKind};
use egui::Ui;
use super::Tables;
use crate::ui::adjust::sliders::{Run, lifted, read, words};
use crate::ui::adjust::sliders::{Run, editor_group, lifted, read, words};
use crate::ui::adjust::{AdjustContext, AdjustField};
/// Selective Color's method.
@@ -110,7 +110,7 @@ impl<'a> SelectiveColorEditor<'a> {
let SelectiveColorEditor { label, mut value, context } = self;
let words = words(ui);
let mut out = None;
let shown = FieldGroup::new(label).show(ui, |ui, cx| {
let shown = editor_group(ui, label, context, |ui, cx| {
let now = read(&mut value, cx).unwrap_or_default();
let memory = cx.memory::<SelectiveMemory>().clone();
let range = memory.range.min(RANGES - 1);
+15 -3
View File
@@ -12,9 +12,9 @@ use std::ops::RangeInclusive;
use std::sync::Arc;
use craft_behavior::{EditEvent, EditEvents, Mixed, Value, decimals_for_step};
use craft_ui::contract::{Bind, BodyCx, EditResponse, Pattern, Props as _, Remember as _, Show as _, ShowContainer as _};
use craft_ui::contract::{Bind, BodyCx, EditResponse, Inner, Pattern, Props as _, Remember as _, Show as _, ShowContainer as _};
use craft_ui::form::{FieldGroup, SliderField};
use craft_ui::runtime::env::{Env, Label, UnitKind};
use craft_ui::runtime::env::{Env, Label, UnitKind, WheelScope, with_env};
use craft_ui::style::DataColor;
use craft_ui::value_drag::TrackFace;
use egui::{Response, Ui};
@@ -177,7 +177,7 @@ impl<'a> AdjustSliders<'a> {
pub fn show(self, ui: &mut Ui) -> EditResponse<Vec<f64>> {
let AdjustSliders { label, fields, mut values, context } = self;
let mut edit = None;
let shown = FieldGroup::new(label).show(ui, |ui, cx| {
let shown = editor_group(ui, label, context, |ui, cx| {
let held = read(&mut values, cx).unwrap_or_default();
let now: Vec<f64> = fields.iter().enumerate().map(|(i, f)| f.clamp(held.get(i).copied().unwrap_or(f.default))).collect();
let mut run = Run::start(&mut values, context, now.clone(), cx.memory::<Memory>().began.clone());
@@ -195,6 +195,18 @@ impl<'a> AdjustSliders<'a> {
}
}
/// The editor's `FieldGroup` around `body`. In a dialog its sliders take the wheel without focus
/// (`WheelScope::Free`); in the Properties panel only while focused or armed, so the panel scrolls over them.
pub(super) fn editor_group<R>(
ui: &mut Ui,
label: Label,
context: AdjustContext,
body: impl FnMut(&mut Ui, &mut BodyCx<'_>) -> R,
) -> Inner<Response, R> {
let wheel = if context.is_dialog() { WheelScope::Free } else { WheelScope::Plain };
with_env(ui, |scope| scope.wheel = Some(wheel), |ui| FieldGroup::new(label).show(ui, body))
}
/// The value of `bind` a body starts its pass from; `None` while it is mixed.
pub(super) fn read<V: Value>(bind: &mut Bind<'_, V>, cx: &mut BodyCx<'_>) -> Option<V> {
match bind.reborrow().read(cx) {
@@ -570,7 +570,7 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
.vertical(vertical)
.horizontal(horizontal)
.scrolls(true)
.gated(crate::runtime::env::Env::of(pcx.ui).wheel_gated)
.gated(crate::runtime::env::Env::of(pcx.ui).wheel == crate::runtime::env::WheelScope::Gated)
.notch(notch)
.room(WheelRoom::new(positive, negative)),
);
@@ -13,6 +13,7 @@ use crate::contract::{Bind, Collection, Cx, Internal, ItemCx, ItemOutput as _, P
use crate::primitives::{HiddenContent, ScrollBar};
use crate::runtime::access::{self, Role, SetPosition};
use crate::runtime::egui::{alloc, areas, child, response};
use crate::runtime::env::WheelScope;
use crate::runtime::env::{AppValues, ArenaId, Env, ItemFacts};
use crate::runtime::memory::{MemoryStage, sub};
use crate::runtime::{focus, keys, layout_memory, lazy, overlay, wheel};
@@ -295,7 +296,7 @@ impl<C: Collection> ShapeHooks<C> for ItemsHooks<'_, '_, C> {
.vertical((vertical && max.y > 0.0) || horizontal)
.horizontal(horizontal)
.scrolls(true)
.gated(cx.core.env.wheel_gated())
.gated(cx.core.env.wheel() == WheelScope::Gated)
.room(WheelRoom::new(offset, max - offset))
.zoom(comp.zooms()),
);
+1 -1
View File
@@ -676,7 +676,7 @@ fn run_in_host<C: Component>(p: &mut Pass<'_, '_, C>, ui: &mut Ui, host_at: Opti
// A body's wheel share is its scroll taker (body step, step 7); the gate value does not take the wheel. A body root that
// senses the wheel itself (a canvas) registers like any other component.
if !inert && (p.hooks.shape() != ShapeKind::Body || own.intersects(Sense::WHEEL | Sense::WHEEL_X)) {
steps::register_wheel(&ctx, id, rect, own, comp.bind().is_some(), env.wheel_gated);
steps::register_wheel(&ctx, id, rect, own, comp.bind().is_some(), env.wheel);
}
// 8 sense
p.trace.mark(Step::Sense);
+11 -8
View File
@@ -1,19 +1,22 @@
//! Step 8, sense: part states from the sensing core and the wheel takers.
use crate::runtime::env::WheelScope;
use crate::runtime::wheel;
use crate::style::{Flags, StateSet};
use craft_behavior::Sense;
use craft_theme::{State, StateMix};
use egui::{Context, Id, Rect};
/// Registers a wheel taker for next pass's split (8.6) from the wheel bits of `sense` (`WheelTaker::for_sense`); a
/// value control without them takes the vertical wheel only while focused or armed. Inside a wheel-gated scope
/// (`Overrides::wheel_gated`) every taker takes the wheel, on every axis, only while focused or armed.
pub(crate) fn register_wheel(ctx: &Context, id: Id, rect: Rect, sense: Sense, value_control: bool, gated: bool) {
if let Some(taker) = craft_behavior::WheelTaker::for_sense(id, rect, sense) {
wheel::register(ctx, taker.gated(taker.gated || gated));
} else if value_control {
wheel::register(ctx, craft_behavior::WheelTaker::new(id, rect).vertical(true).gated(true));
/// Registers a wheel taker for next pass's split (8.6) from the wheel bits of `sense` (`WheelTaker::for_sense`). 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.
pub(crate) fn register_wheel(ctx: &Context, id: Id, rect: Rect, sense: Sense, value_control: bool, scope: WheelScope) {
let sensed = craft_behavior::WheelTaker::for_sense(id, rect, sense);
let free = sensed.is_some() && scope == WheelScope::Free;
let taker = sensed.or_else(|| value_control.then(|| craft_behavior::WheelTaker::new(id, rect).vertical(true)));
if let Some(taker) = taker {
wheel::register(ctx, taker.gated(scope == WheelScope::Gated || (value_control && !free)));
}
}
+5 -6
View File
@@ -39,7 +39,7 @@ mod view;
pub use app_values::{AppValues, EnvValue, StyleValue};
use host_words::{host_dates, host_format, host_words};
pub use overrides::{Overrides, ThemeScope, WordsOverride, with_env};
pub use overrides::{Overrides, ThemeScope, WheelScope, WordsOverride, with_env};
pub use root::{ResolvedRoot, RootEnv};
pub(crate) use tokens::TokenInputs;
#[cfg(feature = "testing")]
@@ -82,9 +82,8 @@ pub struct Scoped {
pub enabled: bool,
/// OR of every scope above.
pub read_only: bool,
/// OR of every scope above: wheel takers inside register gated, taking the wheel only while focused or armed
/// (a card in a scrolling overview). A layer opened from inside starts ungated.
pub wheel_gated: bool,
/// How wheel takers inside take the wheel (`WheelScope`). A layer opened from inside starts plain.
pub wheel: WheelScope,
/// The flow direction: layout order, arrow keys and roving. A container whose axis keeps its order
/// (`Props::ltr_axis`) sets it to left to right for what is inside.
pub direction: Direction,
@@ -345,7 +344,7 @@ impl Env {
size: ControlSize::Md,
enabled: true,
read_only: false,
wheel_gated: false,
wheel: WheelScope::Plain,
direction: root.direction,
text_direction: root.direction,
ids_stable: true,
@@ -411,7 +410,7 @@ impl Env {
s.roving = None;
s.transform = None;
s.scroll_owner = None;
s.wheel_gated = false;
s.wheel = WheelScope::Plain;
s.unbounded = (false, false);
s.lazy = None;
s.item = None;
+20 -4
View File
@@ -40,6 +40,20 @@ impl std::fmt::Debug for ThemeScope {
}
}
/// How the wheel takers of a scope take the wheel.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum WheelScope {
/// A value control takes the wheel only while focused or armed; every other taker whenever the pointer is over it.
#[default]
Plain,
/// A value control that senses the wheel takes it without focus: the sliders of an adjustment dialog.
Free,
/// Every taker takes the wheel only while focused or armed: a card in a scrolling overview. Wins over a `Free` set
/// inside it, so a scroll of the overview never stops on a story's slider.
Gated,
}
/// Changes to the inherited values for a stretch of code.
#[derive(Default)]
#[non_exhaustive]
@@ -50,8 +64,8 @@ pub struct Overrides {
pub enabled: Option<bool>,
/// Only `true` has an effect.
pub read_only: Option<bool>,
/// Only `true` has an effect.
pub wheel_gated: Option<bool>,
/// Has no effect inside a `WheelScope::Gated` scope.
pub wheel: Option<WheelScope>,
/// Can only lower the mode.
pub motion: Option<MotionMode>,
/// Also the child `Ui`'s direction and layout.
@@ -83,8 +97,10 @@ impl Overrides {
if self.read_only == Some(true) {
scoped.read_only = true;
}
if self.wheel_gated == Some(true) {
scoped.wheel_gated = true;
if let Some(wheel) = self.wheel
&& scoped.wheel != WheelScope::Gated
{
scoped.wheel = wheel;
}
if let Some(motion) = self.motion {
let inherited = scoped.inherited_mut();
+3 -3
View File
@@ -33,9 +33,9 @@ impl<'a> EnvView<'a> {
self.scoped.facts_of(id)
}
/// Whether wheel takers in this scope take the wheel only while focused or armed.
pub(crate) fn wheel_gated(&self) -> bool {
self.scoped.wheel_gated
/// How wheel takers in this scope take the wheel.
pub(crate) fn wheel(&self) -> super::WheelScope {
self.scoped.wheel
}
/// The innermost scrolling body around the component.
+1 -1
View File
@@ -394,7 +394,7 @@ impl Host<'_> {
|env| {
env.direction = look.direction;
env.size = look.size;
env.wheel_gated = Some(gated);
env.wheel = gated.then_some(craft_ui::runtime::env::WheelScope::Gated);
},
|ui| show(ui, data),
)
@@ -269,7 +269,7 @@ impl Component for AngleDial<'_> {
}
fn sense(&self) -> Sense {
Sense::FOCUS
Sense::FOCUS | Sense::WHEEL_X | Sense::WHEEL_Y
}
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
@@ -274,7 +274,7 @@ impl Component for PointPicker<'_> {
}
fn sense(&self) -> Sense {
Sense::FOCUS
Sense::FOCUS | Sense::WHEEL_X | Sense::WHEEL_Y
}
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
@@ -198,8 +198,10 @@ impl Component for RangeSlider<'_> {
Vec2::new(cx.style.length, cx.icon() + self.marks.below(&cx.style.track))
}
/// No wheel bits: as a value control the row takes the vertical wheel only while focused or armed, and no scope
/// frees it, since a wheel over the track has no one thumb to step.
fn sense(&self) -> Sense {
Sense::WHEEL | Sense::WHEEL_X
Sense::empty()
}
/// The track, and a thumb each that is its own Tab stop and takes the arrow keys.
+4 -3
View File
@@ -1,7 +1,8 @@
//! `Slider`: a thumb on a track over an `f64` range. A press on the thumb grabs it and a drag moves it by the pointer's
//! travel; a press on the track jumps the thumb there; arrows, the wheel and AccessKit step the value; a double click
//! or the reset intent restores the binding's reset value. The track maps positions to values through a
//! [`SliderScale`], linear by default.
//! or the reset intent restores the binding's reset value. The vertical wheel steps it while it is focused or armed, so
//! a panel scrolls over it; inside a `WheelScope::Free` scope (an adjustment dialog) without focus too. The track maps
//! positions to values through a [`SliderScale`], linear by default.
use super::track::{self, Along, Fill, MarkInk, MarkSpace, Marks, Pick, Press, Scale, SliderScale, TrackFace, Travel};
use crate::contract::{
@@ -183,7 +184,7 @@ impl Component for Slider<'_> {
}
fn sense(&self) -> Sense {
Sense::FOCUS | Sense::WHEEL | Sense::WHEEL_X
Sense::FOCUS | Sense::WHEEL_Y
}
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
@@ -758,8 +758,10 @@ impl<const N: usize> Component for ThumbRow<'_, N> {
Some(craft_behavior::Axis::X)
}
/// No wheel bits: as a value control the row takes the vertical wheel only while focused or armed, and no scope
/// frees it, since a wheel over the track has no one thumb to step.
fn sense(&self) -> Sense {
Sense::WHEEL | Sense::WHEEL_X
Sense::empty()
}
fn parts(&mut self, rect: Rect, cx: &mut PartsCx<'_, Self>) {
+60
View File
@@ -126,3 +126,63 @@ fn a_leaf_at_a_degenerate_rect_neither_panics_nor_changes_its_value() {
assert_eq!(*value.borrow(), START, "a slider shown at {rect:?} changed 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.
#[trial]
fn the_wheel_steps_a_slider_when_focused_or_freed_and_otherwise_scrolls_the_panel() {
use craft_ui::contract::{ContainerProps, Scroll, ShowContainer as _};
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`
/// (outer first) inside the panel.
fn turned(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)),
None => body(ui),
}
}
let value = RefCell::new(START);
let (top, slider) = (Cell::new(0.0_f32), Cell::new(None));
let mut show = |ui: &mut Ui| {
in_region(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(300.0, 200.0)), |ui| {
Slab::new(ContainerProps::new().scroll(Scroll::vertical())).id_salt("panel").show(ui, |ui, _| {
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)));
});
Block::new(Vec2::new(100.0, 1000.0)).show(ui);
});
});
};
let mut frames = Frames::new();
frames.idle(3, &mut show);
let (id, rect) = slider.get().expect("the slider showed");
if focused {
request(&frames.ctx, FocusTarget::Id(id));
frames.idle(2, &mut show);
}
let (value_before, top_before) = (*value.borrow(), top.get());
frames.frame(vec![pointer::moved(rect.center())], &mut show);
frames.frame(vec![pointer::wheel(-40.0)], &mut show);
frames.idle(2, &mut show);
(*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})");
}