Skip to content

feat(components): unify interaction states for Button and Slider - #65

Open
FarnaHerry wants to merge 1 commit into
sudoevolve:devfrom
FarnaHerry:feat/unified-control-states
Open

feat(components): unify interaction states for Button and Slider#65
FarnaHerry wants to merge 1 commit into
sudoevolve:devfrom
FarnaHerry:feat/unified-control-states

Conversation

@FarnaHerry

Copy link
Copy Markdown
Contributor

中文说明

为什么做这个改动

当前组件已经分别拥有部分 normalhoverpressedfocuseddisabled 行为,但这些状态没有统一的基础模型和主题 token。结果是不同控件的状态优先级和视觉反馈不一致:Button 有 hover/pressed,Input 有自己的 focus 样式,而 Slider 主要依赖鼠标拖动,缺少 disabled/focus 反馈。

这次 PR 先做一个小范围、可审查的基础接入,不重做键盘 Tab 导航、不修改字体,也不引入平台 accessibility bridge。

做了什么

  1. components/theme.h 增加共享的 ControlState
    • Normal
    • Hovered
    • Pressed
    • Focused
    • Disabled
  2. 增加 InteractionTokens,统一提供 hover border、pressed overlay、focus ring、disabled fill/content 和 focus ring 几何参数。
  3. 明确基础状态优先级:
    • Disabled > Pressed > Focused > Hovered > Normal
    • checkedselectedexpanded 等保持为正交的可叠加状态。
  4. Button 接入统一 focus ring 和 disabled 视觉;disabled Button 不再获得焦点。
  5. Slider 增加 disabled(bool),接入 focusable/disabled 行为、knob 高亮和 focus ring。
  6. 增加 examples/control_states_demo.cpp,展示 Button、Checkbox、Switch、Input 和 Slider 的状态反馈。
  7. 增加状态优先级和主题 token 单元测试,并补充中文组件文档。

明确不包含

  • 不实现 Tab/Shift+Tab 焦点遍历或 Enter/Space 键盘导航;
  • 不修改字体解析或默认字体;
  • 不实现 Linux/Windows/macOS 原生 accessibility;
  • 不批量重构其他控件;
  • 不改变现有 Button 的 normal/hover/pressed API。

验证

已通过:

cmake --build build --target control_states_demo ui_state -j2
./build/ui_state
git diff --check

Demo 启动命令:

./build/control_states_demo

请重点 review:

  • InteractionTokens 是否适合作为后续控件接入的公共基础;
  • focus ring 是否应当作为控件外置绘制层,而不是控件自身 border;
  • Slider 的 disabled/focus 语义是否符合项目运行时模型;
  • 后续应优先接入哪些控件。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant