diff --git a/box.go b/box.go index a67a545..07f868f 100644 --- a/box.go +++ b/box.go @@ -500,8 +500,3 @@ func (b *Box) GetFocusable() Focusable { return b.focus } - -// GetChildren returns nil because Box doesn't have any use for children. -func (b *Box) GetChildren() []Primitive { - return nil -} diff --git a/demos/presentation/colors.go b/demos/presentation/colors.go index 7e5b97b..486b5ac 100644 --- a/demos/presentation/colors.go +++ b/demos/presentation/colors.go @@ -1,33 +1,33 @@ package main import ( - "strings" - "github.com/gdamore/tcell" "gitlab.com/tslocum/cview" ) -const colorsText = `You can use color tags almost everywhere to partially change the color of a string. Simply put a color name or hex string in square brackets to change the following characters' color. H[green]er[white]e i[yellow]s a[darkcyan]n ex[red]amp[white]le. The [black:red]tags [black:green]look [black:yellow]like [::u]this: [blue:yellow:u[] [#00ff00[]` +const colorsText = `You can use color tags almost everywhere to partially change the color of a string. + +Simply put a color name or hex string in square brackets to change the following characters' color. + +H[green]er[white]e i[yellow]s a[darkcyan]n ex[red]amp[white]le. + +The [black:red]tags [black:green]look [black:yellow]like [::u]this: + +[cyan[] +[blue:yellow:u[] +[#00ff00[]` // Colors demonstrates how to use colors. func Colors(nextSlide func()) (title string, content cview.Primitive) { - table := cview.NewTable(). - SetBorders(true). - SetBordersColor(tcell.ColorBlue). + tv := cview.NewTextView(). + SetWordWrap(true). + SetDynamicColors(true). + SetText(colorsText). SetDoneFunc(func(key tcell.Key) { nextSlide() }) - var row, column int - for _, word := range strings.Split(colorsText, " ") { - table.SetCellSimple(row, column, word) - column++ - if column > 6 { - column = 0 - row++ - } - } - table.SetBorderPadding(1, 1, 2, 2). + tv. SetBorder(true). SetTitle("A [red]c[yellow]o[green]l[darkcyan]o[blue]r[darkmagenta]f[red]u[yellow]l[white] [black:red]c[:yellow]o[:green]l[:darkcyan]o[:blue]r[:darkmagenta]f[:red]u[:yellow]l[white:] [::bu]title") - return "Colors", Center(78, 19, table) + return "Colors", Center(44, 16, tv) } diff --git a/demos/presentation/helloworld.go b/demos/presentation/helloworld.go deleted file mode 100644 index 27e6c64..0000000 --- a/demos/presentation/helloworld.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "github.com/gdamore/tcell" - "gitlab.com/tslocum/cview" -) - -const helloWorld = `[green]package[white] main - -[green]import[white] ( - [red]"gitlab.com/tslocum/cview"[white] -) - -[green]func[white] [yellow]main[white]() { - box := cview.[yellow]NewBox[white](). - [yellow]SetBorder[white](true). - [yellow]SetTitle[white]([red]"Hello, world!"[white]) - cview.[yellow]NewApplication[white](). - [yellow]SetRoot[white](box, true). - [yellow]Run[white]() -}` - -// HelloWorld shows a simple "Hello world" example. -func HelloWorld(nextSlide func()) (title string, content cview.Primitive) { - // We use a text view because we want to capture keyboard input. - textView := cview.NewTextView().SetDoneFunc(func(key tcell.Key) { - nextSlide() - }) - textView.SetBorder(true).SetTitle("Hello, world!") - return "Hello, world", Code(textView, 30, 10, helloWorld) -} diff --git a/demos/presentation/main.go b/demos/presentation/main.go index 52443fb..e441fc3 100644 --- a/demos/presentation/main.go +++ b/demos/presentation/main.go @@ -48,17 +48,15 @@ func main() { slides := []Slide{ Cover, Introduction, - HelloWorld, - InputField, - Form, + Colors, TextView1, TextView2, - ProgressBar, + InputField, + Form, Table, TreeView, Flex, Grid, - Colors, End, } @@ -71,12 +69,6 @@ func main() { SetRegions(true). SetWrap(false). SetHighlightedFunc(func(added, removed, remaining []string) { - n, err := strconv.Atoi(added[0]) - if err == nil && n >= 1000 { - info.Highlight(strconv.Itoa((n - 1) / 1000)) - return - } - pages.SwitchToPage(added[0]) }) @@ -101,7 +93,7 @@ func main() { title, primitive := slide(nextSlide) pages.AddPage(strconv.Itoa(index), primitive, true, index == 0) - fmt.Fprintf(info, `["%d"]%d [""]["%d"][darkcyan]%s[white][""] `, (index+1)*1000, index+1, index, title) + fmt.Fprintf(info, `["%d"][darkcyan] %s [white][""]|`, index, title) cursor += len(title) + 4 } diff --git a/demos/presentation/progressbar.go b/demos/presentation/progressbar.go deleted file mode 100644 index a3b4bb5..0000000 --- a/demos/presentation/progressbar.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "time" - - "gitlab.com/tslocum/cview" -) - -// ProgressBar demonstrates the ProgressBar. -func ProgressBar(nextSlide func()) (title string, content cview.Primitive) { - grid := cview.NewGrid().SetColumns(-1, 6, 4, 30, -1).SetRows(-1, 12, 4, 4, -1) - grid.SetBackgroundColor(cview.Styles.PrimitiveBackgroundColor) - - verticalProgressBar := cview.NewProgressBar() - verticalProgressBar.SetBorder(true) - verticalProgressBar.SetVertical(true) - - horizontalProgressBar := cview.NewProgressBar() - horizontalProgressBar.SetBorder(true) - horizontalProgressBar.SetMax(150) - - padding := cview.NewTextView() - grid.AddItem(padding, 0, 0, 1, 5, 0, 0, false) - grid.AddItem(padding, 1, 0, 1, 1, 0, 0, false) - grid.AddItem(verticalProgressBar, 1, 1, 2, 1, 0, 0, false) - grid.AddItem(padding, 1, 2, 1, 1, 0, 0, false) - grid.AddItem(padding, 2, 0, 1, 5, 0, 0, false) - grid.AddItem(horizontalProgressBar, 3, 3, 1, 1, 0, 0, false) - grid.AddItem(padding, 1, 4, 1, 1, 0, 0, false) - grid.AddItem(padding, 4, 0, 1, 5, 0, 0, false) - - go func() { - t := time.NewTicker(100 * time.Millisecond) - for range t.C { - if verticalProgressBar.Complete() { - verticalProgressBar.SetProgress(0) - } else { - verticalProgressBar.AddProgress(1) - } - - if horizontalProgressBar.Complete() { - horizontalProgressBar.SetProgress(0) - } else { - horizontalProgressBar.AddProgress(1) - } - - // Queue draw - app.QueueUpdateDraw(func() {}) - } - }() - - return "ProgressBar", grid -}