v0.21.0 73bf644

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

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