-
Notifications
You must be signed in to change notification settings - Fork 1
/
documentComponent.go
36 lines (31 loc) · 970 Bytes
/
documentComponent.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
package pdf
import (
vit "github.com/omniskop/vitrum/vit"
)
func (d *DocumentComponent) recalculateLayout() {
var x, y float64
width, height := pageSize(PageComponent_Format(d.format.Int()), PageComponent_Orientation(d.orientation.Int()))
for _, child := range d.Children() {
var localW, localH float64 = width, height
layout := d.childLayouts[child]
if w, ok := layout.GetTargetWidth(); ok && w != 0 {
localW = w
}
if h, ok := layout.GetTargetHeight(); ok && h != 0 {
localH = h
}
d.childLayouts[child].SetPosition(&x, &y)
d.childLayouts[child].SetSize(&localW, &localH)
}
}
func (d *DocumentComponent) createNewChildLayout(child vit.Component) *vit.Layout {
l := vit.NewLayout()
d.childLayouts[child] = l
l.SetTargetSize(nil, nil)
l.AddDependent(vit.FuncDep(d.recalculateLayout))
return l
}
func (d *DocumentComponent) childWasAdded(child vit.Component) {
child.ApplyLayout(d.createNewChildLayout(child))
d.recalculateLayout()
}