@@ -160,6 +160,11 @@ protected override void OnMouseClicked(MouseButton mouseButton, Point mousePosit
160
160
) ;
161
161
}
162
162
163
+ protected override void OnPositionChanged ( Point oldPosition , Point newPosition )
164
+ {
165
+ base . OnPositionChanged ( oldPosition , newPosition ) ;
166
+ }
167
+
163
168
/// <summary>
164
169
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
165
170
/// </summary>
@@ -404,34 +409,42 @@ public override bool SizeToChildren(bool resizeX = true, bool resizeY = true, bo
404
409
405
410
public override bool SetBounds ( int x , int y , int width , int height )
406
411
{
412
+ var updatedX = x ;
413
+ var updatedY = y ;
414
+ var updatedWidth = width ;
415
+ var updatedHeight = height ;
407
416
if ( MaintainAspectRatio )
408
417
{
409
418
var bounds = Bounds ;
410
419
var aspectRatio = _textureAspectRatio ;
411
- if ( width == bounds . Width )
420
+ if ( updatedWidth == bounds . Width )
412
421
{
413
- if ( height != bounds . Height )
422
+ if ( updatedHeight != bounds . Height )
414
423
{
415
- var aspectRatioWidth = ( int ) ( height * aspectRatio ) ;
416
- if ( aspectRatioWidth > width )
424
+ var aspectRatioWidth = ( int ) ( updatedHeight * aspectRatio ) ;
425
+ if ( aspectRatioWidth > updatedWidth )
417
426
{
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
+ }
421
434
}
422
435
}
423
436
}
424
- else if ( height == bounds . Height )
437
+ else if ( updatedHeight == bounds . Height )
425
438
{
426
- var aspectRatioHeight = ( int ) ( width / aspectRatio ) ;
427
- if ( aspectRatioHeight > height )
439
+ var aspectRatioHeight = ( int ) ( updatedWidth / aspectRatio ) ;
440
+ if ( aspectRatioHeight > updatedHeight )
428
441
{
429
- height = aspectRatioHeight ;
442
+ updatedHeight = aspectRatioHeight ;
430
443
}
431
444
}
432
445
}
433
446
434
- return base . SetBounds ( x , y , width , height ) ;
447
+ return base . SetBounds ( updatedX , updatedY , updatedWidth , updatedHeight ) ;
435
448
}
436
449
437
450
public override Point GetChildrenSize ( )
0 commit comments