]> O.S.I.I.S - jp/crow.git/commitdiff
allow wrapper to fit in the opposite direction of the orientation
authorjpbruyere <jp.bruyere@hotmail.com>
Sat, 13 Aug 2016 02:07:52 +0000 (04:07 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Sat, 13 Aug 2016 02:07:52 +0000 (04:07 +0200)
Tests/Interfaces/basicTests/0.crow
src/GraphicObjects/Wrapper.cs

index 798b8ff141428a694268e28ce944a77c88846fd2..07f9ce9f53e953f78b12c29840978a217e58bc8f 100755 (executable)
@@ -1,13 +1,14 @@
 <?xml version="1.0"?>
 <Window Width="50%" Height="50%">      
-       <Wrapper Margin="10" Background="Teal" Spacing="30" Width="50%">
+       <Wrapper Orientation="Horizontal" Height="Fit" Width="Fit" Margin="5" Background="Teal" Spacing="1" >
+               <GraphicObject Width="50" Height="50" Background="Mantis"/>
+               <GraphicObject Width="50" Height="50" Background="Mantis"/>
+               <GraphicObject Width="50" Height="50" Background="Mantis"/>
                <GraphicObject Width="50" Height="50" Background="Mantis"/>
-               <GraphicObject Width="Stretched" Height="10" Background="Mantis"/>
                <GraphicObject Width="50%" Height="50" Background="Mantis"/>
-               <GraphicObject Width="Stretched" Height="50" Background="Mantis"/>
-               <GraphicObject Width="50" Height="70" Background="Mantis"/>
-               <GraphicObject Width="30" Height="Stretched" Background="Mantis"/>
                <GraphicObject Width="50" Height="50" Background="Mantis"/>
-               <GraphicObject Width="Stretched" Height="50" Background="Mantis"/>
+               <GraphicObject Width="50" Height="50" Background="Mantis"/>
+               <GraphicObject Width="50" Height="50%" Background="Mantis"/>
+               <GraphicObject Width="50" Height="50" Background="Mantis"/>
        </Wrapper>
 </Window>
\ No newline at end of file
index cfd745245f366646bc97def7f4ba49e542779164..9b9f0563b60ef4352c9072eb8be2f815b0f79ddc 100644 (file)
@@ -67,12 +67,13 @@ namespace Crow
                                                c.Slot.X = dx;
                                                c.Slot.Y = dy;
                                                largestChild = c.Slot.Width;
-                                       } else if (largestChild < c.Slot.Width){
-                                               largestChild = c.Slot.Width;
+                                       } else {
+                                               if (largestChild < c.Slot.Width)
+                                                       largestChild = c.Slot.Width;
                                                c.Slot.X = dx;
                                                c.Slot.Y = dy;
-                                               dy += c.Slot.Height + Spacing;
                                        }
+                                       dy += c.Slot.Height + Spacing;
                                }
                        }
                        bmp = null;
@@ -84,13 +85,13 @@ namespace Crow
                        //Debug.WriteLine ("child layout change: " + go.LastSlots.ToString() + " => " + go.Slot.ToString());
                        switch (arg.LayoutType) {
                        case LayoutingType.Width:
-                               if (Orientation == Orientation.Vertical && go.Width == Measure.Stretched) {
+                               if (Orientation == Orientation.Vertical && go.Width.Units == Unit.Percent) {
                                        go.Width = Measure.Fit;
                                        return;
                                }
                                break;
                        case LayoutingType.Height:
-                               if (Orientation == Orientation.Horizontal && go.Height == Measure.Stretched) {
+                               if (Orientation == Orientation.Horizontal && go.Height.Units == Unit.Percent) {
                                        go.Height = Measure.Fit;
                                        return;
                                }
@@ -105,12 +106,67 @@ namespace Crow
                #region GraphicObject Overrides
                protected override int measureRawSize (LayoutingType lt)
                {
-                       //Wrapper can't fit
-                       if (lt == LayoutingType.Width)
-                               Width = Measure.Stretched;
-                       else
+                       int tmp = 0;
+                       //Wrapper can't fit in the direction of the wrapper
+                       if (lt == LayoutingType.Width) {
+                               if (Orientation == Orientation.Horizontal) {
+                                       Width = Measure.Stretched;
+                                       return -1;
+                               } else if (RegisteredLayoutings.HasFlag (LayoutingType.Height))
+                                       return -1;
+                               else {
+                                       int dy = 0;
+                                       int largestChild = 0;
+                                       lock (Children) {
+                                               foreach (GraphicObject c in Children) {
+                                                       if (!c.Visible)
+                                                               continue;
+                                                       if (c.Height.Units == Unit.Percent &&
+                                                               c.RegisteredLayoutings.HasFlag (LayoutingType.Height))
+                                                               return -1;
+                                                       if (dy + c.Slot.Height > ClientRectangle.Height) {
+                                                               dy = 0;
+                                                               tmp += largestChild + Spacing;
+                                                               largestChild = c.Slot.Width;
+                                                       } else if (largestChild < c.Slot.Width)
+                                                               largestChild = c.Slot.Width;
+
+                                                       dy += c.Slot.Height + Spacing;
+                                               }
+                                               if (dy == 0)
+                                                       tmp -= Spacing;
+                                               return tmp + largestChild + 2 * Margin;
+                                       }
+                               }
+                       } else if (Orientation == Orientation.Vertical) {
                                Height = Measure.Stretched;
-                       return -1;                              
+                               return -1;
+                       } else if (RegisteredLayoutings.HasFlag (LayoutingType.Width))
+                               return -1;
+                       else {
+                               int dx = 0;
+                               int tallestChild = 0;
+                               lock (Children) {
+                                       foreach (GraphicObject c in Children) {
+                                               if (!c.Visible)
+                                                       continue;
+                                               if (c.Width.Units == Unit.Percent &&
+                                                       c.RegisteredLayoutings.HasFlag (LayoutingType.Width))
+                                                       return -1;
+                                               if (dx + c.Slot.Width > ClientRectangle.Width) {
+                                                       dx = 0;
+                                                       tmp += tallestChild + Spacing;
+                                                       tallestChild = c.Slot.Height;
+                                               } else if (tallestChild < c.Slot.Height)
+                                                       tallestChild = c.Slot.Height;
+
+                                               dx += c.Slot.Width + Spacing;
+                                       }
+                                       if (dx == 0)
+                                               tmp -= Spacing;
+                                       return tmp + tallestChild + 2 * Margin;
+                               }
+                       }
                }
 
                public override bool UpdateLayout (LayoutingType layoutType)
@@ -145,12 +201,18 @@ namespace Crow
                                        if (c.Width.Units == Unit.Percent)
                                                c.RegisterForLayouting (LayoutingType.Width);
                                }
+                               if (Height == Measure.Fit)
+                                       RegisterForLayouting (LayoutingType.Height);
+                               RegisterForLayouting (LayoutingType.X);
                                break;
                        case LayoutingType.Height:
                                foreach (GraphicObject c in Children) {
                                        if (c.Height.Units == Unit.Percent)
                                                c.RegisterForLayouting (LayoutingType.Height);
                                }
+                               if (Width == Measure.Fit)
+                                       RegisterForLayouting (LayoutingType.Width);
+                               RegisterForLayouting (LayoutingType.Y);
                                break;
                        default:
                                return;