]> O.S.I.I.S - jp/crow.git/commitdiff
move stretchedGo changes logic from Widget to GenericStack
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 18 Oct 2019 03:50:38 +0000 (05:50 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Fri, 18 Oct 2019 03:50:38 +0000 (05:50 +0200)
Crow/src/Widgets/GenericStack.cs
Crow/src/Widgets/Widget.cs

index 7d1facf04f09fcc018c4893846fae55903996dd9..3e0a8cfbb0b230c2c5b8355c68fcc2f2c2d60b89 100644 (file)
@@ -157,16 +157,21 @@ namespace Crow
                        case LayoutingType.Width:
                                if (Orientation == Orientation.Horizontal) {
                                        if (go.Width == Measure.Stretched) {
-                                               if (stretchedGO == null && Width != Measure.Fit)
+                                               if (stretchedGO == null && Width != Measure.Fit) {
                                                        stretchedGO = go;
-                                               else if (stretchedGO != go) {
+                                                       contentSize.Width -= go.LastSlots.Width;
+                                               } else if (stretchedGO != go) {
                                                        go.Slot.Width = 0;
                                                        go.Width = Measure.Fit;
                                                        return;
                                                }
+                                       } else if (stretchedGO == go) {
+                                               stretchedGO = null;
+                                               contentSize.Width += go.Slot.Width;
                                        } else
                                                contentSize.Width += go.Slot.Width - go.LastSlots.Width;
 
+
                                        adjustStretchedGo (LayoutingType.Width);                                        
                                        
                                        if (Width == Measure.Fit)
@@ -179,13 +184,17 @@ namespace Crow
                        case LayoutingType.Height:
                                if (Orientation == Orientation.Vertical) {
                                        if (go.Height == Measure.Stretched) {
-                                               if (stretchedGO == null && Height != Measure.Fit)
+                                               if (stretchedGO == null && Height != Measure.Fit) {
                                                        stretchedGO = go;
-                                               else if (stretchedGO != go){
+                                                       contentSize.Height -= go.LastSlots.Height;
+                                               } else if (stretchedGO != go) {
                                                        go.Slot.Height = 0;
                                                        go.Height = Measure.Fit;
                                                        return;
                                                }
+                                       } else if (stretchedGO == go) {
+                                               stretchedGO = null;
+                                               contentSize.Height += go.Slot.Height;
                                        } else
                                                contentSize.Height += go.Slot.Height - go.LastSlots.Height;
                                        
index 7fdec5a1bda6d9342f0ff671904b8fa605045ba6..4fe87abe544aa7846fac7895cd03967ad2037de1 100644 (file)
@@ -316,7 +316,7 @@ namespace Crow
                /// widget inside the stack, which is never added to the contentSize, instead, its size
                /// is deducted from (parent.ClientRectangle - contentSize)
                /// </summary>
-               internal Size contentSize;
+               public Size contentSize;
                #endregion
 
                #region ILayoutable
@@ -615,27 +615,9 @@ namespace Crow
                                        if (value < minimumSize.Width || (value > maximumSize.Width && maximumSize.Width > 0))
                                                return;
                                }
-                               Measure old = width;
                                width = value;
                                NotifyValueChanged ("Width", width);
-                               if (width == Measure.Stretched || old == Measure.Stretched) {
-                                       //NotifyValueChanged ("WidthPolicy", width.Policy);
-                                       //contentSize in Stacks are only update on childLayoutChange, and the single stretched
-                                       //child of the stack is not counted in contentSize, so when changing size policy of a child
-                                       //we should adapt contentSize
-                                       //TODO:check case when child become stretched, and another stretched item already exists.
-                                       GenericStack gs = Parent as GenericStack;
-                                       if (gs != null){ //TODO:check if I should test Group instead
-                                               if (gs.Orientation == Orientation.Horizontal) {
-                                                       if (width == Measure.Stretched)
-                                                               gs.contentSize.Width -= this.LastSlots.Width;
-                                                       else
-                                                               gs.contentSize.Width += this.LastSlots.Width;
-                                               }
-                                       }                                                       
-                               }
-
-                               this.RegisterForLayouting (LayoutingType.Width);
+                               RegisterForLayouting (LayoutingType.Width);
                        }
                }
                /// <summary>
@@ -656,23 +638,9 @@ namespace Crow
                                        if (value < minimumSize.Height || (value > maximumSize.Height && maximumSize.Height > 0))
                                                return;
                                }
-                               Measure old = height;
                                height = value;
                                NotifyValueChanged ("Height", height);
-                               if (height == Measure.Stretched || old == Measure.Stretched) {
-                                       //NotifyValueChanged ("HeightPolicy", HeightPolicy);
-                                       GenericStack gs = Parent as GenericStack;
-                                       if (gs != null){ //TODO:check if I should test Group instead
-                                               if (gs.Orientation == Orientation.Vertical) {
-                                                       if (height == Measure.Stretched)
-                                                               gs.contentSize.Height -= this.LastSlots.Height;
-                                                       else
-                                                               gs.contentSize.Height += this.LastSlots.Height;
-                                               }
-                                       }
-                               }
-
-                               this.RegisterForLayouting (LayoutingType.Height);
+                               RegisterForLayouting (LayoutingType.Height);
                        }
                }
                /// <summary>