v0.28.0 3cb3770

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

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