Browse Source

Some housekeeping.

tablepad
Oliver 4 years ago
parent
commit
c2f07f9548
  1. 19
      application.go
  2. 2
      demos/button/main.go
  3. 2
      demos/checkbox/main.go
  4. 2
      demos/dropdown/main.go
  5. 2
      demos/flex/main.go
  6. 2
      demos/form/main.go
  7. 2
      demos/frame/main.go
  8. 2
      demos/grid/main.go
  9. 2
      demos/inputfield/main.go
  10. 2
      demos/list/main.go
  11. 2
      demos/modal/main.go
  12. 2
      demos/pages/main.go
  13. 2
      demos/presentation/main.go
  14. 2
      demos/table/main.go
  15. 2
      demos/textview/main.go
  16. 2
      demos/unicode/main.go

19
application.go

@ -24,7 +24,7 @@ type Application struct { @@ -24,7 +24,7 @@ type Application struct {
root Primitive
// Whether or not the application resizes the root primitive.
rootAutoSize bool
rootFullscreen bool
// An optional capture function which receives a key event and returns the
// event to be forwarded to the default input handler (nil if nothing should
@ -136,10 +136,6 @@ func (a *Application) Run() error { @@ -136,10 +136,6 @@ func (a *Application) Run() error {
case *tcell.EventResize:
a.Lock()
screen := a.screen
if a.rootAutoSize && a.root != nil {
width, height := screen.Size()
a.root.SetRect(0, 0, width, height)
}
a.Unlock()
screen.Clear()
a.Draw()
@ -166,7 +162,7 @@ func (a *Application) Draw() *Application { @@ -166,7 +162,7 @@ func (a *Application) Draw() *Application {
a.RLock()
screen := a.screen
root := a.root
fullscreen := a.rootAutoSize
fullscreen := a.rootFullscreen
before := a.beforeDraw
after := a.afterDraw
a.RUnlock()
@ -227,14 +223,17 @@ func (a *Application) SetAfterDrawFunc(handler func(screen tcell.Screen)) *Appli @@ -227,14 +223,17 @@ func (a *Application) SetAfterDrawFunc(handler func(screen tcell.Screen)) *Appli
return a
}
// SetRoot sets the root primitive for this application. This function must be
// called or nothing will be displayed when the application starts.
// SetRoot sets the root primitive for this application. If "fullscreen" is set
// to true, the root primitive's position will be changed to fill the screen.
//
// This function must be called at least once or nothing will be displayed when
// the application starts.
//
// It also calls SetFocus() on the primitive.
func (a *Application) SetRoot(root Primitive, autoSize bool) *Application {
func (a *Application) SetRoot(root Primitive, fullscreen bool) *Application {
a.Lock()
a.root = root
a.rootAutoSize = autoSize
a.rootFullscreen = fullscreen
if a.screen != nil {
a.screen.Clear()
}

2
demos/button/main.go

@ -9,7 +9,7 @@ func main() { @@ -9,7 +9,7 @@ func main() {
app.Stop()
})
button.SetBorder(true).SetRect(0, 0, 22, 3)
if err := app.SetRoot(button, false).SetFocus(button).Run(); err != nil {
if err := app.SetRoot(button, false).Run(); err != nil {
panic(err)
}
}

2
demos/checkbox/main.go

@ -6,7 +6,7 @@ import "github.com/rivo/tview" @@ -6,7 +6,7 @@ import "github.com/rivo/tview"
func main() {
app := tview.NewApplication()
checkbox := tview.NewCheckbox().SetLabel("Hit Enter to check box: ")
if err := app.SetRoot(checkbox, true).SetFocus(checkbox).Run(); err != nil {
if err := app.SetRoot(checkbox, true).Run(); err != nil {
panic(err)
}
}

2
demos/dropdown/main.go

@ -8,7 +8,7 @@ func main() { @@ -8,7 +8,7 @@ func main() {
dropdown := tview.NewDropDown().
SetLabel("Select an option (hit Enter): ").
SetOptions([]string{"First", "Second", "Third", "Fourth", "Fifth"}, nil)
if err := app.SetRoot(dropdown, true).SetFocus(dropdown).Run(); err != nil {
if err := app.SetRoot(dropdown, true).Run(); err != nil {
panic(err)
}
}

2
demos/flex/main.go

@ -14,7 +14,7 @@ func main() { @@ -14,7 +14,7 @@ func main() {
AddItem(tview.NewBox().SetBorder(true).SetTitle("Middle (3 x height of Top)"), 0, 3, false).
AddItem(tview.NewBox().SetBorder(true).SetTitle("Bottom (5 rows)"), 5, 1, false), 0, 2, false).
AddItem(tview.NewBox().SetBorder(true).SetTitle("Right (20 cols)"), 20, 1, false)
if err := app.SetRoot(flex, true).SetFocus(flex).Run(); err != nil {
if err := app.SetRoot(flex, true).Run(); err != nil {
panic(err)
}
}

2
demos/form/main.go

@ -18,7 +18,7 @@ func main() { @@ -18,7 +18,7 @@ func main() {
app.Stop()
})
form.SetBorder(true).SetTitle("Enter some data").SetTitleAlign(tview.AlignLeft)
if err := app.SetRoot(form, true).SetFocus(form).Run(); err != nil {
if err := app.SetRoot(form, true).Run(); err != nil {
panic(err)
}
}

2
demos/frame/main.go

@ -16,7 +16,7 @@ func main() { @@ -16,7 +16,7 @@ func main() {
AddText("Header second middle", true, tview.AlignCenter, tcell.ColorRed).
AddText("Footer middle", false, tview.AlignCenter, tcell.ColorGreen).
AddText("Footer second middle", false, tview.AlignCenter, tcell.ColorGreen)
if err := app.SetRoot(frame, true).SetFocus(frame).Run(); err != nil {
if err := app.SetRoot(frame, true).Run(); err != nil {
panic(err)
}
}

2
demos/grid/main.go

@ -31,7 +31,7 @@ func main() { @@ -31,7 +31,7 @@ func main() {
AddItem(main, 1, 1, 1, 1, 0, 100, false).
AddItem(sideBar, 1, 2, 1, 1, 0, 100, false)
if err := tview.NewApplication().SetRoot(grid, true).SetFocus(grid).Run(); err != nil {
if err := tview.NewApplication().SetRoot(grid, true).Run(); err != nil {
panic(err)
}
}

2
demos/inputfield/main.go

@ -15,7 +15,7 @@ func main() { @@ -15,7 +15,7 @@ func main() {
SetDoneFunc(func(key tcell.Key) {
app.Stop()
})
if err := app.SetRoot(inputField, true).SetFocus(inputField).Run(); err != nil {
if err := app.SetRoot(inputField, true).Run(); err != nil {
panic(err)
}
}

2
demos/list/main.go

@ -15,7 +15,7 @@ func main() { @@ -15,7 +15,7 @@ func main() {
AddItem("Quit", "Press to exit", 'q', func() {
app.Stop()
})
if err := app.SetRoot(list, true).SetFocus(list).Run(); err != nil {
if err := app.SetRoot(list, true).Run(); err != nil {
panic(err)
}
}

2
demos/modal/main.go

@ -15,7 +15,7 @@ func main() { @@ -15,7 +15,7 @@ func main() {
app.Stop()
}
})
if err := app.SetRoot(modal, false).SetFocus(modal).Run(); err != nil {
if err := app.SetRoot(modal, false).Run(); err != nil {
panic(err)
}
}

2
demos/pages/main.go

@ -29,7 +29,7 @@ func main() { @@ -29,7 +29,7 @@ func main() {
page == 0)
}(page)
}
if err := app.SetRoot(pages, true).SetFocus(pages).Run(); err != nil {
if err := app.SetRoot(pages, true).Run(); err != nil {
panic(err)
}
}

2
demos/presentation/main.go

@ -89,7 +89,7 @@ func main() { @@ -89,7 +89,7 @@ func main() {
})
// Start the application.
if err := app.SetRoot(layout, true).SetFocus(layout).Run(); err != nil {
if err := app.SetRoot(layout, true).Run(); err != nil {
panic(err)
}
}

2
demos/table/main.go

@ -39,7 +39,7 @@ func main() { @@ -39,7 +39,7 @@ func main() {
table.GetCell(row, column).SetTextColor(tcell.ColorRed)
table.SetSelectable(false, false)
})
if err := app.SetRoot(table, true).SetFocus(table).Run(); err != nil {
if err := app.SetRoot(table, true).Run(); err != nil {
panic(err)
}
}

2
demos/textview/main.go

@ -63,7 +63,7 @@ func main() { @@ -63,7 +63,7 @@ func main() {
}
})
textView.SetBorder(true)
if err := app.SetRoot(textView, true).SetFocus(textView).Run(); err != nil {
if err := app.SetRoot(textView, true).Run(); err != nil {
panic(err)
}
}

2
demos/unicode/main.go

@ -28,7 +28,7 @@ func main() { @@ -28,7 +28,7 @@ func main() {
form.SetBorder(true).SetTitle("输入一些内容").SetTitleAlign(tview.AlignLeft)
pages.AddPage("base", form, true, true)
if err := app.SetRoot(pages, true).SetFocus(pages).Run(); err != nil {
if err := app.SetRoot(pages, true).Run(); err != nil {
panic(err)
}
}

Loading…
Cancel
Save