]> O.S.I.I.S - jp/crow.git/commitdiff
Allow on child in stack to have streatching size, to occupy remaining
authorjpbruyere <jp.bruyere@hotmail.com>
Sun, 7 Jun 2015 09:42:04 +0000 (11:42 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Sun, 7 Jun 2015 09:42:05 +0000 (11:42 +0200)
space if stack size is fixed or stretched.
Usefull in the case of spinner for example.

Templates/Spinner.goml
Tests/Interfaces/testSpinner.goml
src/GraphicObjects/GenericStack.cs

index 8f61f0b1042735e9976b617556a3b89ff133f32c..c537f9779f682039545bc7de419cb5529b451976 100755 (executable)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
-<Border CornerRadius="0" Margin="0" BorderWidth="1" Fit="True">
-       <HorizontalStack Name="hstack" Margin="0" Spacing="5">
-               <Label Width="30" Name="labCpt" Text="55" Margin="1" TextAlignment="RightCenter"/>
+<Border CornerRadius="0" Margin="0" BorderWidth="1" Width="0" Height="-1">
+       <HorizontalStack Name="hstack" Margin="0" Spacing="5" Width="0" Height="-1">
+               <Label Width="0" Name="labCpt" Text="55" Margin="1" TextAlignment="RightCenter"/>
                <VerticalStack Spacing="1" Name="vstack">
                        <Button Width="10" Height="8" MouseClick="onUp">
                                <Image Margin="1" Path="#go.Images.Icons.updown.svg" SvgSub="up"/>
index 12a72991e5996565fef083b82cbba552f5523d11..9767d5462d7883d745beb538e136e1dd631d8422 100755 (executable)
@@ -2,5 +2,5 @@
 <Container Name="TopContainer" Width="400" Height="350"\r
        Margin="20" Focusable="True" Background="DarkGray">\r
 \r
-       <Spinner Width="50"></Spinner>\r
+       <Spinner Width="100"></Spinner>\r
 </Container>
\ No newline at end of file
index 5759bac4c8bcd7df9c6d30b194a27cb80d9877b2..63a70ad3e479751541cb9243c8fefc578a511ece 100644 (file)
@@ -110,12 +110,55 @@ namespace go
 \r
                        if ((layoutType & (int)LayoutingType.PositionChildren) > 0)\r
                                Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this);\r
+                       \r
                }\r
                public override void UpdateLayout (LayoutingType layoutType)\r
         {            \r
-                       if (layoutType == LayoutingType.PositionChildren)\r
+                       if (layoutType == LayoutingType.PositionChildren) {\r
+                               //allow 1 child to have size to 0 if stack has fixed or streched size,\r
+                               //this child will occupy remaining space\r
+                               if (Orientation == Orientation.Horizontal) {\r
+                                       if (Width >= 0) {\r
+                                               GraphicObject[] gobjs = Children.Where (c => c.Width == 0).ToArray();\r
+                                               if (gobjs.Length > 1)\r
+                                                       throw new Exception ("Only one child in stack may have size to stretched");\r
+                                               else if (gobjs.Length == 1) {\r
+                                                       int sz = Children.Except (gobjs).Sum (g => g.Slot.Width);\r
+                                                       if (sz < Slot.Width) {\r
+                                                               gobjs [0].Slot.Width = Slot.Width - sz - Spacing;\r
+                                                               int idx = Children.IndexOf (gobjs [0]);\r
+                                                               if (idx > 0 && idx < Children.Count - 1)\r
+                                                                       gobjs [0].Slot.Width -= Spacing;\r
+\r
+                                                               if (gobjs [0].LastSlots.Width != gobjs [0].Slot.Width) {\r
+                                                                       gobjs [0].bmp = null;\r
+                                                                       gobjs [0].LastSlots.Width = gobjs [0].Slot.Width;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }                                       \r
+                               } else {\r
+                                       if (Height >= 0) {\r
+                                               GraphicObject[] gobjs = Children.Where (c => c.Height == 0).ToArray();\r
+                                               if (gobjs.Length > 1)\r
+                                                       throw new Exception ("Only one child in stack may have size to stretched");\r
+                                               else if (gobjs.Length == 1) {\r
+                                                       int sz = Children.Except (gobjs).Sum (g => g.Slot.Height);\r
+                                                       if (sz < Slot.Height) {\r
+                                                               gobjs [0].Slot.Height = Slot.Height - sz;\r
+                                                               int idx = Children.IndexOf (gobjs [0]);\r
+                                                               if (idx > 0 && idx < Children.Count - 1)\r
+                                                                       gobjs [0].Slot.Height -= Spacing;\r
+                                                               if (gobjs [0].LastSlots.Height != gobjs [0].Slot.Height) {\r
+                                                                       gobjs [0].bmp = null;\r
+                                                                       gobjs [0].LastSlots.Height = gobjs [0].Slot.Height;\r
+                                                               }\r
+                                                       }\r
+                                               }\r
+                                       }\r
+                               }                               \r
                                ComputeChildrenPositions ();\r
-                       else\r
+                       }else\r
                                base.UpdateLayout(layoutType);\r
         }\r
                #endregion\r