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
|
// based off andlabs/ui/examples/table.go
|
||||||
|
|
||||||
// +build OMIT
|
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "log"
|
||||||
import "github.com/andlabs/ui"
|
import "github.com/andlabs/ui"
|
||||||
|
|
||||||
|
type vmRowData struct {
|
||||||
|
hostname string
|
||||||
|
size int
|
||||||
|
IPv6 string
|
||||||
|
IPv4 string
|
||||||
|
memory int
|
||||||
|
disk int
|
||||||
|
}
|
||||||
|
|
||||||
type modelHandler struct {
|
type modelHandler struct {
|
||||||
row9Text string
|
row9Text string
|
||||||
yellowRow int
|
yellowRow int
|
||||||
checkStates [15]int
|
checkStates [15]int
|
||||||
|
vms [15]vmRowData
|
||||||
}
|
}
|
||||||
|
|
||||||
func newModelHandler() *modelHandler {
|
func newModelHandler() *modelHandler {
|
||||||
m := new(modelHandler)
|
m := new(modelHandler)
|
||||||
m.row9Text = "You can edit this one"
|
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
|
m.yellowRow = -1
|
||||||
|
log.Println("Called newModelhandler() with m=", m)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,10 +93,7 @@ func (mh *modelHandler) CellValue(m *ui.TableModel, row, column int) ui.TableVal
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
case 2:
|
case 2:
|
||||||
if row == 9 {
|
return ui.TableString(mh.vms[row].hostname)
|
||||||
return ui.TableString(mh.row9Text)
|
|
||||||
}
|
|
||||||
return ui.TableString("Editing this won't change anything")
|
|
||||||
case 6:
|
case 6:
|
||||||
return ui.TableString("Make Yellow")
|
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) {
|
func (mh *modelHandler) SetCellValue(m *ui.TableModel, row, column int, value ui.TableValue) {
|
||||||
if row == 9 && column == 2 {
|
if column == 2 {
|
||||||
mh.row9Text = string(value.(ui.TableString))
|
mh.vms[row].hostname = string(value.(ui.TableString))
|
||||||
}
|
}
|
||||||
if column == 6 { // row background color
|
if column == 6 { // row background color
|
||||||
prevYellowRow := mh.yellowRow
|
prevYellowRow := mh.yellowRow
|
||||||
|
@ -128,7 +137,7 @@ func maketable() *ui.Table {
|
||||||
ColorModelColumn: 4,
|
ColorModelColumn: 4,
|
||||||
});
|
});
|
||||||
|
|
||||||
table.AppendTextColumn("Editable", 2, ui.TableModelColumnAlwaysEditable, nil)
|
table.AppendTextColumn("hostname", 2, ui.TableModelColumnAlwaysEditable, nil)
|
||||||
table.AppendCheckboxColumn("Checkboxes", 7, ui.TableModelColumnAlwaysEditable)
|
table.AppendCheckboxColumn("Checkboxes", 7, ui.TableModelColumnAlwaysEditable)
|
||||||
table.AppendButtonColumn("Buttons", 6, ui.TableModelColumnAlwaysEditable)
|
table.AppendButtonColumn("Buttons", 6, ui.TableModelColumnAlwaysEditable)
|
||||||
table.AppendProgressBarColumn("Progress Bar", 8)
|
table.AppendProgressBarColumn("Progress Bar", 8)
|
||||||
|
|
Loading…
Reference in New Issue