Rename TabbedContainer to Notebook

This commit is contained in:
Sasha Koshka 2024-09-12 15:08:03 -04:00
parent 38434db75c
commit 8b80520f8c

View File

@ -4,10 +4,10 @@ import "git.tebibyte.media/tomo/tomo"
import "git.tebibyte.media/tomo/tomo/input" import "git.tebibyte.media/tomo/tomo/input"
import "git.tebibyte.media/tomo/objects/layouts" import "git.tebibyte.media/tomo/objects/layouts"
var _ tomo.Object = new(TabbedContainer) var _ tomo.Object = new(Notebook)
// TabbedContainer holds multiple objects, each in their own tab. The user can // Notebook holds multiple objects, each in their own tab. The user can click
// click the tab bar at the top to choose which one is activated. // the tab bar at the top to choose which one is activated.
// //
// Sub-components: // Sub-components:
// - TabRow sits at the top of the container and contains a row of tabs. // - TabRow sits at the top of the container and contains a row of tabs.
@ -21,7 +21,7 @@ var _ tomo.Object = new(TabbedContainer)
// //
// Tab tags: // Tab tags:
// - [active] The tab is currently active and its contents are visible. // - [active] The tab is currently active and its contents are visible.
type TabbedContainer struct { type Notebook struct {
box tomo.ContainerBox box tomo.ContainerBox
leftSpacer tomo.Box leftSpacer tomo.Box
@ -31,37 +31,37 @@ type TabbedContainer struct {
tabs []*tab tabs []*tab
} }
// NewTabbedContainer creates a new tabbed container. // NewNotebook creates a new tabbed notebook.
func NewTabbedContainer () *TabbedContainer { func NewNotebook () *Notebook {
tabbedContainer := &TabbedContainer { Notebook := &Notebook {
box: tomo.NewContainerBox(), box: tomo.NewContainerBox(),
} }
tabbedContainer.box.SetRole(tomo.R("objects", "TabbedContainer")) Notebook.box.SetRole(tomo.R("objects", "Notebook"))
tabbedContainer.box.SetAttr(tomo.ALayout(layouts.Column { false, true })) Notebook.box.SetAttr(tomo.ALayout(layouts.Column { false, true }))
tabbedContainer.tabsRow = tomo.NewContainerBox() Notebook.tabsRow = tomo.NewContainerBox()
tabbedContainer.tabsRow.SetRole(tomo.R("objects", "TabRow")) Notebook.tabsRow.SetRole(tomo.R("objects", "TabRow"))
tabbedContainer.box.Add(tabbedContainer.tabsRow) Notebook.box.Add(Notebook.tabsRow)
tabbedContainer.leftSpacer = tomo.NewBox() Notebook.leftSpacer = tomo.NewBox()
tabbedContainer.leftSpacer.SetRole(tomo.R("objects", "TabSpacer")) Notebook.leftSpacer.SetRole(tomo.R("objects", "TabSpacer"))
tabbedContainer.leftSpacer.SetTag("left", true) Notebook.leftSpacer.SetTag("left", true)
tabbedContainer.rightSpacer = tomo.NewBox() Notebook.rightSpacer = tomo.NewBox()
tabbedContainer.rightSpacer.SetRole(tomo.R("objects", "TabSpacer")) Notebook.rightSpacer.SetRole(tomo.R("objects", "TabSpacer"))
tabbedContainer.rightSpacer.SetTag("right", true) Notebook.rightSpacer.SetTag("right", true)
tabbedContainer.ClearTabs() Notebook.ClearTabs()
tabbedContainer.setTabRowLayout() Notebook.setTabRowLayout()
return tabbedContainer return Notebook
} }
// GetBox returns the underlying box. // GetBox returns the underlying box.
func (this *TabbedContainer) GetBox () tomo.Box { func (this *Notebook) GetBox () tomo.Box {
return this.box return this.box
} }
// Activate switches to a named tab. // Activate switches to a named tab.
func (this *TabbedContainer) Activate (name string) { func (this *Notebook) Activate (name string) {
if _, tab := this.findTab(this.active); tab != nil { if _, tab := this.findTab(this.active); tab != nil {
tab.setActive(false) tab.setActive(false)
this.box.Remove(tab.root) this.box.Remove(tab.root)
@ -76,7 +76,7 @@ func (this *TabbedContainer) Activate (name string) {
} }
// AddTab adds an object as a tab with the specified name. // AddTab adds an object as a tab with the specified name.
func (this *TabbedContainer) AddTab (name string, root tomo.Object) { func (this *Notebook) AddTab (name string, root tomo.Object) {
tab := &tab { tab := &tab {
TextBox: tomo.NewTextBox(), TextBox: tomo.NewTextBox(),
name: name, name: name,
@ -105,7 +105,7 @@ func (this *TabbedContainer) AddTab (name string, root tomo.Object) {
} }
// RemoveTab removes the named tab. // RemoveTab removes the named tab.
func (this *TabbedContainer) RemoveTab (name string) { func (this *Notebook) RemoveTab (name string) {
index, tab := this.findTab(name) index, tab := this.findTab(name)
if index < 0 { return } if index < 0 { return }
nextIndex := index - 1 nextIndex := index - 1
@ -124,20 +124,20 @@ func (this *TabbedContainer) RemoveTab (name string) {
} }
// ClearTabs removes all tabs. // ClearTabs removes all tabs.
func (this *TabbedContainer) ClearTabs () { func (this *Notebook) ClearTabs () {
this.tabs = nil this.tabs = nil
this.tabsRow.Clear() this.tabsRow.Clear()
this.tabsRow.Add(this.leftSpacer) this.tabsRow.Add(this.leftSpacer)
this.tabsRow.Add(this.rightSpacer) this.tabsRow.Add(this.rightSpacer)
} }
func (this *TabbedContainer) setTabRowLayout () { func (this *Notebook) setTabRowLayout () {
row := make(layouts.Row, 1 + len(this.tabs) + 1) row := make(layouts.Row, 1 + len(this.tabs) + 1)
row[len(row) - 1] = true row[len(row) - 1] = true
this.tabsRow.SetAttr(tomo.ALayout(row)) this.tabsRow.SetAttr(tomo.ALayout(row))
} }
func (this *TabbedContainer) findTab (name string) (int, *tab) { func (this *Notebook) findTab (name string) (int, *tab) {
for index, tab := range this.tabs { for index, tab := range this.tabs {
if tab.name == name { return index, tab } if tab.name == name { return index, tab }
} }