Recalc (which satisfies the ILayout interface) recalculates the positions and sizes of the children panels.
(ipan IPanel)
| 30 | |
| 31 | // Recalc (which satisfies the ILayout interface) recalculates the positions and sizes of the children panels. |
| 32 | func (dl *DockLayout) Recalc(ipan IPanel) { |
| 33 | |
| 34 | pan := ipan.GetPanel() |
| 35 | width := pan.Width() |
| 36 | topY := float32(0) |
| 37 | bottomY := pan.Height() |
| 38 | leftX := float32(0) |
| 39 | rightX := width |
| 40 | |
| 41 | // Top and bottom first |
| 42 | for _, iobj := range pan.Children() { |
| 43 | child := iobj.(IPanel).GetPanel() |
| 44 | if child.layoutParams == nil { |
| 45 | continue |
| 46 | } |
| 47 | params := child.layoutParams.(*DockLayoutParams) |
| 48 | if params.Edge == DockTop { |
| 49 | child.SetPosition(0, topY) |
| 50 | topY += child.Height() |
| 51 | child.SetWidth(width) |
| 52 | continue |
| 53 | } |
| 54 | if params.Edge == DockBottom { |
| 55 | child.SetPosition(0, bottomY-child.Height()) |
| 56 | bottomY -= child.Height() |
| 57 | child.SetWidth(width) |
| 58 | continue |
| 59 | } |
| 60 | } |
| 61 | // Left and right |
| 62 | for _, iobj := range pan.Children() { |
| 63 | child := iobj.(IPanel).GetPanel() |
| 64 | if child.layoutParams == nil { |
| 65 | continue |
| 66 | } |
| 67 | params := child.layoutParams.(*DockLayoutParams) |
| 68 | if params.Edge == DockLeft { |
| 69 | child.SetPosition(leftX, topY) |
| 70 | leftX += child.Width() |
| 71 | child.SetHeight(bottomY - topY) |
| 72 | continue |
| 73 | } |
| 74 | if params.Edge == DockRight { |
| 75 | child.SetPosition(rightX-child.Width(), topY) |
| 76 | rightX -= child.Width() |
| 77 | child.SetHeight(bottomY - topY) |
| 78 | continue |
| 79 | } |
| 80 | } |
| 81 | // Center (only the first found) |
| 82 | for _, iobj := range pan.Children() { |
| 83 | child := iobj.(IPanel).GetPanel() |
| 84 | if child.layoutParams == nil { |
| 85 | continue |
| 86 | } |
| 87 | params := child.layoutParams.(*DockLayoutParams) |
| 88 | if params.Edge == DockCenter { |
| 89 | child.SetPosition(leftX, topY) |