@@ -296,6 +296,48 @@ where
296296 )
297297 . height ( * self . height ) ;
298298
299+ let limits = {
300+ let max = limits. max ( ) ;
301+
302+ // Offset is computed from the reference rect, it isn't a translation vector.
303+ let width_before = self . underlay_bounds . x - self . offset . x ;
304+ let width_after =
305+ max. width - self . underlay_bounds . x - self . underlay_bounds . width - self . offset . x ;
306+ let height_above = self . underlay_bounds . y - self . offset . y ;
307+ let height_below =
308+ max. height - self . underlay_bounds . y - self . underlay_bounds . height - self . offset . y ;
309+
310+ let ref_center = self . underlay_bounds . center ( ) ;
311+ let max_width_symmetric = ref_center. x . min ( max. width - ref_center. x ) * 2.0 ;
312+ let max_height_symmetric = ref_center. y . min ( max. height - ref_center. y ) * 2.0 ;
313+ match self . alignment {
314+ Alignment :: TopStart => limits
315+ . max_height ( height_above + self . underlay_bounds . height )
316+ . max_width ( width_before) ,
317+ Alignment :: Top => limits
318+ . max_height ( height_above)
319+ . max_width ( max_width_symmetric) ,
320+ Alignment :: TopEnd => limits
321+ . max_height ( height_above + self . underlay_bounds . height )
322+ . max_width ( width_after) ,
323+ Alignment :: End => limits
324+ . max_width ( width_after)
325+ . max_height ( max_height_symmetric) ,
326+ Alignment :: BottomEnd => limits
327+ . max_height ( height_below + self . underlay_bounds . height )
328+ . max_width ( width_after) ,
329+ Alignment :: Bottom => limits
330+ . max_height ( height_below)
331+ . max_width ( max_width_symmetric) ,
332+ Alignment :: BottomStart => limits
333+ . max_height ( height_below + self . underlay_bounds . height )
334+ . max_width ( width_before) ,
335+ Alignment :: Start => limits
336+ . max_width ( width_before)
337+ . max_height ( max_height_symmetric) ,
338+ }
339+ } ;
340+
299341 let mut node = self
300342 . element
301343 . as_widget ( )
0 commit comments