v0.30.0 eb3068f

gtk_widgets.go RawHistoryFolder

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

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