gtkutil

package
v0.0.0-...-bedf5c0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MPL-2.0 Imports: 15 Imported by: 8

Documentation

Index

Constants

View Source
const PopoverWidth = 150

PopoverWidth is the default popover width.

Variables

View Source
var JSONVariantType = glib.NewVariantType("ay") // array of bytes

JSONVariantType is the GVariantType that describes the JSON argument that NewJSONActionCallback outputs.

Functions

func ActionGroup

func ActionGroup(data ...gio.Actioner) *gio.SimpleActionGroup

ActionGroup constructs an action group from the diven action data.

func AddActionCallbacks

func AddActionCallbacks(actionMapper gio.ActionMapper, m map[string]ActionCallback)

AddActionCallbacks adds the given action callbacks to the given widget. Unlike BindActionCallbackMap, this function does not need prefixed action names.

func AddActionShortcuts

func AddActionShortcuts(w gtk.Widgetter, shortcuts map[string]string)

AddActionShortcuts adds the given shortcuts to the widget. The shortcuts are given as a map of keybindings to action names.

func AddActions

func AddActions(actionMapper gio.ActionMapper, m map[string]func())

AddActions adds the given actions to the given widget. Unlike BindActionMap, this function does not need prefixed action names.

func AddCallbackShortcuts

func AddCallbackShortcuts(w gtk.Widgetter, shortcuts map[string]func())

AddCallbackShortcuts adds the given shortcuts to the widget. The shortcuts are given as a map of keybindings to callbacks.

func Async

func Async(ctx context.Context, asyncFn func() func())

Async runs asyncFn in a goroutine and runs the returned callback in the main thread. If ctx is cancelled during, the returned callback will not be called.

func BindActionCallbackMap

func BindActionCallbackMap(w gtk.Widgetter, m map[string]ActionCallback)

BindActionCallbackMap is a more verbose variant of BindActionMap.

func BindActionMap

func BindActionMap(w gtk.Widgetter, m map[string]func())

BindActionMap binds the given map of actions (of key prefixed appropriately) to the given widget.

func BindKeys

func BindKeys(w gtk.Widgetter, accelFns map[string]func() bool)

BindKeys binds the event controller returned from NewKeybinds being given the map to the given widget.

func BindPopoverMenu

func BindPopoverMenu(w gtk.Widgetter, pos gtk.PositionType, pairs [][2]string)

BindPopoverMenu binds the given widget to a popover menu to be displayed on right-clicking.

func BindPopoverMenuAtMouse

func BindPopoverMenuAtMouse(w gtk.Widgetter, pos gtk.PositionType, pairs [][2]string)

BindPopoverMenuAtMouse binds the given widget to a popover menu to be displayed on right-clicking, but at the mouse position.

func BindPopoverMenuCustom

func BindPopoverMenuCustom(w gtk.Widgetter, pos gtk.PositionType, pairs []PopoverMenuItem)

BindPopoverMenuCustom works similarly to BindPopoverMenu, but the value type can be more than just an action string. The key must be a string.

func BindPopoverMenuLazy

func BindPopoverMenuLazy(w gtk.Widgetter, pos gtk.PositionType, pairsFn func() []PopoverMenuItem)

BindPopoverMenuLazy is similarl to BindPopoverMenuCustom, except the menu items are lazily created.

func BindRightClick

func BindRightClick(w gtk.Widgetter, f func())

BindRightClick binds the given widget to take in right-click gestures. The function will also check for long-hold gestures.

func BindRightClickAt

func BindRightClickAt(w gtk.Widgetter, f func(x, y float64))

BindRightClickAt is a version of BindRightClick with accurate coordinates given to the callback.

func BindSubscribe

func BindSubscribe(widget gtk.Widgetter, f func() (unsub func()))

BindSubscribe calls f when w gets mapped.

func CustomMenu

func CustomMenu(items []PopoverMenuItem) *gio.Menu

CustomMenu returns a new Menu from the given popover menu items. All menu items that have widgets are ignored.

func CustomMenuItems

func CustomMenuItems(items ...PopoverMenuItem) *gio.Menu

CustomMenuItems is the variadic arguments variant of CustomMenu.

func EachChild

func EachChild(w gtk.Widgetter, f func(child gtk.Widgetter) bool)

EachChild iterates over w's children.

func EachList

func EachList[T glib.Objector](list gio.ListModeller, f func(T))

EachList calls f for each item in the list.

func ForwardTyping

func ForwardTyping(w, dst gtk.Widgetter)

ForwardTyping forwards all typing events from w to dst.

func ForwardTypingFunc

func ForwardTypingFunc(w gtk.Widgetter, f func() gtk.Widgetter)

func IdleCtx

func IdleCtx(ctx context.Context, f func())

IdleCtx runs the given callback inside the main loop only if the context has not expired.

func InvokeMain

func InvokeMain(f func())

InvokeMain invokes f in the main loop. It is useful in global helper functions where it's unclear where the caller will invoke it from, but it should be used carefully, since it's easy to be abused.

