mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 00:34:25 +00:00
Check box, switch, radio and segmented take Enter as well as Space
The controls use the default activation keys. Arrows in a radio group move focus without picking; Enter or Space picks.
This commit is contained in:
@@ -76,7 +76,7 @@ impl Outcome for AppearancePageOutput {
|
||||
/// The page edits the bound draft, a [`SelectionChange`] the Preferences model keeps; the chips and lists show
|
||||
/// [`SuiteClient::shown`] with the draft applied. Nothing reaches the suite until the window applies: the model's
|
||||
/// `apply` calls `client.change(draft)`, its `cancel` clears the draft. Each chip row is one radio group: one Tab
|
||||
/// stop, arrows move, Space or a click picks; a chip's context menu (the Menu key and Shift+F10 open it) has Add to
|
||||
/// stop, arrows move, Space, Enter or a click picks; a chip's context menu (the Menu key and Shift+F10 open it) has Add to
|
||||
/// Favorites / Remove from Favorites, the keyboard path to the star.
|
||||
#[must_use = "show the page with `show`"]
|
||||
#[derive(craft_ui::contract::Pattern, craft_ui::contract::Props)]
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
//! `Checkbox`: a box with a check mark, a dash while the value is mixed. Its text is the label step's (a `Field`'s,
|
||||
//! `PaintUi::labelled`'s, or the one `show` runs for a labelled instance); the control draws only the box.
|
||||
|
||||
use crate::contract::{Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Input, MeasureCx, PaintUi, Pointer as _, Role, Styled as _};
|
||||
use crate::contract::{Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, MeasureCx, PaintUi, Pointer as _, Role, Styled as _};
|
||||
use crate::primitives::{PaintShape, StrokeWidth, glyph};
|
||||
use crate::runtime::focus::{ActivateKeys, KeyUse};
|
||||
use crate::style::{ComponentStyle, FocusLook, StyleColor, StyleCx, SurfaceKind, SurfaceLook};
|
||||
use craft_behavior::{Metrics, Sense};
|
||||
use craft_theme::Stateful;
|
||||
@@ -44,7 +43,6 @@ impl<'a> Checkbox<'a> {
|
||||
|
||||
impl Component for Checkbox<'_> {
|
||||
const ROLE: Role = Role::CHECK_BOX;
|
||||
const KEYS: KeyUse = KeyUse::of(Input::Pointer).with_activate(ActivateKeys::Space);
|
||||
const PARTS: bool = false;
|
||||
const LABELLED_AFTER: bool = true;
|
||||
const OVERLAYS: bool = false;
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
//! is the label step's, as the check box's is.
|
||||
|
||||
use crate::contract::{
|
||||
Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Edit as _, EditResponse, GroupHandle, GroupKind, GroupState, Input, MeasureCx,
|
||||
PaintUi, Pointer as _, Props as _, Remember as _, Role, Styled as _, Validity,
|
||||
Bind, BindMut, Common, Component, Container, ContainerProps, Cx, Edit as _, EditResponse, GroupHandle, GroupKind, GroupState, MeasureCx, PaintUi,
|
||||
Pointer as _, Props as _, Remember as _, Role, Styled as _, Validity,
|
||||
};
|
||||
use crate::primitives::glyph;
|
||||
use crate::runtime::env::EnvValue;
|
||||
use crate::runtime::focus::{ActivateKeys, KeyUse};
|
||||
use crate::style::{ComponentStyle, Flags, FocusLook, StyleColor, StyleCx, SurfaceLook};
|
||||
use craft_behavior::{Metrics, NavShape, Roving, Value};
|
||||
use craft_theme::Stateful;
|
||||
@@ -58,7 +57,7 @@ pub struct GroupStyle {
|
||||
metrics: Metrics,
|
||||
}
|
||||
|
||||
/// A group of radio buttons over one value: one Tab stop, arrows move focus, Space or a click selects.
|
||||
/// A group of radio buttons over one value: one Tab stop, arrows move focus, Space, Enter or a click selects.
|
||||
#[derive(crate::contract::Component)]
|
||||
#[component(container, probe(RadioGroup<'static, u8>))]
|
||||
pub struct RadioGroup<'a, T: Value + 'static> {
|
||||
@@ -86,7 +85,6 @@ impl<'a, T: Value + 'static> RadioGroup<'a, T> {
|
||||
|
||||
impl<T: Value + 'static> Component for RadioGroup<'_, T> {
|
||||
const ROLE: Role = Role::RADIO_GROUP;
|
||||
const KEYS: KeyUse = KeyUse::of(Input::Pointer).with_activate(ActivateKeys::Space);
|
||||
const PARTS: bool = false;
|
||||
type Style = GroupStyle;
|
||||
type Output = EditResponse<T>;
|
||||
@@ -173,7 +171,6 @@ impl<T: Value + 'static> Radio<T> {
|
||||
|
||||
impl<T: Value + 'static> Component for Radio<T> {
|
||||
const ROLE: Role = Role::RADIO_BUTTON;
|
||||
const KEYS: KeyUse = KeyUse::of(Input::Pointer).with_activate(ActivateKeys::Space);
|
||||
const LABELLED_AFTER: bool = true;
|
||||
const PARTS: bool = false;
|
||||
const OVERLAYS: bool = false;
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
//! `Segmented`: one of a few options as a strip of segments. A leaf with a part per segment; each segment wears a
|
||||
//! face that is flat and muted, with a hover fill, and takes the selection fill and edge while it is picked. The row is one Tab stop over its segments: arrows, Home and End move focus between them, Space
|
||||
//! or a click picks the focused one.
|
||||
//! face that is flat and muted, with a hover fill, and takes the selection fill and edge while it is picked. The row is one Tab stop over its segments: arrows, Home and End move focus between them, Space,
|
||||
//! Enter or a click picks the focused one.
|
||||
|
||||
use crate::buttons::face::{self, FaceLook, FaceSpec};
|
||||
use crate::contract::{
|
||||
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Entry, Input, MeasureCx, Name, PaintUi, PartsCx, Props as _, Role,
|
||||
SetPosition,
|
||||
Access, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Entry, MeasureCx, Name, PaintUi, PartsCx, Props as _, Role, SetPosition,
|
||||
};
|
||||
use crate::primitives::IconSpec;
|
||||
use crate::runtime::env::Label;
|
||||
use crate::runtime::focus::{ActivateKeys, KeyUse};
|
||||
use crate::style::{ComponentStyle, Flags, FocusLook, IconLook, StyleCx, SurfaceKind, SurfaceLook, TextLook, TypeRole, UiTokens};
|
||||
use craft_behavior::{Flow, Metrics, NavShape, PartKey, PartRef, Roving, Sense, Value};
|
||||
use craft_theme::{Rgba, Stateful, States};
|
||||
@@ -71,7 +69,6 @@ impl<'a, T: Value + 'static> Segmented<'a, T> {
|
||||
impl<T: Value + 'static> Component for Segmented<'_, T> {
|
||||
const ROLE: Role = Role::RADIO_GROUP;
|
||||
const OVERLAYS: bool = false;
|
||||
const KEYS: KeyUse = KeyUse::of(Input::Pointer).with_activate(ActivateKeys::Space);
|
||||
type Style = SegmentedStyle;
|
||||
type Output = EditResponse<T>;
|
||||
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
//! label step's, as the check box's is.
|
||||
|
||||
use crate::contract::{
|
||||
Animate as _, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, Input, MeasureCx, PaintUi, Pointer as _, Role, Styled as _, spec,
|
||||
Animate as _, Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, MeasureCx, PaintUi, Pointer as _, Role, Styled as _, spec,
|
||||
};
|
||||
|
||||
use crate::runtime::focus::{ActivateKeys, KeyUse};
|
||||
use crate::style::{ComponentStyle, FocusLook, StyleCx, SurfaceKind, SurfaceLook, SurfaceStyle};
|
||||
use craft_behavior::{Flow, Metrics, Sense};
|
||||
use craft_theme::{Stateful, States};
|
||||
@@ -49,7 +48,6 @@ impl<'a> Switch<'a> {
|
||||
|
||||
impl Component for Switch<'_> {
|
||||
const ROLE: Role = Role::SWITCH;
|
||||
const KEYS: KeyUse = KeyUse::of(Input::Pointer).with_activate(ActivateKeys::Space);
|
||||
const PARTS: bool = false;
|
||||
const LABELLED_AFTER: bool = true;
|
||||
const OVERLAYS: bool = false;
|
||||
|
||||
@@ -115,3 +115,33 @@ fn the_pointer_over_a_check_box_or_its_label_is_a_pointing_hand_unless_it_is_dis
|
||||
assert_eq!(frames.cursor_icon(), expected, "the cursor over the label (enabled: {enabled})");
|
||||
}
|
||||
}
|
||||
|
||||
#[trial]
|
||||
fn arrows_move_through_a_radio_group_without_picking_and_enter_picks() {
|
||||
use craft_ui::testing::input::key_press;
|
||||
use egui::{Key, Modifiers};
|
||||
let mut frames = Frames::new();
|
||||
let picked = Cell::new(1u8);
|
||||
let mut show = |ui: &mut Ui| {
|
||||
let mut value = picked.get();
|
||||
in_region(ui, REGION, |ui| {
|
||||
RadioGroup::new("Size", Bind::bound(&mut value)).show(ui, |ui, _| {
|
||||
Stack::new().show(ui, |ui, _| {
|
||||
for (at, label) in [(1u8, "Small"), (2, "Medium"), (3, "Large")] {
|
||||
Radio::new(at).label(label).show(ui);
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
picked.set(value);
|
||||
};
|
||||
frames.frame(vec![], &mut show);
|
||||
for key in [Key::Tab, Key::ArrowDown] {
|
||||
frames.frame(vec![key_press(key, Modifiers::NONE)], &mut show);
|
||||
frames.frame(vec![], &mut show);
|
||||
}
|
||||
assert_eq!(picked.get(), 1, "the arrow moves focus without picking");
|
||||
frames.frame(vec![key_press(Key::Enter, Modifiers::NONE)], &mut show);
|
||||
frames.frame(vec![], &mut show);
|
||||
assert_eq!(picked.get(), 2, "Enter picks the focused radio");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user