Splitting Panels

This commit is contained in:
Luke I. Wilson 2021-04-05 17:15:57 -05:00
parent eb8142ea8e
commit cf5803c464
2 changed files with 9 additions and 2 deletions

View File

@ -290,11 +290,11 @@ func main() {
}}, &ui.ItemSeparator{}, &ui.ItemEntry{Name: "Split Top", QuickChar: 6, Callback: func() { }}, &ui.ItemSeparator{}, &ui.ItemEntry{Name: "Split Top", QuickChar: 6, Callback: func() {
}}, &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))
}}, &ui.ItemEntry{Name: "Split Left", QuickChar: 6, Callback: func() { }}, &ui.ItemEntry{Name: "Split Left", QuickChar: 6, Callback: func() {
}}, &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))
}}, &ui.ItemSeparator{}, &ui.ItemEntry{Name: "Move", Shortcut: "Ctrl+M", Callback: func() { }}, &ui.ItemSeparator{}, &ui.ItemEntry{Name: "Move", Shortcut: "Ctrl+M", Callback: func() {
}}, &ui.ItemEntry{Name: "Resize", Shortcut: "Ctrl+R", Callback: func() { }}, &ui.ItemEntry{Name: "Resize", Shortcut: "Ctrl+R", Callback: func() {

View File

@ -77,12 +77,19 @@ func (c *PanelContainer) SplitSelected(kind SplitKind, item Component) {
} }
// It should be asserted that whatever is selected is either PanelKindEmpty or PanelKindSingle // It should be asserted that whatever is selected is either PanelKindEmpty or PanelKindSingle
(**c.selected).Left = &Panel{Parent: *c.selected, Left: (**c.selected).Left, Kind: PanelKindSingle}
if item == nil { if item == nil {
(**c.selected).Right = &Panel{Parent: *c.selected, Kind: PanelKindEmpty} (**c.selected).Right = &Panel{Parent: *c.selected, Kind: PanelKindEmpty}
} else { } else {
(**c.selected).Right = &Panel{Parent: *c.selected, Left: item, Kind: PanelKindSingle} (**c.selected).Right = &Panel{Parent: *c.selected, Left: item, Kind: PanelKindSingle}
} }
(**c.selected).Kind = PanelKind(kind) (**c.selected).Kind = PanelKind(kind)
if kind == SplitVertical {
(**c.selected).SplitAt = (**c.selected).height / 2
} else {
(**c.selected).SplitAt = (**c.selected).width / 2
}
(*c.selected).UpdateSplits() (*c.selected).UpdateSplits()
(*c.selected).SetFocused(false) (*c.selected).SetFocused(false)
panel := (**c.selected).Left.(*Panel) // TODO: watch me... might be a bug lurking in a hidden copy here panel := (**c.selected).Left.(*Panel) // TODO: watch me... might be a bug lurking in a hidden copy here