func IsCancelled

func IsCancelled(cancellable Cancellable) bool

IsCancelled returns true if the cancellable is cancelled.

func MenuPair(pairs [][2]string) *gio.Menu

MenuPair creates a gtk.Menu out of the given menu pair. The returned Menu instance satisfies gio.MenuModeller. The first value of a pair should be the name.

func MustUnmarshalBuilder

func MustUnmarshalBuilder(v any, builder *gtk.Builder)

MustUnmarshalBuilder calls UnmarshalBuilder and panics on any error.

func NewCustomMenuItem

func NewCustomMenuItem(label locale.Localized, id string) *gio.MenuItem

func NewDragSourceWithContent

func NewDragSourceWithContent(w gtk.Widgetter, a gdk.DragAction, v interface{}) *gtk.DragSource

NewDragSourceWithContent creates a new DragSource with the given Go value.

func NewJSONVariant

func NewJSONVariant(v interface{}) *glib.Variant

NewJSONVariant creates a new GVariant instance from any Go value that can be encoded into JSON. If the value cannot be encoded, then the function panics.

func NewKeybinds

func NewKeybinds(accelFns map[string]func() bool) *gtk.EventControllerKey

NewKeybinds binds all accelerators given in the map with their respective functions to the returned EventControllerKey. If any of the accelerators are invalid, then the function panics.

func NewListDropTarget

func NewListDropTarget(l *gtk.ListBox, typ coreglib.Type, actions gdk.DragAction) *gtk.DropTarget

NewListDropTarget creates a new DropTarget that highlights the row.

func NewPopoverMenu

func NewPopoverMenu(w gtk.Widgetter, pos gtk.PositionType, pairs [][2]string) *gtk.PopoverMenu

NewPopoverMenu creates a new Popover menu.

func NewPopoverMenuCustom

func NewPopoverMenuCustom(
	w gtk.Widgetter, pos gtk.PositionType, items []PopoverMenuItem) *gtk.PopoverMenu

NewPopoverMenuCustom creates a new Popover containing the given items.

func NewPopoverMenuFromPairs

func NewPopoverMenuFromPairs(pairs [][2]string) *gtk.PopoverMenu

NewPopoverMenuFromPairs is a convenient function for NewPopoverMenuFromModel and MenuPairs.

func NewRadioButtons

func NewRadioButtons(d RadioData, f func(int)) gtk.Widgetter

NewRadioButtons creates a new box of radio buttons.

func NotifyProperty

func NotifyProperty(obj glib.Objector, property string, f func() bool)

NotifyProperty calls f everytime the object's property changes until it returns true.

func OnFirstDraw

func OnFirstDraw(w gtk.Widgetter, f func())

OnFirstDraw attaches f to be called on the first time the widget is drawn on the screen.

func OnFirstDrawUntil

func OnFirstDrawUntil(w gtk.Widgetter, f func() bool)

OnFirstDrawUntil attaches f to be called on the first time the widget is drawn on the screen. f is called again until it returns false.

func OnFirstMap

func OnFirstMap(w gtk.Widgetter, f func())

OnFirstMap attaches f to be called on the first time the widget is mapped on the screen.

func PopupFinally

func PopupFinally(p Popupper)

PopupFinally pops up the Popover and schedules it to destroy itself when it's closed.

func RecursiveUnfuck

func RecursiveUnfuck(w gtk.Widgetter)

RecursiveUnfuck calls WipeAllClosures on the widget tree.

func RemoveChildren

func RemoveChildren(w gtk.Widgetter)

RemoveChildren removes all children from w.

func RowAtY

func RowAtY(list *gtk.ListBox, y float64) (*gtk.ListBoxRow, gtk.PositionType)

RowAtY returns the row as well as the position type (top or bottom) relative to that row.

func ScaleFactor

func ScaleFactor() int

ScaleFactor returns the largest scale factor from all the displays. It is thread-safe.

func SetScaleFactor

func SetScaleFactor(maxScale int)

SetScaleFactor sets the global maximum scale factor. This function is useful of GDK fails to update the scale factor in time.

func ShowPopoverMenu

func ShowPopoverMenu(w gtk.Widgetter, pos gtk.PositionType, pairs [][2]string) *gtk.PopoverMenu

ShowPopoverMenu is like ShowPopoverMenuCustom but uses a regular string pair list.

func ShowPopoverMenuCustom

func ShowPopoverMenuCustom(w gtk.Widgetter, pos gtk.PositionType, items []PopoverMenuItem) bool

ShowPopoverMenuCustom is like BindPopoverMenuCustom, but it does not bind a handler. This is useful if the caller does not want pairs to be in memory all the time. If any of the menus cannot be added in, then false is returned, and the popover isn't shown.

func SignalToggler

func SignalToggler(signal string, f interface{}) func(obj coreglib.Objector)

SignalToggler is a small helper to allow binding the same signal to different objects while unbinding the previous one.

func UnmarshalBuilder

func UnmarshalBuilder(dst any, builder *gtk.Builder) error

