]> O.S.I.I.S - jp/crow.git/commitdiff
try force measure of stretched children from stack having Fit measure
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Tue, 5 May 2020 14:38:20 +0000 (16:38 +0200)
committerj-p <jp_bruyere@hotmail.com>
Sat, 9 May 2020 22:50:02 +0000 (00:50 +0200)
Crow/src/Widgets/Border.cs
Crow/src/Widgets/GenericStack.cs
Crow/src/Widgets/Group.cs
Crow/src/Widgets/Image.cs
Crow/src/Widgets/Label.cs
Crow/src/Widgets/Shape.cs
Crow/src/Widgets/TextRun.cs
Crow/src/Widgets/Widget.cs
Crow/src/Widgets/Wrapper.cs
Samples/BasicTests/BasicTests.cs
Samples/common/ui/Interfaces/Stack/StretchedInFit.crow [new file with mode: 0644]

index b3c7203000d14f29ea388bc47a9c8dfaac896a52..b9d7e333bf907522f29756b9c7b1980daea2649e 100644 (file)
@@ -122,7 +122,7 @@ namespace Crow
                        }
                }
 
-               protected override int measureRawSize (LayoutingType lt)
+               public override int measureRawSize (LayoutingType lt)
                {
                        int tmp = base.measureRawSize (lt);
                        return tmp < 0 ? tmp : tmp + 2 * BorderWidth;
index 3e0a8cfbb0b230c2c5b8355c68fcc2f2c2d60b89..eeec15c6e09f36fd684612b0e94890d339148721 100644 (file)
@@ -56,7 +56,7 @@ namespace Crow
                        else
                                layoutType &= (~LayoutingType.Y);                       
                }
-               protected override int measureRawSize (LayoutingType lt)
+               public override int measureRawSize (LayoutingType lt)
                {
                        int totSpace = Math.Max(0, Spacing * (Children.Count (c => c.Visible) - 1));
                        if (lt == LayoutingType.Width) {
index b2f6f41867e80591be9820daf3a2a16656da4f56..0a4b964c9a36678d7587c62a7864c6a5e552d7be 100644 (file)
@@ -223,25 +223,19 @@ namespace Crow
                        }
                        return false;
                }
-               protected override int measureRawSize (LayoutingType lt)
+               public override int measureRawSize (LayoutingType lt)
                {
                        if (Children.Count > 0) {
                                if (lt == LayoutingType.Width) {
                                        if (largestChild == null)
                                                searchLargestChild ();
-                                       /*if (largestChild == null) {
-                                               //if still null, not possible to determine a width
-                                               //because all children are stretched, force first one to fit
-                                               Children [0].Width = Measure.Fit;
-                                               return -1;//cancel actual sizing to let child computation take place
-                                       }*/
+                                       if (largestChild == null)
+                                               searchLargestChild (true);
                                } else {
                                        if (tallestChild == null)
                                                searchTallestChild ();
-                                       /*if (tallestChild == null) {
-                                               Children [0].Height = Measure.Fit;
-                                               return -1;
-                                       }*/
+                                       if (tallestChild == null)
+                                               searchTallestChild (true);
                                }
                        }
                        return base.measureRawSize (lt);
@@ -380,7 +374,8 @@ namespace Crow
                        tallestChild = null;
                        contentSize = 0;
                }
-               void searchLargestChild(){
+               void searchLargestChild (bool forceMeasure = false)
+               {
                        #if DEBUG_LAYOUTING
                        Debug.WriteLine("\tSearch largest child");
                        #endif
@@ -389,15 +384,21 @@ namespace Crow
                        for (int i = 0; i < Children.Count; i++) {
                                if (!Children [i].Visible)
                                        continue;
-                               if (children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width))
+                               int cw = 0;
+                               if (forceMeasure)
+                                       cw = children [i].measureRawSize (LayoutingType.Width);
+                               else if (children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width))
                                        continue;
-                               if (Children [i].Slot.Width > contentSize.Width) {
-                                       contentSize.Width = Children [i].Slot.Width;
+                               else
+                                       cw = Children [i].Slot.Width;
+                               if (cw > contentSize.Width) {
+                                       contentSize.Width = cw;
                                        largestChild = Children [i];
                                }
                        }
                }
