filllayout.go 777 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Copyright 2016 The G3N Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package gui
  5. type FillLayout struct {
  6. width bool
  7. height bool
  8. }
  9. // NewFillLayout creates and returns a pointer of a new fill layout
  10. func NewFillLayout(width, height bool) *FillLayout {
  11. f := new(FillLayout)
  12. f.width = width
  13. f.height = height
  14. return f
  15. }
  16. // Recalc is called by the panel which has this layout
  17. func (f *FillLayout) Recalc(ipan IPanel) {
  18. parent := ipan.GetPanel()
  19. children := parent.Children()
  20. if len(children) == 0 {
  21. return
  22. }
  23. child := children[0].(IPanel).GetPanel()
  24. if f.width {
  25. child.SetWidth(parent.ContentWidth())
  26. }
  27. if f.height {
  28. child.SetHeight(parent.ContentHeight())
  29. }
  30. }