UnmarshalBuilder unmarshals the given gtk.Builder instance into the given struct pointer dst. It uses the `name` struct tag to query for objects in the builder. A missing object is an error. An object with mismatching type is an error.

Below is a minimal example of this function:

var built struct {
    Window *gtk.Window `name:"window"`
    Close  *gtk.Button `name:"close"`
}

builder := gtk.NewBuilderFromString(windowUI, -1)
err := UnmarshalBuilder(&built, builder)

func WalkWidget

func WalkWidget(w gtk.Widgetter, f func(w gtk.Widgetter) bool)

WalkWidget walks w and its children recursively down the widget tree.

Types

type ActionCallback

type ActionCallback struct {
	Func    func(*glib.Variant)
	ArgType *glib.VariantType
}

ActionCallback is a type holding a callback with a GVariant argument and a GVariantType field describing its internal structure.

func NewJSONActionCallback

func NewJSONActionCallback(f interface{}) ActionCallback

NewJSONActionCallback creates a new ActionCallback that uses JSON to marshal and unmarshal data.

type ActionData

type ActionData struct {
	Name string
	Func func()
}

ActionData describes a CallbackAction's data.

type CallbackAction

type CallbackAction struct {
	*gio.SimpleAction
}

CallbackAction extends SimpleAction to provide idiomatic callback APIs.

func ActionFunc

func ActionFunc(name string, f func()) *CallbackAction

ActionFunc creates a CallbackActionFunc from a function.

func NewCallbackAction

func NewCallbackAction(name string) *CallbackAction

NewCallbackAction creates a new CallbackAction.

func NewCallbackActionParam

func NewCallbackActionParam(name string, paramType *glib.VariantType) *CallbackAction

NewCallbackActionParam creates a new CallbackAction with a single parameter.

func (*CallbackAction) OnActivate

func (a *CallbackAction) OnActivate(f interface{})

OnActivate binds the given function callback to be called when the action is activated.

type Cancellable

type Cancellable interface {
	// Take returns the current context. This is useful for dropping this
	// context into a background task.
	Take() context.Context
	// OnRenew adds a function to be called once the context is renewed. If the
	// callback returns a non-nil function, then that function is called once
	// the context is cancelled.
	OnRenew(func(context.Context) (undo func())) (remove func())
}

Cancellable describes a renewable and cancelable context. It is primarily used to box a context inside a widget for convenience.

type Canceller

type Canceller interface {
	Cancellable
	// Renew cancels the previous context, if any, and restarts that context
	// using the one given into WithCanceller.
	Renew()
	// Cancel cancels the canceler. If the canceler is a zero-value, then this
	// method does nothing.
	Cancel()
}

Canceller extends Cancellable to allow the user to control the context.

func WithCanceller

func WithCanceller(ctx context.Context) Canceller

WithCanceller wraps around a context.

func WithVisibility

func WithVisibility(ctx context.Context, widget gtk.Widgetter) Canceller

WithVisibility creates a new context that is canceled when the widget is hidden.

type FuncBatch

type FuncBatch func()

FuncBatch batches functions for calling.

func FuncBatcher

func FuncBatcher(funcs ...func()) FuncBatch

FuncBatcher creates a new FuncBatch.

func (*FuncBatch) F

func (b *FuncBatch) F(f func())

F batches f.

func (*FuncBatch) Fs

func (b *FuncBatch) Fs(funcs ...func())

Fs batches multiple funcs.

type PopoverMenuItem

type PopoverMenuItem interface {
	// contains filtered or unexported methods
}

PopoverMenuItem defines a popover menu item constructed from one of the constructors.

func MenuItem(label locale.Localized, action string, ands ...bool) PopoverMenuItem

MenuItem creates a simple popover menu item. If action is empty, then the item is disabled; if action is "---", then a new section is created.

func MenuItemIcon(label locale.Localized, action, icon string) PopoverMenuItem

MenuItemIcon is an icon variant of MenuItem.

func MenuSeparator(label locale.Localized) PopoverMenuItem

MenuSeparator creates a new menu separator.

func MenuWidget(action string, w gtk.Widgetter) PopoverMenuItem

MenuWidget creates a new menu item that contains a widget.

func Submenu(label locale.Localized, sub []PopoverMenuItem) PopoverMenuItem

Submenu creates a popover menu item that is a submenu.

type Popupper

type Popupper interface {
	gtk.Widgetter
	Popup()
	Unparent()
	ConnectHide(func()) glib.SignalHandle
}

Popupper describes the Popover's Popup interface.

type RadioData

type RadioData struct {
	Current int
	Options []locale.Localized
}

RadioData describes the data for the set of radio buttons created by NewRadioButtons.

Directories

Path Synopsis
Package aggressivegc enforces a GC every minute.
Package aggressivegc enforces a GC every minute.
Package textutil contains utilities for handling Pango markup and TextBuffer shenanigans.
Package textutil contains utilities for handling Pango markup and TextBuffer shenanigans.

Jump to

Keyboard shortcuts

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