v0.23.3 fc8669a

widgets.go RawHistoryFolder

1// Package layout provides GTK widget abstractions and layout management for the pane system.
2// It defines interfaces that wrap GTK types, enabling unit testing without GTK runtime.
3package layout
4
5import (
6	"github.com/jwijenbergh/puregotk/v4/gtk"
7)
8
9// Orientation represents the orientation for layout widgets.
10type Orientation = gtk.Orientation
11
12// Orientation constants matching GTK values.
13const (
14	OrientationHorizontal = gtk.OrientationHorizontalValue
15	OrientationVertical   = gtk.OrientationVerticalValue
16)
17
18// Widget is the base interface that all GTK widgets implement.
19// It provides common widget operations needed for layout management.
20type Widget interface {
21	// Visibility
22	Show()
23	Hide()
24	SetVisible(visible bool)
25	IsVisible() bool
26
27	// Focus
28	GrabFocus() bool
29	HasFocus() bool
30	SetCanFocus(canFocus bool)
31	SetFocusable(focusable bool) // GTK4: makes widget able to receive keyboard focus
32	SetFocusOnClick(focusOnClick bool)
33
34	// Pointer events
35	SetCanTarget(canTarget bool) // If false, widget won't receive pointer events
36
37	// Layout
38	SetHexpand(expand bool)
39	SetVexpand(expand bool)
40	GetHexpand() bool
41	GetVexpand() bool
42	SetHalign(align gtk.Align)
43	SetValign(align gtk.Align)
44	SetSizeRequest(width, height int)
45
46	// Geometry - for focus navigation
47	GetAllocatedWidth() int
48	GetAllocatedHeight() int
49	// ComputePoint returns the position of this widget's origin (0,0) relative to
50	// the target widget's coordinate space. If target is nil, returns position
51	// relative to the native window. Returns ok=false if computation fails.
52	ComputePoint(target Widget) (x, y float64, ok bool)
53
54	// CSS styling
55	AddCssClass(cssClass string)
56	RemoveCssClass(cssClass string)
57	HasCssClass(cssClass string) bool
58
59	// Parent management
60	Unparent()
61	GetParent() Widget
62
63	// GTK interop - returns the underlying GTK widget for embedding
64	GtkWidget() *gtk.Widget
65
66	// AddController adds an event controller to the widget
67	AddController(controller *gtk.EventController)
68}
69
70// PanedWidget wraps gtk.Paned for creating split views.
71// It manages two child widgets separated by a draggable divider.
72type PanedWidget interface {
73	Widget
74
75	// Child management
76	SetStartChild(child Widget)
77	SetEndChild(child Widget)
78	GetStartChild() Widget
79	GetEndChild() Widget
80
81	// Divider position
82	SetPosition(position int)
83	GetPosition() int
84
85	// Resize behavior
86	SetResizeStartChild(resize bool)
87	SetResizeEndChild(resize bool)
88	GetResizeStartChild() bool
89	GetResizeEndChild() bool
90
91	// Shrink behavior (whether child can be smaller than its minimum size)
92	SetShrinkStartChild(shrink bool)
93	SetShrinkEndChild(shrink bool)
94	GetShrinkStartChild() bool
95	GetShrinkEndChild() bool
96
97	// Signals
98	ConnectMap(callback func()) uint32
99	ConnectNotifyPosition(callback func()) uint32
100
101	// Tick callback for frame-based updates (returns signal ID)
102	// Callback returns true to continue, false to stop
103	AddTickCallback(callback func() bool) uint
104
105	// Handle appearance
106	SetWideHandle(wide bool)
107	GetWideHandle() bool
108}
109
110// BoxWidget wraps gtk.Box for linear layouts.
111// It arranges children in a single row or column.
112type BoxWidget interface {
113	Widget
114
115	// Child management
116	Append(child Widget)
117	Prepend(child Widget)
118	Remove(child Widget)
119	InsertChildAfter(child Widget, sibling Widget)
120	ReorderChildAfter(child Widget, sibling Widget)
121
122	// Configuration
123	SetHomogeneous(homogeneous bool)
124	GetHomogeneous() bool
125	SetSpacing(spacing int)
126	GetSpacing() int
127	SetOrientation(orientation Orientation)
128	GetOrientation() Orientation
129}
130
131// OverlayWidget wraps gtk.Overlay for layered content.
132// It displays overlay widgets on top of a main child widget.
133type OverlayWidget interface {
134	Widget
135
136	// Main child
137	SetChild(child Widget)
138	GetChild() Widget
139
140	// Overlay management
141	AddOverlay(overlay Widget)
142	RemoveOverlay(overlay Widget)
143
144	// Overlay configuration
145	SetClipOverlay(overlay Widget, clip bool)
146	GetClipOverlay(overlay Widget) bool
147	SetMeasureOverlay(overlay Widget, measure bool)
148	GetMeasureOverlay(overlay Widget) bool
149}
150
151// EllipsizeMode represents pango ellipsize modes.
152type EllipsizeMode = int
153
154// Ellipsize mode constants.
155const (
156	EllipsizeNone   EllipsizeMode = 0
157	EllipsizeStart  EllipsizeMode = 1
158	EllipsizeMiddle EllipsizeMode = 2
159	EllipsizeEnd    EllipsizeMode = 3
160)
161
162// LabelWidget wraps gtk.Label for text display.
163type LabelWidget interface {
164	Widget
165
166	SetText(text string)
167	GetText() string
168	SetMarkup(markup string)
169	SetEllipsize(mode EllipsizeMode)
170	SetMaxWidthChars(nChars int)
171	SetXalign(xalign float32)
172}
173
174// ButtonWidget wraps gtk.Button for clickable elements.
175type ButtonWidget interface {
176	Widget
177
178	SetLabel(label string)
179	GetLabel() string
180	SetChild(child Widget)
181	GetChild() Widget
182
183	// Connect click handler, returns signal ID for disconnection
184	ConnectClicked(callback func()) uint32
185}
186
187// Paintable represents a graphics texture that can be displayed in an image.
188// This interface abstracts over gdk.Paintable/gdk.Texture.
189type Paintable interface {
190	GoPointer() uintptr
191}
192
193// ImageWidget wraps gtk.Image for displaying images.
194type ImageWidget interface {
195	Widget
196
197	SetFromIconName(iconName string)
198	SetFromFile(filename string)
199	SetFromPaintable(paintable Paintable)
200	SetPixelSize(pixelSize int)
201	Clear()
202}
203
204// ProgressBarWidget wraps gtk.ProgressBar for displaying loading progress.
205// Implementations may include smooth animation behavior.
206type ProgressBarWidget interface {
207	Widget
208
209	// SetFraction sets the progress value (0.0 to 1.0).
210	SetFraction(fraction float64)
211	// GetFraction returns the current progress value.
212	GetFraction() float64
213}
214
215// SpinnerWidget wraps gtk.Spinner for displaying indefinite loading.
216type SpinnerWidget interface {
217	Widget
218
219	Start()
220	Stop()
221	SetSpinning(spinning bool)
222	GetSpinning() bool
223}
224
225// WidgetFactory creates widget instances.
226// This abstraction allows tests to inject mock factories.
227type WidgetFactory interface {
228	// Container widgets
229	NewPaned(orientation Orientation) PanedWidget
230	NewBox(orientation Orientation, spacing int) BoxWidget
231	NewOverlay() OverlayWidget
232
233	// Display widgets
234	NewLabel(text string) LabelWidget
235	NewButton() ButtonWidget
236	NewImage() ImageWidget
237	NewProgressBar() ProgressBarWidget
238	NewSpinner() SpinnerWidget
239
240	// Wrap existing GTK widget
241	WrapWidget(w *gtk.Widget) Widget
242}
243
244// PaneRenderer creates pane view widgets from domain entities.
245// This decouples the tree renderer from concrete PaneView implementation.
246type PaneRenderer interface {
247	// RenderPane creates a widget for a pane node.
248	// The webViewWidget is the GTK widget from the WebView.
249	RenderPane(paneID string, webViewWidget Widget) Widget
250}

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