Finished migrating the GTK+ Table to not use ImageList.
This commit is contained in:
parent
2e4c278301
commit
366460a46e
|
@ -40,10 +40,9 @@ func toIconSizedGdkPixbuf(img *image.RGBA) *C.GdkPixbuf {
|
||||||
panic(fmt.Errorf("gtk_icon_size_lookup() failed in ImageList.Append() (no reason available)"))
|
panic(fmt.Errorf("gtk_icon_size_lookup() failed in ImageList.Append() (no reason available)"))
|
||||||
}
|
}
|
||||||
if int(width) == img.Rect.Dx() && int(height) == img.Rect.Dy() {
|
if int(width) == img.Rect.Dx() && int(height) == img.Rect.Dy() {
|
||||||
// just add the base pixbuf; we're good
|
// just return the base pixbuf; we're good
|
||||||
i.list = append(i.list, basepixbuf)
|
|
||||||
C.cairo_surface_destroy(surface)
|
C.cairo_surface_destroy(surface)
|
||||||
return
|
return basepixbuf
|
||||||
}
|
}
|
||||||
// else scale
|
// else scale
|
||||||
pixbuf := C.gdk_pixbuf_scale_simple(basepixbuf, C.int(width), C.int(height), C.GDK_INTERP_NEAREST)
|
pixbuf := C.gdk_pixbuf_scale_simple(basepixbuf, C.int(width), C.int(height), C.GDK_INTERP_NEAREST)
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
"reflect"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
"image"
|
||||||
)
|
)
|
||||||
|
|
||||||
// #include "gtk_unix.h"
|
// #include "gtk_unix.h"
|
||||||
|
@ -25,8 +26,6 @@ type table struct {
|
||||||
modelgtk *C.GtkTreeModel
|
modelgtk *C.GtkTreeModel
|
||||||
selection *C.GtkTreeSelection
|
selection *C.GtkTreeSelection
|
||||||
|
|
||||||
pixbufs []*C.GdkPixbuf
|
|
||||||
|
|
||||||
selected *event
|
selected *event
|
||||||
|
|
||||||
// stuff required by GtkTreeModel
|
// stuff required by GtkTreeModel
|
||||||
|
@ -64,7 +63,7 @@ func finishNewTable(b *tablebase, ty reflect.Type) Table {
|
||||||
for i := 0; i < ty.NumField(); i++ {
|
for i := 0; i < ty.NumField(); i++ {
|
||||||
cname := togstr(ty.Field(i).Name)
|
cname := togstr(ty.Field(i).Name)
|
||||||
switch {
|
switch {
|
||||||
case ty.Field(i).Type == reflect.TypeOf(ImageIndex(0)):
|
case ty.Field(i).Type == reflect.TypeOf((*image.RGBA)(nil)):
|
||||||
// can't use GDK_TYPE_PIXBUF here because it's a macro that expands to a function and cgo hates that
|
// can't use GDK_TYPE_PIXBUF here because it's a macro that expands to a function and cgo hates that
|
||||||
t.types = append(t.types, C.gdk_pixbuf_get_type())
|
t.types = append(t.types, C.gdk_pixbuf_get_type())
|
||||||
C.tableAppendColumn(t.treeview, C.gint(i), cname,
|
C.tableAppendColumn(t.treeview, C.gint(i), cname,
|
||||||
|
@ -113,10 +112,6 @@ func (t *table) Unlock() {
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *table) LoadImageList(i ImageList) {
|
|
||||||
i.apply(&t.pixbufs)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *table) Selected() int {
|
func (t *table) Selected() int {
|
||||||
var iter C.GtkTreeIter
|
var iter C.GtkTreeIter
|
||||||
|
|
||||||
|
@ -172,10 +167,13 @@ func goTableModel_do_get_value(data unsafe.Pointer, row C.gint, col C.gint, valu
|
||||||
d := reflect.Indirect(reflect.ValueOf(t.data))
|
d := reflect.Indirect(reflect.ValueOf(t.data))
|
||||||
datum := d.Index(int(row)).Field(int(col))
|
datum := d.Index(int(row)).Field(int(col))
|
||||||
switch {
|
switch {
|
||||||
case datum.Type() == reflect.TypeOf(ImageIndex(0)):
|
case datum.Type() == reflect.TypeOf((*image.RGBA)(nil)):
|
||||||
d := datum.Interface().(ImageIndex)
|
d := datum.Interface().(*image.RGBA)
|
||||||
|
pixbuf := toIconSizedGdkPixbuf(d)
|
||||||
C.g_value_init(value, C.gdk_pixbuf_get_type())
|
C.g_value_init(value, C.gdk_pixbuf_get_type())
|
||||||
C.g_value_set_object(value, C.gpointer(unsafe.Pointer(t.pixbufs[d])))
|
object := C.gpointer(unsafe.Pointer(pixbuf))
|
||||||
|
// use g_value_take_object() so the GtkTreeView becomes the pixbuf's owner
|
||||||
|
C.g_value_take_object(value, object)
|
||||||
case datum.Kind() == reflect.Bool:
|
case datum.Kind() == reflect.Bool:
|
||||||
d := datum.Interface().(bool)
|
d := datum.Interface().(bool)
|
||||||
C.g_value_init(value, C.G_TYPE_BOOLEAN)
|
C.g_value_init(value, C.G_TYPE_BOOLEAN)
|
||||||
|
|
Loading…
Reference in New Issue