@@ -1170,7 +1170,7 @@ private bool HasNamedChildren()
11701170 /// <summary>
11711171 /// Invoked when control's bounds have been changed.
11721172 /// </summary>
1173- public event GwenEventHandler < EventArgs > BoundsChanged ;
1173+ public event GwenEventHandler < EventArgs > ? BoundsChanged ;
11741174
11751175 /// <summary>
11761176 /// Invoked when the control has been left-clicked.
@@ -1221,7 +1221,7 @@ public override string ToString()
12211221
12221222 if ( this is ControlInternal . Text )
12231223 {
1224- return "[Text: " + ( this as ControlInternal . Text ) . String + "]" ;
1224+ return "[Text: " + ( this as ControlInternal . Text ) . DisplayedText + "]" ;
12251225 }
12261226
12271227 return GetType ( ) . ToString ( ) ;
@@ -1628,20 +1628,14 @@ protected virtual void OnChildRemoved(Base child)
16281628 /// </summary>
16291629 /// <param name="x">X-axis movement.</param>
16301630 /// <param name="y">Y-axis movement.</param>
1631- public virtual void MoveBy ( int x , int y )
1632- {
1633- SetBounds ( X + x , Y + y , Width , Height ) ;
1634- }
1631+ public virtual void MoveBy ( int x , int y ) => SetBounds ( X + x , Y + y , Width , Height ) ;
16351632
16361633 /// <summary>
16371634 /// Moves the control to a specific point.
16381635 /// </summary>
16391636 /// <param name="x">Target x coordinate.</param>
16401637 /// <param name="y">Target y coordinate.</param>
1641- public virtual void MoveTo ( float x , float y )
1642- {
1643- MoveTo ( ( int ) x , ( int ) y ) ;
1644- }
1638+ public virtual void MoveTo ( float x , float y ) => MoveTo ( ( int ) x , ( int ) y ) ;
16451639
16461640 /// <summary>
16471641 /// Moves the control to a specific point, clamping on paren't bounds if RestrictToParent is set.
@@ -1710,31 +1704,36 @@ public virtual void SetPosition(float x, float y)
17101704 /// </summary>
17111705 /// <param name="x">Target x coordinate.</param>
17121706 /// <param name="y">Target y coordinate.</param>
1713- public virtual void SetPosition ( int x , int y )
1714- {
1715- SetBounds ( x , y , Width , Height ) ;
1716- }
1707+ public virtual void SetPosition ( int x , int y ) => SetBounds ( x , y , Width , Height ) ;
1708+
1709+ public virtual void SetPosition ( Point point ) => SetBounds (
1710+ point . X ,
1711+ point . Y ,
1712+ Width ,
1713+ Height
1714+ ) ;
17171715
17181716 /// <summary>
17191717 /// Sets the control size.
17201718 /// </summary>
17211719 /// <param name="width">New width.</param>
17221720 /// <param name="height">New height.</param>
17231721 /// <returns>True if bounds changed.</returns>
1724- public virtual bool SetSize ( int width , int height )
1725- {
1726- return SetBounds ( X , Y , width , height ) ;
1727- }
1722+ public virtual bool SetSize ( int width , int height ) => SetBounds ( X , Y , width , height ) ;
17281723
17291724 /// <summary>
17301725 /// Sets the control bounds.
17311726 /// </summary>
17321727 /// <param name="bounds">New bounds.</param>
17331728 /// <returns>True if bounds changed.</returns>
1734- public virtual bool SetBounds ( Rectangle bounds )
1735- {
1736- return SetBounds ( bounds . X , bounds . Y , bounds . Width , bounds . Height ) ;
1737- }
1729+ public virtual bool SetBounds ( Rectangle bounds ) => SetBounds ( bounds . X , bounds . Y , bounds . Width , bounds . Height ) ;
1730+
1731+ public virtual bool SetBounds ( Point position , Point size ) => SetBounds (
1732+ position . X ,
1733+ position . Y ,
1734+ size . X ,
1735+ size . Y
1736+ ) ;
17381737
17391738 /// <summary>
17401739 /// Sets the control bounds.
@@ -1746,10 +1745,7 @@ public virtual bool SetBounds(Rectangle bounds)
17461745 /// <returns>
17471746 /// True if bounds changed.
17481747 /// </returns>
1749- public virtual bool SetBounds ( float x , float y , float width , float height )
1750- {
1751- return SetBounds ( ( int ) x , ( int ) y , ( int ) width , ( int ) height ) ;
1752- }
1748+ public virtual bool SetBounds ( float x , float y , float width , float height ) => SetBounds ( ( int ) x , ( int ) y , ( int ) width , ( int ) height ) ;
17531749
17541750 /// <summary>
17551751 /// Sets the control bounds.
@@ -1778,10 +1774,7 @@ public virtual bool SetBounds(int x, int y, int width, int height)
17781774
17791775 OnBoundsChanged ( oldBounds ) ;
17801776
1781- if ( BoundsChanged != null )
1782- {
1783- BoundsChanged . Invoke ( this , EventArgs . Empty ) ;
1784- }
1777+ BoundsChanged ? . Invoke ( this , EventArgs . Empty ) ;
17851778
17861779 return true ;
17871780 }
@@ -1840,11 +1833,7 @@ protected virtual void OnBoundsChanged(Rectangle oldBounds)
18401833 {
18411834 //Anything that needs to update on size changes
18421835 //Iterate my children and tell them I've changed
1843- //
1844- if ( Parent != null )
1845- {
1846- Parent . OnChildBoundsChanged ( oldBounds , this ) ;
1847- }
1836+ Parent ? . OnChildBoundsChanged ( oldBounds , this ) ;
18481837
18491838 if ( mBounds . Width != oldBounds . Width || mBounds . Height != oldBounds . Height )
18501839 {
@@ -2476,14 +2465,14 @@ protected virtual void RecurseLayout(Skin.Base skin)
24762465 bounds . Y += mPadding . Top ;
24772466 bounds . Height -= mPadding . Top + mPadding . Bottom ;
24782467
2479- for ( int i = 0 ; i < mChildren . Count ; i ++ )
2468+ foreach ( var child in mChildren )
24802469 {
2481- if ( mChildren [ i ] . IsHidden )
2470+ if ( child . IsHidden )
24822471 {
24832472 continue ;
24842473 }
24852474
2486- var dock = mChildren [ i ] . Dock ;
2475+ var dock = child . Dock ;
24872476
24882477 if ( dock . HasFlag ( Pos . Fill ) )
24892478 {
@@ -2492,84 +2481,99 @@ protected virtual void RecurseLayout(Skin.Base skin)
24922481
24932482 if ( dock . HasFlag ( Pos . Top ) )
24942483 {
2495- var margin = mChildren [ i ] . Margin ;
2484+ var margin = child . Margin ;
24962485
2497- mChildren [ i ] . SetBounds (
2486+ child . SetBounds (
24982487 bounds . X + margin . Left , bounds . Y + margin . Top , bounds . Width - margin . Left - margin . Right ,
2499- mChildren [ i ] . Height
2488+ child . Height
25002489 ) ;
25012490
2502- var height = margin . Top + margin . Bottom + mChildren [ i ] . Height ;
2491+ var height = margin . Top + margin . Bottom + child . Height ;
25032492 bounds . Y += height ;
25042493 bounds . Height -= height ;
25052494 }
25062495
25072496 if ( dock . HasFlag ( Pos . Left ) )
25082497 {
2509- var margin = mChildren [ i ] . Margin ;
2498+ var margin = child . Margin ;
25102499
2511- mChildren [ i ] . SetBounds (
2512- bounds . X + margin . Left , bounds . Y + margin . Top , mChildren [ i ] . Width ,
2500+ child . SetBounds (
2501+ bounds . X + margin . Left , bounds . Y + margin . Top , child . Width ,
25132502 bounds . Height - margin . Top - margin . Bottom
25142503 ) ;
25152504
2516- var width = margin . Left + margin . Right + mChildren [ i ] . Width ;
2505+ var width = margin . Left + margin . Right + child . Width ;
25172506 bounds . X += width ;
25182507 bounds . Width -= width ;
25192508 }
25202509
25212510 if ( dock . HasFlag ( Pos . Right ) )
25222511 {
25232512 // TODO: THIS MARGIN CODE MIGHT NOT BE FULLY FUNCTIONAL
2524- var margin = mChildren [ i ] . Margin ;
2513+ var margin = child . Margin ;
25252514
2526- mChildren [ i ] . SetBounds (
2527- bounds . X + bounds . Width - mChildren [ i ] . Width - margin . Right , bounds . Y + margin . Top , mChildren [ i ] . Width ,
2515+ child . SetBounds (
2516+ bounds . X + bounds . Width - child . Width - margin . Right , bounds . Y + margin . Top , child . Width ,
25282517 bounds . Height - margin . Top - margin . Bottom
25292518 ) ;
25302519
2531- var width = margin . Left + margin . Right + mChildren [ i ] . Width ;
2520+ var width = margin . Left + margin . Right + child . Width ;
25322521 bounds . Width -= width ;
25332522 }
25342523
25352524 if ( dock . HasFlag ( Pos . Bottom ) )
25362525 {
25372526 // TODO: THIS MARGIN CODE MIGHT NOT BE FULLY FUNCTIONAL
2538- var margin = mChildren [ i ] . Margin ;
2527+ var margin = child . Margin ;
25392528
2540- mChildren [ i ] . SetBounds (
2541- bounds . X + margin . Left , bounds . Y + bounds . Height - mChildren [ i ] . Height - margin . Bottom ,
2542- bounds . Width - margin . Left - margin . Right , mChildren [ i ] . Height
2529+ child . SetBounds (
2530+ bounds . X + margin . Left , bounds . Y + bounds . Height - child . Height - margin . Bottom ,
2531+ bounds . Width - margin . Left - margin . Right , child . Height
25432532 ) ;
25442533
2545- bounds . Height -= mChildren [ i ] . Height + margin . Bottom + margin . Top ;
2534+ bounds . Height -= child . Height + margin . Bottom + margin . Top ;
25462535 }
25472536
2548- mChildren [ i ] . RecurseLayout ( skin ) ;
2537+ child . RecurseLayout ( skin ) ;
25492538 }
25502539
25512540 mInnerBounds = bounds ;
25522541
25532542 //
25542543 // Fill uses the left over space, so do that now.
25552544 //
2556- for ( int i = 0 ; i < mChildren . Count ; i ++ )
2545+ foreach ( var child in mChildren )
25572546 {
2558- var dock = mChildren [ i ] . Dock ;
2547+ var dock = child . Dock ;
25592548
25602549 if ( ! dock . HasFlag ( Pos . Fill ) )
25612550 {
25622551 continue ;
25632552 }
25642553
2565- var margin = mChildren [ i ] . Margin ;
2554+ var margin = child . Margin ;
25662555
2567- mChildren [ i ] . SetBounds (
2568- bounds . X + margin . Left , bounds . Y + margin . Top , bounds . Width - margin . Left - margin . Right ,
2569- bounds . Height - margin . Top - margin . Bottom
2556+ var newPosition = new Point (
2557+ bounds . X + margin . Left ,
2558+ bounds . Y + margin . Top
25702559 ) ;
25712560
2572- mChildren [ i ] . RecurseLayout ( skin ) ;
2561+ if ( child is IAutoSizeToContents { AutoSizeToContents : true } )
2562+ {
2563+ child . SetPosition ( newPosition ) ;
2564+ }
2565+ else
2566+ {
2567+ child . SetBounds (
2568+ newPosition ,
2569+ new Point (
2570+ bounds . Width - margin . Left - margin . Right ,
2571+ bounds . Height - margin . Top - margin . Bottom
2572+ )
2573+ ) ;
2574+ }
2575+
2576+ child . RecurseLayout ( skin ) ;
25732577 }
25742578
25752579 PostLayout ( skin ) ;
0 commit comments