gutil

package
v0.18.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert added in v0.18.2

func Assert[T any, V any, C interface {
	Caster
	*V
}](obj C) (v T, ok bool)

Assert casts anything that implements Cast to the specified type. Its main point is to safely and conveniently handle nil.

func ErrHasCode

func ErrHasCode(err error, code int) bool

ErrHasCode returns true if and only if err is a gerror.GError and its error code is code.

func ExpanderRowListBox

func ExpanderRowListBox(row *adw.ExpanderRow) *gtk.ListBox

ExpanderRowListBox returns the gtk.ListBox that is used internally by an adw.ExpanderRow to hold the rows that are shown when it is expanded. This is quite hacky and should be avoided if it can be, but is unfortunately necessary for a couple of things.

func FillFromBuilder

func FillFromBuilder[T any](dst *T, builder *gtk.Builder)

FillFromBuilder sets fields in the struct dst using objects looked up in builder. If the field has a `gtk` tag, the value of it is used as the name to look up in builder, unless the tag is exactly `"-"` in which case the field is skipped. If it does not have a tag, the field name is used instead. If an object by that name does not exist in the builder, it is quietly skipped. If it does exist but is the wrong type, this function will panic.

For example,

var example struct {
	Label *gtk.Label
	Button *gtk.Button `gtk:"DoneButton"`
}
FillFromBuilder(&example, builder)

will cause the Label field to get filled with the object named "Label" and the Button field to get filled with the object named "DoneButton".

func FillFromUI

func FillFromUI[T any](into *T, xml ...string)

FillFromUI loads the given xml data in the order that it is passed and fills into with it in the same way that FillFromBuilder does. Each xml value should be an entire XML UI definition file. This is mostly a convenience function to make it easier to load widgets from embedded files.

func PointerToWidgetter

func PointerToWidgetter[T any, P interface {
	gtk.Widgetter
	*T
}](p P) gtk.Widgetter

PointerToWidgetter converts a *T that implements gtk.Widgetter to a gtk.Widgetter, returning nil if the *T is nil. This avoids the nil interface problem.

func SetCSSClass

func SetCSSClass(w Classy, class string, force bool)

SetCSSClass adds or removes a CSS class based on a boolean argument.

func WidgetChildren

func WidgetChildren(w WidgetParent) iter.Seq[gtk.Widgetter]

WidgetChildren returns an iterator that performs a pre-order traversal of the widget tree rooted at w. It does not yield w itself.

Types

type Caster added in v0.18.2

type Caster interface {
	Cast() glib.Objector
}

Caster wraps the glib.Object.Cast method.

type Classy

type Classy interface {
	AddCSSClass(string)
	RemoveCSSClass(string)
	HasCSSClass(string) bool
	CSSClasses() []string
}

Classy wraps the CSS-related methods of a gtk.Widget.

type WidgetParent

type WidgetParent interface {
	FirstChild() gtk.Widgetter
}

WidgetParent is any type that has child widgets. Gererally speaking, this is every Gtk widget.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL