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
|
package tui
import "testing"
func TestElement_SetHeight_TriggersRelayout(t *testing.T) {
app := newTestApp(40, 24)
child := New(WithHeight(1), WithWidth(10))
root := New(WithDirection(Column))
root.AddChild(child)
app.SetRoot(root)
app.Render()
if got := child.Rect().Height; got != 1 {
t.Fatalf("initial child height = %d, want 1", got)
}
child.SetHeight(Fixed(8))
app.Render()
if got := child.Rect().Height; got != 8 {
t.Fatalf("child height after SetHeight = %d, want 8", got)
}
}
func TestElement_SetWidth_TriggersRelayout(t *testing.T) {
app := newTestApp(40, 24)
child := New(WithHeight(1), WithWidth(5))
root := New(WithDirection(Column))
root.AddChild(child)
app.SetRoot(root)
app.Render()
if got := child.Rect().Width; got != 5 {
t.Fatalf("initial child width = %d, want 5", got)
}
child.SetWidth(Fixed(20))
app.Render()
if got := child.Rect().Width; got != 20 {
t.Fatalf("child width after SetWidth = %d, want 20", got)
}
}
func TestElement_SetHeight_MarksDirty(t *testing.T) {
app := newTestApp(40, 24)
child := New(WithHeight(1))
root := New()
root.AddChild(child)
app.SetRoot(root)
app.Render()
if app.checkAndClearDirty() {
t.Fatal("app should be clean after render")
}
child.SetHeight(Fixed(4))
if !child.IsDirty() {
t.Fatal("child should be dirty after SetHeight")
}
if !app.checkAndClearDirty() {
t.Fatal("app should be dirty after SetHeight")
}
}
|