Updated the widget gallery example to use the new Table without ImageList.

This commit is contained in:
Pietro Gagliardi 2015-02-20 00:23:49 -05:00
parent 87e5e3ed85
commit d855f5df3f
2 changed files with 5 additions and 9 deletions

View File

@ -9,20 +9,18 @@ import (
"image" "image"
"image/draw" "image/draw"
_ "image/png" _ "image/png"
"github.com/andlabs/ui"
) )
type icon struct { type icon struct {
Name string Name string
Icon ui.ImageIndex Icon *image.RGBA
Bool bool Bool bool
} }
var firstimg *image.RGBA var firstimg *image.RGBA
func readIcons() ([]icon, ui.ImageList) { func readIcons() []icon {
out := make([]icon, len(icons)) out := make([]icon, len(icons))
outil := ui.NewImageList()
for i := range icons { for i := range icons {
r := bytes.NewReader(icons[i].data) r := bytes.NewReader(icons[i].data)
png, _, err := image.Decode(r) png, _, err := image.Decode(r)
@ -34,11 +32,10 @@ func readIcons() ([]icon, ui.ImageList) {
if firstimg == nil { if firstimg == nil {
firstimg = img firstimg = img
} }
out[i].Icon = ui.ImageIndex(i) out[i].Icon = img
out[i].Name = icons[i].name out[i].Name = icons[i].name
outil.Append(img)
} }
return out, outil return out
} }
func tileImage(times int) *image.RGBA { func tileImage(times int) *image.RGBA {

View File

@ -37,13 +37,12 @@ func initGUI() {
g := ui.NewGroup("Group", ui.Space()) g := ui.NewGroup("Group", ui.Space())
icons, il := readIcons() icons := readIcons()
table := ui.NewTable(reflect.TypeOf(icons[0])) table := ui.NewTable(reflect.TypeOf(icons[0]))
table.Lock() table.Lock()
d := table.Data().(*[]icon) d := table.Data().(*[]icon)
*d = icons *d = icons
table.Unlock() table.Unlock()
table.LoadImageList(il)
area := ui.NewArea(200, 200, &areaHandler{tileImage(20)}) area := ui.NewArea(200, 200, &areaHandler{tileImage(20)})