mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 23:49:35 +00:00
craft-ui: a root keeps the key focus it holds for a member at step 8
The stop of an arena member (a radio in its group, a theme chip) has its root's egui widget as its widget. Step 8 registers that widget with the root's own and its parts' senses, and the members' senses join once the body has run (widen_root). egui drops the focus of a widget registered without a focus sense, so Tab, an AccessKit Focus or a press that focused a member lost it in the same pass. While the focus service says the root holds focus for another component's stop (focus::held_for_member), the step-8 sense includes focus.
This commit is contained in:
@@ -630,8 +630,8 @@ pub(crate) struct RootResult {
|
||||
pub activation: bool,
|
||||
/// The member a click activated.
|
||||
pub activated_member: Option<Id>,
|
||||
/// The sense the root's egui widget carries at step 8: its own and its parts'. Its members' senses join it once
|
||||
/// its body has run (`widen_root`).
|
||||
/// The sense the root's egui widget carries at step 8: its own and its parts', and focus while it holds key focus
|
||||
/// for a member. Its members' senses join it once its body has run (`widen_root`).
|
||||
pub sense: Sense,
|
||||
}
|
||||
|
||||
@@ -644,11 +644,11 @@ pub(crate) fn sense_root(ui: &Ui, spec: RootSpec<'_>) -> RootResult {
|
||||
let read = PassRead::of(ctx);
|
||||
let (clip, layer) = (ui.clip_rect(), ui.layer_id());
|
||||
// A disabled root only hovers, whatever its parts and members sense; it keeps the focus stop its own sense or a part's grants.
|
||||
let sense = if spec.enabled {
|
||||
spec.own.iter().fold(spec.own_sense, |sense, part| sense | part.sense)
|
||||
} else {
|
||||
Sense::HOVER | spec.own.iter().fold(spec.own_sense, |sense, part| sense | part.sense).intersection(Sense::FOCUS)
|
||||
};
|
||||
let own = spec.own.iter().fold(spec.own_sense, |sense, part| sense | part.sense);
|
||||
let sense = if spec.enabled { own } else { Sense::HOVER | own.intersection(Sense::FOCUS) };
|
||||
// A root that holds key focus for a member's stop senses focus now: egui drops the focus of a widget registered
|
||||
// without it, before the members, which read it, run and join their senses (`widen_root`).
|
||||
let sense = if crate::runtime::focus::held_for_member(ctx, spec.id) { sense | Sense::FOCUS } else { sense };
|
||||
// The response rect is the root's whole rect and egui's hit test uses its part inside the clip (`interact_rect`),
|
||||
// as for any egui widget: a root the clip cuts reports and reveals where it is, not where it shows.
|
||||
let response = response::widget(ui, spec.id, spec.rect, sense);
|
||||
|
||||
@@ -648,6 +648,12 @@ pub(crate) fn request_now(ctx: &Context, target: FocusTarget) {
|
||||
apply(ctx, acts);
|
||||
}
|
||||
|
||||
/// Whether egui key focus is on the widget `root` for another component's stop: an arena member, whose stop's widget
|
||||
/// is its root's (`Stop::root`).
|
||||
pub(crate) fn held_for_member(ctx: &Context, root: Id) -> bool {
|
||||
egui_focus::focused(ctx) == Some(root) && focused_stop(ctx).is_some_and(|(id, _)| id != root)
|
||||
}
|
||||
|
||||
/// Whether `at` (screen points) lies in a popup layer opened above the layer of the widget that holds egui focus: a
|
||||
/// press or a wheel there is the popup's, not the focused widget's. The layer under `at` is the layer test's; the
|
||||
/// focused widget's layer is egui's last-pass record of it, since a stop records no layer of its own.
|
||||
|
||||
Reference in New Issue
Block a user