1package layout
2
3import (
4 "github.com/jwijenbergh/puregotk/v4/gdk"
5 "github.com/jwijenbergh/puregotk/v4/gobject"
6 "github.com/jwijenbergh/puregotk/v4/graphene"
7 "github.com/jwijenbergh/puregotk/v4/gtk"
8 "github.com/jwijenbergh/puregotk/v4/pango"
9)
10
11// Ensure implementations satisfy interfaces at compile time.
12var (
13 _ Widget = (*gtkWidget)(nil)
14 _ PanedWidget = (*gtkPaned)(nil)
15 _ BoxWidget = (*gtkBox)(nil)
16 _ OverlayWidget = (*gtkOverlay)(nil)
17 _ LabelWidget = (*gtkLabel)(nil)
18 _ ButtonWidget = (*gtkButton)(nil)
19 _ ImageWidget = (*gtkImage)(nil)
20 _ ProgressBarWidget = (*gtkProgressBar)(nil)
21 _ SpinnerWidget = (*gtkSpinner)(nil)
22 _ WidgetFactory = (*GtkWidgetFactory)(nil)
23)
24
25// gtkWidget wraps a gtk.Widget to implement the Widget interface.
26type gtkWidget struct {
27 inner *gtk.Widget
28}
29
30func (w *gtkWidget) Show() { w.inner.Show() }
31func (w *gtkWidget) Hide() { w.inner.Hide() }
32func (w *gtkWidget) SetVisible(visible bool) { w.inner.SetVisible(visible) }
33func (w *gtkWidget) IsVisible() bool { return w.inner.GetVisible() }
34func (w *gtkWidget) GrabFocus() bool { return w.inner.GrabFocus() }
35func (w *gtkWidget) HasFocus() bool { return w.inner.HasFocus() }
36func (w *gtkWidget) SetCanFocus(canFocus bool) { w.inner.SetCanFocus(canFocus) }
37func (w *gtkWidget) SetFocusable(focusable bool) { w.inner.SetFocusable(focusable) }
38func (w *gtkWidget) SetFocusOnClick(focus bool) { w.inner.SetFocusOnClick(focus) }
39func (w *gtkWidget) SetCanTarget(canTarget bool) { w.inner.SetCanTarget(canTarget) }
40func (w *gtkWidget) SetHexpand(expand bool) { w.inner.SetHexpand(expand) }
41func (w *gtkWidget) SetVexpand(expand bool) { w.inner.SetVexpand(expand) }
42func (w *gtkWidget) GetHexpand() bool { return w.inner.GetHexpand() }
43func (w *gtkWidget) GetVexpand() bool { return w.inner.GetVexpand() }
44func (w *gtkWidget) SetHalign(align gtk.Align) { w.inner.SetHalign(align) }
45func (w *gtkWidget) SetValign(align gtk.Align) { w.inner.SetValign(align) }
46func (w *gtkWidget) SetSizeRequest(w2, h int) { w.inner.SetSizeRequest(w2, h) }
47func (w *gtkWidget) AddCssClass(class string) { w.inner.AddCssClass(class) }
48func (w *gtkWidget) RemoveCssClass(class string) { w.inner.RemoveCssClass(class) }
49func (w *gtkWidget) HasCssClass(class string) bool { return w.inner.HasCssClass(class) }
50func (w *gtkWidget) Unparent() { w.inner.Unparent() }
51func (w *gtkWidget) GtkWidget() *gtk.Widget { return w.inner }
52
53func (w *gtkWidget) GetParent() Widget {
54 parent := w.inner.GetParent()
55 if parent == nil {
56 return nil
57 }
58 return >kWidget{inner: parent}
59}
60
61func (w *gtkWidget) GetAllocatedWidth() int { return w.inner.GetAllocatedWidth() }
62func (w *gtkWidget) GetAllocatedHeight() int { return w.inner.GetAllocatedHeight() }
63func (w *gtkWidget) AddController(c *gtk.EventController) { w.inner.AddController(c) }
64
65func (w *gtkWidget) ComputePoint(target Widget) (x, y float64, ok bool) {
66 srcPoint := &graphene.Point{X: 0, Y: 0}
67 outPoint := &graphene.Point{}
68
69 var targetGtk *gtk.Widget
70 if target != nil {
71 targetGtk = target.GtkWidget()
72 }
73
74 ok = w.inner.ComputePoint(targetGtk, srcPoint, outPoint)
75 if !ok {
76 return 0, 0, false
77 }
78 return float64(outPoint.X), float64(outPoint.Y), true
79}
80
81// gtkPaned wraps gtk.Paned to implement PanedWidget.
82type gtkPaned struct {
83 inner *gtk.Paned
84}
85
86func (p *gtkPaned) Show() { p.inner.Show() }
87func (p *gtkPaned) Hide() { p.inner.Hide() }
88func (p *gtkPaned) SetVisible(visible bool) { p.inner.SetVisible(visible) }
89func (p *gtkPaned) IsVisible() bool { return p.inner.GetVisible() }
90func (p *gtkPaned) GrabFocus() bool { return p.inner.GrabFocus() }
91func (p *gtkPaned) HasFocus() bool { return p.inner.HasFocus() }
92func (p *gtkPaned) SetCanFocus(canFocus bool) { p.inner.SetCanFocus(canFocus) }
93func (p *gtkPaned) SetFocusable(focusable bool) { p.inner.SetFocusable(focusable) }
94func (p *gtkPaned) SetFocusOnClick(focus bool) { p.inner.SetFocusOnClick(focus) }
95func (p *gtkPaned) SetCanTarget(canTarget bool) { p.inner.SetCanTarget(canTarget) }
96func (p *gtkPaned) SetHexpand(expand bool) { p.inner.SetHexpand(expand) }
97func (p *gtkPaned) SetVexpand(expand bool) { p.inner.SetVexpand(expand) }
98func (p *gtkPaned) GetHexpand() bool { return p.inner.GetHexpand() }
99func (p *gtkPaned) GetVexpand() bool { return p.inner.GetVexpand() }
100func (p *gtkPaned) SetHalign(align gtk.Align) { p.inner.SetHalign(align) }
101func (p *gtkPaned) SetValign(align gtk.Align) { p.inner.SetValign(align) }
102func (p *gtkPaned) SetSizeRequest(w, h int) { p.inner.SetSizeRequest(w, h) }
103func (p *gtkPaned) AddCssClass(class string) { p.inner.AddCssClass(class) }
104func (p *gtkPaned) RemoveCssClass(class string) { p.inner.RemoveCssClass(class) }
105func (p *gtkPaned) HasCssClass(class string) bool { return p.inner.HasCssClass(class) }
106func (p *gtkPaned) Unparent() { p.inner.Unparent() }
107func (p *gtkPaned) GtkWidget() *gtk.Widget { return &p.inner.Widget }
108
109func (p *gtkPaned) GetParent() Widget {
110 parent := p.inner.GetParent()
111 if parent == nil {
112 return nil
113 }
114 return >kWidget{inner: parent}
115}
116
117func (p *gtkPaned) SetStartChild(child Widget) {
118 if child == nil {
119 p.inner.SetStartChild(nil)
120 return
121 }
122 p.inner.SetStartChild(child.GtkWidget())
123}
124
125func (p *gtkPaned) SetEndChild(child Widget) {
126 if child == nil {
127 p.inner.SetEndChild(nil)
128 return
129 }
130 p.inner.SetEndChild(child.GtkWidget())
131}
132
133func (p *gtkPaned) GetStartChild() Widget {
134 child := p.inner.GetStartChild()
135 if child == nil {
136 return nil
137 }
138 return >kWidget{inner: child}
139}
140
141func (p *gtkPaned) GetEndChild() Widget {
142 child := p.inner.GetEndChild()
143 if child == nil {
144 return nil
145 }
146 return >kWidget{inner: child}
147}
148
149func (p *gtkPaned) SetPosition(pos int) { p.inner.SetPosition(pos) }
150func (p *gtkPaned) GetPosition() int { return p.inner.GetPosition() }
151func (p *gtkPaned) SetResizeStartChild(r bool) { p.inner.SetResizeStartChild(r) }
152func (p *gtkPaned) SetResizeEndChild(r bool) { p.inner.SetResizeEndChild(r) }
153func (p *gtkPaned) GetResizeStartChild() bool { return p.inner.GetResizeStartChild() }
154func (p *gtkPaned) GetResizeEndChild() bool { return p.inner.GetResizeEndChild() }
155func (p *gtkPaned) SetShrinkStartChild(s bool) { p.inner.SetShrinkStartChild(s) }
156func (p *gtkPaned) SetShrinkEndChild(s bool) { p.inner.SetShrinkEndChild(s) }
157func (p *gtkPaned) GetShrinkStartChild() bool { return p.inner.GetShrinkStartChild() }
158func (p *gtkPaned) GetShrinkEndChild() bool { return p.inner.GetShrinkEndChild() }
159func (p *gtkPaned) SetWideHandle(wide bool) { p.inner.SetWideHandle(wide) }
160func (p *gtkPaned) GetWideHandle() bool { return p.inner.GetWideHandle() }
161
162func (p *gtkPaned) ConnectMap(callback func()) uint32 {
163 cb := func(_ gtk.Widget) {
164 callback()
165 }
166 return p.inner.ConnectMap(&cb)
167}
168
169func (p *gtkPaned) ConnectNotifyPosition(callback func()) uint32 {
170 cb := func(_ gobject.Object, _ uintptr) {
171 callback()
172 }
173 return p.inner.ConnectNotifyWithDetail("position", &cb)
174}
175
176func (p *gtkPaned) AddTickCallback(callback func() bool) uint {
177 cb := gtk.TickCallback(func(widget uintptr, frameClock uintptr, userData uintptr) bool {
178 return callback()
179 })
180 return p.inner.AddTickCallback(&cb, 0, nil)
181}
182
183func (p *gtkPaned) GetAllocatedWidth() int { return p.inner.GetAllocatedWidth() }
184func (p *gtkPaned) GetAllocatedHeight() int { return p.inner.GetAllocatedHeight() }
185func (p *gtkPaned) AddController(c *gtk.EventController) { p.inner.AddController(c) }
186
187func (p *gtkPaned) ComputePoint(target Widget) (x, y float64, ok bool) {
188 srcPoint := &graphene.Point{X: 0, Y: 0}
189 outPoint := &graphene.Point{}
190
191 var targetGtk *gtk.Widget
192 if target != nil {
193 targetGtk = target.GtkWidget()
194 }
195
196 ok = p.inner.ComputePoint(targetGtk, srcPoint, outPoint)
197 if !ok {
198 return 0, 0, false
199 }
200 return float64(outPoint.X), float64(outPoint.Y), true
201}
202
203// gtkBox wraps gtk.Box to implement BoxWidget.
204type gtkBox struct {
205 inner *gtk.Box
206}
207
208func (b *gtkBox) Show() { b.inner.Show() }
209func (b *gtkBox) Hide() { b.inner.Hide() }
210func (b *gtkBox) SetVisible(visible bool) { b.inner.SetVisible(visible) }
211func (b *gtkBox) IsVisible() bool { return b.inner.GetVisible() }
212func (b *gtkBox) GrabFocus() bool { return b.inner.GrabFocus() }
213func (b *gtkBox) HasFocus() bool { return b.inner.HasFocus() }
214func (b *gtkBox) SetCanFocus(canFocus bool) { b.inner.SetCanFocus(canFocus) }
215func (b *gtkBox) SetFocusable(focusable bool) { b.inner.SetFocusable(focusable) }
216func (b *gtkBox) SetFocusOnClick(focus bool) { b.inner.SetFocusOnClick(focus) }
217func (b *gtkBox) SetCanTarget(canTarget bool) { b.inner.SetCanTarget(canTarget) }
218func (b *gtkBox) SetHexpand(expand bool) { b.inner.SetHexpand(expand) }
219func (b *gtkBox) SetVexpand(expand bool) { b.inner.SetVexpand(expand) }
220func (b *gtkBox) GetHexpand() bool { return b.inner.GetHexpand() }
221func (b *gtkBox) GetVexpand() bool { return b.inner.GetVexpand() }
222func (b *gtkBox) SetHalign(align gtk.Align) { b.inner.SetHalign(align) }
223func (b *gtkBox) SetValign(align gtk.Align) { b.inner.SetValign(align) }
224func (b *gtkBox) SetSizeRequest(w, h int) { b.inner.SetSizeRequest(w, h) }
225func (b *gtkBox) AddCssClass(class string) { b.inner.AddCssClass(class) }
226func (b *gtkBox) RemoveCssClass(class string) { b.inner.RemoveCssClass(class) }
227func (b *gtkBox) HasCssClass(class string) bool { return b.inner.HasCssClass(class) }
228func (b *gtkBox) Unparent() { b.inner.Unparent() }
229func (b *gtkBox) GtkWidget() *gtk.Widget { return &b.inner.Widget }
230
231func (b *gtkBox) GetParent() Widget {
232 parent := b.inner.GetParent()
233 if parent == nil {
234 return nil
235 }
236 return >kWidget{inner: parent}
237}
238
239func (b *gtkBox) Append(child Widget) {
240 if child == nil {
241 return
242 }
243 b.inner.Append(child.GtkWidget())
244}
245
246func (b *gtkBox) Prepend(child Widget) {
247 if child == nil {
248 return
249 }
250 b.inner.Prepend(child.GtkWidget())
251}
252
253func (b *gtkBox) Remove(child Widget) {
254 if child == nil {
255 return
256 }
257 b.inner.Remove(child.GtkWidget())
258}
259
260func (b *gtkBox) InsertChildAfter(child, sibling Widget) {
261 if child == nil {
262 return
263 }
264 var sibGtk *gtk.Widget
265 if sibling != nil {
266 sibGtk = sibling.GtkWidget()
267 }
268 b.inner.InsertChildAfter(child.GtkWidget(), sibGtk)
269}
270
271func (b *gtkBox) ReorderChildAfter(child, sibling Widget) {
272 if child == nil {
273 return
274 }
275 var sibGtk *gtk.Widget
276 if sibling != nil {
277 sibGtk = sibling.GtkWidget()
278 }
279 b.inner.ReorderChildAfter(child.GtkWidget(), sibGtk)
280}
281
282func (b *gtkBox) SetHomogeneous(h bool) { b.inner.SetHomogeneous(h) }
283func (b *gtkBox) GetHomogeneous() bool { return b.inner.GetHomogeneous() }
284func (b *gtkBox) SetSpacing(s int) { b.inner.SetSpacing(s) }
285func (b *gtkBox) GetSpacing() int { return b.inner.GetSpacing() }
286func (b *gtkBox) SetOrientation(o Orientation) { b.inner.SetOrientation(o) }
287func (b *gtkBox) GetOrientation() Orientation { return b.inner.GetOrientation() }
288
289func (b *gtkBox) GetAllocatedWidth() int { return b.inner.GetAllocatedWidth() }
290func (b *gtkBox) GetAllocatedHeight() int { return b.inner.GetAllocatedHeight() }
291func (b *gtkBox) AddController(c *gtk.EventController) { b.inner.AddController(c) }
292
293func (b *gtkBox) ComputePoint(target Widget) (x, y float64, ok bool) {
294 srcPoint := &graphene.Point{X: 0, Y: 0}
295 outPoint := &graphene.Point{}
296
297 var targetGtk *gtk.Widget
298 if target != nil {
299 targetGtk = target.GtkWidget()
300 }
301
302 ok = b.inner.ComputePoint(targetGtk, srcPoint, outPoint)
303 if !ok {
304 return 0, 0, false
305 }
306 return float64(outPoint.X), float64(outPoint.Y), true
307}
308
309// gtkOverlay wraps gtk.Overlay to implement OverlayWidget.
310type gtkOverlay struct {
311 inner *gtk.Overlay
312}
313
314func (o *gtkOverlay) Show() { o.inner.Show() }
315func (o *gtkOverlay) Hide() { o.inner.Hide() }
316func (o *gtkOverlay) SetVisible(visible bool) { o.inner.SetVisible(visible) }
317func (o *gtkOverlay) IsVisible() bool { return o.inner.GetVisible() }
318func (o *gtkOverlay) GrabFocus() bool { return o.inner.GrabFocus() }
319func (o *gtkOverlay) HasFocus() bool { return o.inner.HasFocus() }
320func (o *gtkOverlay) SetCanFocus(canFocus bool) { o.inner.SetCanFocus(canFocus) }
321func (o *gtkOverlay) SetFocusable(focusable bool) { o.inner.SetFocusable(focusable) }
322func (o *gtkOverlay) SetFocusOnClick(focus bool) { o.inner.SetFocusOnClick(focus) }
323func (o *gtkOverlay) SetCanTarget(canTarget bool) { o.inner.SetCanTarget(canTarget) }
324func (o *gtkOverlay) SetHexpand(expand bool) { o.inner.SetHexpand(expand) }
325func (o *gtkOverlay) SetVexpand(expand bool) { o.inner.SetVexpand(expand) }
326func (o *gtkOverlay) GetHexpand() bool { return o.inner.GetHexpand() }
327func (o *gtkOverlay) GetVexpand() bool { return o.inner.GetVexpand() }
328func (o *gtkOverlay) SetHalign(align gtk.Align) { o.inner.SetHalign(align) }
329func (o *gtkOverlay) SetValign(align gtk.Align) { o.inner.SetValign(align) }
330func (o *gtkOverlay) SetSizeRequest(w, h int) { o.inner.SetSizeRequest(w, h) }
331func (o *gtkOverlay) AddCssClass(class string) { o.inner.AddCssClass(class) }
332func (o *gtkOverlay) RemoveCssClass(class string) { o.inner.RemoveCssClass(class) }
333func (o *gtkOverlay) HasCssClass(class string) bool { return o.inner.HasCssClass(class) }
334func (o *gtkOverlay) Unparent() { o.inner.Unparent() }
335func (o *gtkOverlay) GtkWidget() *gtk.Widget { return &o.inner.Widget }
336
337func (o *gtkOverlay) GetParent() Widget {
338 parent := o.inner.GetParent()
339 if parent == nil {
340 return nil
341 }
342 return >kWidget{inner: parent}
343}
344
345func (o *gtkOverlay) SetChild(child Widget) {
346 if child == nil {
347 o.inner.SetChild(nil)
348 return
349 }
350 o.inner.SetChild(child.GtkWidget())
351}
352
353func (o *gtkOverlay) GetChild() Widget {
354 child := o.inner.GetChild()
355 if child == nil {
356 return nil
357 }
358 return >kWidget{inner: child}
359}
360
361func (o *gtkOverlay) AddOverlay(overlay Widget) {
362 if overlay == nil {
363 return
364 }
365 o.inner.AddOverlay(overlay.GtkWidget())
366}
367
368func (o *gtkOverlay) RemoveOverlay(overlay Widget) {
369 if overlay == nil {
370 return
371 }
372 o.inner.RemoveOverlay(overlay.GtkWidget())
373}
374
375func (o *gtkOverlay) SetClipOverlay(overlay Widget, clip bool) {
376 if overlay == nil {
377 return
378 }
379 o.inner.SetClipOverlay(overlay.GtkWidget(), clip)
380}
381
382func (o *gtkOverlay) GetClipOverlay(overlay Widget) bool {
383 if overlay == nil {
384 return false
385 }
386 return o.inner.GetClipOverlay(overlay.GtkWidget())
387}
388
389func (o *gtkOverlay) SetMeasureOverlay(overlay Widget, measure bool) {
390 if overlay == nil {
391 return
392 }
393 o.inner.SetMeasureOverlay(overlay.GtkWidget(), measure)
394}
395
396func (o *gtkOverlay) GetMeasureOverlay(overlay Widget) bool {
397 if overlay == nil {
398 return false
399 }
400 return o.inner.GetMeasureOverlay(overlay.GtkWidget())
401}
402
403func (o *gtkOverlay) GetAllocatedWidth() int { return o.inner.GetAllocatedWidth() }
404func (o *gtkOverlay) GetAllocatedHeight() int { return o.inner.GetAllocatedHeight() }
405func (o *gtkOverlay) AddController(c *gtk.EventController) { o.inner.AddController(c) }
406
407func (o *gtkOverlay) ComputePoint(target Widget) (x, y float64, ok bool) {
408 srcPoint := &graphene.Point{X: 0, Y: 0}
409 outPoint := &graphene.Point{}
410
411 var targetGtk *gtk.Widget
412 if target != nil {
413 targetGtk = target.GtkWidget()
414 }
415
416 ok = o.inner.ComputePoint(targetGtk, srcPoint, outPoint)
417 if !ok {
418 return 0, 0, false
419 }
420 return float64(outPoint.X), float64(outPoint.Y), true
421}
422
423// gtkLabel wraps gtk.Label to implement LabelWidget.
424type gtkLabel struct {
425 inner *gtk.Label
426}
427
428func (l *gtkLabel) Show() { l.inner.Show() }
429func (l *gtkLabel) Hide() { l.inner.Hide() }
430func (l *gtkLabel) SetVisible(visible bool) { l.inner.SetVisible(visible) }
431func (l *gtkLabel) IsVisible() bool { return l.inner.GetVisible() }
432func (l *gtkLabel) GrabFocus() bool { return l.inner.GrabFocus() }
433func (l *gtkLabel) HasFocus() bool { return l.inner.HasFocus() }
434func (l *gtkLabel) SetCanFocus(canFocus bool) { l.inner.SetCanFocus(canFocus) }
435func (l *gtkLabel) SetFocusable(focusable bool) { l.inner.SetFocusable(focusable) }
436func (l *gtkLabel) SetFocusOnClick(focus bool) { l.inner.SetFocusOnClick(focus) }
437func (l *gtkLabel) SetCanTarget(canTarget bool) { l.inner.SetCanTarget(canTarget) }
438func (l *gtkLabel) SetHexpand(expand bool) { l.inner.SetHexpand(expand) }
439func (l *gtkLabel) SetVexpand(expand bool) { l.inner.SetVexpand(expand) }
440func (l *gtkLabel) GetHexpand() bool { return l.inner.GetHexpand() }
441func (l *gtkLabel) GetVexpand() bool { return l.inner.GetVexpand() }
442func (l *gtkLabel) SetHalign(align gtk.Align) { l.inner.SetHalign(align) }
443func (l *gtkLabel) SetValign(align gtk.Align) { l.inner.SetValign(align) }
444func (l *gtkLabel) SetSizeRequest(w, h int) { l.inner.SetSizeRequest(w, h) }
445func (l *gtkLabel) AddCssClass(class string) { l.inner.AddCssClass(class) }
446func (l *gtkLabel) RemoveCssClass(class string) { l.inner.RemoveCssClass(class) }
447func (l *gtkLabel) HasCssClass(class string) bool { return l.inner.HasCssClass(class) }
448func (l *gtkLabel) Unparent() { l.inner.Unparent() }
449func (l *gtkLabel) GtkWidget() *gtk.Widget { return &l.inner.Widget }
450
451func (l *gtkLabel) GetParent() Widget {
452 parent := l.inner.GetParent()
453 if parent == nil {
454 return nil
455 }
456 return >kWidget{inner: parent}
457}
458
459func (l *gtkLabel) SetText(text string) { l.inner.SetText(text) }
460func (l *gtkLabel) GetText() string { return l.inner.GetText() }
461func (l *gtkLabel) SetMarkup(markup string) { l.inner.SetMarkup(markup) }
462func (l *gtkLabel) SetEllipsize(mode EllipsizeMode) { l.inner.SetEllipsize(pango.EllipsizeMode(mode)) }
463func (l *gtkLabel) SetMaxWidthChars(n int) { l.inner.SetMaxWidthChars(n) }
464func (l *gtkLabel) SetXalign(x float32) { l.inner.SetXalign(x) }
465
466func (l *gtkLabel) GetAllocatedWidth() int { return l.inner.GetAllocatedWidth() }
467func (l *gtkLabel) GetAllocatedHeight() int { return l.inner.GetAllocatedHeight() }
468func (l *gtkLabel) AddController(c *gtk.EventController) { l.inner.AddController(c) }
469
470func (l *gtkLabel) ComputePoint(target Widget) (x, y float64, ok bool) {
471 srcPoint := &graphene.Point{X: 0, Y: 0}
472 outPoint := &graphene.Point{}
473
474 var targetGtk *gtk.Widget
475 if target != nil {
476 targetGtk = target.GtkWidget()
477 }
478
479 ok = l.inner.ComputePoint(targetGtk, srcPoint, outPoint)
480 if !ok {
481 return 0, 0, false
482 }
483 return float64(outPoint.X), float64(outPoint.Y), true
484}
485
486// gtkButton wraps gtk.Button to implement ButtonWidget.
487type gtkButton struct {
488 inner *gtk.Button
489}
490
491func (btn *gtkButton) Show() { btn.inner.Show() }
492func (btn *gtkButton) Hide() { btn.inner.Hide() }
493func (btn *gtkButton) SetVisible(visible bool) { btn.inner.SetVisible(visible) }
494func (btn *gtkButton) IsVisible() bool { return btn.inner.GetVisible() }
495func (btn *gtkButton) GrabFocus() bool { return btn.inner.GrabFocus() }
496func (btn *gtkButton) HasFocus() bool { return btn.inner.HasFocus() }
497func (btn *gtkButton) SetCanFocus(canFocus bool) { btn.inner.SetCanFocus(canFocus) }
498func (btn *gtkButton) SetFocusable(focusable bool) { btn.inner.SetFocusable(focusable) }
499func (btn *gtkButton) SetFocusOnClick(focus bool) { btn.inner.SetFocusOnClick(focus) }
500func (btn *gtkButton) SetCanTarget(canTarget bool) { btn.inner.SetCanTarget(canTarget) }
501func (btn *gtkButton) SetHexpand(expand bool) { btn.inner.SetHexpand(expand) }
502func (btn *gtkButton) SetVexpand(expand bool) { btn.inner.SetVexpand(expand) }
503func (btn *gtkButton) GetHexpand() bool { return btn.inner.GetHexpand() }
504func (btn *gtkButton) GetVexpand() bool { return btn.inner.GetVexpand() }
505func (btn *gtkButton) SetHalign(align gtk.Align) { btn.inner.SetHalign(align) }
506func (btn *gtkButton) SetValign(align gtk.Align) { btn.inner.SetValign(align) }
507func (btn *gtkButton) SetSizeRequest(w, h int) { btn.inner.SetSizeRequest(w, h) }
508func (btn *gtkButton) AddCssClass(class string) { btn.inner.AddCssClass(class) }
509func (btn *gtkButton) RemoveCssClass(class string) { btn.inner.RemoveCssClass(class) }
510func (btn *gtkButton) HasCssClass(class string) bool { return btn.inner.HasCssClass(class) }
511func (btn *gtkButton) Unparent() { btn.inner.Unparent() }
512func (btn *gtkButton) GtkWidget() *gtk.Widget { return &btn.inner.Widget }
513
514func (btn *gtkButton) GetParent() Widget {
515 parent := btn.inner.GetParent()
516 if parent == nil {
517 return nil
518 }
519 return >kWidget{inner: parent}
520}
521
522func (btn *gtkButton) SetLabel(label string) { btn.inner.SetLabel(label) }
523func (btn *gtkButton) GetLabel() string { return btn.inner.GetLabel() }
524
525func (btn *gtkButton) SetChild(child Widget) {
526 if child == nil {
527 btn.inner.SetChild(nil)
528 return
529 }
530 btn.inner.SetChild(child.GtkWidget())
531}
532
533func (btn *gtkButton) GetChild() Widget {
534 child := btn.inner.GetChild()
535 if child == nil {
536 return nil
537 }
538 return >kWidget{inner: child}
539}
540
541func (btn *gtkButton) ConnectClicked(callback func()) uint32 {
542 cb := func(_ gtk.Button) {
543 callback()
544 }
545 return btn.inner.ConnectClicked(&cb)
546}
547
548func (btn *gtkButton) GetAllocatedWidth() int { return btn.inner.GetAllocatedWidth() }
549func (btn *gtkButton) GetAllocatedHeight() int { return btn.inner.GetAllocatedHeight() }
550func (btn *gtkButton) AddController(c *gtk.EventController) { btn.inner.AddController(c) }
551
552func (btn *gtkButton) ComputePoint(target Widget) (x, y float64, ok bool) {
553 srcPoint := &graphene.Point{X: 0, Y: 0}
554 outPoint := &graphene.Point{}
555
556 var targetGtk *gtk.Widget
557 if target != nil {
558 targetGtk = target.GtkWidget()
559 }
560
561 ok = btn.inner.ComputePoint(targetGtk, srcPoint, outPoint)
562 if !ok {
563 return 0, 0, false
564 }
565 return float64(outPoint.X), float64(outPoint.Y), true
566}
567
568// gtkImage wraps gtk.Image to implement ImageWidget.
569type gtkImage struct {
570 inner *gtk.Image
571}
572
573func (img *gtkImage) Show() { img.inner.Show() }
574func (img *gtkImage) Hide() { img.inner.Hide() }
575func (img *gtkImage) SetVisible(visible bool) { img.inner.SetVisible(visible) }
576func (img *gtkImage) IsVisible() bool { return img.inner.GetVisible() }
577func (img *gtkImage) GrabFocus() bool { return img.inner.GrabFocus() }
578func (img *gtkImage) HasFocus() bool { return img.inner.HasFocus() }
579func (img *gtkImage) SetCanFocus(canFocus bool) { img.inner.SetCanFocus(canFocus) }
580func (img *gtkImage) SetFocusable(focusable bool) { img.inner.SetFocusable(focusable) }
581func (img *gtkImage) SetFocusOnClick(focus bool) { img.inner.SetFocusOnClick(focus) }
582func (img *gtkImage) SetCanTarget(canTarget bool) { img.inner.SetCanTarget(canTarget) }
583func (img *gtkImage) SetHexpand(expand bool) { img.inner.SetHexpand(expand) }
584func (img *gtkImage) SetVexpand(expand bool) { img.inner.SetVexpand(expand) }
585func (img *gtkImage) GetHexpand() bool { return img.inner.GetHexpand() }
586func (img *gtkImage) GetVexpand() bool { return img.inner.GetVexpand() }
587func (img *gtkImage) SetHalign(align gtk.Align) { img.inner.SetHalign(align) }
588func (img *gtkImage) SetValign(align gtk.Align) { img.inner.SetValign(align) }
589func (img *gtkImage) SetSizeRequest(w, h int) { img.inner.SetSizeRequest(w, h) }
590func (img *gtkImage) AddCssClass(class string) { img.inner.AddCssClass(class) }
591func (img *gtkImage) RemoveCssClass(class string) { img.inner.RemoveCssClass(class) }
592func (img *gtkImage) HasCssClass(class string) bool { return img.inner.HasCssClass(class) }
593func (img *gtkImage) Unparent() { img.inner.Unparent() }
594func (img *gtkImage) GtkWidget() *gtk.Widget { return &img.inner.Widget }
595
596func (img *gtkImage) GetParent() Widget {
597 parent := img.inner.GetParent()
598 if parent == nil {
599 return nil
600 }
601 return >kWidget{inner: parent}
602}
603
604func (img *gtkImage) SetFromIconName(name string) { img.inner.SetFromIconName(&name) }
605func (img *gtkImage) SetFromFile(filename string) { img.inner.SetFromFile(&filename) }
606func (img *gtkImage) SetFromPaintable(p Paintable) {
607 if p == nil {
608 img.inner.Clear()
609 return
610 }
611 // Create a gdk.Paintable from the pointer
612 // gdk.Texture implements gdk.Paintable
613 texture := &gdk.Texture{}
614 texture.Ptr = p.GoPointer()
615 img.inner.SetFromPaintable(texture)
616}
617func (img *gtkImage) SetPixelSize(size int) { img.inner.SetPixelSize(size) }
618func (img *gtkImage) Clear() { img.inner.Clear() }
619
620func (img *gtkImage) GetAllocatedWidth() int { return img.inner.GetAllocatedWidth() }
621func (img *gtkImage) GetAllocatedHeight() int { return img.inner.GetAllocatedHeight() }
622func (img *gtkImage) AddController(c *gtk.EventController) { img.inner.AddController(c) }
623
624func (img *gtkImage) ComputePoint(target Widget) (x, y float64, ok bool) {
625 srcPoint := &graphene.Point{X: 0, Y: 0}
626 outPoint := &graphene.Point{}
627
628 var targetGtk *gtk.Widget
629 if target != nil {
630 targetGtk = target.GtkWidget()
631 }
632
633 ok = img.inner.ComputePoint(targetGtk, srcPoint, outPoint)
634 if !ok {
635 return 0, 0, false
636 }
637 return float64(outPoint.X), float64(outPoint.Y), true
638}
639
640// gtkProgressBar wraps gtk.ProgressBar to implement ProgressBarWidget.
641type gtkProgressBar struct {
642 inner *gtk.ProgressBar
643}
644
645func (p *gtkProgressBar) Show() { p.inner.Show() }
646func (p *gtkProgressBar) Hide() { p.inner.Hide() }
647func (p *gtkProgressBar) SetVisible(visible bool) { p.inner.SetVisible(visible) }
648func (p *gtkProgressBar) IsVisible() bool { return p.inner.GetVisible() }
649func (p *gtkProgressBar) GrabFocus() bool { return p.inner.GrabFocus() }
650func (p *gtkProgressBar) HasFocus() bool { return p.inner.HasFocus() }
651func (p *gtkProgressBar) SetCanFocus(canFocus bool) { p.inner.SetCanFocus(canFocus) }
652func (p *gtkProgressBar) SetFocusable(focusable bool) { p.inner.SetFocusable(focusable) }
653func (p *gtkProgressBar) SetFocusOnClick(focus bool) { p.inner.SetFocusOnClick(focus) }
654func (p *gtkProgressBar) SetCanTarget(canTarget bool) { p.inner.SetCanTarget(canTarget) }
655func (p *gtkProgressBar) SetHexpand(expand bool) { p.inner.SetHexpand(expand) }
656func (p *gtkProgressBar) SetVexpand(expand bool) { p.inner.SetVexpand(expand) }
657func (p *gtkProgressBar) GetHexpand() bool { return p.inner.GetHexpand() }
658func (p *gtkProgressBar) GetVexpand() bool { return p.inner.GetVexpand() }
659func (p *gtkProgressBar) SetHalign(align gtk.Align) { p.inner.SetHalign(align) }
660func (p *gtkProgressBar) SetValign(align gtk.Align) { p.inner.SetValign(align) }
661func (p *gtkProgressBar) SetSizeRequest(w, h int) { p.inner.SetSizeRequest(w, h) }
662func (p *gtkProgressBar) AddCssClass(class string) { p.inner.AddCssClass(class) }
663func (p *gtkProgressBar) RemoveCssClass(class string) { p.inner.RemoveCssClass(class) }
664func (p *gtkProgressBar) HasCssClass(class string) bool { return p.inner.HasCssClass(class) }
665func (p *gtkProgressBar) Unparent() { p.inner.Unparent() }
666func (p *gtkProgressBar) GtkWidget() *gtk.Widget { return &p.inner.Widget }
667
668func (p *gtkProgressBar) GetParent() Widget {
669 parent := p.inner.GetParent()
670 if parent == nil {
671 return nil
672 }
673 return >kWidget{inner: parent}
674}
675
676func (p *gtkProgressBar) GetAllocatedWidth() int { return p.inner.GetAllocatedWidth() }
677func (p *gtkProgressBar) GetAllocatedHeight() int { return p.inner.GetAllocatedHeight() }
678func (p *gtkProgressBar) AddController(c *gtk.EventController) { p.inner.AddController(c) }
679
680func (p *gtkProgressBar) ComputePoint(target Widget) (x, y float64, ok bool) {
681 srcPoint := &graphene.Point{X: 0, Y: 0}
682 outPoint := &graphene.Point{}
683
684 var targetGtk *gtk.Widget
685 if target != nil {
686 targetGtk = target.GtkWidget()
687 }
688
689 ok = p.inner.ComputePoint(targetGtk, srcPoint, outPoint)
690 if !ok {
691 return 0, 0, false
692 }
693 return float64(outPoint.X), float64(outPoint.Y), true
694}
695
696func (p *gtkProgressBar) SetFraction(fraction float64) { p.inner.SetFraction(fraction) }
697func (p *gtkProgressBar) GetFraction() float64 { return p.inner.GetFraction() }
698
699// gtkSpinner wraps gtk.Spinner to implement SpinnerWidget.
700type gtkSpinner struct {
701 inner *gtk.Spinner
702}
703
704func (s *gtkSpinner) Show() { s.inner.Show() }
705func (s *gtkSpinner) Hide() { s.inner.Hide() }
706func (s *gtkSpinner) SetVisible(visible bool) { s.inner.SetVisible(visible) }
707func (s *gtkSpinner) IsVisible() bool { return s.inner.GetVisible() }
708func (s *gtkSpinner) GrabFocus() bool { return s.inner.GrabFocus() }
709func (s *gtkSpinner) HasFocus() bool { return s.inner.HasFocus() }
710func (s *gtkSpinner) SetCanFocus(canFocus bool) { s.inner.SetCanFocus(canFocus) }
711func (s *gtkSpinner) SetFocusable(focusable bool) { s.inner.SetFocusable(focusable) }
712func (s *gtkSpinner) SetFocusOnClick(focus bool) { s.inner.SetFocusOnClick(focus) }
713func (s *gtkSpinner) SetCanTarget(canTarget bool) { s.inner.SetCanTarget(canTarget) }
714func (s *gtkSpinner) SetHexpand(expand bool) { s.inner.SetHexpand(expand) }
715func (s *gtkSpinner) SetVexpand(expand bool) { s.inner.SetVexpand(expand) }
716func (s *gtkSpinner) GetHexpand() bool { return s.inner.GetHexpand() }
717func (s *gtkSpinner) GetVexpand() bool { return s.inner.GetVexpand() }
718func (s *gtkSpinner) SetHalign(align gtk.Align) { s.inner.SetHalign(align) }
719func (s *gtkSpinner) SetValign(align gtk.Align) { s.inner.SetValign(align) }
720func (s *gtkSpinner) SetSizeRequest(w, h int) { s.inner.SetSizeRequest(w, h) }
721func (s *gtkSpinner) AddCssClass(class string) { s.inner.AddCssClass(class) }
722func (s *gtkSpinner) RemoveCssClass(class string) { s.inner.RemoveCssClass(class) }
723func (s *gtkSpinner) HasCssClass(class string) bool { return s.inner.HasCssClass(class) }
724func (s *gtkSpinner) Unparent() { s.inner.Unparent() }
725func (s *gtkSpinner) GtkWidget() *gtk.Widget { return &s.inner.Widget }
726
727func (s *gtkSpinner) GetParent() Widget {
728 parent := s.inner.GetParent()
729 if parent == nil {
730 return nil
731 }
732 return >kWidget{inner: parent}
733}
734
735func (s *gtkSpinner) GetAllocatedWidth() int { return s.inner.GetAllocatedWidth() }
736func (s *gtkSpinner) GetAllocatedHeight() int { return s.inner.GetAllocatedHeight() }
737func (s *gtkSpinner) AddController(c *gtk.EventController) { s.inner.AddController(c) }
738
739func (s *gtkSpinner) ComputePoint(target Widget) (x, y float64, ok bool) {
740 srcPoint := &graphene.Point{X: 0, Y: 0}
741 outPoint := &graphene.Point{}
742
743 var targetGtk *gtk.Widget
744 if target != nil {
745 targetGtk = target.GtkWidget()
746 }
747
748 ok = s.inner.ComputePoint(targetGtk, srcPoint, outPoint)
749 if !ok {
750 return 0, 0, false
751 }
752 return float64(outPoint.X), float64(outPoint.Y), true
753}
754
755func (s *gtkSpinner) Start() { s.inner.Start() }
756func (s *gtkSpinner) Stop() { s.inner.Stop() }
757func (s *gtkSpinner) SetSpinning(spinning bool) { s.inner.SetSpinning(spinning) }
758func (s *gtkSpinner) GetSpinning() bool { return s.inner.GetSpinning() }
759
760// GtkWidgetFactory creates real GTK widgets.
761type GtkWidgetFactory struct{}
762
763// NewGtkWidgetFactory creates a new factory for real GTK widgets.
764func NewGtkWidgetFactory() *GtkWidgetFactory {
765 return &GtkWidgetFactory{}
766}
767
768func (f *GtkWidgetFactory) NewPaned(orientation Orientation) PanedWidget {
769 paned := gtk.NewPaned(orientation)
770 paned.SetHexpand(true)
771 paned.SetVexpand(true)
772 return >kPaned{inner: paned}
773}
774
775func (f *GtkWidgetFactory) NewBox(orientation Orientation, spacing int) BoxWidget {
776 box := gtk.NewBox(orientation, spacing)
777 box.SetHexpand(true)
778 box.SetVexpand(true)
779 return >kBox{inner: box}
780}
781
782func (f *GtkWidgetFactory) NewOverlay() OverlayWidget {
783 overlay := gtk.NewOverlay()
784 overlay.SetHexpand(true)
785 overlay.SetVexpand(true)
786 return >kOverlay{inner: overlay}
787}
788
789func (f *GtkWidgetFactory) NewLabel(text string) LabelWidget {
790 label := gtk.NewLabel(&text)
791 return >kLabel{inner: label}
792}
793
794func (f *GtkWidgetFactory) NewButton() ButtonWidget {
795 button := gtk.NewButton()
796 return >kButton{inner: button}
797}
798
799func (f *GtkWidgetFactory) NewImage() ImageWidget {
800 image := gtk.NewImage()
801 return >kImage{inner: image}
802}
803
804func (f *GtkWidgetFactory) NewProgressBar() ProgressBarWidget {
805 progressBar := gtk.NewProgressBar()
806 return >kProgressBar{inner: progressBar}
807}
808
809func (f *GtkWidgetFactory) NewSpinner() SpinnerWidget {
810 spinner := gtk.NewSpinner()
811 return >kSpinner{inner: spinner}
812}
813
814func (f *GtkWidgetFactory) WrapWidget(w *gtk.Widget) Widget {
815 if w == nil {
816 return nil
817 }
818 return >kWidget{inner: w}
819}