Feat/tab focus traversal - #62
Open
FarnaHerry wants to merge 3 commits into
Open
Conversation
added 3 commits
August 17, 2026 08:52
Tab was previously dropped in the input backends. Add InputKey::Tab, map GLFW_KEY_TAB / SDLK_TAB, and traverse focus among focusable elements (z-order, wrapping, skipping disabled subtrees) in Runtime before text input dispatch. Buttons stay non-focusable by default; only .focusable()/.onTextInput()/.onFocusChanged() elements participate.
Headless unit test for collectOrderedFocusableIds/nextFocusTarget and Runtime::traverseFocus (order, z-index, disabled subtrees, wrap, onFocusChanged, focus clearing). Extend window_only_probe to verify Tab+Shift reaches the input queue, and add a windowed focus_traversal_viewer fixture for manual Tab/Shift+Tab testing.
Note Tab/Shift+Tab traversal in the Runtime flow, the keyboard capability lists, and the current limitations (no scrolled/clipped skipping, Alt+Tab indistinguishable, buttons not focusable by default).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
此前 Tab 键在输入后端直接被丢弃(GLFW / SDL 的按键映射都没有 Tab),
键盘焦点只能靠鼠标点击驱动。本 PR 加入纯增量的 Tab / Shift+Tab 焦点遍历:
zIndex升序稳定排序(同 zIndex 按声明序)——即用户视觉上感知到的堆叠顺序。
变更
InputKey新增Tab,两端后端补上映射(GLFW_KEY_TAB、SDLK_TAB)。core/dsl_focus.h:collectOrderedFocusableIds(前序收集 focusable元素、跳过 disabled 子树)与
nextFocusTarget(前进 / 后退 / 回绕决策)。Runtime新增公开traverseFocus(bool reverse)、focusedId(),私有handleFocusTraversal(const KeyboardEvent&)。Runtime::update在updateTextInput之前消费 Tab 键;被消费时不再转发给当前焦点输入框。
行为
.focusable()/.onTextInput()/.onFocusChanged()的元素,与鼠标 focus 命中的集合一致;跳过 disabled / 禁用子树。
components::button默认只设interactive、不设focusable,默认不参与Tab(需显式
.focusable()),保持既有默认行为不变。测试与验证
测试与验证
tests/unit/focus_traversal.cpp(20 个用例:顺序、zIndex、disabled 子树、回绕、
onFocusChanged、禁用时清焦点)。window_only_probe扩展:验证 Tab+Shift 携带方向进入输入队列。tests/fixtures/focus_traversal_viewer.cpp供人工Tab / Shift+Tab 验证。
ctest -L unit16/16、ctest -L probe5/5 全部通过。已知限制
\t文本加固未包含(可选后续)。