Files
aego/ui/richtext/cull_test.go
sanspie 50be5c04bc
ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Stage 12.5: Art Workspace and asset authoring
Add dockable Art tools, animation and previews, guarded asset workflows,
and the Web Asset Studio built on the shared Art Core. Expand English and
Russian documentation, interactive Try scenes, examples and editor icons.

Add audio waveform navigation, source analysis, guarded previews and a
browser Worker mixer. Preserve source changes and recovery with bounded
checks, and strengthen native, browser and interoperability CI.

Prepare version 0.12.5 and manually built native artifact candidates.
Fix the production site image demo build dependency.
Reuse immutable scene indices when capturing keyframes.
Wait for real Persist save/load completion in component tests.
Stabilize browser Game View captures outside pointer hover.
Aseprite interchange and persistent Audio EDL recovery remain limited;
the artifact workflow does not publish releases or change stable.
2026-11-15 10:37:50 +03:00

115 lines
3.2 KiB
Go

package richtext
import (
"strings"
"testing"
"aego/core/mathx"
"aego/platform/input"
"aego/render/text"
"aego/ui/core"
"aego/ui/theme"
)
func TestClipMarginsCoverGlyphOverhangAndRunButtons(t *testing.T) {
f := text.NewFont(14, 2, 20, 14)
f.SetGlyph('A', text.FontGlyph{Offset: mathx.Vec2{Y: -80}, Size: mathx.Vec2{Y: 180}})
var fs fonts
for i := range fs.face {
fs.face[i] = f
}
top, bottom := clipMargins(&fs, 30)
if top < 90.25 || bottom < 90.25 {
t.Fatalf("glyph can overhang clipping bounds: top=%v bottom=%v", top, bottom)
}
f.SetGlyph('A', text.FontGlyph{})
top, bottom = clipMargins(&fs, 200)
if top < 90.25 || bottom < 202 {
t.Fatalf("glyph or run button can be culled: top=%v bottom=%v", top, bottom)
}
}
func TestCulledLinksKeepTheirIDsAcrossParentClipChange(t *testing.T) {
f := text.NewFont(14, 1, 18, 14)
for r := rune(32); r < 127; r++ {
f.SetGlyph(r, text.FontGlyph{Advance: 8})
}
ui := core.New(f)
ui.Theme = theme.Editor()
var rt Text
rt.CullClipped = true
rt.Set(Parse(strings.Repeat("[earlier](ref:earlier)\n\n", 10) + "[target](ref:target)"))
r := mathx.Rect{W: 260}
r.H = rt.Measure(ui, r.W)
doc := rt.Doc()
var target *Line
for i := range doc.Lines {
for _, run := range doc.Lines[i].Runs {
if run.Target == "ref:target" {
target = &doc.Lines[i]
}
}
}
if target == nil {
t.Fatal("target link not laid out")
}
pad := ui.Theme.Padding * 2
at := mathx.Vec2{X: pad + 2, Y: pad + target.Y + target.H/2}
var in input.State
draw := func(clip mathx.Rect) Action {
ui.Begin(&in, mathx.Vec2{X: 400, Y: r.H + 20}, 1)
ui.PushClip(clip)
act := rt.Draw(ui, ui.ID("rich"), r)
ui.PopClip()
ui.End()
return act
}
in.BeginFrame()
in.ApplyMouseMove(at, mathx.Vec2{})
in.ApplyMouseDown(at, input.MouseLeft)
clip := mathx.Rect{Y: pad + target.Y - 2, W: 300, H: target.H + 4}
draw(clip)
in.BeginFrame()
in.ApplyMouseUp(at, input.MouseLeft)
if act := draw(mathx.Rect{W: 300, H: r.H}); act.Target != "ref:target" {
t.Fatalf("the target link lost its active ID after parent clipping: %+v", act)
}
}
func TestCulledLinkStillReceivesReleaseAfterScrollingOut(t *testing.T) {
f := text.NewFont(14, 1, 18, 14)
for r := rune(32); r < 127; r++ {
f.SetGlyph(r, text.FontGlyph{Advance: 8})
}
ui := core.New(f)
ui.Theme = theme.Editor()
var rt Text
rt.CullClipped = true
rt.Set(Parse("[target](ref:target)\n\n" + strings.Repeat("later\n\n", 20)))
r := mathx.Rect{W: 260}
r.H = rt.Measure(ui, r.W)
pad := ui.Theme.Padding * 2
at := mathx.Vec2{X: pad + 2, Y: pad + rt.Doc().Lines[0].H/2}
var in input.State
draw := func(clip mathx.Rect) Action {
ui.Begin(&in, mathx.Vec2{X: 400, Y: r.H + 20}, 1)
ui.PushClip(clip)
act := rt.Draw(ui, ui.ID("rich"), r)
ui.PopClip()
ui.End()
return act
}
in.BeginFrame()
in.ApplyMouseMove(at, mathx.Vec2{})
in.ApplyMouseDown(at, input.MouseLeft)
draw(mathx.Rect{W: 300, H: r.H})
if ui.Active() == 0 {
t.Fatal("link did not receive the press")
}
in.BeginFrame()
in.ApplyMouseUp(at, input.MouseLeft)
if act := draw(mathx.Rect{Y: r.H / 2, W: 300, H: 50}); act.Target != "" || ui.Active() != 0 {
t.Fatalf("offscreen release must cancel the link and clear active state: action=%+v active=%v", act, ui.Active())
}
}