Documentation
¶
Overview ¶
Package gtk4 binds the parts of GTK4 a windowing toolkit needs — windows, the common controls, GObject signals and the GLib main loop — from pure Go with CGO_ENABLED=0, over github.com/ebitengine/purego. It is the Linux sibling of github.com/go-macos/objc: the shared native-toolkit bridge a go-widgets host backend embeds real controls through.
It links no cgo: libgtk-4, libgobject-2.0 and libglib-2.0 are dlopen'd by soname and every entry point is resolved with purego.RegisterLibFunc, exactly as the feasibility spike proved on a stock Linux GTK4. A GObject signal reaches Go through a purego.NewCallback, so a control's clicks and edits are ordinary Go closures.
Index ¶
- Variables
- func IdleAdd(fn func())
- func Init() (ok bool, err error)
- type MainLoop
- type Widget
- func (w Widget) Active() bool
- func (w Widget) Connect(signal string, fn func()) uint64
- func (f Widget) Move(child Widget, x, y float64)
- func (w Widget) Present()
- func (f Widget) Put(child Widget, x, y float64)
- func (w Widget) SetActive(on bool)
- func (w Widget) SetChild(child Widget)
- func (w Widget) SetDefaultSize(width, height int)
- func (w Widget) SetLabel(label string)
- func (w Widget) SetSizeRequest(width, height int)
- func (w Widget) SetText(s string)
- func (w Widget) SetTitle(title string)
- func (w Widget) SetVisibility(vis bool)
- func (w Widget) SetVisible(vis bool)
- func (w Widget) Text() string
- func (w Widget) Unparent()
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupported = errors.New("gtk4: only available on Linux")
ErrUnsupported is returned by Init on any platform without GTK4 (everything but Linux). It is defined on every platform so a portable consumer can test for it with errors.Is.
Functions ¶
Types ¶
type Widget ¶
type Widget uintptr
A Widget is a GTK widget — a GObject pointer. The zero value is the null widget. Methods on it are thin wrappers over the C API.
func ButtonNewWithLabel ¶
ButtonNewWithLabel creates a push button.
func CheckButtonNewWithLabel ¶
CheckButtonNewWithLabel creates a labelled check button. GTK check buttons that share a group act as radios; a host groups them for a NativeRadio.
func EntryNew ¶
func EntryNew() Widget
EntryNew creates a single-line text entry. Call SetVisibility(false) for a secure (password) entry.
func FixedNew ¶
func FixedNew() Widget
FixedNew creates a GtkFixed — the container a host overlays native controls in at absolute positions, over the pixel drawing area.
func (Widget) Connect ¶
Connect wires a GObject signal (e.g. "clicked", "changed") to a Go func. The callback keeps the widget's value reachable through its own accessors, so the zero-argument closure is enough for the control signals a host cares about. The returned handler id is GObject's; a host rarely needs it.
The callback is retained for the process life (like the go-macos target classes): GTK holds a C pointer to it, and letting Go collect it would leave a dangling call.
func (Widget) SetDefaultSize ¶
func (Widget) SetSizeRequest ¶
SetSizeRequest fixes a widget's size (a host sizes controls to the region it laid out).
func (Widget) SetVisibility ¶
func (Widget) SetVisible ¶
SetVisible shows or hides a widget in place.