18
18
class TogaContainerLayoutManager (Gtk .LayoutManager ):
19
19
def __init__ (self ):
20
20
super ().__init__ ()
21
+ print ("[DEBUG CONTAINER] TogaContainerLayoutManager initialized" )
21
22
22
23
def do_get_request_mode (self , container ):
24
+ print (f"[DEBUG CONTAINER] Getting request mode for container { container } " )
23
25
return Gtk .SizeRequestMode .CONSTANT_SIZE
24
26
25
27
def do_measure (self , container , orientation , for_size ):
@@ -30,19 +32,42 @@ def do_measure(self, container, orientation, for_size):
30
32
31
33
If the container does not yet have content, the minimum size is set to 0x0.
32
34
"""
33
- # print("GET PREFERRED SIZE", self._content)
35
+ orient_name = (
36
+ "HORIZONTAL"
37
+ if orientation == Gtk .Orientation .HORIZONTAL
38
+ else "VERTICAL"
39
+ )
40
+ print (
41
+ f"[DEBUG CONTAINER] Measuring container: orientation={ orient_name } , "
42
+ f"for_size={ for_size } "
43
+ )
44
+
34
45
if container ._content is None :
46
+ print (
47
+ "[DEBUG CONTAINER] Container has no content, returning 0, 0, -1, -1"
48
+ )
35
49
return 0 , 0 , - 1 , - 1
36
50
37
51
# Ensure we have an accurate min layout size
52
+ print ("[DEBUG CONTAINER] Recomputing container layout for measurement" )
38
53
container .recompute ()
39
54
40
55
# The container will conform to the size of the allocation it is given,
41
56
# so the min and preferred size are the same.
42
57
if orientation == Gtk .Orientation .HORIZONTAL :
43
- return container .min_width , container .min_width , - 1 , - 1
58
+ result = container .min_width , container .min_width , - 1 , - 1
59
+ print (
60
+ f"[DEBUG CONTAINER] Horizontal measure result: "
61
+ f"min={ result [0 ]} , nat={ result [1 ]} "
62
+ )
63
+ return result
44
64
elif orientation == Gtk .Orientation .VERTICAL :
45
- return container .min_height , container .min_height , - 1 , - 1
65
+ result = container .min_height , container .min_height , - 1 , - 1
66
+ print (
67
+ f"[DEBUG CONTAINER] Vertical measure result: "
68
+ f"min={ result [0 ]} , nat={ result [1 ]} "
69
+ )
70
+ return result
46
71
return None
47
72
48
73
def do_allocate (self , container , width , height , baseline ):
@@ -53,35 +78,52 @@ def do_allocate(self, container, width, height, baseline):
53
78
layout will then be re-computed based on this new available size, and
54
79
that new geometry will be applied to all child widgets of the container.
55
80
"""
56
- # print(widget._content, f"Container layout {width}x{height} @ 0x0")
81
+ print (
82
+ f"[DEBUG CONTAINER] Allocating container: "
83
+ f"width={ width } , height={ height } , baseline={ baseline } "
84
+ )
57
85
58
86
if container ._content :
59
87
current_width = container .width
60
88
current_height = container .height
61
89
resized = (width , height ) != (current_width , current_height )
62
90
91
+ print (
92
+ f"[DEBUG CONTAINER] Current container size: "
93
+ f"{ current_width } x{ current_height } , "
94
+ f"resized={ resized } , needs_redraw={ container .needs_redraw } "
95
+ )
96
+
63
97
if resized or container .needs_redraw :
64
- # print("REFRESH LAYOUT", width, height)
98
+ print (f"[DEBUG CONTAINER] Refreshing layout to { width } x { height } " )
65
99
container ._content .interface .style .layout (container )
66
100
container .min_width = container ._content .interface .layout .min_width
67
101
container .min_height = (
68
102
container ._content .interface .layout .min_height
69
103
)
104
+ print (
105
+ f"[DEBUG CONTAINER] New min size: "
106
+ f"{ container .min_width } x{ container .min_height } "
107
+ )
70
108
71
109
# WARNING! This is the list of children of the *container*, not
72
110
# the Toga widget. Toga maintains a tree of children; all nodes
73
111
# in that tree are direct children of the container.
74
112
75
113
# Process each child widget
114
+ print ("[DEBUG CONTAINER] Allocating children:" )
115
+ child_count = 0
76
116
child_widget = container .get_first_child ()
77
117
while child_widget is not None :
118
+ child_count += 1
78
119
if child_widget .get_visible ():
79
120
# Set the allocation of the child widget to the computed
80
121
# layout size.
81
- # print(
82
- # f" allocate child {child_widget.interface}: "
83
- # "{child_widget.interface.layout}"
84
- # )
122
+ print (
123
+ f"[DEBUG CONTAINER] Child { child_count } : "
124
+ f"{ getattr (child_widget , 'interface' , 'unknown' )} "
125
+ )
126
+
85
127
child_widget_allocation = Gdk .Rectangle ()
86
128
child_widget_allocation .x = (
87
129
child_widget .interface .layout .absolute_content_left
@@ -95,11 +137,31 @@ def do_allocate(self, container, width, height, baseline):
95
137
child_widget_allocation .height = (
96
138
child_widget .interface .layout .content_height
97
139
)
140
+
141
+ print (
142
+ f"[DEBUG CONTAINER] Allocating at "
143
+ f"({ child_widget_allocation .x } ,"
144
+ f"{ child_widget_allocation .y } ) "
145
+ f"size { child_widget_allocation .width } x"
146
+ f"{ child_widget_allocation .height } "
147
+ )
98
148
child_widget .size_allocate (child_widget_allocation , - 1 )
149
+ else :
150
+ print (
151
+ f"[DEBUG CONTAINER] Child { child_count } : "
152
+ f"{ getattr (child_widget , 'interface' , 'unknown' )} "
153
+ f"(not visible)"
154
+ )
99
155
child_widget = child_widget .get_next_sibling ()
100
156
157
+ print (f"[DEBUG CONTAINER] Allocated { child_count } children" )
158
+
101
159
# The layout has been redrawn
102
160
container .needs_redraw = False
161
+ print (
162
+ "[DEBUG CONTAINER] Allocation complete, "
163
+ "container.needs_redraw set to False"
164
+ )
103
165
104
166
class TogaContainer (Gtk .Box ):
105
167
"""A GTK container widget implementing Toga's layout.
@@ -109,11 +171,13 @@ class TogaContainer(Gtk.Box):
109
171
110
172
def __init__ (self ):
111
173
super ().__init__ ()
174
+ print ("[DEBUG CONTAINER] TogaContainer initialized" )
112
175
113
176
# Because we don't have access to the existing layout manager, we must
114
177
# create our custom layout manager class.
115
178
layout_manager = TogaContainerLayoutManager ()
116
179
self .set_layout_manager (layout_manager )
180
+ print ("[DEBUG CONTAINER] Custom layout manager set" )
117
181
118
182
self ._content = None
119
183
self .min_width = 100
@@ -128,8 +192,14 @@ def __init__(self):
128
192
129
193
# A flag that can be used to explicitly flag that a redraw is required.
130
194
self .needs_redraw = True
195
+ print (
196
+ f"[DEBUG CONTAINER] Initial state: "
197
+ f"min_size={ self .min_width } x{ self .min_height } , dpi={ self .dpi } , "
198
+ f"needs_redraw={ self .needs_redraw } "
199
+ )
131
200
132
201
def refreshed (self ):
202
+ print ("[DEBUG CONTAINER] Container refreshed called" )
133
203
pass
134
204
135
205
def make_dirty (self , widget = None ):
@@ -140,7 +210,16 @@ def make_dirty(self, widget=None):
140
210
self .needs_redraw = True
141
211
if widget is not None :
142
212
self ._dirty_widgets .add (widget )
213
+ print (
214
+ f"[DEBUG CONTAINER] Widget { widget } marked as dirty, "
215
+ f"dirty count: { len (self ._dirty_widgets )} "
216
+ )
217
+ else :
218
+ print (
219
+ "[DEBUG CONTAINER] Container marked as dirty (no specific widget)"
220
+ )
143
221
self .queue_resize ()
222
+ print ("[DEBUG CONTAINER] Resize queued" )
144
223
145
224
@property
146
225
def width (self ):
@@ -149,11 +228,13 @@ def width(self):
149
228
If the container doesn't have any content yet, the width is 0.
150
229
"""
151
230
if self ._content is None :
231
+ print ("[DEBUG CONTAINER] width property: No content, returning 0" )
152
232
return 0
153
233
154
234
if self ._dirty_widgets and self .needs_redraw :
155
235
self .recompute ()
156
236
width = self .get_width ()
237
+ print (f"[DEBUG CONTAINER] width property: returning { width } " )
157
238
return width
158
239
159
240
@property
@@ -163,11 +244,13 @@ def height(self):
163
244
If the container doesn't have any content yet, the height is 0.
164
245
"""
165
246
if self ._content is None :
247
+ print ("[DEBUG CONTAINER] height property: No content, returning 0" )
166
248
return 0
167
249
168
250
if self ._dirty_widgets and self .needs_redraw :
169
251
self .recompute ()
170
252
height = self .get_height ()
253
+ print (f"[DEBUG CONTAINER] height property: returning { height } " )
171
254
return height
172
255
173
256
@property
@@ -185,14 +268,20 @@ def content(self):
185
268
186
269
@content .setter
187
270
def content (self , widget ):
271
+ print (f"[DEBUG CONTAINER] Setting container content to { widget } " )
188
272
if self ._content :
273
+ print (f"[DEBUG CONTAINER] Removing old content { self ._content } " )
189
274
self ._content .container = None
190
275
191
276
self ._content = widget
192
277
if widget :
278
+ print (
279
+ f"[DEBUG CONTAINER] Setting container reference on widget { widget } "
280
+ )
193
281
widget .container = self
194
282
self .make_dirty (widget )
195
283
else :
284
+ print ("[DEBUG CONTAINER] No new content, marking container as dirty" )
196
285
self .make_dirty ()
197
286
198
287
def recompute (self ):
@@ -201,19 +290,42 @@ def recompute(self):
201
290
Any widgets known to be dirty will be rehinted. The minimum possible
202
291
layout size for the container will also be recomputed.
203
292
"""
293
+ print (
294
+ f"[DEBUG CONTAINER] recompute() called. Has content: "
295
+ f"{ self ._content is not None } , "
296
+ f"Dirty widgets: { len (self ._dirty_widgets )} "
297
+ )
204
298
if self ._content and self ._dirty_widgets :
205
299
# If any of the widgets have been marked as dirty,
206
300
# recompute their bounds, and re-evaluate the minimum
207
301
# allowed size for the layout.
302
+ print (
303
+ f"[DEBUG CONTAINER] Rehinting "
304
+ f"{ len (self ._dirty_widgets )} dirty widgets"
305
+ )
208
306
while self ._dirty_widgets :
209
307
widget = self ._dirty_widgets .pop ()
308
+ print (f"[DEBUG CONTAINER] Rehinting widget { widget } " )
210
309
widget .rehint ()
211
310
212
311
# Recompute the layout
312
+ print ("[DEBUG CONTAINER] Recomputing layout for content" )
213
313
self ._content .interface .style .layout (self )
214
314
315
+ old_min_width = self .min_width
316
+ old_min_height = self .min_height
215
317
self .min_width = self ._content .interface .layout .min_width
216
318
self .min_height = self ._content .interface .layout .min_height
319
+ print (
320
+ f"[DEBUG CONTAINER] Min size updated: "
321
+ f"{ old_min_width } x{ old_min_height } -> "
322
+ f"{ self .min_width } x{ self .min_height } "
323
+ )
324
+ else :
325
+ print (
326
+ "[DEBUG CONTAINER] No content or no dirty widgets, "
327
+ "skipping recompute"
328
+ )
217
329
218
330
else : # pragma: no-cover-if-gtk4
219
331
0 commit comments