v0.25.0 2e6c485

gtk_widgets.go RawHistoryFolder

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 &gtkWidget{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 &gtkWidget{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 &gtkWidget{inner: child}
139}
140
141func (p *gtkPaned) GetEndChild() Widget {
142	child := p.inner.GetEndChild()
143	if child == nil {
144		return nil
145	}
146	return &gtkWidget{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 &gtkWidget{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 &gtkWidget{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 &gtkWidget{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 &gtkWidget{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 &gtkWidget{inner: parent}
520}
521
522func (btn *gtkButton) SetLabel(label string)   { btn.inner.SetLabel(label) }
523func (btn *gtkButton) GetLabel() string        { return btn.inner.GetLabel() }
524func (btn *gtkButton) SetIconName(name string) { btn.inner.SetIconName(name) }
525
526func (btn *gtkButton) SetChild(child Widget) {
527	if child == nil {
528		btn.inner.SetChild(nil)
529		return
530	}
531	btn.inner.SetChild(child.GtkWidget())
532}
533
534func (btn *gtkButton) GetChild() Widget {
535	child := btn.inner.GetChild()
536	if child == nil {
537		return nil
538	}
539	return &gtkWidget{inner: child}
540}
541
542func (btn *gtkButton) ConnectClicked(callback func()) uint32 {
543	cb := func(_ gtk.Button) {
544		callback()
545	}
546	return btn.inner.ConnectClicked(&cb)
547}
548
549func (btn *gtkButton) GetAllocatedWidth() int               { return btn.inner.GetAllocatedWidth() }
550func (btn *gtkButton) GetAllocatedHeight() int              { return btn.inner.GetAllocatedHeight() }
551func (btn *gtkButton) AddController(c *gtk.EventController) { btn.inner.AddController(c) }
552
553func (btn *gtkButton) ComputePoint(target Widget) (x, y float64, ok bool) {
554	srcPoint := &graphene.Point{X: 0, Y: 0}
555	outPoint := &graphene.Point{}
556
557	var targetGtk *gtk.Widget
558	if target != nil {
559		targetGtk = target.GtkWidget()
560	}
561
562	ok = btn.inner.ComputePoint(targetGtk, srcPoint, outPoint)
563	if !ok {
564		return 0, 0, false
565	}
566	return float64(outPoint.X), float64(outPoint.Y), true
567}
568
569// gtkImage wraps gtk.Image to implement ImageWidget.
570type gtkImage struct {
571	inner *gtk.Image
572}
573
574func (img *gtkImage) Show()                         { img.inner.Show() }
575func (img *gtkImage) Hide()                         { img.inner.Hide() }
576func (img *gtkImage) SetVisible(visible bool)       { img.inner.SetVisible(visible) }
577func (img *gtkImage) IsVisible() bool               { return img.inner.GetVisible() }
578func (img *gtkImage) GrabFocus() bool               { return img.inner.GrabFocus() }
579func (img *gtkImage) HasFocus() bool                { return img.inner.HasFocus() }
580func (img *gtkImage) SetCanFocus(canFocus bool)     { img.inner.SetCanFocus(canFocus) }
581func (img *gtkImage) SetFocusable(focusable bool)   { img.inner.SetFocusable(focusable) }
582func (img *gtkImage) SetFocusOnClick(focus bool)    { img.inner.SetFocusOnClick(focus) }
583func (img *gtkImage) SetCanTarget(canTarget bool)   { img.inner.SetCanTarget(canTarget) }
584func (img *gtkImage) SetHexpand(expand bool)        { img.inner.SetHexpand(expand) }
585func (img *gtkImage) SetVexpand(expand bool)        { img.inner.SetVexpand(expand) }
586func (img *gtkImage) GetHexpand() bool              { return img.inner.GetHexpand() }
587func (img *gtkImage) GetVexpand() bool              { return img.inner.GetVexpand() }
588func (img *gtkImage) SetHalign(align gtk.Align)     { img.inner.SetHalign(align) }
589func (img *gtkImage) SetValign(align gtk.Align)     { img.inner.SetValign(align) }
590func (img *gtkImage) SetSizeRequest(w, h int)       { img.inner.SetSizeRequest(w, h) }
591func (img *gtkImage) AddCssClass(class string)      { img.inner.AddCssClass(class) }
592func (img *gtkImage) RemoveCssClass(class string)   { img.inner.RemoveCssClass(class) }
593func (img *gtkImage) HasCssClass(class string) bool { return img.inner.HasCssClass(class) }
594func (img *gtkImage) Unparent()                     { img.inner.Unparent() }
595func (img *gtkImage) GtkWidget() *gtk.Widget        { return &img.inner.Widget }
596
597func (img *gtkImage) GetParent() Widget {
598	parent := img.inner.GetParent()
599	if parent == nil {
600		return nil
601	}
602	return &gtkWidget{inner: parent}
603}
604
605func (img *gtkImage) SetFromIconName(name string) { img.inner.SetFromIconName(&name) }
606func (img *gtkImage) SetFromFile(filename string) { img.inner.SetFromFile(&filename) }
607func (img *gtkImage) SetFromPaintable(p Paintable) {
608	if p == nil {
609		img.inner.Clear()
610		return
611	}
612	// Create a gdk.Paintable from the pointer
613	// gdk.Texture implements gdk.Paintable
614	texture := &gdk.Texture{}
615	texture.Ptr = p.GoPointer()
616	img.inner.SetFromPaintable(texture)
617}
618func (img *gtkImage) SetPixelSize(size int) { img.inner.SetPixelSize(size) }
619func (img *gtkImage) Clear()                { img.inner.Clear() }
620
621func (img *gtkImage) GetAllocatedWidth() int               { return img.inner.GetAllocatedWidth() }
622func (img *gtkImage) GetAllocatedHeight() int              { return img.inner.GetAllocatedHeight() }
623func (img *gtkImage) AddController(c *gtk.EventController) { img.inner.AddController(c) }
624
625func (img *gtkImage) ComputePoint(target Widget) (x, y float64, ok bool) {
626	srcPoint := &graphene.Point{X: 0, Y: 0}
627	outPoint := &graphene.Point{}
628
629	var targetGtk *gtk.Widget
630	if target != nil {
631		targetGtk = target.GtkWidget()
632	}
633
634	ok = img.inner.ComputePoint(targetGtk, srcPoint, outPoint)
635	if !ok {
636		return 0, 0, false
637	}
638	return float64(outPoint.X), float64(outPoint.Y), true
639}
640
641// gtkProgressBar wraps gtk.ProgressBar to implement ProgressBarWidget.
642type gtkProgressBar struct {
643	inner *gtk.ProgressBar
644}
645
646func (p *gtkProgressBar) Show()                         { p.inner.Show() }
647func (p *gtkProgressBar) Hide()                         { p.inner.Hide() }
648func (p *gtkProgressBar) SetVisible(visible bool)       { p.inner.SetVisible(visible) }
649func (p *gtkProgressBar) IsVisible() bool               { return p.inner.GetVisible() }
650func (p *gtkProgressBar) GrabFocus() bool               { return p.inner.GrabFocus() }
651func (p *gtkProgressBar) HasFocus() bool                { return p.inner.HasFocus() }
652func (p *gtkProgressBar) SetCanFocus(canFocus bool)     { p.inner.SetCanFocus(canFocus) }
653func (p *gtkProgressBar) SetFocusable(focusable bool)   { p.inner.SetFocusable(focusable) }
654func (p *gtkProgressBar) SetFocusOnClick(focus bool)    { p.inner.SetFocusOnClick(focus) }
655func (p *gtkProgressBar) SetCanTarget(canTarget bool)   { p.inner.SetCanTarget(canTarget) }
656func (p *gtkProgressBar) SetHexpand(expand bool)        { p.inner.SetHexpand(expand) }
657func (p *gtkProgressBar) SetVexpand(expand bool)        { p.inner.SetVexpand(expand) }
658func (p *gtkProgressBar) GetHexpand() bool              { return p.inner.GetHexpand() }
659func (p *gtkProgressBar) GetVexpand() bool              { return p.inner.GetVexpand() }
660func (p *gtkProgressBar) SetHalign(align gtk.Align)     { p.inner.SetHalign(align) }
661func (p *gtkProgressBar) SetValign(align gtk.Align)     { p.inner.SetValign(align) }
662func (p *gtkProgressBar) SetSizeRequest(w, h int)       { p.inner.SetSizeRequest(w, h) }
663func (p *gtkProgressBar) AddCssClass(class string)      { p.inner.AddCssClass(class) }
664func (p *gtkProgressBar) RemoveCssClass(class string)   { p.inner.RemoveCssClass(class) }
665func (p *gtkProgressBar) HasCssClass(class string) bool { return p.inner.HasCssClass(class) }
666func (p *gtkProgressBar) Unparent()                     { p.inner.Unparent() }
667func (p *gtkProgressBar) GtkWidget() *gtk.Widget        { return &p.inner.Widget }
668
669func (p *gtkProgressBar) GetParent() Widget {
670	parent := p.inner.GetParent()
671	if parent == nil {
672		return nil
673	}
674	return &gtkWidget{inner: parent}
675}
676
677func (p *gtkProgressBar) GetAllocatedWidth() int               { return p.inner.GetAllocatedWidth() }
678func (p *gtkProgressBar) GetAllocatedHeight() int              { return p.inner.GetAllocatedHeight() }
679func (p *gtkProgressBar) AddController(c *gtk.EventController) { p.inner.AddController(c) }
680
681func (p *gtkProgressBar) ComputePoint(target Widget) (x, y float64, ok bool) {
682	srcPoint := &graphene.Point{X: 0, Y: 0}
683	outPoint := &graphene.Point{}
684
685	var targetGtk *gtk.Widget
686	if target != nil {
687		targetGtk = target.GtkWidget()
688	}
689
690	ok = p.inner.ComputePoint(targetGtk, srcPoint, outPoint)
691	if !ok {
692		return 0, 0, false
693	}
694	return float64(outPoint.X), float64(outPoint.Y), true
695}
696
697func (p *gtkProgressBar) SetFraction(fraction float64) { p.inner.SetFraction(fraction) }
698func (p *gtkProgressBar) GetFraction() float64         { return p.inner.GetFraction() }
699
700// gtkSpinner wraps gtk.Spinner to implement SpinnerWidget.
701type gtkSpinner struct {
702	inner *gtk.Spinner
703}
704
705func (s *gtkSpinner) Show()                         { s.inner.Show() }
706func (s *gtkSpinner) Hide()                         { s.inner.Hide() }
707func (s *gtkSpinner) SetVisible(visible bool)       { s.inner.SetVisible(visible) }
708func (s *gtkSpinner) IsVisible() bool               { return s.inner.GetVisible() }
709func (s *gtkSpinner) GrabFocus() bool               { return s.inner.GrabFocus() }
710func (s *gtkSpinner) HasFocus() bool                { return s.inner.HasFocus() }
711func (s *gtkSpinner) SetCanFocus(canFocus bool)     { s.inner.SetCanFocus(canFocus) }
712func (s *gtkSpinner) SetFocusable(focusable bool)   { s.inner.SetFocusable(focusable) }
713func (s *gtkSpinner) SetFocusOnClick(focus bool)    { s.inner.SetFocusOnClick(focus) }
714func (s *gtkSpinner) SetCanTarget(canTarget bool)   { s.inner.SetCanTarget(canTarget) }
715func (s *gtkSpinner) SetHexpand(expand bool)        { s.inner.SetHexpand(expand) }
716func (s *gtkSpinner) SetVexpand(expand bool)        { s.inner.SetVexpand(expand) }
717func (s *gtkSpinner) GetHexpand() bool              { return s.inner.GetHexpand() }
718func (s *gtkSpinner) GetVexpand() bool              { return s.inner.GetVexpand() }
719func (s *gtkSpinner) SetHalign(align gtk.Align)     { s.inner.SetHalign(align) }
720func (s *gtkSpinner) SetValign(align gtk.Align)     { s.inner.SetValign(align) }
721func (s *gtkSpinner) SetSizeRequest(w, h int)       { s.inner.SetSizeRequest(w, h) }
722func (s *gtkSpinner) AddCssClass(class string)      { s.inner.AddCssClass(class) }
723func (s *gtkSpinner) RemoveCssClass(class string)   { s.inner.RemoveCssClass(class) }
724func (s *gtkSpinner) HasCssClass(class string) bool { return s.inner.HasCssClass(class) }
725func (s *gtkSpinner) Unparent()                     { s.inner.Unparent() }
726func (s *gtkSpinner) GtkWidget() *gtk.Widget        { return &s.inner.Widget }
727
728func (s *gtkSpinner) GetParent() Widget {
729	parent := s.inner.GetParent()
730	if parent == nil {
731		return nil
732	}
733	return &gtkWidget{inner: parent}
734}
735
736func (s *gtkSpinner) GetAllocatedWidth() int               { return s.inner.GetAllocatedWidth() }
737func (s *gtkSpinner) GetAllocatedHeight() int              { return s.inner.GetAllocatedHeight() }
738func (s *gtkSpinner) AddController(c *gtk.EventController) { s.inner.AddController(c) }
739
740func (s *gtkSpinner) ComputePoint(target Widget) (x, y float64, ok bool) {
741	srcPoint := &graphene.Point{X: 0, Y: 0}
742	outPoint := &graphene.Point{}
743
744	var targetGtk *gtk.Widget
745	if target != nil {
746		targetGtk = target.GtkWidget()
747	}
748
749	ok = s.inner.ComputePoint(targetGtk, srcPoint, outPoint)
750	if !ok {
751		return 0, 0, false
752	}
753	return float64(outPoint.X), float64(outPoint.Y), true
754}
755
756func (s *gtkSpinner) Start()                    { s.inner.Start() }
757func (s *gtkSpinner) Stop()                     { s.inner.Stop() }
758func (s *gtkSpinner) SetSpinning(spinning bool) { s.inner.SetSpinning(spinning) }
759func (s *gtkSpinner) GetSpinning() bool         { return s.inner.GetSpinning() }
760
761// GtkWidgetFactory creates real GTK widgets.
762type GtkWidgetFactory struct{}
763
764// NewGtkWidgetFactory creates a new factory for real GTK widgets.
765func NewGtkWidgetFactory() *GtkWidgetFactory {
766	return &GtkWidgetFactory{}
767}
768
769func (f *GtkWidgetFactory) NewPaned(orientation Orientation) PanedWidget {
770	paned := gtk.NewPaned(orientation)
771	paned.SetHexpand(true)
772	paned.SetVexpand(true)
773	return &gtkPaned{inner: paned}
774}
775
776func (f *GtkWidgetFactory) NewBox(orientation Orientation, spacing int) BoxWidget {
777	box := gtk.NewBox(orientation, spacing)
778	box.SetHexpand(true)
779	box.SetVexpand(true)
780	return &gtkBox{inner: box}
781}
782
783func (f *GtkWidgetFactory) NewOverlay() OverlayWidget {
784	overlay := gtk.NewOverlay()
785	overlay.SetHexpand(true)
786	overlay.SetVexpand(true)
787	return &gtkOverlay{inner: overlay}
788}
789
790func (f *GtkWidgetFactory) NewLabel(text string) LabelWidget {
791	label := gtk.NewLabel(&text)
792	return &gtkLabel{inner: label}
793}
794
795func (f *GtkWidgetFactory) NewButton() ButtonWidget {
796	button := gtk.NewButton()
797	return &gtkButton{inner: button}
798}
799
800func (f *GtkWidgetFactory) NewImage() ImageWidget {
801	image := gtk.NewImage()
802	return &gtkImage{inner: image}
803}
804
805func (f *GtkWidgetFactory) NewProgressBar() ProgressBarWidget {
806	progressBar := gtk.NewProgressBar()
807	return &gtkProgressBar{inner: progressBar}
808}
809
810func (f *GtkWidgetFactory) NewSpinner() SpinnerWidget {
811	spinner := gtk.NewSpinner()
812	return &gtkSpinner{inner: spinner}
813}
814
815func (f *GtkWidgetFactory) WrapWidget(w *gtk.Widget) Widget {
816	if w == nil {
817		return nil
818	}
819	return &gtkWidget{inner: w}
820}

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 8

Tags 42

↑↓ moveenter openesc close