diff --git a/application.go b/application.go index 9a802f1..debe11c 100644 --- a/application.go +++ b/application.go @@ -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 { 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 { 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 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() } diff --git a/demos/button/main.go b/demos/button/main.go index 13710c4..429b5be 100644 --- a/demos/button/main.go +++ b/demos/button/main.go @@ -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) } } diff --git a/demos/checkbox/main.go b/demos/checkbox/main.go index f13c179..ef9ef8e 100644 --- a/demos/checkbox/main.go +++ b/demos/checkbox/main.go @@ -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) } } diff --git a/demos/dropdown/main.go b/demos/dropdown/main.go index 43bd75a..be9db66 100644 --- a/demos/dropdown/main.go +++ b/demos/dropdown/main.go @@ -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) } } diff --git a/demos/flex/main.go b/demos/flex/main.go index d2b7da6..1c22172 100644 --- a/demos/flex/main.go +++ b/demos/flex/main.go @@ -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) } } diff --git a/demos/form/main.go b/demos/form/main.go index ef24cdb..e64614f 100644 --- a/demos/form/main.go +++ b/demos/form/main.go @@ -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) } } diff --git a/demos/frame/main.go b/demos/frame/main.go index bc85976..9b03e64 100644 --- a/demos/frame/main.go +++ b/demos/frame/main.go @@ -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) } } diff --git a/demos/grid/main.go b/demos/grid/main.go index d8f6caa..0f4dbb5 100644 --- a/demos/grid/main.go +++ b/demos/grid/main.go @@ -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) } } diff --git a/demos/inputfield/main.go b/demos/inputfield/main.go index 60e3360..a9878cf 100644 --- a/demos/inputfield/main.go +++ b/demos/inputfield/main.go @@ -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) } } diff --git a/demos/list/main.go b/demos/list/main.go index 7188863..50cae17 100644 --- a/demos/list/main.go +++ b/demos/list/main.go @@ -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) } } diff --git a/demos/modal/main.go b/demos/modal/main.go index b3eafef..893230d 100644 --- a/demos/modal/main.go +++ b/demos/modal/main.go @@ -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) } } diff --git a/demos/pages/main.go b/demos/pages/main.go index d60fbdb..8eb67ab 100644 --- a/demos/pages/main.go +++ b/demos/pages/main.go @@ -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) } } diff --git a/demos/presentation/main.go b/demos/presentation/main.go index b142b06..dabea18 100644 --- a/demos/presentation/main.go +++ b/demos/presentation/main.go @@ -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) } } diff --git a/demos/table/main.go b/demos/table/main.go index 1ad5278..38cb0c1 100644 --- a/demos/table/main.go +++ b/demos/table/main.go @@ -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) } } diff --git a/demos/textview/main.go b/demos/textview/main.go index 4ba50a6..66cc45e 100644 --- a/demos/textview/main.go +++ b/demos/textview/main.go @@ -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) } } diff --git a/demos/unicode/main.go b/demos/unicode/main.go index ee2e3ea..761b100 100644 --- a/demos/unicode/main.go +++ b/demos/unicode/main.go @@ -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) } }