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

@ -288,11 +288,13 @@ func main() {
}}, &ui.ItemEntry{Name: "Focus Right", QuickChar: -1, Shortcut: "Alt+Right", Callback: func() { }}, &ui.ItemEntry{Name: "Focus Right", QuickChar: -1, Shortcut: "Alt+Right", Callback: func() {
}}, &ui.ItemSeparator{}, &ui.ItemEntry{Name: "Split Top", QuickChar: 6, 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() { }}, &ui.ItemEntry{Name: "Split Bottom", QuickChar: 6, Callback: func() {
panelContainer.SplitSelected(ui.SplitVertical, ui.NewTabContainer(&theme)) panelContainer.SplitSelected(ui.SplitVertical, ui.NewTabContainer(&theme))
}}, &ui.ItemEntry{Name: "Split Left", QuickChar: 6, Callback: func() { }}, &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() { }}, &ui.ItemEntry{Name: "Split Right", QuickChar: 6, Callback: func() {
panelContainer.SplitSelected(ui.SplitHorizontal, ui.NewTabContainer(&theme)) panelContainer.SplitSelected(ui.SplitHorizontal, ui.NewTabContainer(&theme))
}}, &ui.ItemSeparator{}, &ui.ItemEntry{Name: "Move", Shortcut: "Ctrl+M", Callback: func() { }}, &ui.ItemSeparator{}, &ui.ItemEntry{Name: "Move", Shortcut: "Ctrl+M", Callback: func() {

View File

@ -59,7 +59,6 @@ func (c *PanelContainer) DeleteSelected() Component {
(*p).Kind = PanelKindSingle (*p).Kind = PanelKindSingle
(*c.selected).SetFocused(false) // Unfocus item (*c.selected).SetFocused(false) // Unfocus item
(*c.selected) = nil // Tell garbage collector to come pick up selected (being safe)
c.selected = &p c.selected = &p
(*c.selected).UpdateSplits() (*c.selected).UpdateSplits()
(*c.selected).SetFocused(c.focused) (*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`. // SplitSelected splits the selected Panel with the given Component `item`.
// The type of split (vertical or horizontal) is determined with the `kind`. // The type of split (vertical or horizontal) is determined with the `kind`.
// If `item` is nil, the new Panel will be of kind empty. // If `item` is nil, the new Panel will be of kind empty.