1// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gtk
3
4import (
5 "github.com/ebitengine/purego"
6
7 "github.com/bnema/puregotk/pkg/core"
8 "github.com/bnema/puregotk/v4/glib"
9 "github.com/bnema/puregotk/v4/gobject"
10 "github.com/bnema/puregotk/v4/gobject/types"
11)
12
13// Groups widgets together so they all request the same size.
14//
15// This is typically useful when you want a column of widgets to have
16// the same size, but you can’t use a [class@Gtk.Grid] or [class@Gtk.Box].
17//
18// In detail, the size requested for each widget in a `GtkSizeGroup` is
19// the maximum of the sizes that would have been requested for each
20// widget in the size group if they were not in the size group. The
21// [mode][method@Gtk.SizeGroup.set_mode] of the size group determines
22// whether this applies to the horizontal size, the vertical size, or
23// both sizes.
24//
25// Note that size groups only affect the amount of space requested, not
26// the size that the widgets finally receive. If you want the widgets in
27// a `GtkSizeGroup` to actually be the same size, you need to pack them in
28// such a way that they get the size they request and not more. In
29// particular it doesn't make a lot of sense to set
30// [the expand flags][method@Gtk.Widget.set_hexpand] on the widgets that
31// are members of a size group.
32//
33// `GtkSizeGroup` objects are referenced by each widget in the size group,
34// so once you have added all widgets to a `GtkSizeGroup`, you can drop
35// the initial reference to the size group with
36// [method@GObject.Object.unref]. If the widgets in the size group are
37// subsequently destroyed, then they will be removed from the size group
38// and drop their references on the size group; when all widgets have been
39// removed, the size group will be freed.
40//
41// Widgets can be part of multiple size groups; GTK will compute the
42// horizontal size of a widget from the horizontal requisition of all widgets
43// that can be reached from the widget by a chain of size groups with mode
44// [enum@Gtk.SizeGroupMode.HORIZONTAL] or [enum@Gtk.SizeGroupMode.BOTH], and
45// the vertical size from the vertical requisition of all widgets that can be
46// reached from the widget by a chain of size groups with mode
47// [enum@Gtk.SizeGroupMode.VERTICAL] or [enum@Gtk.SizeGroupMode.BOTH].
48//
49// # Size groups and trading height-for-width
50//
51// ::: warning
52//
53// Generally, size groups don't interact well with widgets that
54// trade height for width (or width for height), such as wrappable
55// labels. Avoid using size groups with such widgets.
56//
57// A size group with mode [enum@Gtk.SizeGroupMode.HORIZONTAL] or
58// [enum@Gtk.SizeGroupMode.VERTICAL] only consults non-contextual sizes
59// of widgets other than the one being measured, since it has no
60// knowledge of what size a widget will get allocated in the other
61// orientation. This can lead to widgets in a group actually requesting
62// different contextual sizes, contrary to the purpose of
63// `GtkSizeGroup`.
64//
65// In contrast, a size group with mode [enum@Gtk.SizeGroupMode.BOTH] can
66// properly propagate the available size in the opposite orientation
67// when measuring widgets in the group, which results in consistent and
68// accurate measurements.
69//
70// In case some mechanism other than a size group is already used to
71// ensure that widgets in a group all get the same size in one
72// orientation (for example, some common ancestor is known to allocate
73// the same width to all its children), and the size group is only
74// really needed to also make the widgets request the same size in the
75// other orientation, it is beneficial to still set the group's mode to
76// [enum@Gtk.SizeGroupMode.BOTH]. This lets the group assume and count
77// on sizes of the widgets in the former orientation being the same,
78// which enables it to propagate the available size as described above.
79//
80// # Alternatives to size groups
81//
82// Size groups have many limitations, such as only influencing size
83// requests but not allocations, and poor height-for-width support. When
84// possible, prefer using dedicated mechanisms that can properly ensure
85// that the widgets get the same size.
86//
87// Various container widgets and layout managers support a homogeneous
88// layout mode, where they will explicitly give the same size to their
89// children (see [property@Gtk.Box:homogeneous]). Using homogeneous mode
90// can also have large performance benefits compared to either the same
91// container in non-homogeneous mode, or to size groups.
92//
93// [class@Gtk.Grid] can be used to position widgets into rows and
94// columns. Members of each column will have the same width among them;
95// likewise, members of each row will have the same height. On top of
96// that, the heights can be made equal between all rows with
97// [property@Gtk.Grid:row-homogeneous], and the widths can be made equal
98// between all columns with [property@Gtk.Grid:column-homogeneous].
99//
100// # GtkSizeGroup as GtkBuildable
101//
102// Size groups can be specified in a UI definition by placing an `<object>`
103// element with `class="GtkSizeGroup"` somewhere in the UI definition. The
104// widgets that belong to the size group are specified by a `<widgets>` element
105// that may contain multiple `<widget>` elements, one for each member of the
106// size group. The ”name” attribute gives the id of the widget.
107//
108// An example of a UI definition fragment with `GtkSizeGroup`:
109// ```xml
110// <object class="GtkSizeGroup">
111//
112// <property name="mode">horizontal</property>
113// <widgets>
114// <widget name="radio1"/>
115// <widget name="radio2"/>
116// </widgets>
117//
118// </object>
119// ```
120type SizeGroup struct {
121 gobject.Object
122}
123
124var xSizeGroupGLibType func() types.GType
125
126func SizeGroupGLibType() types.GType {
127 return xSizeGroupGLibType()
128}
129
130func SizeGroupNewFromInternalPtr(ptr uintptr) *SizeGroup {
131 cls := &SizeGroup{}
132 cls.Ptr = ptr
133 return cls
134}
135
136var xNewSizeGroup func(SizeGroupMode) uintptr
137
138// Create a new `GtkSizeGroup`.
139func NewSizeGroup(ModeVar SizeGroupMode) *SizeGroup {
140 var cls *SizeGroup
141
142 cret := xNewSizeGroup(ModeVar)
143
144 if cret == 0 {
145 return nil
146 }
147 cls = &SizeGroup{}
148 cls.Ptr = cret
149 return cls
150}
151
152var xSizeGroupAddWidget func(uintptr, uintptr)
153
154// Adds a widget to a `GtkSizeGroup`.
155//
156// In the future, the requisition
157// of the widget will be determined as the maximum of its requisition
158// and the requisition of the other widgets in the size group.
159// Whether this applies horizontally, vertically, or in both directions
160// depends on the mode of the size group.
161// See [method@Gtk.SizeGroup.set_mode].
162//
163// When the widget is destroyed or no longer referenced elsewhere, it
164// will be removed from the size group.
165func (x *SizeGroup) AddWidget(WidgetVar *Widget) {
166
167 xSizeGroupAddWidget(x.GoPointer(), WidgetVar.GoPointer())
168
169}
170
171var xSizeGroupGetMode func(uintptr) SizeGroupMode
172
173// Gets the current mode of the size group.
174func (x *SizeGroup) GetMode() SizeGroupMode {
175
176 cret := xSizeGroupGetMode(x.GoPointer())
177 return cret
178}
179
180var xSizeGroupGetWidgets func(uintptr) *glib.SList
181
182// Returns the list of widgets associated with @size_group.
183func (x *SizeGroup) GetWidgets() *glib.SList {
184
185 cret := xSizeGroupGetWidgets(x.GoPointer())
186 return cret
187}
188
189var xSizeGroupRemoveWidget func(uintptr, uintptr)
190
191// Removes a widget from a `GtkSizeGroup`.
192func (x *SizeGroup) RemoveWidget(WidgetVar *Widget) {
193
194 xSizeGroupRemoveWidget(x.GoPointer(), WidgetVar.GoPointer())
195
196}
197
198var xSizeGroupSetMode func(uintptr, SizeGroupMode)
199
200// Sets the `GtkSizeGroupMode` of the size group.
201//
202// The mode of the size group determines whether the widgets in the
203// size group should all have the same horizontal requisition
204// (%GTK_SIZE_GROUP_HORIZONTAL) all have the same vertical requisition
205// (%GTK_SIZE_GROUP_VERTICAL), or should all have the same requisition
206// in both directions (%GTK_SIZE_GROUP_BOTH).
207func (x *SizeGroup) SetMode(ModeVar SizeGroupMode) {
208
209 xSizeGroupSetMode(x.GoPointer(), ModeVar)
210
211}
212
213func (c *SizeGroup) GoPointer() uintptr {
214 if c == nil {
215 return 0
216 }
217 return c.Ptr
218}
219
220func (c *SizeGroup) SetGoPointer(ptr uintptr) {
221 c.Ptr = ptr
222}
223
224// Gets the ID of the @buildable object.
225//
226// `GtkBuilder` sets the name based on the ID attribute
227// of the `<object>` tag used to construct the @buildable.
228func (x *SizeGroup) GetBuildableId() string {
229
230 cret := XGtkBuildableGetBuildableId(x.GoPointer())
231 return cret
232}
233
234func init() {
235 core.SetPackageName("GTK", "gtk4")
236 core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
237 var libs []uintptr
238 for _, libPath := range core.GetPaths("GTK") {
239 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
240 if err != nil {
241 panic(err)
242 }
243 libs = append(libs, lib)
244 }
245
246 core.PuregoSafeRegister(&xSizeGroupGLibType, libs, "gtk_size_group_get_type")
247
248 core.PuregoSafeRegister(&xNewSizeGroup, libs, "gtk_size_group_new")
249
250 core.PuregoSafeRegister(&xSizeGroupAddWidget, libs, "gtk_size_group_add_widget")
251 core.PuregoSafeRegister(&xSizeGroupGetMode, libs, "gtk_size_group_get_mode")
252 core.PuregoSafeRegister(&xSizeGroupGetWidgets, libs, "gtk_size_group_get_widgets")
253 core.PuregoSafeRegister(&xSizeGroupRemoveWidget, libs, "gtk_size_group_remove_widget")
254 core.PuregoSafeRegister(&xSizeGroupSetMode, libs, "gtk_size_group_set_mode")
255
256}