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:
+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