filllayout.go 886 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. // FillLayout is the simple layout where the assigned panel "fills" its parent in the specified dimension(s)
  6. type FillLayout struct {
  7. width bool
  8. height bool
  9. }
  10. // NewFillLayout creates and returns a pointer of a new fill layout
  11. func NewFillLayout(width, height bool) *FillLayout {
  12. f := new(FillLayout)
  13. f.width = width
  14. f.height = height
  15. return f
  16. }
  17. // Recalc is called by the panel which has this layout
  18. func (f *FillLayout) Recalc(ipan IPanel) {
  19. parent := ipan.GetPanel()
  20. children := parent.Children()
  21. if len(children) == 0 {
  22. return
  23. }
  24. child := children[0].(IPanel).GetPanel()
  25. if f.width {
  26. child.SetWidth(parent.ContentWidth())
  27. }
  28. if f.height {
  29. child.SetHeight(parent.ContentHeight())
  30. }
  31. }