@@ -160,6 +160,11 @@ protected override void OnMouseClicked(MouseButton mouseButton, Point mousePosit
160160 ) ;
161161 }
162162
163+ protected override void OnPositionChanged ( Point oldPosition , Point newPosition )
164+ {
165+ base . OnPositionChanged ( oldPosition , newPosition ) ;
166+ }
167+
163168 /// <summary>
164169 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
165170 /// </summary>
@@ -404,34 +409,42 @@ public override bool SizeToChildren(bool resizeX = true, bool resizeY = true, bo
404409
405410 public override bool SetBounds ( int x , int y , int width , int height )
406411 {
412+ var updatedX = x ;
413+ var updatedY = y ;
414+ var updatedWidth = width ;
415+ var updatedHeight = height ;
407416 if ( MaintainAspectRatio )
408417 {
409418 var bounds = Bounds ;
410419 var aspectRatio = _textureAspectRatio ;
411- if ( width == bounds . Width )
420+ if ( updatedWidth == bounds . Width )
412421 {
413- if ( height != bounds . Height )
422+ if ( updatedHeight != bounds . Height )
414423 {
415- var aspectRatioWidth = ( int ) ( height * aspectRatio ) ;
416- if ( aspectRatioWidth > width )
424+ var aspectRatioWidth = ( int ) ( updatedHeight * aspectRatio ) ;
425+ if ( aspectRatioWidth > updatedWidth )
417426 {
418- var deltaWidth = width - aspectRatioWidth ;
419- x += deltaWidth / 2 ;
420- width = aspectRatioWidth ;
427+ var deltaWidth = updatedWidth - aspectRatioWidth ;
428+ updatedX += deltaWidth / 2 ;
429+ updatedWidth = aspectRatioWidth ;
430+ if ( RestrictToParent )
431+ {
432+ updatedX = Math . Max ( 0 , updatedX ) ;
433+ }
421434 }
422435 }
423436 }
424- else if ( height == bounds . Height )
437+ else if ( updatedHeight == bounds . Height )
425438 {
426- var aspectRatioHeight = ( int ) ( width / aspectRatio ) ;
427- if ( aspectRatioHeight > height )
439+ var aspectRatioHeight = ( int ) ( updatedWidth / aspectRatio ) ;
440+ if ( aspectRatioHeight > updatedHeight )
428441 {
429- height = aspectRatioHeight ;
442+ updatedHeight = aspectRatioHeight ;
430443 }
431444 }
432445 }
433446
434- return base . SetBounds ( x , y , width , height ) ;
447+ return base . SetBounds ( updatedX , updatedY , updatedWidth , updatedHeight ) ;
435448 }
436449
437450 public override Point GetChildrenSize ( )
0 commit comments