1// Package adw was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package adw
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11 "github.com/bnema/puregotk/v4/glib"
12 "github.com/bnema/puregotk/v4/gobject"
13 "github.com/bnema/puregotk/v4/gobject/types"
14 "github.com/bnema/puregotk/v4/gtk"
15)
16
17type ToastClass struct {
18 _ structs.HostLayout
19
20 ParentClass gobject.ObjectClass
21}
22
23func (x *ToastClass) GoPointer() uintptr {
24 return uintptr(unsafe.Pointer(x))
25}
26
27// [class@Toast] behavior when another toast is already displayed.
28type ToastPriority int
29
30var xToastPriorityGLibType func() types.GType
31
32func ToastPriorityGLibType() types.GType {
33 return xToastPriorityGLibType()
34}
35
36const (
37
38 // the toast will be queued if another toast is
39 // already displayed.
40 ToastPriorityNormalValue ToastPriority = 0
41 // the toast will be displayed immediately, pushing
42 // the previous toast into the queue instead.
43 ToastPriorityHighValue ToastPriority = 1
44)
45
46// A helper object for [class@ToastOverlay].
47//
48// Toasts are meant to be passed into [method@ToastOverlay.add_toast] as
49// follows:
50//
51// ```c
52// adw_toast_overlay_add_toast (overlay, adw_toast_new (_("Simple Toast")));
53// ```
54//
55// <picture>
56//
57// <source srcset="toast-simple-dark.png" media="(prefers-color-scheme: dark)">
58// <img src="toast-simple.png" alt="toast-simple">
59//
60// </picture>
61//
62// Toasts always have a close button. They emit the [signal@Toast::dismissed]
63// signal when disappearing.
64//
65// [property@Toast:timeout] determines how long the toast stays on screen, while
66// [property@Toast:priority] determines how it behaves if another toast is
67// already being displayed.
68//
69// Toast titles use Pango markup by default, set [property@Toast:use-markup] to
70// `FALSE` if this is unwanted.
71//
72// [property@Toast:custom-title] can be used to replace the title label with a
73// custom widget.
74//
75// ## Actions
76//
77// Toasts can have one button on them, with a label and an attached
78// [iface@Gio.Action].
79//
80// ```c
81// AdwToast *toast = adw_toast_new (_("Toast with Action"));
82//
83// adw_toast_set_button_label (toast, _("_Example"));
84// adw_toast_set_action_name (toast, "win.example");
85//
86// adw_toast_overlay_add_toast (overlay, toast);
87// ```
88//
89// <picture>
90//
91// <source srcset="toast-action-dark.png" media="(prefers-color-scheme: dark)">
92// <img src="toast-action.png" alt="toast-action">
93//
94// </picture>
95//
96// ## Modifying toasts
97//
98// Toasts can be modified after they have been shown. For this, an `AdwToast`
99// reference must be kept around while the toast is visible.
100//
101// A common use case for this is using toasts as undo prompts that stack with
102// each other, allowing to batch undo the last deleted items:
103//
104// ```c
105//
106// static void
107// toast_undo_cb (GtkWidget *sender,
108//
109// const char *action,
110// GVariant *param)
111//
112// {
113// // Undo the deletion
114// }
115//
116// static void
117// dismissed_cb (MyWindow *self)
118//
119// {
120// self->undo_toast = NULL;
121//
122// // Permanently delete the items
123// }
124//
125// static void
126// delete_item (MyWindow *self,
127//
128// MyItem *item)
129//
130// {
131// g_autofree char *title = NULL;
132// int n_items;
133//
134// // Mark the item as waiting for deletion
135// n_items = ... // The number of waiting items
136//
137// if (!self->undo_toast) {
138// self->undo_toast = adw_toast_new_format (_("‘%s’ deleted"), ...);
139//
140// adw_toast_set_priority (self->undo_toast, ADW_TOAST_PRIORITY_HIGH);
141// adw_toast_set_button_label (self->undo_toast, _("_Undo"));
142// adw_toast_set_action_name (self->undo_toast, "toast.undo");
143//
144// g_signal_connect_swapped (self->undo_toast, "dismissed",
145// G_CALLBACK (dismissed_cb), self);
146//
147// adw_toast_overlay_add_toast (self->toast_overlay, self->undo_toast);
148//
149// return;
150// }
151//
152// title =
153// g_strdup_printf (ngettext ("<span font_features='tnum=1'>%d</span> item deleted",
154// "<span font_features='tnum=1'>%d</span> items deleted",
155// n_items), n_items);
156//
157// adw_toast_set_title (self->undo_toast, title);
158//
159// // Bump the toast timeout
160// adw_toast_overlay_add_toast (self->toast_overlay, g_object_ref (self->undo_toast));
161// }
162//
163// static void
164// my_window_class_init (MyWindowClass *klass)
165//
166// {
167// GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
168//
169// gtk_widget_class_install_action (widget_class, "toast.undo", NULL, toast_undo_cb);
170// }
171//
172// ```
173//
174// <picture>
175//
176// <source srcset="toast-undo-dark.png" media="(prefers-color-scheme: dark)">
177// <img src="toast-undo.png" alt="toast-undo">
178//
179// </picture>
180type Toast struct {
181 gobject.Object
182}
183
184var xToastGLibType func() types.GType
185
186func ToastGLibType() types.GType {
187 return xToastGLibType()
188}
189
190func ToastNewFromInternalPtr(ptr uintptr) *Toast {
191 cls := &Toast{}
192 cls.Ptr = ptr
193 return cls
194}
195
196var xNewToast func(string) uintptr
197
198// Creates a new `AdwToast`.
199//
200// The toast will use @title as its title.
201//
202// @title can be marked up with the Pango text markup language.
203func NewToast(TitleVar string) *Toast {
204 var cls *Toast
205
206 cret := xNewToast(TitleVar)
207
208 if cret == 0 {
209 return nil
210 }
211 cls = &Toast{}
212 cls.Ptr = cret
213 return cls
214}
215
216var xNewToastFormat func(string, ...interface{}) uintptr
217
218// Creates a new `AdwToast`.
219//
220// The toast will use the format string as its title.
221//
222// See also: [ctor@Toast.new]
223func NewToastFormat(FormatVar string, varArgs ...interface{}) *Toast {
224 var cls *Toast
225
226 cret := xNewToastFormat(FormatVar, varArgs...)
227
228 if cret == 0 {
229 return nil
230 }
231 cls = &Toast{}
232 cls.Ptr = cret
233 return cls
234}
235
236var xToastDismiss func(uintptr)
237
238// Dismisses @self.
239//
240// Does nothing if @self has already been dismissed, or hasn't been added to an
241// [class@ToastOverlay].
242func (x *Toast) Dismiss() {
243
244 xToastDismiss(x.GoPointer())
245
246}
247
248var xToastGetActionName func(uintptr) string
249
250// Gets the name of the associated action.
251func (x *Toast) GetActionName() string {
252
253 cret := xToastGetActionName(x.GoPointer())
254 return cret
255}
256
257var xToastGetActionTargetValue func(uintptr) *glib.Variant
258
259// Gets the parameter for action invocations.
260func (x *Toast) GetActionTargetValue() *glib.Variant {
261
262 cret := xToastGetActionTargetValue(x.GoPointer())
263 return cret
264}
265
266var xToastGetButtonLabel func(uintptr) string
267
268// Gets the label to show on the button.
269func (x *Toast) GetButtonLabel() string {
270
271 cret := xToastGetButtonLabel(x.GoPointer())
272 return cret
273}
274
275var xToastGetCustomTitle func(uintptr) uintptr
276
277// Gets the custom title widget of @self.
278func (x *Toast) GetCustomTitle() *gtk.Widget {
279 var cls *gtk.Widget
280
281 cret := xToastGetCustomTitle(x.GoPointer())
282
283 if cret == 0 {
284 return nil
285 }
286 gobject.IncreaseRef(cret)
287 cls = >k.Widget{}
288 cls.Ptr = cret
289 return cls
290}
291
292var xToastGetPriority func(uintptr) ToastPriority
293
294// Gets priority for @self.
295func (x *Toast) GetPriority() ToastPriority {
296
297 cret := xToastGetPriority(x.GoPointer())
298 return cret
299}
300
301var xToastGetTimeout func(uintptr) uint
302
303// Gets timeout for @self.
304func (x *Toast) GetTimeout() uint {
305
306 cret := xToastGetTimeout(x.GoPointer())
307 return cret
308}
309
310var xToastGetTitle func(uintptr) string
311
312// Gets the title that will be displayed on the toast.
313//
314// If a custom title has been set with [method@Adw.Toast.set_custom_title]
315// the return value will be %NULL.
316func (x *Toast) GetTitle() string {
317
318 cret := xToastGetTitle(x.GoPointer())
319 return cret
320}
321
322var xToastGetUseMarkup func(uintptr) bool
323
324// Gets whether to use Pango markup for the toast title.
325func (x *Toast) GetUseMarkup() bool {
326
327 cret := xToastGetUseMarkup(x.GoPointer())
328 return cret
329}
330
331var xToastSetActionName func(uintptr, uintptr)
332
333// Sets the name of the associated action.
334//
335// It will be activated when clicking the button.
336//
337// See [property@Toast:action-target].
338func (x *Toast) SetActionName(ActionNameVar *string) {
339
340 ActionNameVarPtr := core.GStrdupNullable(ActionNameVar)
341 defer core.GFreeNullable(ActionNameVarPtr)
342
343 xToastSetActionName(x.GoPointer(), ActionNameVarPtr)
344
345}
346
347var xToastSetActionTarget func(uintptr, uintptr, ...interface{})
348
349// Sets the parameter for action invocations.
350//
351// This is a convenience function that calls [ctor@GLib.Variant.new] for
352// @format_string and uses the result to call
353// [method@Toast.set_action_target_value].
354//
355// If you are setting a string-valued target and want to set
356// the action name at the same time, you can use
357// [method@Toast.set_detailed_action_name].
358func (x *Toast) SetActionTarget(FormatStringVar *string, varArgs ...interface{}) {
359
360 FormatStringVarPtr := core.GStrdupNullable(FormatStringVar)
361 defer core.GFreeNullable(FormatStringVarPtr)
362
363 xToastSetActionTarget(x.GoPointer(), FormatStringVarPtr, varArgs...)
364
365}
366
367var xToastSetActionTargetValue func(uintptr, *glib.Variant)
368
369// Sets the parameter for action invocations.
370//
371// If the @action_target variant has a floating reference this function
372// will sink it.
373func (x *Toast) SetActionTargetValue(ActionTargetVar *glib.Variant) {
374
375 xToastSetActionTargetValue(x.GoPointer(), ActionTargetVar)
376
377}
378
379var xToastSetButtonLabel func(uintptr, uintptr)
380
381// Sets the label to show on the button.
382//
383// Underlines in the button text can be used to indicate a mnemonic.
384//
385// If set to `NULL`, the button won't be shown.
386//
387// See [property@Toast:action-name].
388func (x *Toast) SetButtonLabel(ButtonLabelVar *string) {
389
390 ButtonLabelVarPtr := core.GStrdupNullable(ButtonLabelVar)
391 defer core.GFreeNullable(ButtonLabelVarPtr)
392
393 xToastSetButtonLabel(x.GoPointer(), ButtonLabelVarPtr)
394
395}
396
397var xToastSetCustomTitle func(uintptr, uintptr)
398
399// Sets the custom title widget of @self.
400//
401// It will be displayed instead of the title if set. In this case,
402// [property@Toast:title] is ignored.
403//
404// Setting a custom title will unset [property@Toast:title].
405func (x *Toast) SetCustomTitle(WidgetVar *gtk.Widget) {
406
407 xToastSetCustomTitle(x.GoPointer(), WidgetVar.GoPointer())
408
409}
410
411var xToastSetDetailedActionName func(uintptr, uintptr)
412
413// Sets the action name and its parameter.
414//
415// @detailed_action_name is a string in the format accepted by
416// [func@Gio.Action.parse_detailed_name].
417func (x *Toast) SetDetailedActionName(DetailedActionNameVar *string) {
418
419 DetailedActionNameVarPtr := core.GStrdupNullable(DetailedActionNameVar)
420 defer core.GFreeNullable(DetailedActionNameVarPtr)
421
422 xToastSetDetailedActionName(x.GoPointer(), DetailedActionNameVarPtr)
423
424}
425
426var xToastSetPriority func(uintptr, ToastPriority)
427
428// Sets priority for @self.
429//
430// Priority controls how the toast behaves when another toast is already
431// being displayed.
432//
433// If @priority is `ADW_TOAST_PRIORITY_NORMAL`, the toast will be queued.
434//
435// If @priority is `ADW_TOAST_PRIORITY_HIGH`, the toast will be displayed
436// immediately, pushing the previous toast into the queue instead.
437func (x *Toast) SetPriority(PriorityVar ToastPriority) {
438
439 xToastSetPriority(x.GoPointer(), PriorityVar)
440
441}
442
443var xToastSetTimeout func(uintptr, uint)
444
445// Sets timeout for @self.
446//
447// If @timeout is 0, the toast is displayed indefinitely until manually
448// dismissed.
449//
450// Toasts cannot disappear while being hovered, pressed (on touchscreen), or
451// have keyboard focus inside them.
452func (x *Toast) SetTimeout(TimeoutVar uint) {
453
454 xToastSetTimeout(x.GoPointer(), TimeoutVar)
455
456}
457
458var xToastSetTitle func(uintptr, string)
459
460// Sets the title that will be displayed on the toast.
461//
462// The title can be marked up with the Pango text markup language.
463//
464// Setting a title will unset [property@Toast:custom-title].
465//
466// If [property@Toast:custom-title] is set, it will be used instead.
467func (x *Toast) SetTitle(TitleVar string) {
468
469 xToastSetTitle(x.GoPointer(), TitleVar)
470
471}
472
473var xToastSetUseMarkup func(uintptr, bool)
474
475// Whether to use Pango markup for the toast title.
476//
477// See also [func@Pango.parse_markup].
478func (x *Toast) SetUseMarkup(UseMarkupVar bool) {
479
480 xToastSetUseMarkup(x.GoPointer(), UseMarkupVar)
481
482}
483
484func (c *Toast) GoPointer() uintptr {
485 if c == nil {
486 return 0
487 }
488 return c.Ptr
489}
490
491func (c *Toast) SetGoPointer(ptr uintptr) {
492 c.Ptr = ptr
493}
494
495// SetPropertyActionName sets the "action-name" property.
496// The name of the associated action.
497//
498// It will be activated when clicking the button.
499//
500// See [property@Toast:action-target].
501func (x *Toast) SetPropertyActionName(value string) {
502 var v gobject.Value
503 v.Init(gobject.TypeStringVal)
504 v.SetString(&value)
505 x.SetProperty("action-name", &v)
506}
507
508// GetPropertyActionName gets the "action-name" property.
509// The name of the associated action.
510//
511// It will be activated when clicking the button.
512//
513// See [property@Toast:action-target].
514func (x *Toast) GetPropertyActionName() string {
515 var v gobject.Value
516 x.GetProperty("action-name", &v)
517 return v.GetString()
518}
519
520// SetPropertyActionTarget sets the "action-target" property.
521// The parameter for action invocations.
522func (x *Toast) SetPropertyActionTarget(value uintptr) {
523 var v gobject.Value
524 v.Init(gobject.TypePointerVal)
525 v.SetPointer(value)
526 x.SetProperty("action-target", &v)
527}
528
529// GetPropertyActionTarget gets the "action-target" property.
530// The parameter for action invocations.
531func (x *Toast) GetPropertyActionTarget() uintptr {
532 var v gobject.Value
533 x.GetProperty("action-target", &v)
534 return v.GetPointer()
535}
536
537// SetPropertyButtonLabel sets the "button-label" property.
538// The label to show on the button.
539//
540// Underlines in the button text can be used to indicate a mnemonic.
541//
542// If set to `NULL`, the button won't be shown.
543//
544// See [property@Toast:action-name].
545func (x *Toast) SetPropertyButtonLabel(value string) {
546 var v gobject.Value
547 v.Init(gobject.TypeStringVal)
548 v.SetString(&value)
549 x.SetProperty("button-label", &v)
550}
551
552// GetPropertyButtonLabel gets the "button-label" property.
553// The label to show on the button.
554//
555// Underlines in the button text can be used to indicate a mnemonic.
556//
557// If set to `NULL`, the button won't be shown.
558//
559// See [property@Toast:action-name].
560func (x *Toast) GetPropertyButtonLabel() string {
561 var v gobject.Value
562 x.GetProperty("button-label", &v)
563 return v.GetString()
564}
565
566// SetPropertyTimeout sets the "timeout" property.
567// The timeout of the toast, in seconds.
568//
569// If timeout is 0, the toast is displayed indefinitely until manually
570// dismissed.
571//
572// Toasts cannot disappear while being hovered, pressed (on touchscreen), or
573// have keyboard focus inside them.
574func (x *Toast) SetPropertyTimeout(value uint) {
575 var v gobject.Value
576 v.Init(gobject.TypeUintVal)
577 v.SetUint(value)
578 x.SetProperty("timeout", &v)
579}
580
581// GetPropertyTimeout gets the "timeout" property.
582// The timeout of the toast, in seconds.
583//
584// If timeout is 0, the toast is displayed indefinitely until manually
585// dismissed.
586//
587// Toasts cannot disappear while being hovered, pressed (on touchscreen), or
588// have keyboard focus inside them.
589func (x *Toast) GetPropertyTimeout() uint {
590 var v gobject.Value
591 x.GetProperty("timeout", &v)
592 return v.GetUint()
593}
594
595// SetPropertyTitle sets the "title" property.
596// The title of the toast.
597//
598// The title can be marked up with the Pango text markup language.
599//
600// Setting a title will unset [property@Toast:custom-title].
601//
602// If [property@Toast:custom-title] is set, it will be used instead.
603func (x *Toast) SetPropertyTitle(value string) {
604 var v gobject.Value
605 v.Init(gobject.TypeStringVal)
606 v.SetString(&value)
607 x.SetProperty("title", &v)
608}
609
610// GetPropertyTitle gets the "title" property.
611// The title of the toast.
612//
613// The title can be marked up with the Pango text markup language.
614//
615// Setting a title will unset [property@Toast:custom-title].
616//
617// If [property@Toast:custom-title] is set, it will be used instead.
618func (x *Toast) GetPropertyTitle() string {
619 var v gobject.Value
620 x.GetProperty("title", &v)
621 return v.GetString()
622}
623
624// SetPropertyUseMarkup sets the "use-markup" property.
625// Whether to use Pango markup for the toast title.
626//
627// See also [func@Pango.parse_markup].
628func (x *Toast) SetPropertyUseMarkup(value bool) {
629 var v gobject.Value
630 v.Init(gobject.TypeBooleanVal)
631 v.SetBoolean(value)
632 x.SetProperty("use-markup", &v)
633}
634
635// GetPropertyUseMarkup gets the "use-markup" property.
636// Whether to use Pango markup for the toast title.
637//
638// See also [func@Pango.parse_markup].
639func (x *Toast) GetPropertyUseMarkup() bool {
640 var v gobject.Value
641 x.GetProperty("use-markup", &v)
642 return v.GetBoolean()
643}
644
645// Emitted after the button has been clicked.
646//
647// It can be used as an alternative to setting an action.
648func (x *Toast) ConnectButtonClicked(cb *func(Toast)) uint {
649 cbPtr := uintptr(unsafe.Pointer(cb))
650 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
651 handlerID := gobject.SignalConnect(x.GoPointer(), "button-clicked", cbRefPtr)
652 glib.SaveHandlerMapping(handlerID, cbPtr)
653 return handlerID
654 }
655
656 fcb := func(clsPtr uintptr) {
657 fa := Toast{}
658 fa.Ptr = clsPtr
659 cbFn := *cb
660
661 cbFn(fa)
662
663 }
664 cbRefPtr := purego.NewCallback(fcb)
665 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
666 handlerID := gobject.SignalConnect(x.GoPointer(), "button-clicked", cbRefPtr)
667 glib.SaveHandlerMapping(handlerID, cbPtr)
668 return handlerID
669}
670
671// Emitted when the toast has been dismissed.
672func (x *Toast) ConnectDismissed(cb *func(Toast)) uint {
673 cbPtr := uintptr(unsafe.Pointer(cb))
674 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
675 handlerID := gobject.SignalConnect(x.GoPointer(), "dismissed", cbRefPtr)
676 glib.SaveHandlerMapping(handlerID, cbPtr)
677 return handlerID
678 }
679
680 fcb := func(clsPtr uintptr) {
681 fa := Toast{}
682 fa.Ptr = clsPtr
683 cbFn := *cb
684
685 cbFn(fa)
686
687 }
688 cbRefPtr := purego.NewCallback(fcb)
689 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
690 handlerID := gobject.SignalConnect(x.GoPointer(), "dismissed", cbRefPtr)
691 glib.SaveHandlerMapping(handlerID, cbPtr)
692 return handlerID
693}
694
695func init() {
696 core.SetPackageName("ADW", "libadwaita-1")
697 core.SetSharedLibraries("ADW", []string{"libadwaita-1.so.0"})
698 var libs []uintptr
699 for _, libPath := range core.GetPaths("ADW") {
700 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
701 if err != nil {
702 panic(err)
703 }
704 libs = append(libs, lib)
705 }
706
707 core.PuregoSafeRegister(&xToastPriorityGLibType, libs, "adw_toast_priority_get_type")
708
709 core.PuregoSafeRegister(&xToastGLibType, libs, "adw_toast_get_type")
710
711 core.PuregoSafeRegister(&xNewToast, libs, "adw_toast_new")
712 core.PuregoSafeRegister(&xNewToastFormat, libs, "adw_toast_new_format")
713
714 core.PuregoSafeRegister(&xToastDismiss, libs, "adw_toast_dismiss")
715 core.PuregoSafeRegister(&xToastGetActionName, libs, "adw_toast_get_action_name")
716 core.PuregoSafeRegister(&xToastGetActionTargetValue, libs, "adw_toast_get_action_target_value")
717 core.PuregoSafeRegister(&xToastGetButtonLabel, libs, "adw_toast_get_button_label")
718 core.PuregoSafeRegister(&xToastGetCustomTitle, libs, "adw_toast_get_custom_title")
719 core.PuregoSafeRegister(&xToastGetPriority, libs, "adw_toast_get_priority")
720 core.PuregoSafeRegister(&xToastGetTimeout, libs, "adw_toast_get_timeout")
721 core.PuregoSafeRegister(&xToastGetTitle, libs, "adw_toast_get_title")
722 core.PuregoSafeRegister(&xToastGetUseMarkup, libs, "adw_toast_get_use_markup")
723 core.PuregoSafeRegister(&xToastSetActionName, libs, "adw_toast_set_action_name")
724 core.PuregoSafeRegister(&xToastSetActionTarget, libs, "adw_toast_set_action_target")
725 core.PuregoSafeRegister(&xToastSetActionTargetValue, libs, "adw_toast_set_action_target_value")
726 core.PuregoSafeRegister(&xToastSetButtonLabel, libs, "adw_toast_set_button_label")
727 core.PuregoSafeRegister(&xToastSetCustomTitle, libs, "adw_toast_set_custom_title")
728 core.PuregoSafeRegister(&xToastSetDetailedActionName, libs, "adw_toast_set_detailed_action_name")
729 core.PuregoSafeRegister(&xToastSetPriority, libs, "adw_toast_set_priority")
730 core.PuregoSafeRegister(&xToastSetTimeout, libs, "adw_toast_set_timeout")
731 core.PuregoSafeRegister(&xToastSetTitle, libs, "adw_toast_set_title")
732 core.PuregoSafeRegister(&xToastSetUseMarkup, libs, "adw_toast_set_use_markup")
733
734}