]> O.S.I.I.S - jp/crow.git/commitdiff
Grid control, Stack sizing default reset to stretched as all the other
authorjpbruyere <jp.bruyere@hotmail.com>
Fri, 11 Sep 2015 16:48:00 +0000 (18:48 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Fri, 11 Sep 2015 16:48:00 +0000 (18:48 +0200)
controls

GOLib.csproj
Templates/Checkbox.goml
Templates/Spinner.goml
Tests/GOLIBTests.cs
Tests/Interfaces/testGrid.goml [new file with mode: 0755]
Tests/Interfaces/testSpinner.goml
Tests/Tests.csproj
src/GraphicObjects/GenericStack.cs
src/GraphicObjects/Grid.cs [new file with mode: 0644]

index 06fe014c0f0ab639f60b969d50dd9e63282b515a..92896b0f36eef11443aece5228be49bfb2d61f33 100644 (file)
     <Compile Include="src\LayoutChangeEventArgs.cs" />\r
     <Compile Include="src\ReflexionExtensions.cs" />\r
     <Compile Include="src\XCursor.cs" />\r
+    <Compile Include="src\GraphicObjects\Grid.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Reference Include="System" />\r
index c9dbe5b44cd2c8eb474ae03d404806b2831c3274..a2f8bb211e9eae3dfd5400e70bb4f8dbdb1be77e 100755 (executable)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>\r
-<HorizontalStack Margin="0" Spacing="1">\r
+<HorizontalStack Width="{Width}" Height="{Height}" Margin="0" Spacing="1">\r
        <Image Name="Image" Width="16" Height="16" Path="#go.Images.Icons.checkbox.svg"/>\r
-       <Label Name="Caption"/>\r
+       <Label Name="Caption" Height="{Height}" Width="0"/>\r
 </HorizontalStack>
\ No newline at end of file
index 36af43c1ab9a400b6e12def32e20ab0ef108242d..70b459b22b8415afbb52b501e4954c4abb78846c 100755 (executable)
@@ -1,12 +1,13 @@
 <?xml version="1.0"?>
-<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="{Value}" Margin="1" TextAlignment="RightCenter"/>
-               <VerticalStack Spacing="1" Name="vstack">
-                       <Button Width="10" Height="8" MouseClick="onUp">
+<Border BorderWidth="1" Width="{Width}" Height="{Height}" Background="White">
+       <HorizontalStack Name="hstack" Margin="0" Spacing="2" Width="{Width}" Height="{Height}">
+               <Label Foreground="DimGray" Width="0" Height="{Height}" Name="labCpt" 
+                       Text="{Value}" Margin="1" TextAlignment="RightCenter"/>
+               <VerticalStack RowCount="2" Width="-1" Height="-1" Spacing="1" >
+                       <Button Width="12" Height="8" MouseClick="onUp">
                                <Image Margin="1" Path="#go.Images.Icons.updown.svg" SvgSub="up"/>
                        </Button>
-                       <Button Width="10" Height="8"  MouseClick="onDown">
+                       <Button Width="12" Height="8" MouseClick="onDown">
                                <Image Margin="1" Path="#go.Images.Icons.updown.svg" SvgSub="down"/>
                        </Button>
                </VerticalStack>
index a7645cb9052d7d8131b9e77c5040bb96308e3510..29cfc9fd7094d5011ff3406a0a633858c3793293 100644 (file)
@@ -31,6 +31,7 @@ namespace test
                int frameCpt = 0;\r
                int idx = 0;\r
                string[] testFiles = {\r
+                       "testGrid.goml",\r
                        "test1.goml",\r
                        "test1.1.goml",\r
                        "test1.2.goml",\r
diff --git a/Tests/Interfaces/testGrid.goml b/Tests/Interfaces/testGrid.goml
new file mode 100755 (executable)
index 0000000..2478492
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>\r
+<Grid RowCount="2" ColumnCount="2">\r
+       <GraphicObject Background="1,0;0,0;0,0;1,0"/>\r
+       <GraphicObject Background="0,0;0,0;0,5;1,0"/>\r
+       <GraphicObject Background="0,0;0,5;0,0;1,0"/>\r
+       <GraphicObject Background="0,5;0,0;0,0;1,0"/>\r
+</Grid>
\ No newline at end of file
index 9767d5462d7883d745beb538e136e1dd631d8422..c1980eb780d0f28d0e60f8b4a6515c67eaac5781 100755 (executable)
@@ -2,5 +2,5 @@
 <Container Name="TopContainer" Width="400" Height="350"\r
        Margin="20" Focusable="True" Background="DarkGray">\r
 \r
-       <Spinner Width="100"></Spinner>\r
+       <Spinner Height="-1" Width="-1" Value="5"></Spinner>\r
 </Container>
\ No newline at end of file
index b6f2125384dc971e1eb6072889ea6e2a149d262e..8694d0e06a4bf1d5db0bb6257e67f326218f62ee 100644 (file)
     <None Include="Interfaces\tmpDirItem.goml">
       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
     </None>
+    <None Include="Interfaces\testGrid.goml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\" />
index bac7d8af9937d215fa36af61a8d8f56bb766ba63..c6260c6b8520d00c5d0fc505edad7e32ef8bd01d 100644 (file)
@@ -39,7 +39,12 @@ namespace go
         public int Spacing\r
         {\r
                        get { return _spacing; }\r
-            set { _spacing = value; }\r
+            set { \r
+                               if (_spacing == value)\r
+                                       return;\r
+                               _spacing = value; \r
+                               NotifyValueChanged ("Spacing", Spacing);\r
+                       }\r
         }\r
         [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)]\r
         public virtual Orientation Orientation\r
@@ -50,19 +55,6 @@ namespace go
                #endregion\r
 \r
                #region GraphicObject Overrides\r
-               //TODO: to be coherent, those overrides should be removed\r
-               //I could maybe set size to fit dynamicaly in the direction of the stack\r
-               [XmlAttributeAttribute()][DefaultValue(-1)]\r
-               public override int Width {\r
-                       get { return base.Width; }\r
-                       set { base.Width = value; }\r
-               }\r
-               [XmlAttributeAttribute()][DefaultValue(-1)]\r
-               public override int Height {\r
-                       get { return base.Height; }\r
-                       set { base.Height = value; }\r
-               }\r
-\r
                protected override Size measureRawSize ()\r
                {\r
                        Size tmp = new Size ();\r
diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs
new file mode 100644 (file)
index 0000000..e8bd7ba
--- /dev/null
@@ -0,0 +1,149 @@
+using System;\r
+using System.Diagnostics;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using System.Xml.Serialization;\r
+using System.ComponentModel;\r
+\r
+namespace go\r
+{\r
+       /// <summary>\r
+       /// Simple grid container\r
+       /// Allow symetric placement of children on a grid,\r
+       /// excedental child (above grid sizing) are ignored\r
+       /// and invisible child keep their place in the grid\r
+       /// </summary>\r
+    public class Grid : Group\r
+    {\r
+               #region CTOR\r
+               public Grid()\r
+                       : base()\r
+               {            \r
+               }\r
+               #endregion\r
+\r
+               #region Private fields\r
+        int _spacing;\r
+               int _columnCount;\r
+               int _rowCount;\r
+               #endregion\r
+\r
+               public override T addChild<T> (T child)\r
+               {\r
+                       T tmp = base.addChild (child);\r
+                       this.RegisterForLayouting ((int)LayoutingType.PositionChildren);\r
+                       return tmp;\r
+               }\r
+               public override void removeChild (GraphicObject child)\r
+               {\r
+                       base.removeChild (child);\r
+                       this.RegisterForLayouting ((int)LayoutingType.PositionChildren);\r
+               }\r
+\r
+               #region Public Properties\r
+        [XmlAttributeAttribute()][DefaultValue(2)]\r
+        public int Spacing\r
+        {\r
+                       get { return _spacing; }\r
+            set { _spacing = value; }\r
+        }\r
+        [XmlAttributeAttribute()][DefaultValue(1)]\r
+        public virtual int ColumnCount\r
+        {\r
+            get { return _columnCount; }\r
+            set { \r
+                               if (_columnCount == value)\r
+                                       return;\r
+\r
+                               _columnCount = value; \r
+\r
+                               NotifyValueChanged ("ColumnCount", ColumnCount);\r
+                               this.RegisterForLayouting ((int)LayoutingType.PositionChildren);\r
+                       }\r
+        }\r
+               [XmlAttributeAttribute()][DefaultValue(1)]\r
+               public virtual int RowCount\r
+               {\r
+                       get { return _rowCount; }\r
+                       set { \r
+                               if (_rowCount == value)\r
+                                       return;\r
+\r
+                               _rowCount = value; \r
+\r
+                               NotifyValueChanged ("RowCount", RowCount);\r
+                               this.RegisterForLayouting ((int)LayoutingType.PositionChildren);\r
+                       }\r
+               }\r
+               public virtual int CaseWidth {\r
+                       get { return (Slot.Width - (ColumnCount - 1) * Spacing) / ColumnCount; }\r
+               }\r
+               public virtual int CaseHeight {\r
+                       get { return (Slot.Height - (RowCount - 1) * Spacing) / RowCount; }\r
+               }\r
+\r
+               #endregion\r
+\r
+               #region GraphicObject Overrides\r
+//             protected override Size measureRawSize ()\r
+//             {\r
+//                     Size tmp = new Size ();\r
+//\r
+//                     foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) {\r
+//                             tmp.Width = Math.Max (tmp.Width, c.Slot.Width);\r
+//                             tmp.Height = Math.Max (tmp.Height, c.Slot.Height);\r
+//                     }\r
+//\r
+//                     tmp.Width *= (ColumnCount - 1) * Spacing / ColumnCount;;\r
+//                     tmp.Height *= (RowCount - 1) * Spacing / RowCount;\r
+//                     tmp.Width += 2 * Margin;\r
+//                     tmp.Height += 2 * Margin;\r
+//\r
+//                     return tmp;\r
+//             }\r
+               public virtual void ComputeChildrenPositions()\r
+               {\r
+                       int slotWidth = CaseWidth;\r
+                       int slotHeight = CaseHeight;\r
+                       for (int curY = 0; curY < RowCount; curY++) {\r
+                               for (int curX = 0; curX < ColumnCount; curX++) {\r
+                                       int idx = curY * ColumnCount + curX;\r
+                                       if (idx >= Children.Count)\r
+                                               return;\r
+                                       GraphicObject c = Children [idx];\r
+                                       if (!c.Visible)\r
+                                               continue;\r
+                                       //ensure Item are not realigned\r
+                                       c.HorizontalAlignment = HorizontalAlignment.Left;\r
+                                       c.VerticalAlignment = VerticalAlignment.Top;\r
+                                       c.Left = curX * (slotWidth + Spacing);\r
+                                       c.Top = curY * (slotHeight + Spacing);\r
+                                       c.Width = slotWidth;\r
+                                       c.Height = slotHeight;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               public override void RegisterForLayouting (int layoutType)\r
+               {                       \r
+                       base.RegisterForLayouting (layoutType);\r
+\r
+                       if ((layoutType & (int)LayoutingType.PositionChildren) > 0)\r
+                               Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this);                        \r
+               }\r
+               public override void UpdateLayout (LayoutingType layoutType)\r
+               {            \r
+                       if (layoutType == LayoutingType.PositionChildren) {                             \r
+                               ComputeChildrenPositions ();\r
+                               //if no layouting remains in queue for item, registre for redraw\r
+                               if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count () <= 0 && bmp==null)\r
+                                       this.RegisterForRedraw ();\r
+                       }else\r
+                               base.UpdateLayout(layoutType);\r
+               }\r
+               #endregion\r
+\r
+    \r
+       }\r
+}\r