Skip to content

Commit 46b10fd

Browse files
authored
Merge pull request #48 from Lithe-IDEA/sync/upstream-f5b634b
merge: sync upstream main (f5b634b, v0.6.6+) into the fork
2 parents c7bffdd + 1cbbd7f commit 46b10fd

12 files changed

Lines changed: 259 additions & 14 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Pango and Cairo libraries, and a Vulkan loader and driver for GPU acceleration
5656
and DirectWrite. Viva loads the system libraries at runtime and bundles none of
5757
them.
5858

59-
The current release is `v0.6.5`; name it explicitly (`@v0.6.5`) to pin it. Guides,
59+
The current release is `v0.6.6`; name it explicitly (`@v0.6.6`) to pin it. Guides,
6060
the API reference, and a component catalog with live previews live in
6161
[`website/`](website/); run it with `npm run dev` there, or read them on
6262
[vivaui.dev](https://vivaui.dev/en/), which is also available in

‎README.zh-CN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ viva dev . # hot reload: save a file, the window updates and keeps its st
3434

3535
环境要求:Go 1.26 或更新版本(缺失时 viva 会自己下载)。macOS 上需要 Xcode 命令行工具,因为 Viva 通过 cgo 访问 Cocoa 和 Metal;Linux 上需要带系统 XCB、Pango 和 Cairo 库的 X11,Vulkan 加载库和驱动用于 GPU 加速,缺失时窗口用 CPU 渲染;Windows 上需要 Win32、Direct3D 11 和 DirectWrite。Viva 在运行时加载系统库,自身不捆绑任何一个。
3636

37-
当前版本是 `v0.6.5`;要固定版本就写明(`@v0.6.5`)。指南、API 参考和带实时预览的组件目录在 [`website/`](website/) 里,本地用 `npm run dev` 运行;也已经发布在 [vivaui.dev](https://vivaui.dev/zh/)。
37+
当前版本是 `v0.6.6`;要固定版本就写明(`@v0.6.6`)。指南、API 参考和带实时预览的组件目录在 [`website/`](website/) 里,本地用 `npm run dev` 运行;也已经发布在 [vivaui.dev](https://vivaui.dev/zh/)。
3838

3939
下面的一切描述的都是这个仓库:它的测量、它自己的程序,以及如何开发框架本身,而不是如何用框架。
4040

‎base/accessors.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,9 @@ func (x *TabsDecl) GetLabels() []string { return x.labels }
12141214
// GetIcon reads the icon function of TabsDecl for the styled painting layer.
12151215
func (x *TabsDecl) GetIcon() func(index int) gfx.Icon { return x.icon }
12161216

1217+
// GetIconOnly reads the iconOnly of TabsDecl for the styled painting layer.
1218+
func (x *TabsDecl) GetIconOnly() bool { return x.iconOnly }
1219+
12171220
// GetLine reads the line of TabsDecl for the styled painting layer.
12181221
func (x *TabsDecl) GetLine() bool { return x.line }
12191222

‎base/page.go‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,10 +1108,27 @@ func (p *Page) PointerOver(r Rect) bool {
11081108
return p != nil && p.pointerIn && pointInRect(p.pointer.X, p.pointer.Y, r)
11091109
}
11101110

1111-
// Wheel scrolls an open Select, else the scroll area under the pointer, and gives
1112-
// an event neither takes to the OnScroll Config was given. It is the Config's
1113-
// OnScroll; a host that draws a page into a region calls it itself.
1111+
// Wheel routes the wheel through the page and gives an event no route takes to
1112+
// the OnScroll Config was given. It is the Config's OnScroll; a host that draws a
1113+
// page into a region calls it itself, and a host whose own OnScroll hands the
1114+
// wheel to the page gives RouteWheel instead, so the page does not fall back into
1115+
// the handler already routing it.
11141116
func (p *Page) Wheel(event gfx.ScrollEvent) gfx.EventResult {
1117+
if result := p.RouteWheel(event); result.Handled || result.Repaint {
1118+
return result
1119+
}
1120+
if p.baseScroll != nil {
1121+
return p.baseScroll(event)
1122+
}
1123+
return gfx.EventResult{}
1124+
}
1125+
1126+
// RouteWheel scrolls an open Select, a TextArea under the pointer, or the scroll
1127+
// area or sideways list under it, and reports an event none of them takes as not
1128+
// handled. It is the page's own routing without the OnScroll fallback: a host
1129+
// that forwards a wheel to the page from its own OnScroll calls this, so the page
1130+
// cannot hand the same event back to the handler that is already routing it.
1131+
func (p *Page) RouteWheel(event gfx.ScrollEvent) gfx.EventResult {
11151132
if h := p.controlOf(event.Target); h != nil && h.Scroll != nil {
11161133
if result := h.Scroll(event); result.Handled {
11171134
return result
@@ -1174,9 +1191,6 @@ func (p *Page) Wheel(event gfx.ScrollEvent) gfx.EventResult {
11741191
if panel >= 0 && !manual {
11751192
return gfx.EventResult{Handled: true} // what the panel covers is out of the wheel's reach
11761193
}
1177-
if p.baseScroll != nil {
1178-
return p.baseScroll(event)
1179-
}
11801194
return gfx.EventResult{}
11811195
}
11821196

‎base/tabs.go‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type TabsDecl struct {
1111
selected int
1212
line bool
1313
vertical bool
14+
iconOnly bool
1415
}
1516

1617
// tabHeight is the height of one trigger of a components.Tabs; the line variant
@@ -51,6 +52,20 @@ func (b Box) TabIcons(icon func(index int) gfx.Icon) Box {
5152
return b
5253
}
5354

55+
// TabIconOnly hides the labels of a Tabs strip and paints only the icons that
56+
// TabIcons gives it, for a strip too narrow to hold its labels. The labels stay
57+
// the tabs' accessible names and their hover hints, as components.TabOption.IconOnly
58+
// keeps them. A tab whose icon function returns a zero icon keeps its label, since
59+
// there would be nothing to see otherwise.
60+
//
61+
// ui.Tabs(c, &m.tab, tabs, nil).TabIcons(icons).TabIconOnly().Vertical()
62+
func (b Box) TabIconOnly() Box {
63+
if n := b.N(); n.Kind == kindTabs {
64+
WidgetsOf(b.f).tabs[n.Aux].iconOnly = true
65+
}
66+
return b
67+
}
68+
5469
// Line makes a Tabs strip the transparent variant with an underline under the active
5570
// tab. Vertical stacks its tabs in a column, with the line at their trailing edge.
5671
func (b Box) Line() Box {
@@ -84,8 +99,20 @@ func (b Box) TabClicked() (int, bool) {
8499
func (f *Frame) measureTabs(n *Node) {
85100
t := &WidgetsOf(f).tabs[n.Aux]
86101
var widest float32
87-
for _, label := range t.labels {
88-
widest = max(widest, f.Surface.TextWidthWeight(label, f.Palette.Metrics.FontSizeM, gfx.WeightMedium))
102+
for index, label := range t.labels {
103+
width := f.Surface.TextWidthWeight(label, f.Palette.Metrics.FontSizeM, gfx.WeightMedium)
104+
if t.icon != nil {
105+
icon := t.icon(index)
106+
if len(icon.Commands) > 0 || len(icon.Layers) > 0 {
107+
if t.iconOnly {
108+
// The label is the tab's accessible name, not its face.
109+
width = f.Palette.Metrics.FontSizeM
110+
} else {
111+
width += f.Palette.Metrics.FontSizeM + 6
112+
}
113+
}
114+
}
115+
widest = max(widest, width)
89116
}
90117
count := float32(len(t.labels))
91118
var gap float32

‎base/tabs_test.go‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,64 @@ func TestTabsReportTheClickedTabAndTheContentFollowsTheIndex(t *testing.T) {
119119
}
120120
}
121121

122+
// A strip too narrow for its labels paints only the icons TabIcons gives it,
123+
// while the labels remain the names a tab is reached and read by.
124+
func TestIconOnlyTabsPaintTheirIconsAndKeepTheirNames(t *testing.T) {
125+
theme := gfx.LightTheme()
126+
icons := []gfx.Icon{
127+
{ViewBox: 24, Stroke: 2, Commands: []gfx.PathCommand{gfx.MoveTo(4, 4), gfx.LineTo(20, 20)}},
128+
{ViewBox: 24, Stroke: 2, Commands: []gfx.PathCommand{gfx.MoveTo(4, 12), gfx.LineTo(20, 12)}},
129+
{ViewBox: 24, Stroke: 2, Commands: []gfx.PathCommand{gfx.MoveTo(12, 4), gfx.LineTo(12, 20)}},
130+
}
131+
flexed, direct := testCanvas(), testCanvas()
132+
var view View
133+
view.Draw(flexed, theme, gfx.Rect{Width: 40, Height: 108}, func(f *Frame) {
134+
f.Column().Children(func() {
135+
f.Tabs(tabsScope, tabLabels, 1).
136+
TabIcons(func(index int) gfx.Icon { return icons[index] }).
137+
TabIconOnly().Vertical().Height(108)
138+
})
139+
})
140+
options := make([]TabOption, len(tabLabels))
141+
for index, label := range tabLabels {
142+
options[index] = TabOption{ID: tabsScope.At(index), Label: label, Icon: icons[index], IconOnly: true}
143+
}
144+
components.BeginTabs(direct, theme, gfx.Rect{Width: 40, Height: 108}, options, options[1].ID).Vertical().Paint()
145+
sameCanvas(t, "icon-only", flexed, direct)
146+
if texts := flexed.Texts(); len(texts) != 0 {
147+
t.Fatalf("an icon-only strip painted %d labels, want none", len(texts))
148+
}
149+
for index, label := range tabLabels {
150+
if hit := hitByID(flexed, tabsScope.At(index)); hit.Label != label || hit.Hint != label {
151+
t.Errorf("tab %d is named %q and hinted %q, want %q", index, hit.Label, hit.Hint, label)
152+
}
153+
}
154+
}
155+
156+
// A tab of an icon-only strip whose icon is zero keeps its label: the strip
157+
// would otherwise show an empty trigger.
158+
func TestAnIconOnlyTabWithoutAnIconKeepsItsLabel(t *testing.T) {
159+
theme := gfx.LightTheme()
160+
icon := gfx.Icon{ViewBox: 24, Stroke: 2, Commands: []gfx.PathCommand{gfx.MoveTo(4, 4), gfx.LineTo(20, 20)}}
161+
canvas := testCanvas()
162+
var view View
163+
view.Draw(canvas, theme, gfx.Rect{Width: 40, Height: 108}, func(f *Frame) {
164+
f.Column().Children(func() {
165+
f.Tabs(tabsScope, tabLabels, 1).
166+
TabIcons(func(index int) gfx.Icon {
167+
if index == 0 {
168+
return gfx.Icon{}
169+
}
170+
return icon
171+
}).TabIconOnly().Vertical().Height(108)
172+
})
173+
})
174+
texts := canvas.Texts()
175+
if len(texts) != 1 || texts[0].Value != tabLabels[0] {
176+
t.Fatalf("texts = %v, want only %q", texts, tabLabels[0])
177+
}
178+
}
179+
122180
func TestTabsAllocateNothingOnceWarm(t *testing.T) {
123181
var view View
124182
canvas := testCanvas()

‎cmd/viva/initfiles/AGENTS.md.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@ func (m *model) page(c ui.C) {
517517

518518
- Tabs: `if ui.Tabs(c, &m.tab, tabs, nil).Line().Changed() { ... }`, then declare the active tab's content under it with an
519519
ordinary `switch m.tab`. `Line()` is the underlined variant (it draws 5 px under the strip), `Vertical()` stacks the tabs,
520-
and `TabIcons(func(i int) gfx.Icon)` puts an icon before each label without a second constructor.
520+
and `TabIcons(func(i int) gfx.Icon)` puts an icon before each label without a second constructor. A strip too narrow for
521+
its labels adds `TabIconOnly()`: it paints the icons alone and keeps each label as the tab's accessible name and hint.
521522
`Choice`, `Tabs` and `Select` write the value in the declaration, so disable them with an `if`, not a chained
522523
`.Disabled`: `if !m.locked { if ui.Tabs(c, &m.tab, tabs, nil).Changed() { ... } }`. `Tabs` and `Select` also honor a
523524
chained `.Disabled` for input; `Choice` ignores it, so never rely on it there.

‎docs/releases/0.6.6.md‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
v0.6.6 是 v0.6.5 之后的版本:页面控件补齐单选、标签、分页、拆分按钮、颜色选择与组合框选项,表单、布局和画布组件有了页面版 API;应用侧新增窗口标题、菜单动作结果、拖拽预览与 PCM 音频输出。macOS 是参考平台。有一处签名变化需要迁移,见“注意 · Caveats”。
2+
3+
v0.6.6 comes after v0.6.5: the page controls gain radio groups, badges, pagination, split buttons, color choices and described combobox options, the form, layout and canvas components get page-first APIs, and applications gain window titles, menu action results, drag previews and PCM audio output. macOS is the reference platform. One signature change needs a migration; see "注意 · Caveats".
4+
5+
## 拿到它 · Getting it
6+
7+
`go get github.com/vivaui/viva@v0.6.6`,需要 Go 1.26 或更新;系统依赖与 v0.6.5 相同,Vulkan 加载器现在只是推荐安装,没有时用 CPU 渲染。每个 Release 附带 `viva` 命令的预编译压缩包、`SHA256SUMS`,以及 Homebrew 与 Scoop 清单(`brew install vivaui/tap/viva`,或 `scoop bucket add vivaui https://github.com/vivaui/homebrew-tap` 后 `scoop install viva`);压缩包没有代码签名或公证,浏览器下载的 macOS 版会被 Gatekeeper 拦下,brew、curl 与 `go install` 不受影响。
8+
9+
`go get github.com/vivaui/viva@v0.6.6` needs Go 1.26 or newer; the system requirements are those of v0.6.5, with the Vulkan loader now a recommendation whose absence falls back to CPU rendering. Every Release carries prebuilt archives of the `viva` command, `SHA256SUMS`, and Homebrew and Scoop manifests (`brew install vivaui/tap/viva`, or `scoop bucket add vivaui https://github.com/vivaui/homebrew-tap` then `scoop install viva`); the archives are not code-signed or notarized, so a browser download on macOS is stopped by Gatekeeper while brew, curl and `go install` are not affected.
10+
11+
## 有什么 · What is in it
12+
13+
- `ui.Radio` 与 `ui.RadioGroup` 在页面里做单选,`ui.RadioID` 给应用命名的选项一个身份。
14+
- `ui.Badge`、`ui.Pagination`、`ui.SplitButton` 与 `ui.Kbd` 覆盖标签、分页、拆分操作和快捷键按键提示。
15+
- `ui.AlertDialog` 提供确认对话框;`ui.Dialog` 不设高度时按应用绘制的主体决定高度。
16+
- `ui.ColorSwatch` 与 `ui.ColorPicker` 让页面选择颜色,`ColorPickerState.Draft` 让预览跟随拖动。
17+
- `ui.ComboboxItems` 为每个选项给出说明、搜索文本与禁用状态,`ui.Select` 可以用 `DisabledOptions` 禁用单个选项,并用 `XSmall` 画更短的触发器。
18+
- `ui.Checkbox.Mixed` 表达部分选中,`ui.Toggle` 是带样式的开关,`ui.RangeSlider` 是两个拇指的范围滑块。
19+
- `ui.List` 的拖动可以从行的手柄开始,Alt 加方向键移动行,焦点留在移动后的手柄上。
20+
- `ui.FormField` 与 `ui.Field` 支持说明、错误、无效、禁用与提示,`FormField` 可以标出它命名的控件。
21+
- `ui.Box.ButtonRecipe` 与 `SwitchRecipe` 让单个按钮或开关使用自己的外观,而不是页面统一的 `Styles`。
22+
- `AlwaysScrollbars` 保留滚动条的槽位,滚动条在指针离开后停留并淡出,菜单行与滚动条值可以被辅助技术读出。
23+
- 弹出层与抽屉在窗口边缘内夹住,弹出层可以带自己的圆角与锚点偏移。
24+
- `ui.OpenWindow` 从页面打开自己的窗口,`Page.RouteWheel` 把滚轮交给页面而不落回窗口的 `OnScroll`。
25+
- 表单、布局与画布组件有了 `ui/<组件>` 的页面版 API,例如 `ui/chart`、`ui/buttongroup`、`ui/calendar`,只在被导入时链接。
26+
- 新增可选的 `ui/multiselect` 与 `ui/hierarchypicker` 控件包。
27+
- `components` 新增可组合的头像裁剪编辑器。
28+
- `Window.SetTitle` 在 macOS、Windows、X11 与无头后端设置窗口标题。
29+
- `MenuBarItem.OnSelect` 返回 `gfx.EventResult`,菜单命令的焦点、剪贴板与重绘应用到当前窗口,菜单快捷键先交给焦点控件处理。
30+
- `Application.OpenDragPreview` 显示跟随拖动的透明预览窗口。
31+
- `audio` 包把 PCM 播放到系统默认输出设备:macOS 用 AudioUnit,Windows 用 WASAPI 共享模式,Linux 用 ALSA 默认插件。
32+
- `window`、`base` 与 `style` 包公开窗口契约、页面引擎与样式层,`ui` 仍是写页面的入口。
33+
- Web 部署用 WebGL2 渲染,不支持时回退 Canvas2D。
34+
- 安装包把 Vulkan 加载器当作可选项,`viva doctor` 会把缺少加载器报告为 CPU 渲染说明。
35+
- Linux 上合成桌面没有同步缩放时仍绘制窗口框,隐藏与窗口管理器的竞争会报告正确的可见性。
36+
- Linux 上 GTK 组合被取消时保留选区,只含图片的 X11 剪贴板可以粘贴,CPU 渲染器会缩放位图。
37+
- Linux 上在 XDG 配置目录查找 Vulkan ICD,只读编辑器在第一次按键前恢复输入,Wayland 内容点击后保留键盘与输入法。
38+
- Windows 上隐藏窗口的唤醒不再等 `WM_PAINT`,实时缩放保持响应且不拉伸内容。
39+
- Windows 上安装时替换被程序加载的原生文件,更新在退出前暂存补丁载荷。
40+
- macOS 上双击选中单词、三击选中整行,建议的保存扩展名保持完整。
41+
- 文本编辑与代码行保留 CRLF 行尾。
42+
- memo 重放保留完整的命中语义、命中文本与无效状态,禁用控件仍能接收次要按键。
43+
- `ui.Tabs` 按给定的高度绘制,上下文菜单从焦点控件取方向键,`ui.Radio` 的标签放不下时以省略号结尾。
44+
- 场景与渲染只在删除节点时收缩保留实例,无障碍镜像只重建变化的语义,页面没有用到的控件画笔不链接。
45+
46+
- `ui.Radio` and `ui.RadioGroup` offer a single choice in a page, and `ui.RadioID` names an option the application identifies.
47+
- `ui.Badge`, `ui.Pagination`, `ui.SplitButton` and `ui.Kbd` cover labels, page items, a joined action and a menu, and shortcut keycaps.
48+
- `ui.AlertDialog` gives a page a confirmation dialog; a `ui.Dialog` with no height is as tall as the body the application paints.
49+
- `ui.ColorSwatch` and `ui.ColorPicker` let a page choose colors, and `ColorPickerState.Draft` makes the preview follow the drag.
50+
- `ui.ComboboxItems` gives every option a detail, search text and disabled state, and `ui.Select` disables single options with `DisabledOptions` and draws a shorter trigger with `XSmall`.
51+
- `ui.Checkbox.Mixed` shows a partial choice, `ui.Toggle` is a styled switch, and `ui.RangeSlider` is a two-thumb range.
52+
- A `ui.List` drag can start on a row's handle, and Alt with the arrow keys moves a row while the focus stays on the handle it moved.
53+
- `ui.FormField` and `ui.Field` take a description, an error, the invalid look, disabled and a hint, and `FormField` labels the control it names.
54+
- `ui.Box.ButtonRecipe` and `SwitchRecipe` give one button or switch its own look instead of the page's `Styles`.
55+
- `AlwaysScrollbars` keeps a scroll area's gutter, a bar lingers and fades after the pointer leaves, and menu rows and scrollbar values reach assistive technology.
56+
- Popovers and drawers stay clear of the page edges, and a popover can carry its own radius and anchor offset.
57+
- `ui.OpenWindow` opens a page's own window, and `Page.RouteWheel` gives the wheel to the page without falling back into the window's `OnScroll`.
58+
- The form, layout and canvas components have page-first APIs in `ui/<component>`, such as `ui/chart`, `ui/buttongroup` and `ui/calendar`, linked only when imported.
59+
- `ui/multiselect` and `ui/hierarchypicker` are new opt-in page controls.
60+
- `components` gains a composable avatar crop editor.
61+
- `Window.SetTitle` sets the window title on macOS, Windows, X11 and the headless backends.
62+
- `MenuBarItem.OnSelect` returns a `gfx.EventResult`; the runtime applies the focus, clipboard and repaint a menu command returns to the active window, and a menu shortcut is offered to the focused control first.
63+
- `Application.OpenDragPreview` shows a transparent preview window that follows a drag.
64+
- Package `audio` plays PCM on the default output device: an AudioUnit on macOS, WASAPI shared mode on Windows and ALSA's default plugin on Linux.
65+
- Packages `window`, `base` and `style` publish the window contracts, the page engine and the styled layer, and `ui` stays how a page is written.
66+
- Web deployments render with WebGL2 and fall back to Canvas2D.
67+
- The packages treat the Vulkan loader as optional, and `viva doctor` reports a missing loader as a CPU-rendering note.
68+
- On Linux a compositing desktop without synced resize still draws the frame, and Hide racing the window manager reports the correct visibility.
69+
- On Linux a cancelled GTK preedit keeps its selection, an image-only X11 clipboard can be pasted, and the CPU renderer scales bitmaps.
70+
- On Linux the Vulkan ICD search covers XDG config directories, a read-only editor restores input before the first key, and Wayland keeps the keyboard and IME after a content click.
71+
- On Windows a hidden window's wake no longer waits for `WM_PAINT`, and a live resize stays responsive without stretching the content.
72+
- On Windows an install replaces the native files a running program loaded, and an update stages its patch payload before quitting.
73+
- On macOS a double-click selects a word and a triple-click the line, and a suggested save extension is kept intact.
74+
- Line editing and code rows keep CRLF line endings.
75+
- A memo replay keeps the complete hit semantics, the hit texts and the invalid state, and a disabled control still takes a secondary press.
76+
- `ui.Tabs` paints at the height it is given, a context menu takes the arrow keys from the focused control, and a `ui.Radio` label ends with an ellipsis when it does not fit.
77+
- The scene and render paths shrink retained instances only on deletion, the accessibility mirror rebuilds only the semantics a repaint changed, and a page links only the control painters it uses.
78+
79+
## 注意 · Caveats
80+
81+
- `MenuBarItem.OnSelect` 的签名从 `func()` 变为 `func() gfx.EventResult`:每个菜单项返回命令的结果,没有变化时返回 `gfx.EventResult{}`。编译器会指出需要改的入口。
82+
- 通过窗口自己的 `OnScroll` 把滚轮转给页面的宿主,改用 `Page.RouteWheel`;否则页面会把同一个事件交回正在路由它的处理器。
83+
84+
- `MenuBarItem.OnSelect` changed from `func()` to `func() gfx.EventResult`: every entry returns what its command did, and `gfx.EventResult{}` when it changes nothing. The compiler points at each entry to update.
85+
- A host whose own `OnScroll` forwards the wheel to the page calls the new `Page.RouteWheel`; otherwise the page hands the same event back to the handler already routing it.

0 commit comments

Comments
 (0)