allow editting the whole column start on a golang struct
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
701339dd7c
commit
a07d6f6898
31
table.go
31
table.go
|
@ -1,22 +1,34 @@
|
|||
// 26 august 2018
|
||||
|
||||
// +build OMIT
|
||||
// based off andlabs/ui/examples/table.go
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
import "log"
|
||||
import "github.com/andlabs/ui"
|
||||
|
||||
type vmRowData struct {
|
||||
hostname string
|
||||
size int
|
||||
IPv6 string
|
||||
IPv4 string
|
||||
memory int
|
||||
disk int
|
||||
}
|
||||
|
||||
type modelHandler struct {
|
||||
row9Text string
|
||||
row9Text string
|
||||
yellowRow int
|
||||
checkStates [15]int
|
||||
vms [15]vmRowData
|
||||
}
|
||||
|
||||
func newModelHandler() *modelHandler {
|
||||
m := new(modelHandler)
|
||||
m.row9Text = "You can edit this one"
|
||||
m.vms[8].hostname = "fire"
|
||||
m.vms[9].hostname = "librem15.this.is.a.really.long.string.test"
|
||||
m.yellowRow = -1
|
||||
log.Println("Called newModelhandler() with m=", m)
|
||||
return m
|
||||
}
|
||||
|
||||
|
@ -81,10 +93,7 @@ func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableVal
|
|||
}
|
||||
return nil
|
||||
case 2:
|
||||
if row == 9 {
|
||||
return ui.TableString(mh.row9Text)
|
||||
}
|
||||
return ui.TableString("Editing this won't change anything")
|
||||
return ui.TableString(mh.vms[row].hostname)
|
||||
case 6:
|
||||
return ui.TableString("Make Yellow")
|
||||
}
|
||||
|
@ -92,8 +101,8 @@ func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableVal
|
|||
}
|
||||
|
||||
func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
|
||||
if row == 9 && column == 2 {
|
||||
mh.row9Text = string(value.(ui.TableString))
|
||||
if column == 2 {
|
||||
mh.vms[row].hostname = string(value.(ui.TableString))
|
||||
}
|
||||
if column == 6 { // row background color
|
||||
prevYellowRow := mh.yellowRow
|
||||
|
@ -128,7 +137,7 @@ func maketable() *ui.Table {
|
|||
ColorModelColumn: 4,
|
||||
});
|
||||
|
||||
table.AppendTextColumn("Editable", 2, ui.TableModelColumnAlwaysEditable, nil)
|
||||
table.AppendTextColumn("hostname", 2, ui.TableModelColumnAlwaysEditable, nil)
|
||||
table.AppendCheckboxColumn("Checkboxes", 7, ui.TableModelColumnAlwaysEditable)
|
||||
table.AppendButtonColumn("Buttons", 6, ui.TableModelColumnAlwaysEditable)
|
||||
table.AppendProgressBarColumn("Progress Bar", 8)
|
||||
|
|
Loading…
Reference in New Issue