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
99 // Tick callback for frame-based updates (returns signal ID)
100 // Callback returns true to continue, false to stop
101 AddTickCallback(callback func() bool) uint
102
103 // Handle appearance
104 SetWideHandle(wide bool)
105 GetWideHandle() bool
106}
107
108// BoxWidget wraps gtk.Box for linear layouts.
109// It arranges children in a single row or column.
110type BoxWidget interface {
111 Widget
112
113 // Child management
114 Append(child Widget)
115 Prepend(child Widget)
116 Remove(child Widget)
117 InsertChildAfter(child Widget, sibling Widget)
118 ReorderChildAfter(child Widget, sibling Widget)
119
120 // Configuration
121 SetHomogeneous(homogeneous bool)
122 GetHomogeneous() bool
123 SetSpacing(spacing int)
124 GetSpacing() int
125 SetOrientation(orientation Orientation)
126 GetOrientation() Orientation
127}
128
129// OverlayWidget wraps gtk.Overlay for layered content.
130// It displays overlay widgets on top of a main child widget.
131type OverlayWidget interface {
132 Widget
133
134 // Main child
135 SetChild(child Widget)
136 GetChild() Widget
137
138 // Overlay management
139 AddOverlay(overlay Widget)
140 RemoveOverlay(overlay Widget)
141
142 // Overlay configuration
143 SetClipOverlay(overlay Widget, clip bool)
144 GetClipOverlay(overlay Widget) bool
145 SetMeasureOverlay(overlay Widget, measure bool)
146 GetMeasureOverlay(overlay Widget) bool
147}
148
149// EllipsizeMode represents pango ellipsize modes.
150type EllipsizeMode = int
151
152// Ellipsize mode constants.
153const (
154 EllipsizeNone EllipsizeMode = 0
155 EllipsizeStart EllipsizeMode = 1
156 EllipsizeMiddle EllipsizeMode = 2
157 EllipsizeEnd EllipsizeMode = 3
158)
159
160// LabelWidget wraps gtk.Label for text display.
161type LabelWidget interface {
162 Widget
163
164 SetText(text string)
165 GetText() string
166 SetMarkup(markup string)
167 SetEllipsize(mode EllipsizeMode)
168 SetMaxWidthChars(nChars int)
169 SetXalign(xalign float32)
170}
171
172// ButtonWidget wraps gtk.Button for clickable elements.
173type ButtonWidget interface {
174 Widget
175
176 SetLabel(label string)
177 GetLabel() string
178 SetChild(child Widget)
179 GetChild() Widget
180
181 // Connect click handler, returns signal ID for disconnection
182 ConnectClicked(callback func()) uint32
183}
184
185// Paintable represents a graphics texture that can be displayed in an image.
186// This interface abstracts over gdk.Paintable/gdk.Texture.
187type Paintable interface {
188 GoPointer() uintptr
189}
190
191// ImageWidget wraps gtk.Image for displaying images.
192type ImageWidget interface {
193 Widget
194
195 SetFromIconName(iconName string)
196 SetFromFile(filename string)
197 SetFromPaintable(paintable Paintable)
198 SetPixelSize(pixelSize int)
199 Clear()
200}
201
202// ProgressBarWidget wraps gtk.ProgressBar for displaying loading progress.
203// Implementations may include smooth animation behavior.
204type ProgressBarWidget interface {
205 Widget
206
207 // SetFraction sets the progress value (0.0 to 1.0).
208 SetFraction(fraction float64)
209 // GetFraction returns the current progress value.
210 GetFraction() float64
211}
212
213// WidgetFactory creates widget instances.
214// This abstraction allows tests to inject mock factories.
215type WidgetFactory interface {
216 // Container widgets
217 NewPaned(orientation Orientation) PanedWidget
218 NewBox(orientation Orientation, spacing int) BoxWidget
219 NewOverlay() OverlayWidget
220
221 // Display widgets
222 NewLabel(text string) LabelWidget
223 NewButton() ButtonWidget
224 NewImage() ImageWidget
225 NewProgressBar() ProgressBarWidget
226
227 // Wrap existing GTK widget
228 WrapWidget(w *gtk.Widget) Widget
229}
230
231// PaneRenderer creates pane view widgets from domain entities.
232// This decouples the tree renderer from concrete PaneView implementation.
233type PaneRenderer interface {
234 // RenderPane creates a widget for a pane node.
235 // The webViewWidget is the GTK widget from the WebView.
236 RenderPane(paneID string, webViewWidget Widget) Widget
237}