Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ jobs:
env:
VIVA_NATIVE_GLOBAL_SHORTCUT_TEST: '1'
run: go test ./internal/platform/windows -run '^TestNativeGlobalShortcutRegistration$' -count=1 -v
- name: Native Windows clipboard transactions
env:
VIVA_WINDOWS_CLIPBOARD: '1'
run: go test ./internal/platform/windows -run '^TestColumnClipboardNative' -count=1 -v -timeout=2m
- name: Native Direct2D text origins and hidden labels
run: go test ./internal/platform/windows -run '^Test(DirectTextLayoutOriginByValue|HiddenNativeEditorDoesNotDrawColorEmoji|TextEngineRasterizesProportionalText)$' -count=1 -v
- name: Promised file drag
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Wayland client and needs the system's GTK 3), and a Vulkan loader and driver for
and DirectWrite. Viva loads the system libraries at runtime and bundles none of
them.

The current release is `v0.6.8`; name it explicitly (`@v0.6.8`) to pin it. Guides,
The current release is `v0.6.9`; name it explicitly (`@v0.6.9`) to pin it. Guides,
the API reference, and a component catalog with live previews live in
[`website/`](website/); run it with `npm run dev` there, or read them on
[vivaui.dev](https://vivaui.dev/en/), which is also available in
Expand Down
2 changes: 1 addition & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ viva dev . # hot reload: save a file, the window updates and keeps its st

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

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

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

Expand Down
33 changes: 33 additions & 0 deletions app/accessibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,36 @@ func TestRegionsNeverReportTheKeyboard(t *testing.T) {
t.Errorf("region = %+v", painter.accessibility[0])
}
}

