v0.2.1 c0399be

gtkswitch.go RawHistoryFolder

1// Package gtk was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package gtk
3
4import (
5	"unsafe"
6
7	"github.com/ebitengine/purego"
8
9	"github.com/bnema/puregotk/pkg/core"
10	"github.com/bnema/puregotk/v4/glib"
11	"github.com/bnema/puregotk/v4/gobject"
12	"github.com/bnema/puregotk/v4/gobject/types"
13)
14
15// Shows a "light switch" that has two states: on or off.
16//
17// <picture>
18//
19//	<source srcset="switch-dark.png" media="(prefers-color-scheme: dark)">
20//	<img alt="An example GtkSwitch" src="switch.png">
21//
22// </picture>
23//
24// The user can control which state should be active by clicking the
25// empty area, or by dragging the slider.
26//
27// `GtkSwitch` can also express situations where the underlying state changes
28// with a delay. In this case, the slider position indicates the user's recent
29// change (represented by the [property@Gtk.Switch:active] property), while the
30// trough color indicates the present underlying state (represented by the
31// [property@Gtk.Switch:state] property).
32//
33// <picture>
34//
35//	<source srcset="switch-state-dark.png" media="(prefers-color-scheme: dark)">
36//	<img alt="GtkSwitch with delayed state change" src="switch-state.png">
37//
38// </picture>
39//
40// See [signal@Gtk.Switch::state-set] for details.
41//
42// # Shortcuts and Gestures
43//
44// `GtkSwitch` supports pan and drag gestures to move the slider.
45//
46// # CSS nodes
47//
48// ```
49// switch
50// ├── image
51// ├── image
52// ╰── slider
53// ```
54//
55// `GtkSwitch` has four css nodes, the main node with the name switch and
56// subnodes for the slider and the on and off images. Neither of them is
57// using any style classes.
58//
59// # Accessibility
60//
61// `GtkSwitch` uses the [enum@Gtk.AccessibleRole.switch] role.
62type Switch struct {
63	Widget
64}
65
66var xSwitchGLibType func() types.GType
67
68func SwitchGLibType() types.GType {
69	return xSwitchGLibType()
70}
71
72func SwitchNewFromInternalPtr(ptr uintptr) *Switch {
73	cls := &Switch{}
74	cls.Ptr = ptr
75	return cls
76}
77
78var xNewSwitch func() uintptr
79
80// Creates a new `GtkSwitch` widget.
81func NewSwitch() *Switch {
82	var cls *Switch
83
84	cret := xNewSwitch()
85
86	if cret == 0 {
87		return nil
88	}
89	gobject.IncreaseRef(cret)
90	cls = &Switch{}
91	cls.Ptr = cret
92	return cls
93}
94
95var xSwitchGetActive func(uintptr) bool
96
97// Gets whether the `GtkSwitch` is in its “on” or “off” state.
98func (x *Switch) GetActive() bool {
99
100	cret := xSwitchGetActive(x.GoPointer())
101	return cret
102}
103
104var xSwitchGetState func(uintptr) bool
105
106// Gets the underlying state of the `GtkSwitch`.
107func (x *Switch) GetState() bool {
108
109	cret := xSwitchGetState(x.GoPointer())
110	return cret
111}
112
113var xSwitchSetActive func(uintptr, bool)
114
115// Changes the state of @self to the desired one.
116func (x *Switch) SetActive(IsActiveVar bool) {
117
118	xSwitchSetActive(x.GoPointer(), IsActiveVar)
119
120}
121
122var xSwitchSetState func(uintptr, bool)
123
124// Sets the underlying state of the `GtkSwitch`.
125//
126// This function is typically called from a [signal@Gtk.Switch::state-set]
127// signal handler in order to set up delayed state changes.
128//
129// See [signal@Gtk.Switch::state-set] for details.
130func (x *Switch) SetState(StateVar bool) {
131
132	xSwitchSetState(x.GoPointer(), StateVar)
133
134}
135
136func (c *Switch) GoPointer() uintptr {
137	if c == nil {
138		return 0
139	}
140	return c.Ptr
141}
142
143func (c *Switch) SetGoPointer(ptr uintptr) {
144	c.Ptr = ptr
145}
146
147// SetPropertyActive sets the "active" property.
148// Whether the `GtkSwitch` widget is in its on or off state.
149func (x *Switch) SetPropertyActive(value bool) {
150	var v gobject.Value
151	v.Init(gobject.TypeBooleanVal)
152	v.SetBoolean(value)
153	x.SetProperty("active", &v)
154}
155
156// GetPropertyActive gets the "active" property.
157// Whether the `GtkSwitch` widget is in its on or off state.
158func (x *Switch) GetPropertyActive() bool {
159	var v gobject.Value
160	x.GetProperty("active", &v)
161	return v.GetBoolean()
162}
163
164// SetPropertyState sets the "state" property.
165// The backend state that is controlled by the switch.
166//
167// Applications should usually set the [property@Gtk.Switch:active] property,
168// except when indicating a change to the backend state which occurs
169// separately from the user's interaction.
170//
171// See [signal@Gtk.Switch::state-set] for details.
172func (x *Switch) SetPropertyState(value bool) {
173	var v gobject.Value
174	v.Init(gobject.TypeBooleanVal)
175	v.SetBoolean(value)
176	x.SetProperty("state", &v)
177}
178
179// GetPropertyState gets the "state" property.
180// The backend state that is controlled by the switch.
181//
182// Applications should usually set the [property@Gtk.Switch:active] property,
183// except when indicating a change to the backend state which occurs
184// separately from the user's interaction.
185//
186// See [signal@Gtk.Switch::state-set] for details.
187func (x *Switch) GetPropertyState() bool {
188	var v gobject.Value
189	x.GetProperty("state", &v)
190	return v.GetBoolean()
191}
192
193// Emitted to animate the switch.
194//
195// Applications should never connect to this signal,
196// but use the [property@Gtk.Switch:active] property.
197func (x *Switch) ConnectActivate(cb *func(Switch)) uint {
198	cbPtr := uintptr(unsafe.Pointer(cb))
199	if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
200		handlerID := gobject.SignalConnect(x.GoPointer(), "activate", cbRefPtr)
201		glib.SaveHandlerMapping(handlerID, cbPtr)
202		return handlerID
203	}
204
205	fcb := func(clsPtr uintptr) {
206		fa := Switch{}
207		fa.Ptr = clsPtr
208		cbFn := *cb
209
210		cbFn(fa)
211
212	}
213	cbRefPtr := purego.NewCallback(fcb)
214	glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
215	handlerID := gobject.SignalConnect(x.GoPointer(), "activate", cbRefPtr)
216	glib.SaveHandlerMapping(handlerID, cbPtr)
217	return handlerID
218}
219
220// Emitted to change the underlying state.
221//
222// The ::state-set signal is emitted when the user changes the switch
223// position. The default handler calls [method@Gtk.Switch.set_state] with the
224// value of @state.
225//
226// To implement delayed state change, applications can connect to this
227// signal, initiate the change of the underlying state, and call
228// [method@Gtk.Switch.set_state] when the underlying state change is
229// complete. The signal handler should return %TRUE to prevent the
230// default handler from running.
231func (x *Switch) ConnectStateSet(cb *func(Switch, bool) bool) uint {
232	cbPtr := uintptr(unsafe.Pointer(cb))
233	if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
234		handlerID := gobject.SignalConnect(x.GoPointer(), "state-set", cbRefPtr)
235		glib.SaveHandlerMapping(handlerID, cbPtr)
236		return handlerID
237	}
238
239	fcb := func(clsPtr uintptr, StateVarp bool) bool {
240		fa := Switch{}
241		fa.Ptr = clsPtr
242		cbFn := *cb
243
244		return cbFn(fa, StateVarp)
245
246	}
247	cbRefPtr := purego.NewCallback(fcb)
248	glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
249	handlerID := gobject.SignalConnect(x.GoPointer(), "state-set", cbRefPtr)
250	glib.SaveHandlerMapping(handlerID, cbPtr)
251	return handlerID
252}
253
254// Requests the user's screen reader to announce the given message.
255//
256// This kind of notification is useful for messages that
257// either have only a visual representation or that are not
258// exposed visually at all, e.g. a notification about a
259// successful operation.
260//
261// Also, by using this API, you can ensure that the message
262// does not interrupts the user's current screen reader output.
263func (x *Switch) Announce(MessageVar string, PriorityVar AccessibleAnnouncementPriority) {
264
265	XGtkAccessibleAnnounce(x.GoPointer(), MessageVar, PriorityVar)
266
267}
268
269// Retrieves the accessible parent for an accessible object.
270//
271// This function returns `NULL` for top level widgets.
272func (x *Switch) GetAccessibleParent() *AccessibleBase {
273	var cls *AccessibleBase
274
275	cret := XGtkAccessibleGetAccessibleParent(x.GoPointer())
276
277	if cret == 0 {
278		return nil
279	}
280	cls = &AccessibleBase{}
281	cls.Ptr = cret
282	return cls
283}
284
285// Retrieves the accessible role of an accessible object.
286func (x *Switch) GetAccessibleRole() AccessibleRole {
287
288	cret := XGtkAccessibleGetAccessibleRole(x.GoPointer())
289	return cret
290}
291
292// Retrieves the implementation for the given accessible object.
293func (x *Switch) GetAtContext() *ATContext {
294	var cls *ATContext
295
296	cret := XGtkAccessibleGetAtContext(x.GoPointer())
297
298	if cret == 0 {
299		return nil
300	}
301	cls = &ATContext{}
302	cls.Ptr = cret
303	return cls
304}
305
306// Queries the coordinates and dimensions of this accessible
307//
308// This functionality can be overridden by `GtkAccessible`
309// implementations, e.g. to get the bounds from an ignored
310// child widget.
311func (x *Switch) GetBounds(XVar *int, YVar *int, WidthVar *int, HeightVar *int) bool {
312
313	cret := XGtkAccessibleGetBounds(x.GoPointer(), XVar, YVar, WidthVar, HeightVar)
314	return cret
315}
316
317// Retrieves the first accessible child of an accessible object.
318func (x *Switch) GetFirstAccessibleChild() *AccessibleBase {
319	var cls *AccessibleBase
320
321	cret := XGtkAccessibleGetFirstAccessibleChild(x.GoPointer())
322
323	if cret == 0 {
324		return nil
325	}
326	cls = &AccessibleBase{}
327	cls.Ptr = cret
328	return cls
329}
330
331// Retrieves the next accessible sibling of an accessible object
332func (x *Switch) GetNextAccessibleSibling() *AccessibleBase {
333	var cls *AccessibleBase
334
335	cret := XGtkAccessibleGetNextAccessibleSibling(x.GoPointer())
336
337	if cret == 0 {
338		return nil
339	}
340	cls = &AccessibleBase{}
341	cls.Ptr = cret
342	return cls
343}
344
345// Queries a platform state, such as focus.
346//
347// This functionality can be overridden by `GtkAccessible`
348// implementations, e.g. to get platform state from an ignored
349// child widget, as is the case for `GtkText` wrappers.
350func (x *Switch) GetPlatformState(StateVar AccessiblePlatformState) bool {
351
352	cret := XGtkAccessibleGetPlatformState(x.GoPointer(), StateVar)
353	return cret
354}
355
356// Resets the accessible property to its default value.
357func (x *Switch) ResetProperty(PropertyVar AccessibleProperty) {
358
359	XGtkAccessibleResetProperty(x.GoPointer(), PropertyVar)
360
361}
362
363// Resets the accessible relation to its default value.
364func (x *Switch) ResetRelation(RelationVar AccessibleRelation) {
365
366	XGtkAccessibleResetRelation(x.GoPointer(), RelationVar)
367
368}
369
370// Resets the accessible state to its default value.
371func (x *Switch) ResetState(StateVar AccessibleState) {
372
373	XGtkAccessibleResetState(x.GoPointer(), StateVar)
374
375}
376
377// Sets the parent and sibling of an accessible object.
378//
379// This function is meant to be used by accessible implementations that are
380// not part of the widget hierarchy, and but act as a logical bridge between
381// widgets. For instance, if a widget creates an object that holds metadata
382// for each child, and you want that object to implement the `GtkAccessible`
383// interface, you will use this function to ensure that the parent of each
384// child widget is the metadata object, and the parent of each metadata
385// object is the container widget.
386func (x *Switch) SetAccessibleParent(ParentVar Accessible, NextSiblingVar Accessible) {
387
388	XGtkAccessibleSetAccessibleParent(x.GoPointer(), ParentVar.GoPointer(), NextSiblingVar.GoPointer())
389
390}
391
392// Updates the next accessible sibling.
393//
394// That might be useful when a new child of a custom accessible
395// is created, and it needs to be linked to a previous child.
396func (x *Switch) UpdateNextAccessibleSibling(NewSiblingVar Accessible) {
397
398	XGtkAccessibleUpdateNextAccessibleSibling(x.GoPointer(), NewSiblingVar.GoPointer())
399
400}
401
402// Informs ATs that the platform state has changed.
403//
404// This function should be used by `GtkAccessible` implementations that
405// have a platform state but are not widgets. Widgets handle platform
406// states automatically.
407func (x *Switch) UpdatePlatformState(StateVar AccessiblePlatformState) {
408
409	XGtkAccessibleUpdatePlatformState(x.GoPointer(), StateVar)
410
411}
412
413// Updates a list of accessible properties.
414//
415// See the [enum@Gtk.AccessibleProperty] documentation for the
416// value types of accessible properties.
417//
418// This function should be called by `GtkWidget` types whenever
419// an accessible property change must be communicated to assistive
420// technologies.
421//
422// Example:
423// ```c
424// value = gtk_adjustment_get_value (adjustment);
425// gtk_accessible_update_property (GTK_ACCESSIBLE (spin_button),
426//
427//	GTK_ACCESSIBLE_PROPERTY_VALUE_NOW, value,
428//	-1);
429//
430// ```
431func (x *Switch) UpdateProperty(FirstPropertyVar AccessibleProperty, varArgs ...interface{}) {
432
433	XGtkAccessibleUpdateProperty(x.GoPointer(), FirstPropertyVar, varArgs...)
434
435}
436
437// Updates an array of accessible properties.
438//
439// This function should be called by `GtkWidget` types whenever an accessible
440// property change must be communicated to assistive technologies.
441//
442// This function is meant to be used by language bindings.
443func (x *Switch) UpdatePropertyValue(NPropertiesVar int, PropertiesVar []AccessibleProperty, ValuesVar []gobject.Value) {
444
445	XGtkAccessibleUpdatePropertyValue(x.GoPointer(), NPropertiesVar, PropertiesVar, ValuesVar)
446
447}
448
449// Updates a list of accessible relations.
450//
451// This function should be called by `GtkWidget` types whenever an accessible
452// relation change must be communicated to assistive technologies.
453//
454// If the [enum@Gtk.AccessibleRelation] requires a list of references,
455// you should pass each reference individually, followed by `NULL`, e.g.
456//
457// ```c
458// gtk_accessible_update_relation (accessible,
459//
460//	GTK_ACCESSIBLE_RELATION_CONTROLS,
461//	  ref1, NULL,
462//	GTK_ACCESSIBLE_RELATION_LABELLED_BY,
463//	  ref1, ref2, ref3, NULL,
464//	-1);
465//
466// ```
467func (x *Switch) UpdateRelation(FirstRelationVar AccessibleRelation, varArgs ...interface{}) {
468
469	XGtkAccessibleUpdateRelation(x.GoPointer(), FirstRelationVar, varArgs...)
470
471}
472
473// Updates an array of accessible relations.
474//
475// This function should be called by `GtkWidget` types whenever an accessible
476// relation change must be communicated to assistive technologies.
477//
478// This function is meant to be used by language bindings.
479func (x *Switch) UpdateRelationValue(NRelationsVar int, RelationsVar []AccessibleRelation, ValuesVar []gobject.Value) {
480
481	XGtkAccessibleUpdateRelationValue(x.GoPointer(), NRelationsVar, RelationsVar, ValuesVar)
482
483}
484
485// Updates a list of accessible states.
486//
487// See the [enum@Gtk.AccessibleState] documentation for the
488// value types of accessible states.
489//
490// This function should be called by `GtkWidget` types whenever
491// an accessible state change must be communicated to assistive
492// technologies.
493//
494// Example:
495//
496// ```c
497// value = GTK_ACCESSIBLE_TRISTATE_MIXED;
498// gtk_accessible_update_state (GTK_ACCESSIBLE (check_button),
499//
500//	GTK_ACCESSIBLE_STATE_CHECKED, value,
501//	-1);
502//
503// ```
504func (x *Switch) UpdateState(FirstStateVar AccessibleState, varArgs ...interface{}) {
505
506	XGtkAccessibleUpdateState(x.GoPointer(), FirstStateVar, varArgs...)
507
508}
509
510// Updates an array of accessible states.
511//
512// This function should be called by `GtkWidget` types whenever an accessible
513// state change must be communicated to assistive technologies.
514//
515// This function is meant to be used by language bindings.
516func (x *Switch) UpdateStateValue(NStatesVar int, StatesVar []AccessibleState, ValuesVar []gobject.Value) {
517
518	XGtkAccessibleUpdateStateValue(x.GoPointer(), NStatesVar, StatesVar, ValuesVar)
519
520}
521
522// Gets the action name for @actionable.
523func (x *Switch) GetActionName() string {
524
525	cret := XGtkActionableGetActionName(x.GoPointer())
526	return cret
527}
528
529// Gets the current target value of @actionable.
530func (x *Switch) GetActionTargetValue() *glib.Variant {
531
532	cret := XGtkActionableGetActionTargetValue(x.GoPointer())
533	return cret
534}
535
536// Specifies the name of the action with which this widget should be
537// associated.
538//
539// If @action_name is %NULL then the widget will be unassociated from
540// any previous action.
541//
542// Usually this function is used when the widget is located (or will be
543// located) within the hierarchy of a `GtkApplicationWindow`.
544//
545// Names are of the form “win.save” or “app.quit” for actions on the
546// containing [class@ApplicationWindow] or its associated [class@Application],
547// respectively. This is the same form used for actions in the [class@Gio.Menu]
548// associated with the window.
549func (x *Switch) SetActionName(ActionNameVar *string) {
550
551	ActionNameVarPtr := core.GStrdupNullable(ActionNameVar)
552	defer core.GFreeNullable(ActionNameVarPtr)
553
554	XGtkActionableSetActionName(x.GoPointer(), ActionNameVarPtr)
555
556}
557
558// Sets the target of an actionable widget.
559//
560// This is a convenience function that calls [ctor@GLib.Variant.new] for
561// @format_string and uses the result to call
562// [method@Gtk.Actionable.set_action_target_value].
563//
564// If you are setting a string-valued target and want to set
565// the action name at the same time, you can use
566// [method@Gtk.Actionable.set_detailed_action_name].
567func (x *Switch) SetActionTarget(FormatStringVar string, varArgs ...interface{}) {
568
569	XGtkActionableSetActionTarget(x.GoPointer(), FormatStringVar, varArgs...)
570
571}
572
573// Sets the target value of an actionable widget.
574//
575// If @target_value is %NULL then the target value is unset.
576//
577// The target value has two purposes. First, it is used as the parameter
578// to activation of the action associated with the `GtkActionable` widget.
579// Second, it is used to determine if the widget should be rendered as
580// “active” — the widget is active if the state is equal to the given target.
581//
582// Consider the example of associating a set of buttons with a [iface@Gio.Action]
583// with string state in a typical “radio button” situation. Each button
584// will be associated with the same action, but with a different target
585// value for that action. Clicking on a particular button will activate
586// the action with the target of that button, which will typically cause
587// the action’s state to change to that value. Since the action’s state
588// is now equal to the target value of the button, the button will now
589// be rendered as active (and the other buttons, with different targets,
590// rendered inactive).
591func (x *Switch) SetActionTargetValue(TargetValueVar *glib.Variant) {
592
593	XGtkActionableSetActionTargetValue(x.GoPointer(), TargetValueVar)
594
595}
596
597// Sets the action-name and associated string target value of an
598// actionable widget.
599//
600// @detailed_action_name is a string in the format accepted by
601// [func@Gio.Action.parse_detailed_name].
602func (x *Switch) SetDetailedActionName(DetailedActionNameVar string) {
603
604	XGtkActionableSetDetailedActionName(x.GoPointer(), DetailedActionNameVar)
605
606}
607
608// Gets the ID of the @buildable object.
609//
610// `GtkBuilder` sets the name based on the ID attribute
611// of the `<object>` tag used to construct the @buildable.
612func (x *Switch) GetBuildableId() string {
613
614	cret := XGtkBuildableGetBuildableId(x.GoPointer())
615	return cret
616}
617
618func init() {
619	core.SetPackageName("GTK", "gtk4")
620	core.SetSharedLibraries("GTK", []string{"libgtk-4.so.1"})
621	var libs []uintptr
622	for _, libPath := range core.GetPaths("GTK") {
623		lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
624		if err != nil {
625			panic(err)
626		}
627		libs = append(libs, lib)
628	}
629
630	core.PuregoSafeRegister(&xSwitchGLibType, libs, "gtk_switch_get_type")
631
632	core.PuregoSafeRegister(&xNewSwitch, libs, "gtk_switch_new")
633
634	core.PuregoSafeRegister(&xSwitchGetActive, libs, "gtk_switch_get_active")
635	core.PuregoSafeRegister(&xSwitchGetState, libs, "gtk_switch_get_state")
636	core.PuregoSafeRegister(&xSwitchSetActive, libs, "gtk_switch_set_active")
637	core.PuregoSafeRegister(&xSwitchSetState, libs, "gtk_switch_set_state")
638
639}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 102

↑↓ moveenter openesc close