-               void searchTallestChild(){
+               void searchTallestChild (bool forceMeasure = false)
+               { 
                        #if DEBUG_LAYOUTING
                        Debug.WriteLine("\tSearch tallest child");
                        #endif
@@ -406,10 +407,15 @@ namespace Crow
                        for (int i = 0; i < Children.Count; i++) {
                                if (!Children [i].Visible)
                                        continue;
-                               if (children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height))
+                               int ch = 0;
+                               if (forceMeasure)
+                                       ch = children [i].measureRawSize (LayoutingType.Height);
+                               else if (children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height))
                                        continue;
-                               if (Children [i].Slot.Height > contentSize.Height) {
-                                       contentSize.Height = Children [i].Slot.Height;
+                               else
+                                       ch = Children [i].Slot.Height;
+                               if (ch > contentSize.Height) {
+                                       contentSize.Height = ch;
                                        tallestChild = Children [i];
                                }
                        }
index 87111e845a8e107b960b5c9de49988227344f931..dd80a1bccff17ebce6f2e96aac1f048f67c109ea 100644 (file)
@@ -160,7 +160,7 @@ namespace Crow
                #endregion
 
                #region GraphicObject overrides
-               protected override int measureRawSize (LayoutingType lt)
+               public override int measureRawSize (LayoutingType lt)
                {
                        if (_pic == null)
                                return 2 * Margin;
index a03a0bdc053b07cd047390214e13fddd71c7e720..071c993b40037363848fd6cba15799bf98405593 100644 (file)
@@ -417,7 +417,7 @@ namespace Crow {
                Size cachedTextSize = default(Size);
 
                #region GraphicObject overrides
-               protected override int measureRawSize(LayoutingType lt)
+               public override int measureRawSize(LayoutingType lt)
                {
                        if (lines == null)
                                lines = getLines;
index ac006b82254edd0c2cfa69f9c198358111a3d2f9..5f5761344f26f6deccd2e60a9772627135db795b 100644 (file)
@@ -218,7 +218,7 @@ namespace Crow
                }
 
 
-               protected override int measureRawSize (LayoutingType lt)
+               public override int measureRawSize (LayoutingType lt)
                {
                        if ((lt == LayoutingType.Width && contentSize.Width == 0) || (lt == LayoutingType.Height && contentSize.Height == 0)) {
                                if (size != default (Size))
index f784f90e63cc1a64434a0b12bfc8bc00a6aab08b..054d2c2a29440af97ea9e5d9895a667bcf279cb2 100644 (file)
@@ -145,7 +145,7 @@ namespace Crow
                }
 
                #region GraphicObject overrides
-               protected override int measureRawSize (LayoutingType lt)
+               public override int measureRawSize (LayoutingType lt)
                {
                        if (lines == null)
                                lines = getLines;
index 736ed59dda19df18cee26522113bda82676ff8d6..98198d0538a7795912aada16fce2f7c12b5e96c2 100644 (file)
@@ -1441,7 +1441,7 @@ namespace Crow
                #region Layouting
 
                /// <summary> return size of content + margins </summary>
-               protected virtual int measureRawSize (LayoutingType lt) {
+               public virtual int measureRawSize (LayoutingType lt) {
                        return lt == LayoutingType.Width ?
                                contentSize.Width + 2 * margin: contentSize.Height + 2 * margin;
                }
index cc319856ae724adbb6f5f3784258a370fb673ef3..a170e3907512852b7f967fb28c1d583cab71ba46 100644 (file)
@@ -118,7 +118,7 @@ namespace Crow
                #endregion
 
                #region GraphicObject Overrides
-               protected override int measureRawSize (LayoutingType lt)
+               public override int measureRawSize (LayoutingType lt)
                {
                        int tmp = 0;
                        //Wrapper can't fit in the opposite direction of the wrapper, this func is called only if Fit
index 9091730288bd7815dda8d5976adbd40c1107bca3..4e89ca79221fff35d8715599b37560ef339b8139 100644 (file)
@@ -33,7 +33,8 @@ namespace tests
                        //testFiles = new string [] { @"Interfaces/Divers/welcome.crow" };
                        //testFiles = new string [] { @"Interfaces/TemplatedGroup/3.crow" };
                        //testFiles = new string [] { @"Interfaces/Divers/testShape.crow" };
-                       testFiles = new string [] { @"Interfaces/TemplatedControl/testEnumSelector.crow" };
+                       //testFiles = new string [] { @"Interfaces/TemplatedControl/testEnumSelector.crow" };
+                       testFiles = new string [] { @"Interfaces/Stack/StretchedInFit.crow" };
                        //testFiles = new string [] { @"Interfaces/Divers/colorPicker2.crow" };
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/GraphicObject", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray ();
diff --git a/Samples/common/ui/Interfaces/Stack/StretchedInFit.crow b/Samples/common/ui/Interfaces/Stack/StretchedInFit.crow
new file mode 100644 (file)
index 0000000..42c3064
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<VerticalStack Background="DimGrey" Margin="1" Width="Fit" Height="Fit">
+       <Label Text="this is a test" Margin="0" Width="Stretched" Height="Fit" Background="SeaGreen"/>
+       <Label Text="this is a test" Margin="0" Width="Stretched" Height="Fit" Background="SeaGreen"/>
+       <Label Text="this is a test" Margin="0" Width="Stretched" Height="Fit" Background="SeaGreen"/>
+       <Label Text="this is a test" Margin="0" Width="Stretched" Height="Fit" Background="SeaGreen" MinimumSize="5,5"/>
+</VerticalStack>
\ No newline at end of file