Skip to content

Buttons:SegmentedControl 新增 on_context,告诉调用方右键点在哪一段 - #11

Merged
Raiden-MeixElysia merged 1 commit into
ELY-Open-Source:mainfrom
lnyuyu:segment-context-main
Nov 2, 2026
Merged

Raiden-MeixElysia merged 1 commit into
ELY-Open-Source:mainfrom
lnyuyu:segment-context-main

Conversation

@lnyuyu

@lnyuyu lnyuyu commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

这是 #10 在 main 上的版本:改动相同,移植到 crates/ely-core,另外补了 API 快照和 CHANGELOG。

SegmentedControl 新增了 on_context(value, point, window, cx):右键按在某一段上时,把这一段的值和指针位置交给调用方。写法和已有的 Tabs::on_context、Tree::on_context 保持一致。

起因是 ELYTerminal:右栏顶部的 Git/文件 切换用的就是 SegmentedControl,我想做到“右键文件那一段,展开一个在指定文件夹新建会话的操作栏”。原组件只告诉外部“左键选中了哪一段”,没法知道右键点在哪,ELYTerminal 只能自己重画一个控件,丢掉了滑块动画和阴影。有了这个接口,就能继续用原组件。

处理器放在每一段自身上,并在那里拦住这次按下。原因是 gpui 在任意鼠标键按下时都会把焦点交给可聚焦的元素,而且子元素先于父元素执行;如果放在外层,等它收到事件时,焦点已经被这一段抢走了,键盘输入也会跟着跑掉。

没有新的绘制,控件外观和原来一样。

  • scripts/check.sh 通过:在 Windows 上跑了 fmt、clippy(-D warnings)和库测试,见下文;GPUI Kit 兼容、wasm 和 stories 这几步没跑
  • gallery 里有演示:没有新增 story,原有的 SegmentedControl story 没变
  • 键盘可用:行为不变;右键不会挪走焦点,新测试专门检查了这一点
  • 减弱动效:不涉及
  • AGENTS.md 写明新规则或新依赖:没有新增

在 Windows 11(MSVC)上测过:

  • elyterminal-0.1.1 分支:cargo fmt --check、cargo clippy --all-targets --features test-support -- -D warnings 通过;cargo test --lib --features test-support 2156 项通过。新增测试 buttons::tests::a_right_press_names_its_segment_and_keeps_the_focus。
  • main 分支:cargo fmt --all --check 通过;cargo clippy -p ely-core --all-targets --all-features -- -D warnings 通过,cargo test -p ely-core --lib --all-features 579 项通过。我本机是 Rust 1.95,而工作区要求 1.98,所以这两项加了 --ignore-rust-version。
  • 变异检查:把处理器里的 prevent_default 和 stop_propagation 去掉,新测试会失败,报“focus stays put”。
  • api/ely-core.txt 里那一行是我照 Tabs::on_context 的格式手写的。scripts/api.py --write 要在 Linux 上跑,我没跑,留给 CI 的 api 任务检查。CHANGELOG.md 的 Unreleased 下加了一条。
  • ELYTerminal 套上这个分支后,407 项测试通过;我在 Windows 上实际试了右键“文件”标签,没有发现问题。

🤖 Generated with Claude Code

… lands on, for ELYTerminal's Files tab; the press stops on the segment, so its focus never moves

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Raiden-MeixElysia
Raiden-MeixElysia merged commit 34604b9 into ELY-Open-Source:main Nov 2, 2026
8 of 14 checks passed
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.

2 participants