From 95e4db4d3e284c00d13d390ecfeb8cd3edc5b77b Mon Sep 17 00:00:00 2001 From: "Luke I. Wilson" Date: Mon, 5 Apr 2021 17:31:16 -0500 Subject: [PATCH] PanelContainer: SwapNeighborsSelected() to split left and split top --- main.go | 6 ++++-- ui/panelcontainer.go | 14 +++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index c0c853e..f1ab7f8 100644 --- a/main.go +++ b/main.go @@ -288,11 +288,13 @@ func main() { }}, &ui.ItemEntry{Name: "Focus Right", QuickChar: -1, Shortcut: "Alt+Right", Callback: func() { }}, &ui.ItemSeparator{}, &ui.ItemEntry{Name: "Split Top", QuickChar: 6, Callback: func() { - + panelContainer.SplitSelected(ui.SplitVertical, ui.NewTabContainer(&theme)) + panelContainer.SwapNeighborsSelected() }}, &ui.ItemEntry{Name: "Split Bottom", QuickChar: 6, Callback: func() { panelContainer.SplitSelected(ui.SplitVertical, ui.NewTabContainer(&theme)) }}, &ui.ItemEntry{Name: "Split Left", QuickChar: 6, Callback: func() { - + panelContainer.SplitSelected(ui.SplitHorizontal, ui.NewTabContainer(&theme)) + panelContainer.SwapNeighborsSelected() }}, &ui.ItemEntry{Name: "Split Right", QuickChar: 6, Callback: func() { panelContainer.SplitSelected(ui.SplitHorizontal, ui.NewTabContainer(&theme)) }}, &ui.ItemSeparator{}, &ui.ItemEntry{Name: "Move", Shortcut: "Ctrl+M", Callback: func() { diff --git a/ui/panelcontainer.go b/ui/panelcontainer.go index 661dd86..ff96b34 100755 --- a/ui/panelcontainer.go +++ b/ui/panelcontainer.go @@ -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.