PanelContainer: SwapNeighborsSelected() to split left and split top

This commit is contained in:
Luke I. Wilson
2021-04-05 17:31:16 -05:00
parent cf5803c464
commit 95e4db4d3e
2 changed files with 17 additions and 3 deletions

View File

@@ -59,7 +59,6 @@ func (c *PanelContainer) DeleteSelected() Component {
(*p).Kind = PanelKindSingle
(*c.selected).SetFocused(false) // Unfocus item
(*c.selected) = nil // Tell garbage collector to come pick up selected (being safe)
c.selected = &p
(*c.selected).UpdateSplits()
(*c.selected).SetFocused(c.focused)
@@ -68,6 +67,19 @@ func (c *PanelContainer) DeleteSelected() Component {
}
}
// SwapNeighborsSelected swaps two Left and Right child Panels of a vertical or
// horizontally split Panel. This is necessary to achieve a "split top" or
// "split left" effect, as Panels only split open to the bottom or right.
func (c *PanelContainer) SwapNeighborsSelected() {
parent := (**c.selected).Parent
if parent != nil {
left := (*parent).Left
(*parent).Left = parent.Right
(*parent).Right = left
parent.UpdateSplits() // Updates position and size of reordered children
}
}
// SplitSelected splits the selected Panel with the given Component `item`.
// The type of split (vertical or horizontal) is determined with the `kind`.
// If `item` is nil, the new Panel will be of kind empty.