-
Notifications
You must be signed in to change notification settings - Fork 1
/
baseline_func_test.go
55 lines (45 loc) · 1.75 KB
/
baseline_func_test.go
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
package flex
import "testing"
func baselineFunc(node *Node, width float32, height float32) float32 {
baseline := node.Context.(float32)
return baseline
}
func TestAlign_baseline_customer_func(t *testing.T) {
root := NewNode()
root.StyleSetFlexDirection(FlexDirectionRow)
root.StyleSetAlignItems(AlignBaseline)
root.StyleSetWidth(100)
root.StyleSetHeight(100)
rootChild0 := NewNode()
rootChild0.StyleSetWidth(50)
rootChild0.StyleSetHeight(50)
root.InsertChild(rootChild0, 0)
rootChild1 := NewNode()
rootChild1.StyleSetWidth(50)
rootChild1.StyleSetHeight(20)
root.InsertChild(rootChild1, 1)
var baselineValue float32 = 10
rootChild1child0 := NewNode()
rootChild1child0.Context = baselineValue
rootChild1child0.StyleSetWidth(50)
rootChild1child0.Baseline = baselineFunc
rootChild1child0.StyleSetHeight(20)
rootChild1.InsertChild(rootChild1child0, 0)
CalculateLayout(root, Undefined, Undefined, DirectionLTR)
assertFloatEqual(t, 0, root.LayoutGetLeft())
assertFloatEqual(t, 0, root.LayoutGetTop())
assertFloatEqual(t, 100, root.LayoutGetWidth())
assertFloatEqual(t, 100, root.LayoutGetHeight())
assertFloatEqual(t, 0, rootChild0.LayoutGetLeft())
assertFloatEqual(t, 0, rootChild0.LayoutGetTop())
assertFloatEqual(t, 50, rootChild0.LayoutGetWidth())
assertFloatEqual(t, 50, rootChild0.LayoutGetHeight())
assertFloatEqual(t, 50, rootChild1.LayoutGetLeft())
assertFloatEqual(t, 40, rootChild1.LayoutGetTop())
assertFloatEqual(t, 50, rootChild1.LayoutGetWidth())
assertFloatEqual(t, 20, rootChild1.LayoutGetHeight())
assertFloatEqual(t, 0, rootChild1child0.LayoutGetLeft())
assertFloatEqual(t, 0, rootChild1child0.LayoutGetTop())
assertFloatEqual(t, 50, rootChild1child0.LayoutGetWidth())
assertFloatEqual(t, 20, rootChild1child0.LayoutGetHeight())
}