-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathborder_split_test.go
More file actions
118 lines (108 loc) · 4.09 KB
/
Copy pathborder_split_test.go
File metadata and controls
118 lines (108 loc) · 4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) 2026 the go-widgets/toolkit authors. All rights reserved.
// Use of this source code is governed by a BSD-3-Clause license that can be
// found in the LICENSE file at the root of this repository.
package toolkit
import "testing"
// TestBorderSplitLayout checks a splittable region reserves a BorderSplitW handle
// strip between it and the centre, on every edge, and that the handle sits at the
// region's inner boundary.
func TestBorderSplitLayout(t *testing.T) {
n, w, c := &dockProbe{}, &dockProbe{}, &dockProbe{}
b := NewBorder()
b.North, b.NorthSize, b.NorthSplit = n, 10, true
b.West, b.WestSize, b.WestSplit = w, 20, true
b.Center = c
b.SetBounds(Rect{X: 0, Y: 0, W: 100, H: 50})
// North 10 tall at top; its handle is the next 6px strip (Y 10..16), full width
// at that moment (before West carves), so centre starts at Y=16.
if got := n.Bounds(); got != (Rect{X: 0, Y: 0, W: 100, H: 10}) {
t.Fatalf("north = %+v", got)
}
// West 20 wide, in the band below the north handle (Y 16..50); its handle is the
// next 6px column (X 20..26).
if got := w.Bounds(); got != (Rect{X: 0, Y: 16, W: 20, H: 34}) {
t.Fatalf("west = %+v", got)
}
if got := c.Bounds(); got != (Rect{X: 26, Y: 16, W: 74, H: 34}) {
t.Fatalf("center = %+v", got)
}
// Two handles recorded, at the right places.
ns, ok := b.SplitHandleAt(50, 12) // inside the north handle strip (Y 10..16)
if !ok || ns != DockTop {
t.Fatalf("north handle hit = %v,%v", ns, ok)
}
ws, ok := b.SplitHandleAt(22, 30) // inside the west handle column (X 20..26)
if !ok || ws != DockLeft {
t.Fatalf("west handle hit = %v,%v", ws, ok)
}
if _, ok := b.SplitHandleAt(60, 30); ok { // in the centre, no handle
t.Fatal("centre point should not hit a handle")
}
}
// TestBorderResizeSplit covers ResizeSplit for every edge, the negative and
// over-extent clamps, and the OnResize callback (fired and nil).
func TestBorderResizeSplit(t *testing.T) {
b := NewBorder()
b.North, b.NorthSplit = &dockProbe{}, true
b.South, b.SouthSplit = &dockProbe{}, true
b.West, b.WestSplit = &dockProbe{}, true
b.East, b.EastSplit = &dockProbe{}, true
var gotSide DockSide
var gotSize int
calls := 0
b.OnResize = func(side DockSide, size int) { gotSide, gotSize, calls = side, size, calls+1 }
b.SetBounds(Rect{X: 0, Y: 0, W: 100, H: 60})
b.ResizeSplit(DockTop, 25)
if b.NorthSize != 25 || gotSide != DockTop || gotSize != 25 || calls != 1 {
t.Fatalf("resize north: size=%d cb=%v/%d calls=%d", b.NorthSize, gotSide, gotSize, calls)
}
b.ResizeSplit(DockBottom, 12)
if b.SouthSize != 12 {
t.Fatalf("resize south = %d", b.SouthSize)
}
b.ResizeSplit(DockLeft, 30)
if b.WestSize != 30 {
t.Fatalf("resize west = %d", b.WestSize)
}
b.ResizeSplit(DockRight, 15)
if b.EastSize != 15 {
t.Fatalf("resize east = %d", b.EastSize)
}
// Negative clamps to 0.
b.ResizeSplit(DockTop, -5)
if b.NorthSize != 0 {
t.Fatalf("negative clamp = %d", b.NorthSize)
}
// Over-extent clamps to the axis size: height for N/S, width for E/W.
b.ResizeSplit(DockBottom, 9999)
if b.SouthSize != 60 {
t.Fatalf("vertical over-clamp = %d, want 60", b.SouthSize)
}
b.ResizeSplit(DockRight, 9999)
if b.EastSize != 100 {
t.Fatalf("horizontal over-clamp = %d, want 100", b.EastSize)
}
// nil OnResize must not panic.
b.OnResize = nil
b.ResizeSplit(DockLeft, 5)
}
// TestBorderSplitDraw paints a split border (exercises the handle-fill loop).
func TestBorderSplitDraw(t *testing.T) {
b := NewBorder()
b.West, b.WestSize, b.WestSplit = &dockProbe{}, 10, true
b.Center = &dockProbe{}
b.SetBounds(Rect{X: 0, Y: 0, W: 40, H: 20})
buf := makeSurface(40, 20)
b.Draw(newP(buf, 40), DefaultLight())
// The handle column (X 10..16) is painted with the distinct splitter tone;
// check an interior fill point (12,3) away from the centre grip + edges.
th := DefaultLight()
want := blendRGBA(th.SurfaceAlt, th.Border, 0.45)
if px := pixelAt(buf, 40, 12, 3); px != want {
t.Fatalf("handle fill = %+v want splitter tone %+v", px, want)
}
// Left long edge is the Border delineator.
if px := pixelAt(buf, 40, 10, 3); px != th.Border {
t.Fatalf("handle left edge = %+v want Border", px)
}
}