func TestSyncSemanticsUpdatesZeroIDContainerOnIncrementalPaint(t *testing.T) {
var canvas gfx.Canvas
width := float32(912)
role := gfx.RoleStatus
label := "Loading"
config := Config{
Title: "a11y-container-incremental",
Width: 960,
Height: 200,
Paint: func(canvas *gfx.Canvas, _ gfx.Size) {
canvas.ContainerWithOptions(gfx.Rect{Width: width, Height: 24}, role, label, gfx.HitOptions{Level: 1})
canvas.HitWithLabel(gfx.Item(1), gfx.Rect{Y: 40, Width: 80, Height: 24}, "Save")
},
}
driver, err := NewDriver(config, &canvas)
if err != nil {
t.Fatal(err)
}
defer driver.Close()

// Frame 2: only the zero-ID container changes bounds, role and label; hit count and IDs stay identical.
width = 904
role = gfx.RoleGroup
label = "Article A"
if err := driver.redraw(); err != nil {
t.Fatal(err)
}
nodes := driver.Accessibility()
if len(nodes) == 0 || nodes[0].Bounds.Width != 904 || nodes[0].Role != gfx.RoleGroup || nodes[0].Label != "Article A" {
t.Fatalf("stale zero-ID container accessibility node: %+v", nodes)
}
}
9 changes: 5 additions & 4 deletions app/fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
// system, sorted and without duplicates. An application offers them to the user
// and gives the chosen one to gfx.MonoFamily to draw terminal text in it.
//
// What counts as monospace follows the platform. macOS and Windows measure
// each family and offer every one whose printable ASCII characters share one
// advance width, including coding families that do not set the fixed-pitch
// flag; the other platforms list what the system declares fixed-pitch.
// What counts as monospace follows the platform. macOS, Windows and Linux
// measure each family and offer every one whose printable ASCII characters
// share one advance width, including coding families that do not set the
// fixed-pitch flag; Linux without Pango, and the other platforms, list what the
// system declares fixed-pitch.
//
// The list is read from the system on every call and takes a moment, since a
// family is measured rather than taken at its word, so it is for a settings
Expand Down
5 changes: 4 additions & 1 deletion app/painter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,10 @@ func (painter *painter) syncSemantics(incremental bool) (changed bool) {
fast = false
break
}
if *current != *previous && !current.ID.IsZero() {
if *current != *previous {
// A zero ID is tracked like any other: it marks every zero-ID
// node (headings, groups, live regions) for a rebuild below, and
// matches nothing for an occluder or drag region, which has none.
known := false
for _, id := range dirty {
if id == current.ID {
Expand Down
2 changes: 2 additions & 0 deletions base/state_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type ColorPickerIDs struct {

type ColorPickerLabels struct {
Color, Saturation, Hue, Alpha, Hex, Clear, Cancel, Apply string
// InvalidColor is the message shown for an invalid Hex value.
InvalidColor string
}

// ColorPickerLayout is also the input geometry. Pointer and Key update a copy
Expand Down
96 changes: 91 additions & 5 deletions cmd/viva/templates/code_editor.go.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ type CodeEditorFoldRange struct {
}

// CodeEditorFoldMarker adds a disclosure button to a visible logical line.
// The caller owns its ID and handles clicks. Markers must be sorted by Line.
// The caller owns its ID and handles clicks. PlaceholderID, when nonzero,
// exposes the inline "..." badge on a folded header line as a button too.
// Markers must be sorted by Line.
type CodeEditorFoldMarker struct {
Line int
ID gfx.ID
Collapsed bool
Label string
Line int
ID gfx.ID
PlaceholderID gfx.ID
Collapsed bool
Label string
}

// CodeEditorMaxHighlightedLine is the longest line, in bytes, that is handed to
Expand Down Expand Up @@ -713,6 +716,47 @@ func (editor *CodeEditor) Paint(canvas *gfx.Canvas, theme gfx.Theme, bounds gfx.
}
canvas.Unclip()
}
if len(editor.folds) > 0 && len(snapshot.FoldMarkers) != 0 {
canvas.Clip(content)
markerIndex := 0
if firstRow < len(editor.rows) {
firstLine := int(editor.rows[firstRow].line)
markerIndex = sort.Search(len(snapshot.FoldMarkers), func(i int) bool { return snapshot.FoldMarkers[i].Line >= firstLine })
}
left := content.X - editor.scrollX
for index := firstRow; index < len(editor.rows); index++ {
y := content.Y + float32(index)*lineHeight - editor.scrollY
if y >= content.Y+content.Height {
break
}
row := editor.rows[index]
if editor.softWrapped(index) || !editor.isFoldHeader(int(row.line)) {
continue
}
for markerIndex < len(snapshot.FoldMarkers) && snapshot.FoldMarkers[markerIndex].Line < int(row.line) {
markerIndex++
}
if markerIndex >= len(snapshot.FoldMarkers) || snapshot.FoldMarkers[markerIndex].Line != int(row.line) {
continue
}
marker := snapshot.FoldMarkers[markerIndex]
if marker.PlaceholderID.IsZero() {
continue
}
badge := foldBadgeRect(row, y, left, cellWidth, lineHeight, cellHeight)
if badge.X+badge.Width <= content.X || badge.X >= content.X+content.Width {
continue
}
label := marker.Label
if label == "" {
label = "Expand fold"
}
canvas.HitWithOptions(marker.PlaceholderID, badge, label, gfx.HitOptions{
Role: gfx.RoleButton, Cursor: gfx.PointerCursorHand, Disabled: snapshot.Disabled,
})
}
canvas.Unclip()
}
if !snapshot.ScrollbarID.IsZero() {
area := BeginScrollArea(canvas, theme, gfx.Rect{X: bounds.X + bounds.Width - codeEditorBarSize - 1, Y: content.Y, Width: 10, Height: content.Height},
gfx.Size{Width: 10, Height: float32(len(editor.rows)) * lineHeight}).Offset(0, editor.scrollY).VerticalScrollbar(snapshot.ScrollbarID, snapshot.Label, "")
Expand Down Expand Up @@ -1052,6 +1096,9 @@ func (paint *codePaint) row(index int, y float32) {
(paint.value[rowEnd] == '\n' || paint.value[rowEnd] == '\r' && rowEnd+1 < len(paint.value) && paint.value[rowEnd+1] == '\n') {
paint.lineEnding(row, y, left)
}
if !editor.softWrapped(index) && editor.isFoldHeader(int(row.line)) {
paint.foldBadge(row, y, left)
}
if paint.showWrapSymbol && editor.softWrapped(index) {
paint.wrapSymbol(y)
}
Expand All @@ -1061,6 +1108,45 @@ func (paint *codePaint) row(index int, y float32) {
}
}

func (editor *CodeEditor) isFoldHeader(line int) bool {
if len(editor.folds) == 0 {
return false
}
index := sort.Search(len(editor.folds), func(i int) bool { return editor.folds[i].Header >= line })
return index < len(editor.folds) && editor.folds[index].Header == line
}

func foldBadgeRect(row codeRow, y, left, cellWidth, lineHeight, cellHeight float32) gfx.Rect {
width := max(float32(18), cellWidth*3.5)
height := max(float32(12), cellHeight-2)
return gfx.Rect{
X: left + float32(row.cells)*cellWidth + cellWidth*0.5,
Y: y + (lineHeight-height)/2,
Width: width,
Height: height,
}
}

func (paint *codePaint) foldBadge(row codeRow, y, left float32) {
badge := foldBadgeRect(row, y, left, paint.cellWidth, paint.lineHeight, paint.cellHeight)
bg := paint.muted
bg.Alpha *= 0.16
fg := paint.muted
if paint.editor.disabled {
bg.Alpha *= 0.5
fg.Alpha *= 0.5
}
paint.canvas.Rounded(badge, 3, bg)
textBounds := gfx.Rect{
X: badge.X + max(0, (badge.Width-paint.cellWidth*3)/2),
Y: y + (paint.lineHeight-paint.cellHeight)/2,
Width: paint.cellWidth * 3,
Height: paint.cellHeight,
}
runs := [1]gfx.TextRun{{Column: 0, Bytes: 3, Cells: 3, Color: fg}}
paint.canvas.LabelRuns("...", textBounds, gfx.TextStyle{Size: paint.size, Color: fg, Mono: true, MonoFace: paint.face}, paint.cellWidth, runs[:])
}

func (paint *codePaint) wrapSymbol(y float32) {
content := paint.editor.content
paint.canvas.Label("↪", gfx.Rect{
Expand Down
96 changes: 91 additions & 5 deletions components/code_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,15 @@ type CodeEditorFoldRange struct {
}

// CodeEditorFoldMarker adds a disclosure button to a visible logical line.
// The caller owns its ID and handles clicks. Markers must be sorted by Line.
// The caller owns its ID and handles clicks. PlaceholderID, when nonzero,
// exposes the inline "..." badge on a folded header line as a button too.
// Markers must be sorted by Line.
type CodeEditorFoldMarker struct {
Line int
ID gfx.ID
Collapsed bool
Label string
Line int
ID gfx.ID
PlaceholderID gfx.ID
Collapsed bool
Label string
}

// CodeEditorMaxHighlightedLine is the longest line, in bytes, that is handed to
Expand Down Expand Up @@ -713,6 +716,47 @@ func (editor *CodeEditor) Paint(canvas *gfx.Canvas, theme gfx.Theme, bounds gfx.
}
canvas.Unclip()
}
if len(editor.folds) > 0 && len(snapshot.FoldMarkers) != 0 {
canvas.Clip(content)
markerIndex := 0
if firstRow < len(editor.rows) {
firstLine := int(editor.rows[firstRow].line)
markerIndex = sort.Search(len(snapshot.FoldMarkers), func(i int) bool { return snapshot.FoldMarkers[i].Line >= firstLine })
}
left := content.X - editor.scrollX
for index := firstRow; index < len(editor.rows); index++ {
y := content.Y + float32(index)*lineHeight - editor.scrollY
if y >= content.Y+content.Height {
break
}
row := editor.rows[index]
if editor.softWrapped(index) || !editor.isFoldHeader(int(row.line)) {
continue
}
for markerIndex < len(snapshot.FoldMarkers) && snapshot.FoldMarkers[markerIndex].Line < int(row.line) {
markerIndex++
}
if markerIndex >= len(snapshot.FoldMarkers) || snapshot.FoldMarkers[markerIndex].Line != int(row.line) {
continue
}
marker := snapshot.FoldMarkers[markerIndex]
if marker.PlaceholderID.IsZero() {
continue
}
badge := foldBadgeRect(row, y, left, cellWidth, lineHeight, cellHeight)
if badge.X+badge.Width <= content.X || badge.X >= content.X+content.Width {
continue
}
label := marker.Label
if label == "" {
label = "Expand fold"
}
canvas.HitWithOptions(marker.PlaceholderID, badge, label, gfx.HitOptions{
Role: gfx.RoleButton, Cursor: gfx.PointerCursorHand, Disabled: snapshot.Disabled,
})
}
canvas.Unclip()
}
if !snapshot.ScrollbarID.IsZero() {
area := BeginScrollArea(canvas, theme, gfx.Rect{X: bounds.X + bounds.Width - codeEditorBarSize - 1, Y: content.Y, Width: 10, Height: content.Height},
gfx.Size{Width: 10, Height: float32(len(editor.rows)) * lineHeight}).Offset(0, editor.scrollY).VerticalScrollbar(snapshot.ScrollbarID, snapshot.Label, "")
Expand Down Expand Up @@ -1052,6 +1096,9 @@ func (paint *codePaint) row(index int, y float32) {
(paint.value[rowEnd] == '\n' || paint.value[rowEnd] == '\r' && rowEnd+1 < len(paint.value) && paint.value[rowEnd+1] == '\n') {
paint.lineEnding(row, y, left)
}
if !editor.softWrapped(index) && editor.isFoldHeader(int(row.line)) {
paint.foldBadge(row, y, left)
}
if paint.showWrapSymbol && editor.softWrapped(index) {
paint.wrapSymbol(y)
}
Expand All @@ -1061,6 +1108,45 @@ func (paint *codePaint) row(index int, y float32) {
}
}

func (editor *CodeEditor) isFoldHeader(line int) bool {
if len(editor.folds) == 0 {
return false
}
index := sort.Search(len(editor.folds), func(i int) bool { return editor.folds[i].Header >= line })
return index < len(editor.folds) && editor.folds[index].Header == line
}

func foldBadgeRect(row codeRow, y, left, cellWidth, lineHeight, cellHeight float32) gfx.Rect {
width := max(float32(18), cellWidth*3.5)
height := max(float32(12), cellHeight-2)
return gfx.Rect{
X: left + float32(row.cells)*cellWidth + cellWidth*0.5,
Y: y + (lineHeight-height)/2,
Width: width,
Height: height,
}
}

func (paint *codePaint) foldBadge(row codeRow, y, left float32) {
badge := foldBadgeRect(row, y, left, paint.cellWidth, paint.lineHeight, paint.cellHeight)
bg := paint.muted
bg.Alpha *= 0.16
fg := paint.muted
if paint.editor.disabled {
bg.Alpha *= 0.5
fg.Alpha *= 0.5
}
paint.canvas.Rounded(badge, 3, bg)
textBounds := gfx.Rect{
X: badge.X + max(0, (badge.Width-paint.cellWidth*3)/2),
Y: y + (paint.lineHeight-paint.cellHeight)/2,
Width: paint.cellWidth * 3,
Height: paint.cellHeight,
}
runs := [1]gfx.TextRun{{Column: 0, Bytes: 3, Cells: 3, Color: fg}}
paint.canvas.LabelRuns("...", textBounds, gfx.TextStyle{Size: paint.size, Color: fg, Mono: true, MonoFace: paint.face}, paint.cellWidth, runs[:])
}

func (paint *codePaint) wrapSymbol(y float32) {
content := paint.editor.content
paint.canvas.Label("↪", gfx.Rect{
Expand Down
Loading
Loading