2016-10-13 14:16:05 -07:00
|
|
|
package main
|
2015-12-15 17:19:04 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
ui "github.com/VladimirMarkelov/clui"
|
|
|
|
)
|
|
|
|
|
2016-10-13 14:16:05 -07:00
|
|
|
func createView() *ui.TableView {
|
2015-12-15 17:19:04 -08:00
|
|
|
|
2016-10-13 14:16:05 -07:00
|
|
|
view := ui.AddWindow(0, 0, 10, 7, "TableView Demo")
|
|
|
|
bch := ui.CreateTableView(view, 25, 12, 1)
|
|
|
|
ui.ActivateControl(view, bch)
|
2015-12-15 17:19:04 -08:00
|
|
|
|
|
|
|
return bch
|
|
|
|
}
|
|
|
|
|
|
|
|
func mainLoop() {
|
|
|
|
// Every application must create a single Composer and
|
|
|
|
// call its intialize method
|
2016-10-13 14:16:05 -07:00
|
|
|
ui.InitLibrary()
|
|
|
|
defer ui.DeinitLibrary()
|
2015-12-15 17:19:04 -08:00
|
|
|
|
2016-10-13 14:16:05 -07:00
|
|
|
b := createView()
|
2015-12-15 17:19:04 -08:00
|
|
|
b.SetShowLines(true)
|
|
|
|
b.SetShowRowNumber(true)
|
2015-12-21 15:07:45 -08:00
|
|
|
b.SetRowCount(15)
|
2015-12-15 17:19:04 -08:00
|
|
|
cols := []ui.Column{
|
|
|
|
ui.Column{Title: "Text", Width: 5, Alignment: ui.AlignLeft},
|
|
|
|
ui.Column{Title: "Number", Width: 10, Alignment: ui.AlignRight},
|
2015-12-21 15:07:45 -08:00
|
|
|
ui.Column{Title: "Misc", Width: 12, Alignment: ui.AlignCenter},
|
|
|
|
ui.Column{Title: "Long", Width: 50, Alignment: ui.AlignLeft},
|
|
|
|
ui.Column{Title: "Last", Width: 8, Alignment: ui.AlignLeft},
|
2015-12-15 17:19:04 -08:00
|
|
|
}
|
|
|
|
b.SetColumns(cols)
|
|
|
|
b.OnDrawCell(func(info *ui.ColumnDrawInfo) {
|
|
|
|
info.Text = fmt.Sprintf("%v:%v", info.Row, info.Col)
|
|
|
|
})
|
|
|
|
|
2017-09-07 15:32:25 -07:00
|
|
|
b.OnAction(func(ev ui.TableEvent) {
|
|
|
|
btns := []string{"Close", "Dismiss"}
|
|
|
|
var action string
|
|
|
|
switch ev.Action {
|
|
|
|
case ui.TableActionSort:
|
|
|
|
action = "Sort table"
|
|
|
|
case ui.TableActionEdit:
|
|
|
|
action = "Edit row/cell"
|
|
|
|
case ui.TableActionNew:
|
|
|
|
action = "Add new row"
|
|
|
|
case ui.TableActionDelete:
|
|
|
|
action = "Delete row"
|
|
|
|
default:
|
|
|
|
action = "Unknown action"
|
|
|
|
}
|
|
|
|
|
|
|
|
dlg := ui.CreateConfirmationDialog(
|
|
|
|
"<c:blue>"+action,
|
|
|
|
"Click any button or press <c:yellow>SPACE<c:> to close the dialog",
|
|
|
|
btns, ui.DialogButton1)
|
|
|
|
dlg.OnClose(func() {})
|
|
|
|
})
|
|
|
|
|
2015-12-15 17:19:04 -08:00
|
|
|
// start event processing loop - the main core of the library
|
2016-10-13 14:16:05 -07:00
|
|
|
ui.MainLoop()
|
2015-12-15 17:19:04 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
mainLoop()
|
|
|
|
}
|