Rename TabbedContainer to Notebook
This commit is contained in:
		
							parent
							
								
									38434db75c
								
							
						
					
					
						commit
						8b80520f8c
					
				@ -4,10 +4,10 @@ import "git.tebibyte.media/tomo/tomo"
 | 
			
		||||
import "git.tebibyte.media/tomo/tomo/input"
 | 
			
		||||
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
 | 
			
		||||
// click the tab bar at the top to choose which one is activated.
 | 
			
		||||
// Notebook holds multiple objects, each in their own tab. The user can click
 | 
			
		||||
// the tab bar at the top to choose which one is activated.
 | 
			
		||||
//
 | 
			
		||||
// Sub-components:
 | 
			
		||||
//   - 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:
 | 
			
		||||
//   - [active] The tab is currently active and its contents are visible.
 | 
			
		||||
type TabbedContainer struct {
 | 
			
		||||
type Notebook struct {
 | 
			
		||||
	box tomo.ContainerBox
 | 
			
		||||
	
 | 
			
		||||
	leftSpacer  tomo.Box
 | 
			
		||||
@ -31,37 +31,37 @@ type TabbedContainer struct {
 | 
			
		||||
	tabs []*tab
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NewTabbedContainer creates a new tabbed container.
 | 
			
		||||
func NewTabbedContainer () *TabbedContainer {
 | 
			
		||||
	tabbedContainer := &TabbedContainer {
 | 
			
		||||
// NewNotebook creates a new tabbed notebook.
 | 
			
		||||
func NewNotebook () *Notebook {
 | 
			
		||||
	Notebook := &Notebook {
 | 
			
		||||
		box: tomo.NewContainerBox(),
 | 
			
		||||
	}
 | 
			
		||||
	tabbedContainer.box.SetRole(tomo.R("objects", "TabbedContainer"))
 | 
			
		||||
	tabbedContainer.box.SetAttr(tomo.ALayout(layouts.Column { false, true }))
 | 
			
		||||
	Notebook.box.SetRole(tomo.R("objects", "Notebook"))
 | 
			
		||||
	Notebook.box.SetAttr(tomo.ALayout(layouts.Column { false, true }))
 | 
			
		||||
	
 | 
			
		||||
	tabbedContainer.tabsRow = tomo.NewContainerBox()
 | 
			
		||||
	tabbedContainer.tabsRow.SetRole(tomo.R("objects", "TabRow"))
 | 
			
		||||
	tabbedContainer.box.Add(tabbedContainer.tabsRow)
 | 
			
		||||
	Notebook.tabsRow = tomo.NewContainerBox()
 | 
			
		||||
	Notebook.tabsRow.SetRole(tomo.R("objects", "TabRow"))
 | 
			
		||||
	Notebook.box.Add(Notebook.tabsRow)
 | 
			
		||||
	
 | 
			
		||||
	tabbedContainer.leftSpacer = tomo.NewBox()
 | 
			
		||||
	tabbedContainer.leftSpacer.SetRole(tomo.R("objects", "TabSpacer"))
 | 
			
		||||
	tabbedContainer.leftSpacer.SetTag("left", true)
 | 
			
		||||
	tabbedContainer.rightSpacer = tomo.NewBox()
 | 
			
		||||
	tabbedContainer.rightSpacer.SetRole(tomo.R("objects", "TabSpacer"))
 | 
			
		||||
	tabbedContainer.rightSpacer.SetTag("right", true)
 | 
			
		||||
	Notebook.leftSpacer = tomo.NewBox()
 | 
			
		||||
	Notebook.leftSpacer.SetRole(tomo.R("objects", "TabSpacer"))
 | 
			
		||||
	Notebook.leftSpacer.SetTag("left", true)
 | 
			
		||||
	Notebook.rightSpacer = tomo.NewBox()
 | 
			
		||||
	Notebook.rightSpacer.SetRole(tomo.R("objects", "TabSpacer"))
 | 
			
		||||
	Notebook.rightSpacer.SetTag("right", true)
 | 
			
		||||
	
 | 
			
		||||
	tabbedContainer.ClearTabs()
 | 
			
		||||
	tabbedContainer.setTabRowLayout()
 | 
			
		||||
	return tabbedContainer
 | 
			
		||||
	Notebook.ClearTabs()
 | 
			
		||||
	Notebook.setTabRowLayout()
 | 
			
		||||
	return Notebook
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetBox returns the underlying box.
 | 
			
		||||
func (this *TabbedContainer) GetBox () tomo.Box {
 | 
			
		||||
func (this *Notebook) GetBox () tomo.Box {
 | 
			
		||||
	return this.box
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 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 {
 | 
			
		||||
		tab.setActive(false)
 | 
			
		||||
		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.
 | 
			
		||||
func (this *TabbedContainer) AddTab (name string, root tomo.Object) {
 | 
			
		||||
func (this *Notebook) AddTab (name string, root tomo.Object) {
 | 
			
		||||
	tab := &tab {
 | 
			
		||||
		TextBox: tomo.NewTextBox(),
 | 
			
		||||
		name:    name,
 | 
			
		||||
@ -105,7 +105,7 @@ func (this *TabbedContainer) AddTab (name string, root tomo.Object) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// RemoveTab removes the named tab.
 | 
			
		||||
func (this *TabbedContainer) RemoveTab (name string) {
 | 
			
		||||
func (this *Notebook) RemoveTab (name string) {
 | 
			
		||||
	index, tab := this.findTab(name)
 | 
			
		||||
	if index < 0 { return }
 | 
			
		||||
	nextIndex := index - 1
 | 
			
		||||
@ -124,20 +124,20 @@ func (this *TabbedContainer) RemoveTab (name string) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ClearTabs removes all tabs.
 | 
			
		||||
func (this *TabbedContainer) ClearTabs () {
 | 
			
		||||
func (this *Notebook) ClearTabs () {
 | 
			
		||||
	this.tabs = nil
 | 
			
		||||
	this.tabsRow.Clear()
 | 
			
		||||
	this.tabsRow.Add(this.leftSpacer)
 | 
			
		||||
	this.tabsRow.Add(this.rightSpacer)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *TabbedContainer) setTabRowLayout () {
 | 
			
		||||
func (this *Notebook) setTabRowLayout () {
 | 
			
		||||
	row := make(layouts.Row, 1 + len(this.tabs) + 1)
 | 
			
		||||
	row[len(row) - 1] = true
 | 
			
		||||
	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 {
 | 
			
		||||
		if tab.name == name { return index, tab }
 | 
			
		||||
	}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user