1// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gtk
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/cairo"
12 "github.com/bnema/puregotk/v4/glib"
13 "github.com/bnema/puregotk/v4/gobject"
14 "github.com/bnema/puregotk/v4/gobject/types"
15)
16
17// Whenever @drawing_area needs to redraw, this function will be called.
18//
19// This function should exclusively redraw the contents of the drawing area
20// and must not call any widget functions that cause changes.
21type DrawingAreaDrawFunc func(uintptr, *cairo.Context, int, int, uintptr)
22
23type DrawingAreaClass struct {
24 _ structs.HostLayout
25
26 ParentClass WidgetClass
27
28 xResize uintptr
29
30 Padding [8]uintptr
31}
32
33func (x *DrawingAreaClass) GoPointer() uintptr {
34 return uintptr(unsafe.Pointer(x))
35}
36
37// OverrideResize sets the "resize" callback function.
38func (x *DrawingAreaClass) OverrideResize(cb func(*DrawingArea, int, int)) {
39 if cb == nil {
40 x.xResize = 0
41 } else {
42 x.xResize = purego.NewCallback(func(AreaVarp uintptr, WidthVarp int, HeightVarp int) {
43 cb(DrawingAreaNewFromInternalPtr(AreaVarp), WidthVarp, HeightVarp)
44 })
45 }
46}
47
48// GetResize gets the "resize" callback function.
49func (x *DrawingAreaClass) GetResize() func(*DrawingArea, int, int) {
50 if x.xResize == 0 {
51 return nil
52 }
53 var rawCallback func(AreaVarp uintptr, WidthVarp int, HeightVarp int)
54 purego.RegisterFunc(&rawCallback, x.xResize)
55 return func(AreaVar *DrawingArea, WidthVar int, HeightVar int) {
56 rawCallback(AreaVar.GoPointer(), WidthVar, HeightVar)
57 }
58}
59
60// Allows drawing with cairo.
61//
62// <picture>
63//
64// <source srcset="drawingarea-dark.png" media="(prefers-color-scheme: dark)">
65// <img alt="An example GtkDrawingArea" src="drawingarea.png">
66//
67// </picture>
68//
69// It’s essentially a blank widget; you can draw on it. After
70// creating a drawing area, the application may want to connect to:
71//
72// - The [signal@Gtk.Widget::realize] signal to take any necessary actions
73// when the widget is instantiated on a particular display.
74// (Create GDK resources in response to this signal.)
75//
76// - The [signal@Gtk.DrawingArea::resize] signal to take any necessary
77// actions when the widget changes size.
78//
79// - Call [method@Gtk.DrawingArea.set_draw_func] to handle redrawing the
80// contents of the widget.
81//
82// The following code portion demonstrates using a drawing
83// area to display a circle in the normal widget foreground
84// color.
85//
86// ## Simple GtkDrawingArea usage
87//
88// ```c
89// static void
90// draw_function (GtkDrawingArea *area,
91//
92// cairo_t *cr,
93// int width,
94// int height,
95// gpointer data)
96//
97// {
98// GdkRGBA color;
99//
100// cairo_arc (cr,
101// width / 2.0, height / 2.0,
102// MIN (width, height) / 2.0,
103// 0, 2 * G_PI);
104//
105// gtk_widget_get_color (GTK_WIDGET (area),
106// &color);
107// gdk_cairo_set_source_rgba (cr, &color);
108//
109// cairo_fill (cr);
110// }
111//
112// int
113// main (int argc, char **argv)
114//
115// {
116// gtk_init ();
117//
118// GtkWidget *area = gtk_drawing_area_new ();
119// gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (area), 100);
120// gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (area), 100);
121// gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (area),
122// draw_function,
123// NULL, NULL);
124// return 0;
125// }
126//
127// ```
128//
129// The draw function is normally called when a drawing area first comes
130// onscreen, or when it’s covered by another window and then uncovered.
131// You can also force a redraw by adding to the “damage region” of the
132// drawing area’s window using [method@Gtk.Widget.queue_draw].
133// This will cause the drawing area to call the draw function again.
134//
135// The available routines for drawing are documented in the
136// [Cairo documentation](https://www.cairographics.org/manual/); GDK
137// offers additional API to integrate with Cairo, like [func@Gdk.cairo_set_source_rgba]
138// or [func@Gdk.cairo_set_source_pixbuf].
139//
140// To receive mouse events on a drawing area, you will need to use
141// event controllers. To receive keyboard events, you will need to set
142// the “can-focus” property on the drawing area, and you should probably
143// draw some user-visible indication that the drawing area is focused.
144//
145// If you need more complex control over your widget, you should consider
146// creating your own `GtkWidget` subclass.
147type DrawingArea struct {
148 Widget
149}
150
151var xDrawingAreaGLibType func() types.GType
152
153func DrawingAreaGLibType() types.GType {
154 return xDrawingAreaGLibType()
155}
156
157func DrawingAreaNewFromInternalPtr(ptr uintptr) *DrawingArea {
158 cls := &DrawingArea{}
159 cls.Ptr = ptr
160 return cls
161}
162
163var xNewDrawingArea func() uintptr
164
165// Creates a new drawing area.
166func NewDrawingArea() *DrawingArea {
167 var cls *DrawingArea
168
169 cret := xNewDrawingArea()
170
171 if cret == 0 {
172 return nil
173 }
174 gobject.IncreaseRef(cret)
175 cls = &DrawingArea{}
176 cls.Ptr = cret
177 return cls
178}
179
180var xDrawingAreaGetContentHeight func(uintptr) int
181
182// Retrieves the content height of the `GtkDrawingArea`.
183func (x *DrawingArea) GetContentHeight() int {
184
185 cret := xDrawingAreaGetContentHeight(x.GoPointer())
186 return cret
187}
188
189var xDrawingAreaGetContentWidth func(uintptr) int
190
191// Retrieves the content width of the `GtkDrawingArea`.
192func (x *DrawingArea) GetContentWidth() int {
193
194 cret := xDrawingAreaGetContentWidth(x.GoPointer())
195 return cret
196}
197
198var xDrawingAreaSetContentHeight func(uintptr, int)
199
200// Sets the desired height of the contents of the drawing area.
201//
202// Note that because widgets may be allocated larger sizes than they
203// requested, it is possible that the actual height passed to your draw
204// function is larger than the height set here. You can use
205// [method@Gtk.Widget.set_valign] to avoid that.
206//
207// If the height is set to 0 (the default), the drawing area may disappear.
208func (x *DrawingArea) SetContentHeight(HeightVar int) {
209
210 xDrawingAreaSetContentHeight(x.GoPointer(), HeightVar)
211
212}
213
214var xDrawingAreaSetContentWidth func(uintptr, int)
215
216// Sets the desired width of the contents of the drawing area.
217//
218// Note that because widgets may be allocated larger sizes than they
219// requested, it is possible that the actual width passed to your draw
220// function is larger than the width set here. You can use
221// [method@Gtk.Widget.set_halign] to avoid that.
222//
223// If the width is set to 0 (the default), the drawing area may disappear.
224func (x *DrawingArea) SetContentWidth(WidthVar int) {
225
226 xDrawingAreaSetContentWidth(x.GoPointer(), WidthVar)
227
228}
229
230var xDrawingAreaSetDrawFunc func(uintptr, uintptr, uintptr, uintptr)
231
232// Setting a draw function is the main thing you want to do when using
233// a drawing area.
234//
235// The draw function is called whenever GTK needs to draw the contents
236// of the drawing area to the screen.
237//
238// The draw function will be called during the drawing stage of GTK.
239// In the drawing stage it is not allowed to change properties of any
240// GTK widgets or call any functions that would cause any properties
241// to be changed. You should restrict yourself exclusively to drawing
242// your contents in the draw function.
243//
244// If what you are drawing does change, call [method@Gtk.Widget.queue_draw]
245// on the drawing area. This will cause a redraw and will call @draw_func again.
246func (x *DrawingArea) SetDrawFunc(DrawFuncVar *DrawingAreaDrawFunc, UserDataVar uintptr, DestroyVar *glib.DestroyNotify) {
247
248 var DrawFuncVarRef uintptr
249 if DrawFuncVar != nil {
250 DrawFuncVarPtr := uintptr(unsafe.Pointer(DrawFuncVar))
251 if cbRefPtr, ok := glib.GetCallback(DrawFuncVarPtr); ok {
252 DrawFuncVarRef = cbRefPtr
253 } else {
254 fcb := func(arg0 uintptr, arg1 *cairo.Context, arg2 int, arg3 int, arg4 uintptr) {
255 cbFn := *DrawFuncVar
256 cbFn(arg0, arg1, arg2, arg3, arg4)
257 }
258 DrawFuncVarRef = purego.NewCallback(fcb)
259 glib.SaveCallbackWithClosure(DrawFuncVarPtr, DrawFuncVarRef, DrawFuncVar)
260 }
261 }
262
263 var DestroyVarRef uintptr
264 if DestroyVar != nil {
265 DestroyVarPtr := uintptr(unsafe.Pointer(DestroyVar))
266 if cbRefPtr, ok := glib.GetCallback(DestroyVarPtr); ok {
267 DestroyVarRef = cbRefPtr
268 } else {
269 fcb := func(arg0 uintptr) {
270 cbFn := *DestroyVar
271 cbFn(arg0)
272 }
273 DestroyVarRef = purego.NewCallback(fcb)
274 glib.SaveCallbackWithClosure(DestroyVarPtr, DestroyVarRef, DestroyVar)
275 }
276 }
277
278 xDrawingAreaSetDrawFunc(x.GoPointer(), DrawFuncVarRef, UserDataVar, DestroyVarRef)
279
280}
281
282func (c *DrawingArea) GoPointer() uintptr {
283 if c == nil {
284 return 0
285 }
286 return c.Ptr
287}
288
289func (c *DrawingArea) SetGoPointer(ptr uintptr) {
290 c.Ptr = ptr
291}
292
293// SetPropertyContentHeight sets the "content-height" property.
294// The content height.
295func (x *DrawingArea) SetPropertyContentHeight(value int) {
296 var v gobject.Value
297 v.Init(gobject.TypeIntVal)
298 v.SetInt(value)
299 x.SetProperty("content-height", &v)
300}
301
302// GetPropertyContentHeight gets the "content-height" property.
303// The content height.
304func (x *DrawingArea) GetPropertyContentHeight() int {
305 var v gobject.Value
306 x.GetProperty("content-height", &v)
307 return v.GetInt()
308}
309
310// SetPropertyContentWidth sets the "content-width" property.
311// The content width.
312func (x *DrawingArea) SetPropertyContentWidth(value int) {
313 var v gobject.Value
314 v.Init(gobject.TypeIntVal)
315 v.SetInt(value)
316 x.SetProperty("content-width", &v)
317}
318
319// GetPropertyContentWidth gets the "content-width" property.
320// The content width.
321func (x *DrawingArea) GetPropertyContentWidth() int {
322 var v gobject.Value
323 x.GetProperty("content-width", &v)
324 return v.GetInt()
325}
326
327// Emitted once when the widget is realized, and then each time the widget
328// is changed while realized.
329//
330// This is useful in order to keep state up to date with the widget size,
331// like for instance a backing surface.
332func (x *DrawingArea) ConnectResize(cb *func(DrawingArea, int, int)) uint {
333 cbPtr := uintptr(unsafe.Pointer(cb))
334 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
335 handlerID := gobject.SignalConnect(x.GoPointer(), "resize", cbRefPtr)
336 glib.SaveHandlerMapping(handlerID, cbPtr)
337 return handlerID
338 }
339
340 fcb := func(clsPtr uintptr, WidthVarp int, HeightVarp int) {
341 fa := DrawingArea{}
342 fa.Ptr = clsPtr
343 cbFn := *cb
344
345 cbFn(fa, WidthVarp, HeightVarp)
346
347 }
348 cbRefPtr := purego.NewCallback(fcb)
349 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
350 handlerID := gobject.SignalConnect(x.GoPointer(), "resize", cbRefPtr)
351 glib.SaveHandlerMapping(handlerID, cbPtr)
352 return handlerID
353}
354
355// Requests the user's screen reader to announce the given message.
356//
357// This kind of notification is useful for messages that
358// either have only a visual representation or that are not
359// exposed visually at all, e.g. a notification about a
360// successful operation.
361//
362// Also, by using this API, you can ensure that the message
363// does not interrupts the user's current screen reader output.
364func (x *DrawingArea) Announce(MessageVar string, PriorityVar AccessibleAnnouncementPriority) {
365
366 XGtkAccessibleAnnounce(x.GoPointer(), MessageVar, PriorityVar)
367
368}
369
370// Retrieves the accessible parent for an accessible object.
371//
372// This function returns `NULL` for top level widgets.
373func (x *DrawingArea) GetAccessibleParent() *AccessibleBase {
374 var cls *AccessibleBase
375
376 cret := XGtkAccessibleGetAccessibleParent(x.GoPointer())
377
378 if cret == 0 {
379 return nil
380 }
381 cls = &AccessibleBase{}
382 cls.Ptr = cret
383 return cls
384}
385
386// Retrieves the accessible role of an accessible object.
387func (x *DrawingArea) GetAccessibleRole() AccessibleRole {
388
389 cret := XGtkAccessibleGetAccessibleRole(x.GoPointer())
390 return cret
391}
392
393// Retrieves the implementation for the given accessible object.
394func (x *DrawingArea) GetAtContext() *ATContext {
395 var cls *ATContext
396
397 cret := XGtkAccessibleGetAtContext(x.GoPointer())
398
399 if cret == 0 {
400 return nil
401 }
402 cls = &ATContext{}
403 cls.Ptr = cret
404 return cls
405}
406
407// Queries the coordinates and dimensions of this accessible
408//
409// This functionality can be overridden by `GtkAccessible`
410// implementations, e.g. to get the bounds from an ignored
411// child widget.
412func (x *DrawingArea) GetBounds(XVar *int, YVar *int, WidthVar *int, HeightVar *int) bool {
413
414 cret := XGtkAccessibleGetBounds(x.GoPointer(), XVar, YVar, WidthVar, HeightVar)
415 return cret
416}
417
418// Retrieves the first accessible child of an accessible object.
419func (x *DrawingArea) GetFirstAccessibleChild() *AccessibleBase {
420 var cls *AccessibleBase
421
422 cret := XGtkAccessibleGetFirstAccessibleChild(x.GoPointer())
423
424 if cret == 0 {
425 return nil
426 }
427 cls = &AccessibleBase{}
428 cls.Ptr = cret
429 return cls
430}
431
432// Retrieves the next accessible sibling of an accessible object
433func (x *DrawingArea) GetNextAccessibleSibling() *AccessibleBase {
434 var cls *AccessibleBase
435
436 cret := XGtkAccessibleGetNextAccessibleSibling(x.GoPointer())
437
438 if cret == 0 {
439 return nil
440 }
441 cls = &AccessibleBase{}
442 cls.Ptr = cret
443 return cls
444}
445
446// Queries a platform state, such as focus.
447//
448// This functionality can be overridden by `GtkAccessible`
449// implementations, e.g. to get platform state from an ignored
450// child widget, as is the case for `GtkText` wrappers.
451func (x *DrawingArea) GetPlatformState(StateVar AccessiblePlatformState) bool {
452
453 cret := XGtkAccessibleGetPlatformState(x.GoPointer(), StateVar)
454 return cret
455}
456
457// Resets the accessible property to its default value.
458func (x *DrawingArea) ResetProperty(PropertyVar AccessibleProperty) {
459
460 XGtkAccessibleResetProperty(x.GoPointer(), PropertyVar)
461
462}
463
464// Resets the accessible relation to its default value.
465func (x *DrawingArea) ResetRelation(RelationVar AccessibleRelation) {
466
467 XGtkAccessibleResetRelation(x.GoPointer(), RelationVar)
468
469}
470
471// Resets the accessible state to its default value.
472func (x *DrawingArea) ResetState(StateVar AccessibleState) {
473
474 XGtkAccessibleResetState(x.GoPointer(), StateVar)
475
476}
477
478// Sets the parent and sibling of an accessible object.
479//
480// This function is meant to be used by accessible implementations that are
481// not part of the widget hierarchy, and but act as a logical bridge between
482// widgets. For instance, if a widget creates an object that holds metadata
483// for each child, and you want that object to implement the `GtkAccessible`
484// interface, you will use this function to ensure that the parent of each
485// child widget is the metadata object, and the parent of each metadata
486// object is the container widget.
487func (x *DrawingArea) SetAccessibleParent(ParentVar Accessible, NextSiblingVar Accessible) {
488
489 XGtkAccessibleSetAccessibleParent(x.GoPointer(), ParentVar.GoPointer(), NextSiblingVar.GoPointer())
490
491}
492
493// Updates the next accessible sibling.
494//
495// That might be useful when a new child of a custom accessible
496// is created, and it needs to be linked to a previous child.
497func (x *DrawingArea) UpdateNextAccessibleSibling(NewSiblingVar Accessible) {
498
499 XGtkAccessibleUpdateNextAccessibleSibling(x.GoPointer(), NewSiblingVar.GoPointer())
500
501}
502
503// Informs ATs that the platform state has changed.
504//
505// This function should be used by `GtkAccessible` implementations that
506// have a platform state but are not widgets. Widgets handle platform
507// states automatically.
508func (x *DrawingArea) UpdatePlatformState(StateVar AccessiblePlatformState) {
509
510 XGtkAccessibleUpdatePlatformState(x.GoPointer(), StateVar)
511
512}
513
514// Updates a list of accessible properties.
515//
516// See the [enum@Gtk.AccessibleProperty] documentation for the
517// value types of accessible properties.
518//
519// This function should be called by `GtkWidget` types whenever
520// an accessible property change must be communicated to assistive
521// technologies.
522//
523// Example:
524// ```c
525// value = gtk_adjustment_get_value (adjustment);
526// gtk_accessible_update_property (GTK_ACCESSIBLE (spin_button),
527//
528// GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, value,
529// -1);
530//
531// ```
532func (x *DrawingArea) UpdateProperty(FirstPropertyVar AccessibleProperty, varArgs ...interface{}) {
533
534 XGtkAccessibleUpdateProperty(x.GoPointer(), FirstPropertyVar, varArgs...)
535
536}
537
538// Updates an array of accessible properties.
539//
540// This function should be called by `GtkWidget` types whenever an accessible
541// property change must be communicated to assistive technologies.
542//
543// This function is meant to be used by language bindings.
544func (x *DrawingArea) UpdatePropertyValue(NPropertiesVar int, PropertiesVar []AccessibleProperty, ValuesVar []gobject.Value) {
545
546 XGtkAccessibleUpdatePropertyValue(x.GoPointer(), NPropertiesVar, PropertiesVar, ValuesVar)
547
548}
549
550// Updates a list of accessible relations.
551//
552// This function should be called by `GtkWidget` types whenever an accessible
553// relation change must be communicated to assistive technologies.
554//
555// If the [enum@Gtk.AccessibleRelation] requires a list of references,
556// you should pass each reference individually, followed by `NULL`, e.g.
557//
558// ```c
559// gtk_accessible_update_relation (accessible,
560//
561// GTK_ACCESSIBLE_RELATION_CONTROLS,
562// ref1, NULL,
563// GTK_ACCESSIBLE_RELATION_LABELLED_BY,
564// ref1, ref2, ref3, NULL,
565// -1);
566//
567// ```
568func (x *DrawingArea) UpdateRelation(FirstRelationVar AccessibleRelation, varArgs ...interface{}) {
569
570 XGtkAccessibleUpdateRelation(x.GoPointer(), FirstRelationVar, varArgs...)
571
572}
573
574// Updates an array of accessible relations.
575//
576// This function should be called by `GtkWidget` types whenever an accessible
577// relation change must be communicated to assistive technologies.
578//
579// This function is meant to be used by language bindings.
580func (x *DrawingArea) UpdateRelationValue(NRelationsVar int, RelationsVar []AccessibleRelation, ValuesVar []gobject.Value) {
581
582 XGtkAccessibleUpdateRelationValue(x.GoPointer(), NRelationsVar, RelationsVar, ValuesVar)
583
584}
585
586// Updates a list of accessible states.
587//
588// See the [enum@Gtk.AccessibleState] documentation for the
589// value types of accessible states.
590//
591// This function should be called by `GtkWidget` types whenever
592// an accessible state change must be communicated to assistive
593// technologies.
594//
595// Example:
596//
597// ```c
598// value = GTK_ACCESSIBLE_TRISTATE_MIXED;
599// gtk_accessible_update_state (GTK_ACCESSIBLE (check_button),
600//
601// GTK_ACCESSIBLE_STATE_CHECKED, value,
602// -1);
603//
604// ```
605func (x *DrawingArea) UpdateState(FirstStateVar AccessibleState, varArgs ...interface{}) {
606
607 XGtkAccessibleUpdateState(x.GoPointer(), FirstStateVar, varArgs...)
608
609}
610
611// Updates an array of accessible states.
612//
613// This function should be called by `GtkWidget` types whenever an accessible
614// state change must be communicated to assistive technologies.
615//
616// This function is meant to be used by language bindings.
617func (x *DrawingArea) UpdateStateValue(NStatesVar int, StatesVar []AccessibleState, ValuesVar []gobject.Value) {
618
619 XGtkAccessibleUpdateStateValue(x.GoPointer(), NStatesVar, StatesVar, ValuesVar)
620
621}
622
623// Gets the ID of the @buildable object.
624//
625// `GtkBuilder` sets the name based on the ID attribute
626// of the `<object>` tag used to construct the @buildable.
627func (x *DrawingArea) GetBuildableId() string {
628
629 cret := XGtkBuildableGetBuildableId(x.GoPointer())
630 return cret
631}
632
633func init() {
634 core.SetPackageName("GTK", "gtk4")
635 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
636 var libs []uintptr
637 for _, libPath := range core.GetPaths("GTK") {
638 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
639 if err != nil {
640 panic(err)
641 }
642 libs = append(libs, lib)
643 }
644
645 core.PuregoSafeRegister(&xDrawingAreaGLibType, libs, "gtk_drawing_area_get_type")
646
647 core.PuregoSafeRegister(&xNewDrawingArea, libs, "gtk_drawing_area_new")
648
649 core.PuregoSafeRegister(&xDrawingAreaGetContentHeight, libs, "gtk_drawing_area_get_content_height")
650 core.PuregoSafeRegister(&xDrawingAreaGetContentWidth, libs, "gtk_drawing_area_get_content_width")
651 core.PuregoSafeRegister(&xDrawingAreaSetContentHeight, libs, "gtk_drawing_area_set_content_height")
652 core.PuregoSafeRegister(&xDrawingAreaSetContentWidth, libs, "gtk_drawing_area_set_content_width")
653 core.PuregoSafeRegister(&xDrawingAreaSetDrawFunc, libs, "gtk_drawing_area_set_draw_func")
654
655}