I try to work with the GUI in Go. Chose this library. Want at the touch of a button to process and display information entered into the list of the textbox in the file. The problem is that I cannot access the textBox from outside creator function. Here’s what I did on the basis of examples:
package main
import (
"fmt"
"github.com/google/gxui"
"github.com/google/gxui/drivers/gl"
"github.com/google/gxui/math"
"github.com/google/gxui/samples/flags"
)
type customAdapter struct {
gxui.AdapterBase
}
func (a *customAdapter) Count() int {
return 20
}
func (a *customAdapter) ItemAt(index int) gxui.AdapterItem {
return index
}
func (a *customAdapter) ItemIndex(item gxui.AdapterItem) int {
return item.(int)
}
func (a *customAdapter) Size(theme gxui.Theme) math.Size {
return math.Size{W: 150, H: 30}
}
func (a *customAdapter) Create(theme gxui.Theme, index int) gxui.Control {
layout1 := theme.CreateLinearLayout()
layout1.SetDirection(gxui.LeftToRight)
cell := theme.CreateTextBox()
layout1.AddChild(cell)
return layout1
}
func appMain(driver gxui.Driver) {
theme := flags.CreateTheme(driver)
adapter := &customAdapter{}
layout := theme.CreateLinearLayout()
layout.SetDirection(gxui.LeftToRight)
list := theme.CreateList()
list.SetAdapter(adapter)
list.SetOrientation(gxui.Vertical)
layout.AddChild(list)
button2 := theme.CreateButton()
button2.SetText("Show")
button2.OnClick(func(gxui.MouseEvent) { my_func(list) })
layout.AddChild(button2)
window := theme.CreateWindow(250, 250, "Test")
window.SetScale(flags.DefaultScaleFactor)
window.AddChild(layout)
window.OnClose(driver.Terminate)
}
func main() {
gl.StartDriver(appMain)
}
func my_func(list gxui.List) {
fmt.Println(list.Adapter().Count())
Size := list.Adapter().Count()
for i := 0; i < Size; i++ {
el := list.Adapter().ItemAt(i)
// do_something(el)
fmt.Println(el)
}
}
My questions:
- How do I get a text from textbox?
- How to retrieve an item from this list using ItemAt
- Other ways to solve the problem
I would be grateful for any help