GtkEventBox: wrong size allocation when children change size request mode
Steps to reproduce
- Have a widget that changes its size request mode at runtime after layouting. As an example pick a
GtkBox
and at runtime add aGtkLabel
that has wrap=true with a lot of text, changing theGtkBox
's size request mode from constant to height-for-width. - Put that widget inside a
GtkEventBox
and theGtkEventBox
inside aGtkScrolledWindow
- The scrolled window will not allow to scroll through the full widget.
- Calling
gtk_widget_queue_resize
will fix the issue.
Example code in Vala:
using Gtk;
class App : Gtk.Application {
public override void activate () {
var window = new Window ();
window.application = this;
var scrolled = new ScrolledWindow (null, null) { visible = true };
var event = new EventBox () { visible = true };
var box = new Box (Orientation.VERTICAL, 0) { visible = true };
event.add (box);
scrolled.add (event);
window.add (scrolled);
window.width_request = 300;
window.height_request = 200;
window.present ();
Timeout.add (2000, () => {
box.add (new Label ("This is in a scrolled window and as such should be scrollable, however the size is wrongly allocated. After 5s, gtk_widget_queue_resize is manually invoked, fixing the problem. Use interactive debugger to verify that allocation does not match clip. \n\n Apple pie dragée cotton candy candy canes soufflé fruitcake. Pie jelly-o pudding danish donut macaroon. Halvah soufflé carrot cake. Tootsie roll pudding liquorice chupa chups sesame snaps bonbon toffee cake. Cookie donut cheesecake pie. Chocolate candy bonbon wafer chupa chups pastry tiramisu. Cookie jelly gummies sweet ice cream croissant dragée. Liquorice fruitcake toffee. Oat cake chocolate cake brownie macaroon chocolate cake biscuit. Candy canes cake chupa chups brownie tart jelly gummies. Apple pie jelly beans cake. Dessert tiramisu candy. Apple pie dragée cake croissant tart caramels cheesecake bear claw.") { visible = true, wrap = true });
return false;
});
Timeout.add (7000, () => {
box.queue_resize ();
return false;
});
}
}
void main () {
var app = new App ();
app.run ();
}
You can test this use vala --pkg=gtk+-3.0 filename.vala
.
Current behavior
The allocated size of the widget is wrong. This is because of the GtkEventBox
not returning the correct height in gtk_widget_get_preferred_height_for_width
. In the scrolled window this results in the weird behavior that you can't scroll across the full size of the view.
Expected outcome
I can scroll through the full content of the scrolled window.
Version information
Gtk 3.24.14 on Debian testing.
As there is no GtkEventBox
, it probably does not affect Gtk 4. I don't know of any applications in production affected by this issue.