forked from g3n/engine
/
filllayout.go
38 lines (31 loc) · 886 Bytes
/
filllayout.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
// Copyright 2016 The G3N Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package gui
// FillLayout is the simple layout where the assigned panel "fills" its parent in the specified dimension(s)
type FillLayout struct {
width bool
height bool
}
// NewFillLayout creates and returns a pointer of a new fill layout
func NewFillLayout(width, height bool) *FillLayout {
f := new(FillLayout)
f.width = width
f.height = height
return f
}
// Recalc is called by the panel which has this layout
func (f *FillLayout) Recalc(ipan IPanel) {
parent := ipan.GetPanel()
children := parent.Children()
if len(children) == 0 {
return
}
child := children[0].(IPanel).GetPanel()
if f.width {
child.SetWidth(parent.ContentWidth())
}
if f.height {
child.SetHeight(parent.ContentHeight())
}
}