Focus requests reach widgets clipped by a scroll viewport, and stop retrying after a few frames
A scroll viewport keeps in `widget_rects` only the widgets at least partly inside its visible area (`draw/layout.rs`, the translation of the sub-canvas rects to surface space). A focus request whose target sits below the fold therefore never finds it: `App::take_focus_request` was honoured only for widgets already laid out on screen. The Wi-Fi page of settings is one such case by construction: tapping a secured network inserts the password form under the row and asks for focus on the field, so for a row in the lower part of the list the field is born outside the viewport and the request misses. Worse, the miss branch parked the id in `focus_retry`, marked the view dirty and requested a redraw on every iteration, so the application rebuilt and repainted at the compositor's frame rate for as long as the widget stayed hidden. The layout pass now records the widgets it drops for carrying a `WidgetId`: `DrawCtx::scroll_clipped` holds `(id, scroll flat_idx, rect)` with the rect in the scroll's content coordinates, the same frame the navigable-item list uses, and `draw_frame` hands it to `FrameState`. When a focus request misses, `AppData::reveal_clipped_widget` looks the id up in that list on the main surface and the overlays, finds the viewport in `scroll_rects`, and moves its offset on the axes the scroll allows so the rect lands inside; the next frame lays the widget out and the retry focuses it. Nested scrolls resolve one viewport per frame. The rule that computes the new offset is `scroll::offset_into_view`, extracted from the keyboard navigation in `input/keyboard/nav.rs`, which now calls it instead of carrying its own copy; unit tests cover the three cases. `focus_retry` carries a budget of drawn frames (`FOCUS_RETRY_FRAMES`, four), decremented only on iterations that actually drew, so a request made while a frame callback is pending does not lose its chance. A fresh request from the application replaces a pending retry with a full budget. When the budget runs out the request is dropped, which ends the redraw loop for a widget that never appears. Documented in the `take_focus_request` doc comment, the cookbook and the changelog; Debian revision 0.3.0-3.
This commit is contained in:
@@ -303,6 +303,7 @@ pub( crate ) fn layout_and_draw<Msg: Clone>(
|
||||
|
||||
for mut w in new_rects
|
||||
{
|
||||
let content = Rect { x: w.rect.x + ox, y: w.rect.y + oy, ..w.rect };
|
||||
// Sub-canvas origin (0,0) maps to global (rect.x, rect.y).
|
||||
w.rect.x += rect.x;
|
||||
w.rect.y += rect.y;
|
||||
@@ -317,6 +318,8 @@ pub( crate ) fn layout_and_draw<Msg: Clone>(
|
||||
if visible_x && visible_y
|
||||
{
|
||||
ctx.widget_rects.push( w );
|
||||
} else if let Some( id ) = w.id {
|
||||
ctx.scroll_clipped.push( ( id, my_idx, content ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -32,7 +32,7 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::render::Canvas;
|
||||
use crate::types::Rect;
|
||||
use crate::types::{ Rect, WidgetId };
|
||||
use crate::widget::LaidOutWidget;
|
||||
|
||||
pub( crate ) mod software;
|
||||
@@ -77,6 +77,11 @@ pub( crate ) struct DrawCtx<Msg: Clone>
|
||||
/// needed to bring an item into view without depending on the
|
||||
/// current scroll position.
|
||||
pub scroll_navigable_items: HashMap<usize, Vec<( usize, f32, f32 )>>,
|
||||
/// Widgets carrying a [`WidgetId`] that a scroll viewport clipped out
|
||||
/// of `widget_rects` this frame: `(id, scroll flat_idx, rect)` with the
|
||||
/// rect in the scroll's content coordinates, so a focus request can
|
||||
/// move that scroll until the widget is in view.
|
||||
pub scroll_clipped: Vec<( WidgetId, usize, Rect )>,
|
||||
/// Snapshot of the previous frame's `widget_rects`. Read by
|
||||
/// [`crate::widget::anchored_overlay::AnchoredOverlay`] at draw time
|
||||
/// to look up the rect of an anchor widget by [`crate::WidgetId`] and
|
||||
@@ -116,6 +121,7 @@ pub( crate ) fn build_draw_ctx<Msg: Clone>(
|
||||
scroll_rects: Vec::new(),
|
||||
scroll_canvases: std::mem::take( &mut frame.scroll_canvases ),
|
||||
scroll_navigable_items: std::mem::take( &mut frame.scroll_navigable_items ),
|
||||
scroll_clipped: Vec::new(),
|
||||
previous_widget_rects: frame.widget_rects.clone(),
|
||||
accessible_extras: Vec::new(),
|
||||
live_depth: 0,
|
||||
@@ -147,6 +153,7 @@ pub( crate ) fn commit_draw_ctx<Msg: Clone>(
|
||||
frame.scroll_offsets = ctx.scroll_offsets;
|
||||
frame.accessible_extras = ctx.accessible_extras;
|
||||
frame.scroll_navigable_items = ctx.scroll_navigable_items;
|
||||
frame.scroll_clipped = ctx.scroll_clipped;
|
||||
}
|
||||
|
||||
/// Paint the built-in Copy / Cut / Paste context menu on top of the
|
||||
|
||||
Reference in New Issue
Block a user