Skip to content

fix(ui): keep the icon's room on a menu's rows without one - #83

Merged
xiaoyumuxi merged 1 commit into
mainfrom
fix/menu-icon-slot-fork
Nov 30, 2026
Merged

xiaoyumuxi merged 1 commit into
mainfrom
fix/menu-icon-slot-fork

Conversation

@xiaoyumuxi

Copy link
Copy Markdown

What this changes

把上游 vivaui/viva#523 的同一个补丁(菜单里无图标的行保留图标位置)cherry-pick 到当前 fork main(d71b14c6)上,不带入其他上游提交。只改 ui/menu_paint.go,新增 ui/menu_icon_inset_test.go。

同一个菜单只要有一行带图标,其余无图标的行、子菜单入口、勾选行和分组标题都设置 Inset,文字从同一条竖线开始;整个菜单都没有图标时布局不变。contextItem 补上漏传的 Inset,并删掉没有调用方的 menuItemsRow 副本。

Why

Lithe 正在给编辑器、项目树、标签页等右键菜单加 IntelliJ 图标,只有部分动作有原始图标,其余故意留空。没有这个补丁时,无图标行的文字比有图标行靠左 24px。Lithe 侧的改动会先临时固定本 PR 的 head,本 PR 合入后换成 fork main 的提交再标记 ready。

How it was verified

  • gofmt -l 对改动文件无输出。
  • 本分支 go vet ./ui/... ./components/... ./base/... 无输出。
  • 本分支 go test ./ui/... ./components/... ./base/... -count=1 全部通过,包括新测试 TestMenuRowsWithoutAnIconKeepTheIconsRoom(dropdown 和 context 两种菜单)。
  • 上游分支全量 go test ./...:除与本改动无关的 cmd/viva 既有失败(componentgen 模板过期、本机打包部署目标环境)外全部通过,详见 fix(ui): keep the icon's room on a menu's rows without one vivaui/viva#523。
  • 绘制基准(BenchmarkMenuOpen、BenchmarkPageTextFieldsEditMenu,各 8 次,macOS arm64,非空闲机器)差异在噪声内,仍是 0 B/op、0 allocs/op,数字见 fix(ui): keep the icon's room on a menu's rows without one vivaui/viva#523。
  • Windows、Linux 真实窗口未看;macOS 只通过 Lithe 的无头截图看过。

Where the boundary sits

菜单行与图标列的对齐属于 Viva 的菜单组件;应用没有 API 设置 Inset,也不应该自己补偿缩进。

A menu that shows an icon on some rows painted the label of every other
row 24px further left, so the labels of one menu started at two edges.
When an item row of a menu has an icon, its rows without one, its
submenu triggers, checkboxes and labels now take the inset the icon
would, as macOS and IntelliJ menus do. A menu with no icon is unchanged.

contextItem dropped Inset on the way to the context menu, and
menuItemsRow was an unused copy of menuItemRow; both are fixed with it.
@xiaoyumuxi
xiaoyumuxi merged commit 7378b4e into main Nov 30, 2026
17 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.

1 participant