no longer crashes. seems stable. Can edit text fields

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-08 00:02:47 -07:00
parent 5dcbe40e76
commit f1a37e410c
3 changed files with 66 additions and 26 deletions

35
gui.go
View File

@ -1,7 +1,7 @@
package main
import "log"
import "fmt"
// import "fmt"
import "github.com/gookit/config"
import "github.com/andlabs/ui"
@ -13,9 +13,19 @@ var mainwin *ui.Window
var maintab *ui.Tab
var tabcount int
var jcarrButton *ui.Button
var jcarrEntry *ui.MultilineEntry
func buttonClick(button *ui.Button) {
log.Println("hostname =", config.String("hostname"), button)
spew.Dump(button)
if (jcarrButton == button) {
log.Println("This is the jcarrButton")
cur := jcarrEntry.Text()
jcarrEntry.SetText(cur + "THIS IS A GREAT IDEA\n")
} else {
log.Println("This is NOT the jcarrButton")
}
}
func hostnameButton(hostname string) ui.Control {
@ -26,27 +36,11 @@ func hostnameButton(hostname string) ui.Control {
tmpbox.Append(tmpButton, false)
tmpButton.OnClicked(buttonClick)
jcarrButton = tmpButton
return tmpbox
}
func makeButtonsPage(names []string) ui.Control {
vbox := ui.NewVerticalBox()
vbox.SetPadded(true)
hbox := ui.NewHorizontalBox()
hbox.SetPadded(true)
vbox.Append(hbox, false)
for _, hostname := range names {
fmt.Println("hostname=", hostname)
vbox.Append(hostnameButton(hostname), false)
}
vbox.Append(ui.NewHorizontalSeparator(), false)
return vbox
}
func makeGroupEntries() ui.Control {
group := ui.NewGroup("Entries")
group.SetMargined(true)
@ -57,10 +51,11 @@ func makeGroupEntries() ui.Control {
entryForm.SetPadded(true)
group.SetChild(entryForm)
jcarrEntry = ui.NewMultilineEntry()
entryForm.Append("Entry", ui.NewEntry(), false)
entryForm.Append("Password Entry", ui.NewPasswordEntry(), false)
entryForm.Append("Search Entry", ui.NewSearchEntry(), false)
entryForm.Append("Multiline Entry", ui.NewMultilineEntry(), true)
entryForm.Append("Multiline Entry", jcarrEntry, true)
entryForm.Append("Multiline Entry No Wrap", ui.NewNonWrappingMultilineEntry(), true)
return group

View File

@ -87,6 +87,8 @@ func main() {
hostname := config.String("cloud." + account + ".hostname")
fmt.Println(hostname, port, proto)
addTableTab(account, 4, hostname)
log.Println("Sleep for 30 seconds, then add next table")
time.Sleep(30 * 1000 * 1000 * 1000)
}
for {

View File

@ -4,6 +4,7 @@ package main
import "fmt"
import "log"
// import "os"
import "github.com/andlabs/ui"
import _ "github.com/andlabs/ui/winmanifest"
import "github.com/davecgh/go-spew/spew"
@ -17,6 +18,13 @@ type vmRowData struct {
disk int
}
type jwcTest struct {
part0 ui.TableColor // row background color
part1 ui.TableString // column 0 text
part2 ui.TableColor // column 0 text color
part3 ui.TableString // column 1 button text
}
type modelHandler struct {
name string
rows int
@ -24,12 +32,29 @@ type modelHandler struct {
yellowRow int
checkStates []int
vms []vmRowData
bgcolor []ui.TableColor
cellValues []jwcTest
columnTypes string
funcColumnTypes func() []ui.TableValue
scanCellValue func(*modelHandler, int, int) ui.TableValue
setCellValue func(*modelHandler, *ui.TableModel, int, int, ui.TableValue)
}
func initValues(mh *modelHandler) {
for i := 0; i < mh.rows; i++ {
log.Println("i=",i)
mh.vms[i].hostname = fmt.Sprintf("jcarrnew %d", i)
mh.cellValues[i].part0 = ui.TableColor{0.1, 0.5, 0.5, .3}
mh.cellValues[i].part1 = ui.TableString(fmt.Sprintf("fun %d", i))
mh.cellValues[i].part2 = ui.TableColor{0.5, 0.1, 0.1, .7}
mh.cellValues[i].part3 = ui.TableString(fmt.Sprintf("awesome %d", i))
}
// os.Exit(-1)
}
func newModelHandler(rows int) *modelHandler {
mh := new(modelHandler)
@ -39,11 +64,19 @@ func newModelHandler(rows int) *modelHandler {
mh.scanCellValue = defaultCellValue
mh.setCellValue = defaultSetCellValue
mh.bgcolorColumn = 0
mh.checkStates = make([]int, mh.rows)
mh.vms = make([]vmRowData, mh.rows)
mh.bgcolor = make([]ui.TableColor, mh.rows)
mh.cellValues = make([]jwcTest, mh.rows)
mh.vms[1].hostname = "jcarr"
mh.yellowRow = -1
initValues(mh)
log.Println("Called newModelhandler() with mh=", mh)
spew.Dump(mh)
return mh
@ -78,19 +111,29 @@ func makeTable(name string, rows int, row1Name string) (*ui.Table, *modelHandler
func defaultCellValue(mh *modelHandler, row, column int) ui.TableValue {
switch column {
case 0:
if (row % 2) == 1 {
return ui.TableColor{0.5, 0.5, 0.5, .1}
}
return nil
return mh.cellValues[row].part0
case 1:
return ui.TableString(fmt.Sprintf("jcarrgood %d", row))
return mh.cellValues[row].part1
case 2:
return mh.cellValues[row].part2
case 3:
return mh.cellValues[row].part3
}
return ui.TableString(fmt.Sprintf("jcarrbad %d", row))
}
func defaultSetCellValue(mh *modelHandler, m *ui.TableModel, row, column int, value ui.TableValue) {
if column == 3 { // button row (?)
switch column {
case 0:
// mh.cellValues[row].part0 = ui.TableColor(value)
case 1:
mh.cellValues[row].part1 = value.(ui.TableString)
case 2:
// mh.cellValues[row].part2 = ui.TableColor(value)
case 3:
// mh.cellValues[row].part3 = ui.TableString(value)
log.Println("Button was pressed START", row, column)
}
log.Println("ui.TableValue=", value)
return
}