@@ -2337,6 +2337,7 @@ const TextElement = struct {
23372337};
23382338
23392339/// A texture is held in memory for the entire duration it might be needed.
2340+ ///
23402341/// If a texture is in use by more than one element, then the `references`
23412342/// counter keeps track of how many elements are currently depending on
23422343/// this texture.
@@ -2991,11 +2992,20 @@ pub const Display = struct {
29912992 var expander_weights : f32 = 0 ;
29922993
29932994 // Make sure this element never exceeds its maximum.
2995+ var panel_resized = false ;
29942996 if (parent .layout .x == .grows and parent .maximum .width > 0 ) {
2995- parent .rect .width = @min (parent .rect .width , parent .maximum .width );
2997+ const new_width = @min (parent .rect .width , parent .maximum .width );
2998+ if (parent .rect .width != new_width ) {
2999+ parent .rect .width = new_width ;
3000+ panel_resized = true ;
3001+ }
29963002 }
29973003 if (parent .layout .y == .grows and parent .maximum .height > 0 ) {
2998- parent .rect .height = @min (parent .rect .height , parent .maximum .height );
3004+ const new_height = @min (parent .rect .height , parent .maximum .height );
3005+ if (parent .rect .height != new_height ) {
3006+ parent .rect .height = new_height ;
3007+ panel_resized = true ;
3008+ }
29993009 }
30003010
30013011 // # Step 1
@@ -3010,6 +3020,7 @@ pub const Display = struct {
30103020 if (element .visible == .hidden ) {
30113021 continue ;
30123022 }
3023+ var child_resized = false ;
30133024 if ((dev_build or dev_mode ) and element .layout .position == .float ) {
30143025 if (element .layout .x == .grows ) {
30153026 err ("floating items cant grow. {s} {s}" , .{ element .name , @tagName (element .type ) });
@@ -3024,15 +3035,23 @@ pub const Display = struct {
30243035 .grows = > {
30253036 // Grow to the maximum the parent will allow
30263037 element .rect .x = 0 ;
3027- element .rect .width = parent .rect .width - (parent .pad .left + parent .pad .right );
3028- if (element .maximum .width > 0 and element .rect .width > element .maximum .width ) {
3029- element .rect .width = element .maximum .width ;
3038+ var new_width = parent .rect .width - (parent .pad .left + parent .pad .right );
3039+ if (element .maximum .width > 0 and new_width > element .maximum .width ) {
3040+ new_width = element .maximum .width ;
3041+ }
3042+ if (element .rect .width != new_width ) {
3043+ element .rect .width = new_width ;
3044+ child_resized = true ;
30303045 }
30313046 },
30323047 .shrinks = > {
30333048 // Shrink to the smallest the children will allow
30343049 // Shrink to the left, centre, or right.
3035- element .rect .width = element .shrink_width (self , parent .rect .width );
3050+ const new_width = element .shrink_width (self , parent .rect .width );
3051+ if (element .rect .width != new_width ) {
3052+ element .rect .width = new_width ;
3053+ child_resized = true ;
3054+ }
30363055 switch (element .child_align .x ) {
30373056 .start = > element .rect .x = 0 ,
30383057 .end = > element .rect .x = parent .rect .width - element .rect .width ,
@@ -3043,6 +3062,10 @@ pub const Display = struct {
30433062 // No shrinking or growing applies.
30443063 },
30453064 }
3065+ if (child_resized and element .on_resized .func != null ) {
3066+ debug ("element {s} resized. callback = {any}" , .{ element .name , element .on_resized .func != null });
3067+ _ = element .on_resized .func .? (element .on_resized .ptr , self , element );
3068+ }
30463069 switch (element .layout .y ) {
30473070 .grows = > {
30483071 // Grow to the maximum the parent will allow
@@ -3094,6 +3117,10 @@ pub const Display = struct {
30943117 self .do_relayout (child );
30953118 }
30963119 }
3120+
3121+ if (panel_resized and parent .on_resized .func != null ) {
3122+ _ = parent .on_resized .func .? (parent .on_resized .ptr , self , parent );
3123+ }
30973124 }
30983125
30993126 inline fn relayout_centre (_ : * Display , parent : * Element ) void {
0 commit comments