widgets, input: PatternGrid for pattern unlock, framed icon buttons, and text keys that bubble past a focused non-text widget; Debian 0.3.0-2
PatternGrid is a 3×3 drag widget for the unlock pattern. It is stateless: the app owns the visited nodes and passes them back in for drawing; a press or a drag that reaches a node within the snap radius fires on_node with the index, 0 to 8 row-major, and release fires on_release, so the crossing and minimum-length rules stay in the app. Geometry lives in widget/pattern_grid/theme.rs (size, dot and node radii, stroke width, snap radius, ring alpha), and the snap radius is resolved through the widget-scaling mode at layout time like the slider thumb (set_pattern_snap_px). The gesture machine reuses the slider's drag ownership: WidgetHandlers::is_drag_target covers both, so hover painting, pointer capture and release behave the same, and hover_affects_paint no longer special-cases sliders. The a11y tree maps it to GenericContainer, since a drawn gesture has no assistive equivalent and the app must offer another method. Exported as pattern_grid / PatternGrid, documented in widgets.md, theming.md and architecture.md, with tests for node centres, a wide rect, snapping, the builders, the handler snapshot and map_msg, and a Security tab in examples/widgets.rs that shows the drawn path. Icon buttons given a width or height are framed keys: preferred_size honours the explicit size instead of the icon size, and drawing paints the variant's background, border and focus ring, shared with text buttons through paint_frame, then centres the icon. An icon button without a size keeps the circular hover overlay it had. This is what lets the PIN keypad's backspace and OK keys sit in the same circles as the digits. Keyboard routing now matches what App::on_key documents. handle_key_default, Backspace, Delete and Space checked focused_idx.is_some() and sent the key into text insertion whenever any widget had focus, which is a no-op on a button, so a focused button or pressable swallowed typed characters. focused_text_input replaces the five copies of that check; characters, Backspace and Delete stay in a focused text input and reach the app otherwise, Return and Space still go to the focused widget's submit or press message when it has one, and the arrow, Home and End handlers use the same helper. The lockscreen relies on this to take PIN digits with its dots row focused. debian/changelog: 0.3.0-2.
This commit is contained in:
@@ -95,7 +95,7 @@ In practice, that model is easiest to adopt in three steps:
|
||||
|
||||
- `on_swipe_up`, `on_swipe_down`, `on_swipe_progress`, `on_swipe_down_progress` (follow-the-finger).
|
||||
- `on_tap` — taps that miss every widget.
|
||||
- `on_key` / `on_key_with_modifiers` — global hotkeys.
|
||||
- `on_key` / `on_key_with_modifiers` — global hotkeys. Characters, Backspace and Delete stay in a focused text input and reach the app otherwise, a focused button or pressable included; Return and Space go to the focused widget's submit or press message when it has one; arrows are offered to the app first and fall back to the text cursor or list navigation.
|
||||
- `swipe_threshold`, `swipe_down_threshold` — gesture sensitivity.
|
||||
|
||||
**Implement for animations and focus**
|
||||
@@ -309,7 +309,7 @@ A short, honest list of what ltk does not currently provide. None of these are a
|
||||
|
||||
**AT-SPI2 / assistive technology bridge — wired through AccessKit, with composite widgets still flat.** Combo, Notebook tabs, DatePicker and TimePicker render as collections of inner widgets and currently expose those leaves individually (a combo trigger reads as "Button" + its caption, the popup items as `ListItem`s inside an overlay). Promoting them to their semantic roles (`ComboBoxMenuButton` with `Expanded` state, `TabList`/`Tab`/`TabPanel`, `Date`) needs each compound widget to declare an "outer role hint" the layout pass can attach to the `LaidOutWidget` it pushes. Tracked separately.
|
||||
|
||||
ltk delegates the AT-SPI2 D-Bus protocol to `accesskit_unix`. After every layout pass, the runtime hands the platform adapter a fresh `accesskit::TreeUpdate` built from `widget_rects`: a `Window` root whose children are the main surface's widgets, with each overlay grouped under its own `Dialog` node and rich-text runs nested as `TextRun` children. Buttons / toggles / checkboxes / radios / list items map to `Role::Button` / `Role::Switch` / `Role::CheckBox` / `Role::RadioButton` / `Role::ListItem`; sliders to `Role::Slider`; single- and multi-line text edits to `Role::TextInput` / `Role::MultilineTextInput`; non-interactive labels, images, separators and progress bars surface as `Label` / `Image` / `Splitter` / `ProgressIndicator` nodes. Inbound action requests are translated into the matching widget message on the next iteration of the run loop: `Click` and `Focus` on every interactive node, `SetValue` on sliders and text edits, `Increment` / `Decrement` on sliders, and the scroll actions on scroll viewports. Live regions are wired too — `Container::live_region( true )` marks a subtree `Live::Polite` so status messages and OSDs announce themselves on appearance.
|
||||
ltk delegates the AT-SPI2 D-Bus protocol to `accesskit_unix`. After every layout pass, the runtime hands the platform adapter a fresh `accesskit::TreeUpdate` built from `widget_rects`: a `Window` root whose children are the main surface's widgets, with each overlay grouped under its own `Dialog` node and rich-text runs nested as `TextRun` children. Buttons / toggles / checkboxes / radios / list items map to `Role::Button` / `Role::Switch` / `Role::CheckBox` / `Role::RadioButton` / `Role::ListItem`; sliders to `Role::Slider`; pattern grids to `Role::GenericContainer` (a drawn gesture has no assistive equivalent, so the app must offer another unlock method); single- and multi-line text edits to `Role::TextInput` / `Role::MultilineTextInput`; non-interactive labels, images, separators and progress bars surface as `Label` / `Image` / `Splitter` / `ProgressIndicator` nodes. Inbound action requests are translated into the matching widget message on the next iteration of the run loop: `Click` and `Focus` on every interactive node, `SetValue` on sliders and text edits, `Increment` / `Decrement` on sliders, and the scroll actions on scroll viewports. Live regions are wired too — `Container::live_region( true )` marks a subtree `Live::Polite` so status messages and OSDs announce themselves on appearance.
|
||||
|
||||
The adapter is constructed unconditionally — `accesskit_unix::Adapter::new` is infallible and simply stays inactive when no AT client is attached — and the tree is only built when AT-SPI2 is actually observing the application, so the pipeline costs nothing on headless runners. The current cut covers the common cases — buttons, lists, form fields, dialogs — and intentionally leaves room for follow-up:
|
||||
|
||||
|
||||
+3
-3
@@ -428,11 +428,11 @@ of them falls back to embedded defaults.
|
||||
| `surface` | card / panel surface | color |
|
||||
| `surface-alt` | text-input field background | color |
|
||||
| `text-primary` | regular text colour | color |
|
||||
| `text-secondary` | muted / placeholder text | color |
|
||||
| `accent` | toggle on, slider fill, focus ring | color |
|
||||
| `text-secondary` | muted / placeholder text, pattern-grid idle dots | color |
|
||||
| `accent` | toggle on, slider fill, focus ring, pattern-grid stroke and visited dots | color |
|
||||
| `divider` | separator, toggle off, list item border | color |
|
||||
| `icon` | icon-button glyph colour | color |
|
||||
| `danger` | destructive / error foreground | color |
|
||||
| `danger` | destructive / error foreground, pattern-grid path in error | color |
|
||||
| `danger-bg` | soft fill behind error states | color |
|
||||
|
||||
The default theme defines `danger` but not `danger-bg`, which
|
||||
|
||||
+52
-1
@@ -16,7 +16,7 @@ patterns built from these widgets, see [`docs/cookbook.md`](./cookbook.md).
|
||||
- [Stateful binary controls](#stateful-binary-controls)
|
||||
- [`toggle`](#toggle) · [`checkbox`](#checkbox) · [`radio`](#radio)
|
||||
- [Continuous controls](#continuous-controls)
|
||||
- [`slider`](#slider) · [`vslider`](#vslider) · [`progress_bar`](#progress_bar)
|
||||
- [`slider`](#slider) · [`vslider`](#vslider) · [`progress_bar`](#progress_bar) · [`pattern_grid`](#pattern_grid)
|
||||
- [Text input and display](#text-input-and-display)
|
||||
- [`text`](#text) · [`text_edit`](#text_edit) · [`rich_text`](#rich_text)
|
||||
- [Decoration and chrome](#decoration-and-chrome)
|
||||
@@ -83,6 +83,25 @@ count; pass `Length::widget( n )` instead to follow the widget-scaling
|
||||
mode, which is what stock icons (the [`list_item`](#list_item) disclosure
|
||||
arrow) already do — use it when the two sit side by side and should match.
|
||||
|
||||
Give it a `width( … )` or `height( … )` and it becomes a framed key: it
|
||||
claims that size, paints the background and border of its `variant` like
|
||||
a text [`button`](#button), and centres the icon inside at `icon_size`.
|
||||
That is how a keypad mixes digit keys with an icon key of the same shape:
|
||||
|
||||
```rust,no_run
|
||||
# use std::sync::Arc;
|
||||
# use ltk::{ icon_button, ButtonVariant, Element };
|
||||
# #[ derive( Clone ) ] enum Msg { Backspace }
|
||||
# fn _ex( rgba_bytes: Arc<Vec<u8>>, w: u32, h: u32 ) -> Element<Msg> {
|
||||
icon_button( rgba_bytes, w, h )
|
||||
.variant( ButtonVariant::Secondary )
|
||||
.width( 64.0 ).height( 64.0 )
|
||||
.icon_size( 28.0 )
|
||||
.on_press( Msg::Backspace )
|
||||
.into()
|
||||
# }
|
||||
```
|
||||
|
||||
**See also**: [`button`](#button), [`window_button`](#window_button)
|
||||
(specialised icon button for window decorations).
|
||||
|
||||
@@ -324,6 +343,38 @@ progress_bar( self.download_fraction )
|
||||
**See also**: [`spinner`](#spinner) for indeterminate operations
|
||||
without a known fraction.
|
||||
|
||||
### `pattern_grid`
|
||||
|
||||
A 3×3 grid of dots for drawing an unlock pattern with a finger or the
|
||||
pointer. The widget is stateless: the app owns the list of visited nodes
|
||||
(0 to 8, row-major) and passes it back in for drawing.
|
||||
|
||||
**When**: lock screens and enrolment forms for a pattern secret.
|
||||
|
||||
```rust,no_run
|
||||
# use ltk::{ pattern_grid, PatternGrid };
|
||||
# #[ derive( Clone ) ] enum Msg { Node( u8 ), Released }
|
||||
# struct App { path: Vec<u8> }
|
||||
# impl App { fn _ex( &self ) -> PatternGrid<Msg> {
|
||||
pattern_grid( self.path.clone() )
|
||||
.on_node( Msg::Node )
|
||||
.on_release( Msg::Released )
|
||||
# }}
|
||||
```
|
||||
|
||||
`on_node( f )` fires with a node index whenever a press or a drag reaches
|
||||
a node, including nodes already in the path — appending, skipping a
|
||||
repeat, or taking in the node a straight stroke crosses is the app's
|
||||
rule, not the widget's. `on_release( msg )` fires when the finger lifts.
|
||||
`hide_stroke( true )` draws only the dots, against shoulder surfing;
|
||||
`error( true )` paints the current path in the palette's `danger` colour.
|
||||
|
||||
It sizes itself square to `min( max_width, 264 )` design pixels; wrap it
|
||||
in a `container( … ).max_width( … )` to pin it.
|
||||
|
||||
**See also**: [`slider`](#slider), which owns the pointer during a drag
|
||||
the same way.
|
||||
|
||||
---
|
||||
|
||||
## Text input and display
|
||||
|
||||
Reference in New Issue
Block a user