From 4d67a55fdefdf3b1f553dd0fb3844c2e58622c2b Mon Sep 17 00:00:00 2001 From: Coder Date: Fri, 16 Oct 2026 16:38:25 -0400 Subject: [PATCH] internal/gobj: add widget subclasses and a go-valued list model --- internal/gobj/gobj.go | 260 +++++++++++++++++++++++++++++++++++++ internal/gobj/gobj_test.go | 180 +++++++++++++++++++++++++ internal/gobj/list.go | 167 ++++++++++++++++++++++++ internal/gobj/list_test.go | 102 +++++++++++++++ 4 files changed, 709 insertions(+) create mode 100644 internal/gobj/gobj.go create mode 100644 internal/gobj/gobj_test.go create mode 100644 internal/gobj/list.go create mode 100644 internal/gobj/list_test.go diff --git a/internal/gobj/gobj.go b/internal/gobj/gobj.go new file mode 100644 index 00000000..fccaaa9a --- /dev/null +++ b/internal/gobj/gobj.go @@ -0,0 +1,260 @@ +// Package gobj registers Go-backed GObject types. It is the only place +// that touches type registration, class vfuncs, and the map from +// instance pointers to Go values. +package gobj + +import ( + "cmp" + "fmt" + "reflect" + "sync" + "unsafe" + + "codeberg.org/puregotk/puregotk/v4/glib" + "codeberg.org/puregotk/puregotk/v4/gobject" + "codeberg.org/puregotk/puregotk/v4/gobject/types" + "codeberg.org/puregotk/puregotk/v4/gtk" + "deedles.dev/trayscale/internal/gutil" +) + +// Base is embedded in every Go-backed widget. gobj sets it before any +// Go code sees the struct. +type Base struct{ ptr uintptr } + +func (b *Base) base() *Base { return b } + +// GoPointer returns the instance pointer, so a *T can be passed where +// puregotk wants a gobject.Ptr. +func (b *Base) GoPointer() uintptr { return b.ptr } + +// SetGoPointer exists to satisfy gobject.Ptr. Changing the instance of +// a Go-backed widget makes no sense, so it panics. +func (b *Base) SetGoPointer(uintptr) { panic("gobj: SetGoPointer on a Go-backed widget") } + +// Widget returns the instance as a borrowed *gtk.Widget. +func (b *Base) Widget() *gtk.Widget { return gtk.WidgetNewFromInternalPtr(b.ptr) } + +// Disposer is optional. Dispose runs once, from the class dispose, +// while template children are still alive. +type Disposer interface{ Dispose() } + +// WidgetSpec describes one widget subclass. Template is a full .ui +// document whose