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 AnimationClass struct {
18 _ structs.HostLayout
19}
20
21func (x *AnimationClass) GoPointer() uintptr {
22 return uintptr(unsafe.Pointer(x))
23}
24
25const (
26 // Indicates an [class@Animation] with an infinite duration.
27 //
28 // This value is mostly used internally.
29 DURATION_INFINITE uint = 4294967295
30)
31
32// Describes the possible states of an [class@Animation].
33//
34// The state can be controlled with [method@Animation.play],
35// [method@Animation.pause], [method@Animation.resume],
36// [method@Animation.reset] and [method@Animation.skip].
37type AnimationState int
38
39var xAnimationStateGLibType func() types.GType
40
41func AnimationStateGLibType() types.GType {
42 return xAnimationStateGLibType()
43}
44
45const (
46
47 // The animation hasn't started yet.
48 AnimationIdleValue AnimationState = 0
49 // The animation has been paused.
50 AnimationPausedValue AnimationState = 1
51 // The animation is currently playing.
52 AnimationPlayingValue AnimationState = 2
53 // The animation has finished.
54 AnimationFinishedValue AnimationState = 3
55)
56
57// A base class for animations.
58//
59// `AdwAnimation` represents an animation on a widget. It has a target that
60// provides a value to animate, and a state indicating whether the
61// animation hasn't been started yet, is playing, paused or finished.
62//
63// Currently there are two concrete animation types:
64// [class@TimedAnimation] and [class@SpringAnimation].
65//
66// `AdwAnimation` will automatically skip the animation if
67// [property@Animation:widget] is unmapped, or if
68// [property@Gtk.Settings:gtk-enable-animations] is `FALSE`.
69//
70// The [signal@Animation::done] signal can be used to perform an action after
71// the animation ends, for example hiding a widget after animating its
72// [property@Gtk.Widget:opacity] to 0.
73//
74// `AdwAnimation` will be kept alive while the animation is playing. As such,
75// it's safe to create an animation, start it and immediately unref it:
76// A fire-and-forget animation:
77//
78// ```c
79// static void
80// animation_cb (double value,
81//
82// MyObject *self)
83//
84// {
85// // Do something with @value
86// }
87//
88// static void
89// my_object_animate (MyObject *self)
90//
91// {
92// AdwAnimationTarget *target =
93// adw_callback_animation_target_new ((AdwAnimationTargetFunc) animation_cb,
94// self, NULL);
95// g_autoptr (AdwAnimation) animation =
96// adw_timed_animation_new (widget, 0, 1, 250, target);
97//
98// adw_animation_play (animation);
99// }
100//
101// ```
102//
103// If there's a chance the previous animation for the same target hasn't yet
104// finished, the previous animation should be stopped first, or the existing
105// `AdwAnimation` object can be reused.
106type Animation struct {
107 gobject.Object
108}
109
110var xAnimationGLibType func() types.GType
111
112func AnimationGLibType() types.GType {
113 return xAnimationGLibType()
114}
115
116func AnimationNewFromInternalPtr(ptr uintptr) *Animation {
117 cls := &Animation{}
118 cls.Ptr = ptr
119 return cls
120}
121
122var xAnimationGetFollowEnableAnimationsSetting func(uintptr) bool
123
124// Gets whether @self should be skipped when animations are globally disabled.
125func (x *Animation) GetFollowEnableAnimationsSetting() bool {
126
127 cret := xAnimationGetFollowEnableAnimationsSetting(x.GoPointer())
128 return cret
129}
130
131var xAnimationGetState func(uintptr) AnimationState
132
133// Gets the current value of @self.
134//
135// The state indicates whether @self is currently playing, paused, finished or
136// hasn't been started yet.
137func (x *Animation) GetState() AnimationState {
138
139 cret := xAnimationGetState(x.GoPointer())
140 return cret
141}
142
143var xAnimationGetTarget func(uintptr) uintptr
144
145// Gets the target @self animates.
146func (x *Animation) GetTarget() *AnimationTarget {
147 var cls *AnimationTarget
148
149 cret := xAnimationGetTarget(x.GoPointer())
150
151 if cret == 0 {
152 return nil
153 }
154 gobject.IncreaseRef(cret)
155 cls = &AnimationTarget{}
156 cls.Ptr = cret
157 return cls
158}
159
160var xAnimationGetValue func(uintptr) float64
161
162// Gets the current value of @self.
163func (x *Animation) GetValue() float64 {
164
165 cret := xAnimationGetValue(x.GoPointer())
166 return cret
167}
168
169var xAnimationGetWidget func(uintptr) uintptr
170
171// Gets the widget @self was created for.
172//
173// It provides the frame clock for the animation. It's not strictly necessary
174// for this widget to be same as the one being animated.
175//
176// The widget must be mapped in order for the animation to work. If it's not
177// mapped, or if it gets unmapped during an ongoing animation, the animation
178// will be automatically skipped.
179func (x *Animation) GetWidget() *gtk.Widget {
180 var cls *gtk.Widget
181
182 cret := xAnimationGetWidget(x.GoPointer())
183
184 if cret == 0 {
185 return nil
186 }
187 gobject.IncreaseRef(cret)
188 cls = >k.Widget{}
189 cls.Ptr = cret
190 return cls
191}
192
193var xAnimationPause func(uintptr)
194
195// Pauses a playing animation for @self.
196//
197// Does nothing if the current state of @self isn't `ADW_ANIMATION_PLAYING`.
198//
199// Sets [property@Animation:state] to `ADW_ANIMATION_PAUSED`.
200func (x *Animation) Pause() {
201
202 xAnimationPause(x.GoPointer())
203
204}
205
206var xAnimationPlay func(uintptr)
207
208// Starts the animation for @self.
209//
210// If the animation is playing, paused or has been completed, restarts it from
211// the beginning. This allows to easily play an animation regardless of whether
212// it's already playing or not.
213//
214// Sets [property@Animation:state] to `ADW_ANIMATION_PLAYING`.
215//
216// The animation will be automatically skipped if [property@Animation:widget] is
217// unmapped, or if [property@Gtk.Settings:gtk-enable-animations] is `FALSE`.
218//
219// As such, it's not guaranteed that the animation will actually run. For
220// example, when using [func@GLib.idle_add] and starting an animation
221// immediately afterwards, it's entirely possible that the idle callback will
222// run after the animation has already finished, and not while it's playing.
223func (x *Animation) Play() {
224
225 xAnimationPlay(x.GoPointer())
226
227}
228
229var xAnimationReset func(uintptr)
230
231// Resets the animation for @self.
232//
233// Sets [property@Animation:state] to `ADW_ANIMATION_IDLE`.
234func (x *Animation) Reset() {
235
236 xAnimationReset(x.GoPointer())
237
238}
239
240var xAnimationResume func(uintptr)
241
242// Resumes a paused animation for @self.
243//
244// This function must only be used if the animation has been paused with
245// [method@Animation.pause].
246//
247// Sets [property@Animation:state] to `ADW_ANIMATION_PLAYING`.
248func (x *Animation) Resume() {
249
250 xAnimationResume(x.GoPointer())
251
252}
253
254var xAnimationSetFollowEnableAnimationsSetting func(uintptr, bool)
255
256// Sets whether to skip @self when animations are globally disabled.
257//
258// The default behavior is to skip the animation. Set to `FALSE` to disable this
259// behavior.
260//
261// This can be useful for cases where animation is essential, like spinners, or
262// in demo applications. Most other animations should keep it enabled.
263//
264// See [property@Gtk.Settings:gtk-enable-animations].
265func (x *Animation) SetFollowEnableAnimationsSetting(SettingVar bool) {
266
267 xAnimationSetFollowEnableAnimationsSetting(x.GoPointer(), SettingVar)
268
269}
270
271var xAnimationSetTarget func(uintptr, uintptr)
272
273// Sets the target @self animates to @target.
274func (x *Animation) SetTarget(TargetVar *AnimationTarget) {
275
276 xAnimationSetTarget(x.GoPointer(), TargetVar.GoPointer())
277
278}
279
280var xAnimationSkip func(uintptr)
281
282// Skips the animation for @self.
283//
284// If the animation hasn't been started yet, is playing, or is paused, instantly
285// skips the animation to the end and causes [signal@Animation::done] to be
286// emitted.
287//
288// Sets [property@Animation:state] to `ADW_ANIMATION_FINISHED`.
289func (x *Animation) Skip() {
290
291 xAnimationSkip(x.GoPointer())
292
293}
294
295func (c *Animation) GoPointer() uintptr {
296 if c == nil {
297 return 0
298 }
299 return c.Ptr
300}
301
302func (c *Animation) SetGoPointer(ptr uintptr) {
303 c.Ptr = ptr
304}
305
306// SetPropertyFollowEnableAnimationsSetting sets the "follow-enable-animations-setting" property.
307// Whether to skip the animation when animations are globally disabled.
308//
309// The default behavior is to skip the animation. Set to `FALSE` to disable
310// this behavior.
311//
312// This can be useful for cases where animation is essential, like spinners,
313// or in demo applications. Most other animations should keep it enabled.
314//
315// See [property@Gtk.Settings:gtk-enable-animations].
316func (x *Animation) SetPropertyFollowEnableAnimationsSetting(value bool) {
317 var v gobject.Value
318 v.Init(gobject.TypeBooleanVal)
319 v.SetBoolean(value)
320 x.SetProperty("follow-enable-animations-setting", &v)
321}
322
323// GetPropertyFollowEnableAnimationsSetting gets the "follow-enable-animations-setting" property.
324// Whether to skip the animation when animations are globally disabled.
325//
326// The default behavior is to skip the animation. Set to `FALSE` to disable
327// this behavior.
328//
329// This can be useful for cases where animation is essential, like spinners,
330// or in demo applications. Most other animations should keep it enabled.
331//
332// See [property@Gtk.Settings:gtk-enable-animations].
333func (x *Animation) GetPropertyFollowEnableAnimationsSetting() bool {
334 var v gobject.Value
335 x.GetProperty("follow-enable-animations-setting", &v)
336 return v.GetBoolean()
337}
338
339// GetPropertyValue gets the "value" property.
340// The current value of the animation.
341func (x *Animation) GetPropertyValue() float64 {
342 var v gobject.Value
343 x.GetProperty("value", &v)
344 return v.GetDouble()
345}
346
347// This signal is emitted when the animation has been completed, either on its
348// own or via calling [method@Animation.skip].
349func (x *Animation) ConnectDone(cb *func(Animation)) uint {
350 cbPtr := uintptr(unsafe.Pointer(cb))
351 if cbRefPtr, ok := glib.GetCallback(cbPtr); ok {
352 handlerID := gobject.SignalConnect(x.GoPointer(), "done", cbRefPtr)
353 glib.SaveHandlerMapping(handlerID, cbPtr)
354 return handlerID
355 }
356
357 fcb := func(clsPtr uintptr) {
358 fa := Animation{}
359 fa.Ptr = clsPtr
360 cbFn := *cb
361
362 cbFn(fa)
363
364 }
365 cbRefPtr := purego.NewCallback(fcb)
366 glib.SaveCallbackWithClosure(cbPtr, cbRefPtr, cb)
367 handlerID := gobject.SignalConnect(x.GoPointer(), "done", cbRefPtr)
368 glib.SaveHandlerMapping(handlerID, cbPtr)
369 return handlerID
370}
371
372func init() {
373 core.SetPackageName("ADW", "libadwaita-1")
374 core.SetSharedLibraries("ADW", []string{"libadwaita-1.so.0"})
375 var libs []uintptr
376 for _, libPath := range core.GetPaths("ADW") {
377 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
378 if err != nil {
379 panic(err)
380 }
381 libs = append(libs, lib)
382 }
383
384 core.PuregoSafeRegister(&xAnimationStateGLibType, libs, "adw_animation_state_get_type")
385
386 core.PuregoSafeRegister(&xAnimationGLibType, libs, "adw_animation_get_type")
387
388 core.PuregoSafeRegister(&xAnimationGetFollowEnableAnimationsSetting, libs, "adw_animation_get_follow_enable_animations_setting")
389 core.PuregoSafeRegister(&xAnimationGetState, libs, "adw_animation_get_state")
390 core.PuregoSafeRegister(&xAnimationGetTarget, libs, "adw_animation_get_target")
391 core.PuregoSafeRegister(&xAnimationGetValue, libs, "adw_animation_get_value")
392 core.PuregoSafeRegister(&xAnimationGetWidget, libs, "adw_animation_get_widget")
393 core.PuregoSafeRegister(&xAnimationPause, libs, "adw_animation_pause")
394 core.PuregoSafeRegister(&xAnimationPlay, libs, "adw_animation_play")
395 core.PuregoSafeRegister(&xAnimationReset, libs, "adw_animation_reset")
396 core.PuregoSafeRegister(&xAnimationResume, libs, "adw_animation_resume")
397 core.PuregoSafeRegister(&xAnimationSetFollowEnableAnimationsSetting, libs, "adw_animation_set_follow_enable_animations_setting")
398 core.PuregoSafeRegister(&xAnimationSetTarget, libs, "adw_animation_set_target")
399 core.PuregoSafeRegister(&xAnimationSkip, libs, "adw_animation_skip")
400
401}