Make window scroll in Go with GXUI -
i trying add scroll bars application windows in go using gxui.
say have code:
package main import ( "fmt" "github.com/google/gxui" "github.com/google/gxui/drivers/gl" "github.com/google/gxui/samples/flags" "github.com/google/gxui/themes/dark" ) func appmain(driver gxui.driver) { theme := dark.createtheme(driver) window := theme.createwindow(800, 600, "grid") window.setscale(flags.defaultscalefactor) window.onclose(driver.terminate) row := theme.createlinearlayout() row.setdirection(gxui.lefttoright) c := 0; c < 4; c++ { col := theme.createlinearlayout() col.setdirection(gxui.toptobottom) r := 0; r < 100; r++ { cell := theme.createlabel() cell.settext(fmt.sprintf("%d", r*4+c)) col.addchild(cell) } row.addchild(col) } window.addchild(row) } func main() { gl.startdriver(appmain) } when run it, window:

how can window have scroll bar can view of lines?
i wasn't able scrolllayout, can propose variant on basis of examples github.
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" "github.com/google/gxui/themes/dark" ) type customadapter struct { gxui.adapterbase } func (a *customadapter) count() int { return 1000 } 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: 200, h: 25} } func (a *customadapter) create(theme gxui.theme, index int) gxui.control { layout1 := theme.createlinearlayout() layout1.setdirection(gxui.lefttoright) c := 0; c < 4; c++ { col := theme.createlinearlayout() col.setdirection(gxui.toptobottom) cell := theme.createlabel() cell.settext(fmt.sprintf("%d", index*4+c)) col.addchild(cell) layout1.addchild(col) } return layout1 } func appmain(driver gxui.driver) { theme := dark.createtheme(driver) window := theme.createwindow(600, 400, "grid") window.borderpen() window.setscale(flags.defaultscalefactor) window.onclose(driver.terminate) adapter := &customadapter{} list := theme.createlist() list.setadapter(adapter) list.setorientation(gxui.vertical) window.addchild(list) } func main() { gl.startdriver(appmain) } each line placed in list,their number , size specified in overridden methods. advantage in list have scrollbar.
Comments
Post a Comment