1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11)
12
13// Specifies the type of function passed to g_node_children_foreach().
14// The function is called with each child node, together with the user
15// data passed to g_node_children_foreach().
16type NodeForeachFunc func(*Node, uintptr)
17
18// Specifies the type of function passed to g_node_traverse(). The
19// function is called with each of the nodes visited, together with the
20// user data passed to g_node_traverse(). If the function returns
21// %TRUE, then the traversal is stopped.
22type NodeTraverseFunc func(*Node, uintptr) bool
23
24// The #GNode struct represents one node in a [n-ary tree](data-structures.html#n-ary-trees).
25type Node struct {
26 _ structs.HostLayout
27
28 Data uintptr
29
30 Next *Node
31
32 Prev *Node
33
34 Parent *Node
35
36 Children *Node
37}
38
39func (x *Node) GoPointer() uintptr {
40 return uintptr(unsafe.Pointer(x))
41}
42
43var xNodeChildIndex func(uintptr, uintptr) int
44
45// Gets the position of the first child of a #GNode
46// which contains the given data.
47func (x *Node) ChildIndex(DataVar uintptr) int {
48
49 cret := xNodeChildIndex(x.GoPointer(), DataVar)
50 return cret
51}
52
53var xNodeChildPosition func(uintptr, *Node) int
54
55// Gets the position of a #GNode with respect to its siblings.
56// @child must be a child of @node. The first child is numbered 0,
57// the second 1, and so on.
58func (x *Node) ChildPosition(ChildVar *Node) int {
59
60 cret := xNodeChildPosition(x.GoPointer(), ChildVar)
61 return cret
62}
63
64var xNodeChildrenForeach func(uintptr, TraverseFlags, uintptr, uintptr)
65
66// Calls a function for each of the children of a #GNode. Note that it
67// doesn't descend beneath the child nodes. @func must not do anything
68// that would modify the structure of the tree.
69func (x *Node) ChildrenForeach(FlagsVar TraverseFlags, FuncVar *NodeForeachFunc, DataVar uintptr) {
70
71 var FuncVarRef uintptr
72 if FuncVar != nil {
73 FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
74 if cbRefPtr, ok := GetCallback(FuncVarPtr); ok {
75 FuncVarRef = cbRefPtr
76 } else {
77 fcb := func(arg0 *Node, arg1 uintptr) {
78 cbFn := *FuncVar
79 cbFn(arg0, arg1)
80 }
81 FuncVarRef = purego.NewCallback(fcb)
82 SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
83 }
84 }
85
86 xNodeChildrenForeach(x.GoPointer(), FlagsVar, FuncVarRef, DataVar)
87
88}
89
90var xNodeCopy func(uintptr) *Node
91
92// Recursively copies a #GNode (but does not deep-copy the data inside the
93// nodes, see g_node_copy_deep() if you need that).
94func (x *Node) Copy() *Node {
95
96 cret := xNodeCopy(x.GoPointer())
97 return cret
98}
99
100var xNodeCopyDeep func(uintptr, uintptr, uintptr) *Node
101
102// Recursively copies a #GNode and its data.
103func (x *Node) CopyDeep(CopyFuncVar *CopyFunc, DataVar uintptr) *Node {
104
105 var CopyFuncVarRef uintptr
106 if CopyFuncVar != nil {
107 CopyFuncVarPtr := uintptr(unsafe.Pointer(CopyFuncVar))
108 if cbRefPtr, ok := GetCallback(CopyFuncVarPtr); ok {
109 CopyFuncVarRef = cbRefPtr
110 } else {
111 fcb := func(arg0 uintptr, arg1 uintptr) uintptr {
112 cbFn := *CopyFuncVar
113 return cbFn(arg0, arg1)
114 }
115 CopyFuncVarRef = purego.NewCallback(fcb)
116 SaveCallbackWithClosure(CopyFuncVarPtr, CopyFuncVarRef, CopyFuncVar)
117 }
118 }
119
120 cret := xNodeCopyDeep(x.GoPointer(), CopyFuncVarRef, DataVar)
121 return cret
122}
123
124var xNodeDepth func(uintptr) uint
125
126// Gets the depth of a #GNode.
127//
128// If @node is %NULL the depth is 0. The root node has a depth of 1.
129// For the children of the root node the depth is 2. And so on.
130func (x *Node) Depth() uint {
131
132 cret := xNodeDepth(x.GoPointer())
133 return cret
134}
135
136var xNodeDestroy func(uintptr)
137
138// Removes @root and its children from the tree, freeing any memory
139// allocated.
140func (x *Node) Destroy() {
141
142 xNodeDestroy(x.GoPointer())
143
144}
145
146var xNodeFind func(uintptr, TraverseType, TraverseFlags, uintptr) *Node
147
148// Finds a #GNode in a tree.
149func (x *Node) Find(OrderVar TraverseType, FlagsVar TraverseFlags, DataVar uintptr) *Node {
150
151 cret := xNodeFind(x.GoPointer(), OrderVar, FlagsVar, DataVar)
152 return cret
153}
154
155var xNodeFindChild func(uintptr, TraverseFlags, uintptr) *Node
156
157// Finds the first child of a #GNode with the given data.
158func (x *Node) FindChild(FlagsVar TraverseFlags, DataVar uintptr) *Node {
159
160 cret := xNodeFindChild(x.GoPointer(), FlagsVar, DataVar)
161 return cret
162}
163
164var xNodeFirstSibling func(uintptr) *Node
165
166// Gets the first sibling of a #GNode.
167// This could possibly be the node itself.
168func (x *Node) FirstSibling() *Node {
169
170 cret := xNodeFirstSibling(x.GoPointer())
171 return cret
172}
173
174var xNodeGetRoot func(uintptr) *Node
175
176// Gets the root of a tree.
177func (x *Node) GetRoot() *Node {
178
179 cret := xNodeGetRoot(x.GoPointer())
180 return cret
181}
182
183var xNodeInsert func(uintptr, int, *Node) *Node
184
185// Inserts a #GNode beneath the parent at the given position.
186func (x *Node) Insert(PositionVar int, NodeVar *Node) *Node {
187
188 cret := xNodeInsert(x.GoPointer(), PositionVar, NodeVar)
189 return cret
190}
191
192var xNodeInsertAfter func(uintptr, *Node, *Node) *Node
193
194// Inserts a #GNode beneath the parent after the given sibling.
195func (x *Node) InsertAfter(SiblingVar *Node, NodeVar *Node) *Node {
196
197 cret := xNodeInsertAfter(x.GoPointer(), SiblingVar, NodeVar)
198 return cret
199}
200
201var xNodeInsertBefore func(uintptr, *Node, *Node) *Node
202
203// Inserts a #GNode beneath the parent before the given sibling.
204func (x *Node) InsertBefore(SiblingVar *Node, NodeVar *Node) *Node {
205
206 cret := xNodeInsertBefore(x.GoPointer(), SiblingVar, NodeVar)
207 return cret
208}
209
210var xNodeIsAncestor func(uintptr, *Node) bool
211
212// Returns %TRUE if @node is an ancestor of @descendant.
213// This is true if node is the parent of @descendant,
214// or if node is the grandparent of @descendant etc.
215func (x *Node) IsAncestor(DescendantVar *Node) bool {
216
217 cret := xNodeIsAncestor(x.GoPointer(), DescendantVar)
218 return cret
219}
220
221var xNodeLastChild func(uintptr) *Node
222
223// Gets the last child of a #GNode.
224func (x *Node) LastChild() *Node {
225
226 cret := xNodeLastChild(x.GoPointer())
227 return cret
228}
229
230var xNodeLastSibling func(uintptr) *Node
231
232// Gets the last sibling of a #GNode.
233// This could possibly be the node itself.
234func (x *Node) LastSibling() *Node {
235
236 cret := xNodeLastSibling(x.GoPointer())
237 return cret
238}
239
240var xNodeMaxHeight func(uintptr) uint
241
242// Gets the maximum height of all branches beneath a #GNode.
243// This is the maximum distance from the #GNode to all leaf nodes.
244//
245// If @root is %NULL, 0 is returned. If @root has no children,
246// 1 is returned. If @root has children, 2 is returned. And so on.
247func (x *Node) MaxHeight() uint {
248
249 cret := xNodeMaxHeight(x.GoPointer())
250 return cret
251}
252
253var xNodeNChildren func(uintptr) uint
254
255// Gets the number of children of a #GNode.
256func (x *Node) NChildren() uint {
257
258 cret := xNodeNChildren(x.GoPointer())
259 return cret
260}
261
262var xNodeNNodes func(uintptr, TraverseFlags) uint
263
264// Gets the number of nodes in a tree.
265func (x *Node) NNodes(FlagsVar TraverseFlags) uint {
266
267 cret := xNodeNNodes(x.GoPointer(), FlagsVar)
268 return cret
269}
270
271var xNodeNthChild func(uintptr, uint) *Node
272
273// Gets a child of a #GNode, using the given index.
274// The first child is at index 0. If the index is
275// too big, %NULL is returned.
276func (x *Node) NthChild(NVar uint) *Node {
277
278 cret := xNodeNthChild(x.GoPointer(), NVar)
279 return cret
280}
281
282var xNodePrepend func(uintptr, *Node) *Node
283
284// Inserts a #GNode as the first child of the given parent.
285func (x *Node) Prepend(NodeVar *Node) *Node {
286
287 cret := xNodePrepend(x.GoPointer(), NodeVar)
288 return cret
289}
290
291var xNodeReverseChildren func(uintptr)
292
293// Reverses the order of the children of a #GNode.
294// (It doesn't change the order of the grandchildren.)
295func (x *Node) ReverseChildren() {
296
297 xNodeReverseChildren(x.GoPointer())
298
299}
300
301var xNodeTraverse func(uintptr, TraverseType, TraverseFlags, int, uintptr, uintptr)
302
303// Traverses a tree starting at the given root #GNode.
304// It calls the given function for each node visited.
305// The traversal can be halted at any point by returning %TRUE from @func.
306// @func must not do anything that would modify the structure of the tree.
307func (x *Node) Traverse(OrderVar TraverseType, FlagsVar TraverseFlags, MaxDepthVar int, FuncVar *NodeTraverseFunc, DataVar uintptr) {
308
309 var FuncVarRef uintptr
310 if FuncVar != nil {
311 FuncVarPtr := uintptr(unsafe.Pointer(FuncVar))
312 if cbRefPtr, ok := GetCallback(FuncVarPtr); ok {
313 FuncVarRef = cbRefPtr
314 } else {
315 fcb := func(arg0 *Node, arg1 uintptr) bool {
316 cbFn := *FuncVar
317 return cbFn(arg0, arg1)
318 }
319 FuncVarRef = purego.NewCallback(fcb)
320 SaveCallbackWithClosure(FuncVarPtr, FuncVarRef, FuncVar)
321 }
322 }
323
324 xNodeTraverse(x.GoPointer(), OrderVar, FlagsVar, MaxDepthVar, FuncVarRef, DataVar)
325
326}
327
328var xNodeUnlink func(uintptr)
329
330// Unlinks a #GNode from a tree, resulting in two separate trees.
331func (x *Node) Unlink() {
332
333 xNodeUnlink(x.GoPointer())
334
335}
336
337// Specifies which nodes are visited during several of the tree
338// functions, including g_node_traverse() and g_node_find().
339type TraverseFlags int
340
341const (
342
343 // only leaf nodes should be visited. This name has
344 // been introduced in 2.6, for older version use
345 // %G_TRAVERSE_LEAFS.
346 GTraverseLeavesValue TraverseFlags = 1
347 // only non-leaf nodes should be visited. This
348 // name has been introduced in 2.6, for older
349 // version use %G_TRAVERSE_NON_LEAFS.
350 GTraverseNonLeavesValue TraverseFlags = 2
351 // all nodes should be visited.
352 GTraverseAllValue TraverseFlags = 3
353 // a mask of all traverse flags.
354 GTraverseMaskValue TraverseFlags = 3
355 // identical to %G_TRAVERSE_LEAVES.
356 GTraverseLeafsValue TraverseFlags = 1
357 // identical to %G_TRAVERSE_NON_LEAVES.
358 GTraverseNonLeafsValue TraverseFlags = 2
359)
360
361// Specifies the type of traversal performed by g_tree_traverse(),
362// g_node_traverse() and g_node_find().
363//
364// The different orders are illustrated here:
365//
366// - In order: A, B, C, D, E, F, G, H, I
367// <picture>
368// <source srcset="Sorted_binary_tree_inorder-dark.svg"
369// media="(prefers-color-scheme: dark)">
370// <img src="Sorted_binary_tree_inorder.svg"
371// alt="Sorted binary tree, in-order traversal">
372// </picture>
373// - Pre order: F, B, A, D, C, E, G, I, H
374// <picture>
375// <source srcset="Sorted_binary_tree_preorder-dark.svg"
376// media="(prefers-color-scheme: dark)">
377// <img src="Sorted_binary_tree_preorder.svg"
378// alt="Sorted binary tree, pre-order traversal">
379// </picture>
380// - Post order: A, C, E, D, B, H, I, G, F
381// <picture>
382// <source srcset="Sorted_binary_tree_postorder-dark.svg"
383// media="(prefers-color-scheme: dark)">
384// <img src="Sorted_binary_tree_postorder.svg"
385// alt="Sorted binary tree, post-order traversal">
386// </picture>
387// - Level order: F, B, G, A, D, I, C, E, H
388// <picture>
389// <source srcset="Sorted_binary_tree_breadth-first_traversal-dark.svg"
390// media="(prefers-color-scheme: dark)">
391// <img src="Sorted_binary_tree_breadth-first_traversal.svg"
392// alt="Sorted binary tree, breadth-first level order traversal">
393// </picture>
394type TraverseType int
395
396const (
397
398 // visits a node's left child first, then the node itself,
399 // then its right child. This is the one to use if you
400 // want the output sorted according to the compare
401 // function.
402 GInOrderValue TraverseType = 0
403 // visits a node, then its children.
404 GPreOrderValue TraverseType = 1
405 // visits the node's children, then the node itself.
406 GPostOrderValue TraverseType = 2
407 // is not implemented for
408 // [balanced binary trees](data-structures.html#binary-trees).
409 // For [n-ary trees](data-structures.html#n-ary-trees), it
410 // visits the root node first, then its children, then
411 // its grandchildren, and so on. Note that this is less
412 // efficient than the other orders.
413 GLevelOrderValue TraverseType = 3
414)
415
416func init() {
417 core.SetPackageName("GLIB", "glib-2.0")
418 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
419 var libs []uintptr
420 for _, libPath := range core.GetPaths("GLIB") {
421 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
422 if err != nil {
423 panic(err)
424 }
425 libs = append(libs, lib)
426 }
427
428 core.PuregoSafeRegister(&xNodeChildIndex, libs, "g_node_child_index")
429 core.PuregoSafeRegister(&xNodeChildPosition, libs, "g_node_child_position")
430 core.PuregoSafeRegister(&xNodeChildrenForeach, libs, "g_node_children_foreach")
431 core.PuregoSafeRegister(&xNodeCopy, libs, "g_node_copy")
432 core.PuregoSafeRegister(&xNodeCopyDeep, libs, "g_node_copy_deep")
433 core.PuregoSafeRegister(&xNodeDepth, libs, "g_node_depth")
434 core.PuregoSafeRegister(&xNodeDestroy, libs, "g_node_destroy")
435 core.PuregoSafeRegister(&xNodeFind, libs, "g_node_find")
436 core.PuregoSafeRegister(&xNodeFindChild, libs, "g_node_find_child")
437 core.PuregoSafeRegister(&xNodeFirstSibling, libs, "g_node_first_sibling")
438 core.PuregoSafeRegister(&xNodeGetRoot, libs, "g_node_get_root")
439 core.PuregoSafeRegister(&xNodeInsert, libs, "g_node_insert")
440 core.PuregoSafeRegister(&xNodeInsertAfter, libs, "g_node_insert_after")
441 core.PuregoSafeRegister(&xNodeInsertBefore, libs, "g_node_insert_before")
442 core.PuregoSafeRegister(&xNodeIsAncestor, libs, "g_node_is_ancestor")
443 core.PuregoSafeRegister(&xNodeLastChild, libs, "g_node_last_child")
444 core.PuregoSafeRegister(&xNodeLastSibling, libs, "g_node_last_sibling")
445 core.PuregoSafeRegister(&xNodeMaxHeight, libs, "g_node_max_height")
446 core.PuregoSafeRegister(&xNodeNChildren, libs, "g_node_n_children")
447 core.PuregoSafeRegister(&xNodeNNodes, libs, "g_node_n_nodes")
448 core.PuregoSafeRegister(&xNodeNthChild, libs, "g_node_nth_child")
449 core.PuregoSafeRegister(&xNodePrepend, libs, "g_node_prepend")
450 core.PuregoSafeRegister(&xNodeReverseChildren, libs, "g_node_reverse_children")
451 core.PuregoSafeRegister(&xNodeTraverse, libs, "g_node_traverse")
452 core.PuregoSafeRegister(&xNodeUnlink, libs, "g_node_unlink")
453
454}