]> O.S.I.I.S - jp/crow.git/commitdiff
Layouting queue
authorjpbruyere <jp.bruyere@hotmail.com>
Mon, 27 Apr 2015 12:58:27 +0000 (14:58 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Mon, 27 Apr 2015 12:58:27 +0000 (14:58 +0200)
18 files changed:
GOLib.csproj
Tests/GOLIBTest_1.1.cs [new file with mode: 0644]
Tests/GOLIBTest_1.2.cs [new file with mode: 0644]
Tests/Interfaces/test0.goml
Tests/Interfaces/test1.1.goml [new file with mode: 0755]
Tests/Interfaces/test1.2.goml [new file with mode: 0755]
Tests/Interfaces/test1.goml
Tests/Tests.csproj
src/GraphicObjects/Container.cs
src/GraphicObjects/GenericStack.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/Group.cs
src/GraphicObjects/ILayoutable.cs
src/GraphicObjects/Scroller.cs
src/Interface.cs
src/LayoutingQueue.cs [new file with mode: 0644]
src/LayoutingQueueItem.cs [new file with mode: 0644]
src/OpenTKGameWindow.cs

index 4aad615285c994ed60662c40a4b5ffc59bb49679..567b61c51ed4f9b93d94987d7d0dd9e6c7ef27c4 100644 (file)
       <LogicalName>\r
       </LogicalName>\r
     </Compile>\r
+    <Compile Include="src\LayoutingQueueItem.cs">\r
+      <LogicalName>\r
+      </LogicalName>\r
+    </Compile>\r
+    <Compile Include="src\LayoutingQueue.cs">\r
+      <LogicalName>\r
+      </LogicalName>\r
+    </Compile>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Reference Include="System" />\r
diff --git a/Tests/GOLIBTest_1.1.cs b/Tests/GOLIBTest_1.1.cs
new file mode 100644 (file)
index 0000000..b9cbdf6
--- /dev/null
@@ -0,0 +1,55 @@
+#define MONO_CAIRO_DEBUG_DISPOSE\r
+\r
+\r
+using System;\r
+using System.Runtime.InteropServices;\r
+using OpenTK;\r
+using OpenTK.Graphics.OpenGL;\r
+using OpenTK.Input;\r
+\r
+using System.Diagnostics;\r
+\r
+//using GGL;\r
+using go;\r
+using System.Threading;\r
+\r
+\r
+namespace test\r
+{\r
+       class GOLIBTest_1_1 : OpenTKGameWindow\r
+       {\r
+               public GOLIBTest_1_1 ()\r
+                       : base(1024, 600,"test")\r
+               {}\r
+\r
+               Group g;\r
+\r
+               protected override void OnLoad (EventArgs e)\r
+               {\r
+                       base.OnLoad (e);\r
+                       LoadInterface("Interfaces/test1.1.goml", out g);\r
+\r
+               }\r
+               protected override void OnRenderFrame (FrameEventArgs e)\r
+               {\r
+                       GL.Clear (ClearBufferMask.ColorBufferBit);\r
+                       base.OnRenderFrame (e);\r
+                       SwapBuffers ();\r
+               }\r
+\r
+               protected override void OnUpdateFrame (FrameEventArgs e)\r
+               {\r
+                       base.OnUpdateFrame (e);\r
+               }\r
+\r
+               [STAThread]\r
+               static void Main ()\r
+               {\r
+                       Console.WriteLine ("starting example");\r
+\r
+                       using (GOLIBTest_1_1 win = new GOLIBTest_1_1( )) {\r
+                               win.Run (30.0);\r
+                       }\r
+               }\r
+       }\r
+}
\ No newline at end of file
diff --git a/Tests/GOLIBTest_1.2.cs b/Tests/GOLIBTest_1.2.cs
new file mode 100644 (file)
index 0000000..629b299
--- /dev/null
@@ -0,0 +1,55 @@
+#define MONO_CAIRO_DEBUG_DISPOSE\r
+\r
+\r
+using System;\r
+using System.Runtime.InteropServices;\r
+using OpenTK;\r
+using OpenTK.Graphics.OpenGL;\r
+using OpenTK.Input;\r
+\r
+using System.Diagnostics;\r
+\r
+//using GGL;\r
+using go;\r
+using System.Threading;\r
+\r
+\r
+namespace test\r
+{\r
+       class GOLIBTest_1_2 : OpenTKGameWindow\r
+       {\r
+               public GOLIBTest_1_2 ()\r
+                       : base(1024, 600,"test")\r
+               {}\r
+\r
+               VerticalStack g;\r
+\r
+               protected override void OnLoad (EventArgs e)\r
+               {\r
+                       base.OnLoad (e);\r
+                       LoadInterface("Interfaces/test1.2.goml", out g);\r
+\r
+               }\r
+               protected override void OnRenderFrame (FrameEventArgs e)\r
+               {\r
+                       GL.Clear (ClearBufferMask.ColorBufferBit);\r
+                       base.OnRenderFrame (e);\r
+                       SwapBuffers ();\r
+               }\r
+\r
+               protected override void OnUpdateFrame (FrameEventArgs e)\r
+               {\r
+                       base.OnUpdateFrame (e);\r
+               }\r
+\r
+               [STAThread]\r
+               static void Main ()\r
+               {\r
+                       Console.WriteLine ("starting example");\r
+\r
+                       using (GOLIBTest_1_2 win = new GOLIBTest_1_2( )) {\r
+                               win.Run (30.0);\r
+                       }\r
+               }\r
+       }\r
+}
\ No newline at end of file
index 3163cc9aae06425c4951c8289331615bb48de3ef..102c1cac3faa972f6f05b331fff49098dde47d4d 100755 (executable)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>\r
 <GraphicObject \r
-                       Top="10" Left="10"\r
-                       Width="10" Height="50" \r
+                       HorizontalAlignment="Right"\r
+                       VerticalAlignment="Bottom"\r
                        Margin="10" Background="Green"/>\r
diff --git a/Tests/Interfaces/test1.1.goml b/Tests/Interfaces/test1.1.goml
new file mode 100755 (executable)
index 0000000..6ccf2c1
--- /dev/null
@@ -0,0 +1,15 @@
+<?xml version="1.0"?>\r
+<Group Width="0" Height="0" Margin="50"\r
+       Focusable="True" Background="Yellow">\r
+       <Group Width="-1" Height="-1" Margin="50" \r
+               VerticalAlignment="Top" HorizontalAlignment="Left"\r
+               Focusable="True" Background="Green">\r
+               <Image VerticalAlignment="Bottom"                       \r
+                       Name="PhaseOverlay" Width="100" Height="100" Path="image/u.svg" Background="Red"/>\r
+               <Image Top="100"                \r
+                       Name="PhaseOverlay" Width="100" Height="100" Path="image/u.svg" Background="Red"/>\r
+       </Group>\r
+       <Image Top="100"                \r
+               Name="PhaseOverlay" Width="100" Height="100" Path="image/u.svg" Background="Red"/>\r
+\r
+</Group>
\ No newline at end of file
diff --git a/Tests/Interfaces/test1.2.goml b/Tests/Interfaces/test1.2.goml
new file mode 100755 (executable)
index 0000000..c41135c
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>\r
+<VerticalStack>\r
+       <Label Text="label11"/>\r
+       <Label Text="label21"/>\r
+       <HorizontalStack Width="-1" Height="-1" Margin="50"\r
+               Focusable="True" Background="DarkBlue">\r
+               <Label Text="label12"/>\r
+               <Label Text="label22"/>\r
+               <Label Text="label32"/>\r
+               <Label Text="label42"/>\r
+               <Label Text="label52"/>\r
+       </HorizontalStack>\r
+       <Label Text="label33" Background="Green" Width="0"/>\r
+       <Button/>\r
+       <Label Text="label43"/>\r
+       <Label Text="label53"/>\r
+\r
+</VerticalStack>
\ No newline at end of file
index 43524e8599b5f183529c8267a85eed567948ab5c..ff2707683ee18181964ff1c8d2d8d6c43d784260 100755 (executable)
@@ -1,9 +1,10 @@
 <?xml version="1.0"?>\r
-<Container\r
-       HorizontalAlignment="Left" VerticalAlignment="Center"\r
-       Margin="10" Focusable="True" Fit="True" Background="Green">\r
-       <Group   Background="White" >\r
-               <Image Name="PhaseOverlay" Width="40" Height="40"\r
-                               Path="image/u.svg" Background="Red"/>\r
-       </Group>\r
+<Container Width="0" Height="-1"\r
+       Margin="100" Focusable="True" Background="Yellow">\r
+\r
+       <Container Width="-1" Height="-1"\r
+               Margin="10" Focusable="True" Background="Green">\r
+                       <Image VerticalAlignment="Bottom"                       \r
+                               Name="PhaseOverlay" Width="100" Height="100" Path="image/u.svg" Background="Red"/>\r
+       </Container>\r
 </Container>
\ No newline at end of file
index b65edb44417b80dab9f4f7ee4ff35db867e9631a..7d37271c9865a3ca0b14a2ba7dc1aeae3b4c949d 100644 (file)
@@ -8,7 +8,7 @@
     <OutputType>Exe</OutputType>
     <RootNamespace>Tests</RootNamespace>
     <AssemblyName>Tests</AssemblyName>
-    <StartupObject>test.GOLIBTest_4</StartupObject>
+    <StartupObject>test.GOLIBTest_5</StartupObject>
     <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <OutputPath>..\bin\$(configuration)</OutputPath>
     <IntermediateOutputPath>obj\$(configuration)</IntermediateOutputPath>
       <LogicalName>
       </LogicalName>
     </Compile>
+    <Compile Include="GOLIBTest_1.1.cs">
+      <LogicalName>
+      </LogicalName>
+    </Compile>
+    <Compile Include="GOLIBTest_1.2.cs">
+      <LogicalName>
+      </LogicalName>
+    </Compile>
   </ItemGroup>
   <ItemGroup>
     <None Include="image\u.svg">
       <LogicalName>
       </LogicalName>
     </None>
+    <None Include="Interfaces\test1.1.goml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+      <LogicalName>
+      </LogicalName>
+    </None>
+    <None Include="Interfaces\test1.2.goml">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+      <LogicalName>
+      </LogicalName>
+    </None>
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Interfaces\">
index c1134ec592f61f7b4879de54dcf8f9d296d5428e..1971f00baf495fa1bfb67942606003ec63c5e2f3 100644 (file)
@@ -77,41 +77,37 @@ namespace go
                 child.InvalidateLayout();\r
         }\r
                protected override Size measureRawSize ()\r
+               {                       \r
+                       return child == null ? Bounds.Size : new Size(child.Slot.Width + 2 * (Margin),child.Slot.Height + 2 * (Margin));\r
+               }\r
+               public override void RegisterForLayouting ()\r
                {\r
-                       Size raw = Bounds.Size;\r
-\r
-                       if (child != null) {\r
-                               if (Bounds.Width < 0 && child.WIsValid)\r
-                                       raw.Width = child.Slot.Width + 2 * (Margin);\r
-                               if (Bounds.Height < 0 && child.HIsValid)\r
-                                       raw.Height = child.Slot.Height + 2 * (Margin);\r
-                       }\r
+                       base.RegisterForLayouting ();\r
 \r
-                       return raw;\r
+                       if (child != null)\r
+                               child.RegisterForLayouting ();\r
                }\r
-        public override void UpdateLayout()\r
-        {\r
-                       if (LayoutIsValid)\r
-                return;\r
-\r
-                       if (Width < 0 && child.Width == 0)\r
-                               child.Width = -1;\r
-                       if (Height < 0 && child.Height == 0)\r
-                               child.Height = -1;\r
-\r
-                       if (!(base.LayoutIsValid))\r
-                               base.UpdateLayout();\r
-                               \r
-            if (child != null)\r
-            {\r
-                               if (!child.LayoutIsValid) {\r
-                                       child.UpdateLayout ();\r
-                               }\r
-            }\r
-\r
-            if (LayoutIsValid)\r
-                registerForRedraw();\r
-        }\r
+//             public override void UpdateLayout (LayoutingType layoutType)\r
+//        {\r
+//\r
+////                   if (Width < 0 && child.Width == 0)\r
+////                           child.Width = -1;\r
+////                   if (Height < 0 && child.Height == 0)\r
+////                           child.Height = -1;\r
+////\r
+////                   if (!(base.LayoutIsValid))\r
+////                           base.UpdateLayout();\r
+////                           \r
+////            if (child != null)\r
+////            {\r
+////                           if (!child.LayoutIsValid) {\r
+////                                   child.UpdateLayout ();\r
+////                           }\r
+////            }\r
+////\r
+////            if (LayoutIsValid)\r
+////                registerForRedraw();\r
+//        }\r
                public override Rectangle ContextCoordinates (Rectangle r)\r
                {\r
                        return\r
index a36cd7b194dde1438cf36b0cddd4959f8e6d6bcf..36d41f99e15383a7e15433bacad50df79631dd39 100644 (file)
@@ -18,7 +18,6 @@ namespace go
                #endregion\r
 \r
                #region Private fields\r
-               bool childrenArePositionned = false;\r
         int _spacing;\r
         Orientation _orientation;\r
                #endregion\r
@@ -49,49 +48,25 @@ namespace go
                        get { return base.Height; }\r
                        set { base.Height = value; }\r
                }\r
-               [XmlIgnore]public override bool LayoutIsValid {\r
-                       get { return childrenArePositionned && base.LayoutIsValid; }\r
-                       set { base.LayoutIsValid = value; }\r
-               }\r
 \r
-               public override void InvalidateLayout ()\r
-               {\r
-                       childrenArePositionned = false;\r
-                       base.InvalidateLayout ();\r
-               }\r
                protected override Size measureRawSize ()\r
                {\r
-                       Size raw = Bounds.Size;\r
                        Size tmp = new Size ();\r
 \r
-                       if (raw.Width >= 0 && raw.Height >= 0)\r
-                               return raw;\r
-                               \r
-                       foreach (GraphicObject c in Children) {\r
-                               if (raw.Width < 0) {\r
-                                       if (c.WIsValid) {\r
-                                               if (Orientation == Orientation.Horizontal && c.Bounds.Width != 0)\r
-                                                       tmp.Width += c.Slot.Width + Spacing;\r
-                                               else\r
-                                                       tmp.Width = Math.Max (tmp.Width, c.Slot.Right);\r
-                                       }else\r
-                                               return raw;\r
+                       if (Orientation == Orientation.Horizontal) {\r
+                               foreach (GraphicObject c in Children) {\r
+                                       tmp.Width += c.Slot.Width + Spacing;\r
+                                       tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);\r
                                }\r
-                               if (raw.Height < 0) {\r
-                                       if (c.HIsValid) {\r
-                                               if (Orientation == Orientation.Vertical && c.Bounds.Height != 0)\r
-                                                       tmp.Height += c.Slot.Height + Spacing;\r
-                                               else\r
-                                                       tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);\r
-                                       }else\r
-                                               return raw;\r
+                       } else {\r
+                               foreach (GraphicObject c in Children) {\r
+                                       tmp.Width = Math.Max (tmp.Width, c.Slot.Right);\r
+                                       tmp.Height += c.Slot.Height + Spacing;\r
                                }\r
                        }\r
 \r
-                       if (raw.Width < 0)\r
-                               tmp.Width += 2*Margin;\r
-                       if (raw.Height < 0)\r
-                               tmp.Height += 2*Margin;\r
+                       tmp.Width += 2*Margin;\r
+                       tmp.Height += 2*Margin;\r
 \r
                        return tmp;\r
                }\r
@@ -100,66 +75,36 @@ namespace go
                        int d = 0;\r
                        if (Orientation == Orientation.Horizontal) {\r
                                foreach (GraphicObject c in Children) {\r
-                                       if (c.Bounds.Width == 0)\r
-                                               continue;\r
-\r
                                        c.Slot.X = d;\r
-                                       c.XIsValid = true;\r
                                        d += c.Slot.Width + Spacing;\r
                                }\r
                        } else {\r
                                foreach (GraphicObject c in Children) {\r
-                                       if (c.Bounds.Height == 0)\r
-                                               continue;\r
-\r
                                        c.Slot.Y = d;\r
-                                       c.YIsValid = true;\r
                                        d += c.Slot.Height + Spacing;\r
                                }\r
                        }\r
-                       childrenArePositionned = true;\r
                }\r
+               public override void RegisterForLayouting ()\r
+               {\r
+                       base.RegisterForLayouting ();\r
 \r
-        public override void UpdateLayout()\r
+                       int idx = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where (lq => lq.GraphicObject.Parent == this).LastOrDefault ());\r
+                       if (idx < 0)\r
+                               return;\r
+                       Interface.LayoutingQueue.Insert (\r
+                               idx+1,\r
+                               new LayoutingQueueItem (LayoutingType.PositionChildren, this));\r
+               }\r
+               public override void UpdateLayout (LayoutingType layoutType)\r
         {            \r
-            base.UpdateLayout();\r
-\r
-                       ComputeChildrenPositions ();\r
+                       if (layoutType == LayoutingType.PositionChildren)\r
+                               ComputeChildrenPositions ();\r
 \r
-            if (LayoutIsValid)\r
-                registerForRedraw();\r
+                       base.UpdateLayout(layoutType);\r
         }\r
                #endregion\r
 \r
-               //\r
-//        bool enoughtSpaceForWidget(GraphicObject w)\r
-//        {\r
-//            if (!SizeToContent)\r
-//            {\r
-//                int nextXForWidget = 0;\r
-//                int nextYForWidget = 0;\r
-//\r
-//                if (Orientation == Orientation.Horizontal)\r
-//                    nextXForWidget = currentXForWidget + w.Slot.Width;\r
-//                else\r
-//                    nextYForWidget = nextYForWidget + w.Slot.Height;\r
-//\r
-//\r
-//                if (nextXForWidget > ClientRectangle.Right )\r
-//                    return false;\r
-//                if (currentYForWidget > ClientRectangle.Bottom )\r
-//                    return false;\r
-//            }\r
-//            return true;\r
-//        }\r
-//        void advance(GraphicObject w)\r
-//        {\r
-//            if (Orientation == Orientation.Horizontal)\r
-//                currentXForWidget = currentXForWidget + WidgetSpacing + w.Slot.Width;\r
-//            else\r
-//                currentYForWidget = currentYForWidget + WidgetSpacing + w.Slot.Height;\r
-//\r
-//        }\r
     \r
        }\r
 }\r
index 3ffda14aacb4bf58d935438ac74ff00e65d176f5..c6756db2027a722c3a25dccc0fe27b17db4c0f54 100755 (executable)
@@ -117,7 +117,7 @@ namespace go
                        }\r
                }\r
                [XmlIgnore]public virtual IGOLibHost TopContainer {\r
-                       get { return Parent.TopContainer; }\r
+                       get { return Parent == null ? null : Parent.TopContainer; }\r
                }\r
                public virtual void InvalidateLayout ()\r
                {\r
@@ -373,7 +373,8 @@ namespace go
                public virtual void registerForGraphicUpdate ()\r
                {\r
                        bmp = null;\r
-                       registerForRedraw ();\r
+                       RegisterForLayouting ();\r
+                       //registerForRedraw ();\r
                        //Interface.registerForGraphicUpdate(this);\r
                }\r
                /// <summary>\r
@@ -381,7 +382,7 @@ namespace go
                /// </summary>\r
                public virtual void registerForRedraw ()\r
                {\r
-                       if (LayoutIsValid && Visible)\r
+                       if (Visible && TopContainer != null)\r
                                TopContainer.gobjsToRedraw.Add (this);\r
                }\r
                public virtual void registerClipRect()\r
@@ -392,50 +393,48 @@ namespace go
                {\r
                        return Bounds.Size;\r
                }\r
-\r
-               protected virtual void ComputeSize()\r
+               public virtual void RegisterForLayouting()\r
                {\r
-                       Size rawSize = measureRawSize ();\r
-\r
-                       if (!wIsValid) {\r
-                               wIsValid = true;\r
-                               if (Width > 0)\r
-                                       Slot.Width = Width;\r
-                               else if (Width < 0) {\r
-                                       if (rawSize.Width > 0)\r
-                                               Slot.Width = rawSize.Width;\r
-                                       else\r
-                                               wIsValid = false;\r
-                               } else if (Parent.WIsValid)\r
-                                       Slot.Width = Parent.ClientRectangle.Width;\r
-                               else\r
-                                       wIsValid = false;                               \r
+                       //clear previous layouting for item\r
+                       Interface.LayoutingQueue.RemoveAll (lq => lq.GraphicObject == this);\r
+\r
+                       if (Bounds.Width == 0) { //stretch in parent\r
+                               int idxParentW = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Width).FirstOrDefault());\r
+                               if (idxParentW < 0)\r
+                                       Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this));\r
+                               else//insert after parent sizing\r
+                                       Interface.LayoutingQueue.Insert (idxParentW + 1, new LayoutingQueueItem (LayoutingType.Width, this));\r
+                       } else {//fit ou fixed\r
+                               Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Width, this));\r
+                               //for x positionning, sizing of obj and parent have to be done\r
+                               int idxParentW = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Width).FirstOrDefault());\r
+                               if (idxParentW < 0)\r
+                                       Interface.LayoutingQueue.Insert (1, new LayoutingQueueItem (LayoutingType.X, this));\r
+                               else//insert after parent sizing\r
+                                       Interface.LayoutingQueue.Insert (idxParentW + 1, new LayoutingQueueItem (LayoutingType.X, this));\r
                        }\r
-\r
-                       if (!hIsValid) {\r
-                               hIsValid = true;\r
-                               if (Height > 0)\r
-                                       Slot.Height = Height;\r
-                               else if (Height < 0) {\r
-                                       if (rawSize.Height > 0)\r
-                                               Slot.Height = rawSize.Height;\r
-                                       else\r
-                                               hIsValid = false;\r
-                               } else if (Parent.HIsValid)\r
-                                       Slot.Height = Parent.ClientRectangle.Height;\r
+                       if (Bounds.Height == 0) { //stretch\r
+                               int idxParentH = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Height).FirstOrDefault());\r
+                               if (idxParentH < 0)\r
+                                       Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this));\r
                                else\r
-                                       hIsValid = false;                               \r
+                                       Interface.LayoutingQueue.Insert (idxParentH + 1, new LayoutingQueueItem (LayoutingType.Height, this));\r
+                       } else {\r
+                               Interface.LayoutingQueue.Insert (0, new LayoutingQueueItem (LayoutingType.Height, this));\r
+                               int idxParentH = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where(lq => lq.GraphicObject == this.Parent && lq.LayoutType == LayoutingType.Height).FirstOrDefault());\r
+                               if (idxParentH < 0)\r
+                                       Interface.LayoutingQueue.Insert (1, new LayoutingQueueItem (LayoutingType.Y, this));\r
+                               else//insert after parent sizing\r
+                                       Interface.LayoutingQueue.Insert (idxParentH + 1, new LayoutingQueueItem (LayoutingType.Y, this));\r
                        }\r
+\r
                }\r
-               protected virtual void ComputePosition()\r
-               {\r
-                       if (!xIsValid) {\r
-                               xIsValid = true;\r
-                               if (Width == 0)\r
-                                       Slot.X = 0;\r
-                               else if (Left != 0)\r
-                                       Slot.X = Left;\r
-                               else if (Parent.WIsValid && WIsValid) {\r
+\r
+               public virtual void UpdateLayout (LayoutingType layoutType)\r
+               {                       \r
+                       switch (layoutType) {\r
+                       case LayoutingType.X:\r
+                               if (Bounds.X == 0) {\r
                                        switch (HorizontalAlignment) {\r
                                        case HorizontalAlignment.Left:\r
                                                Slot.X = 0;\r
@@ -447,17 +446,12 @@ namespace go
                                                Slot.X = Parent.ClientRectangle.Width / 2 - Slot.Width / 2;\r
                                                break;\r
                                        }\r
-                               } else// if (Parent.getBounds().Width>=0)\r
-                                       xIsValid = false;\r
-                       }\r
-\r
-                       if (!yIsValid) {\r
-                               yIsValid = true;\r
-                               if (Height== 0)\r
-                                       Slot.Y = 0;\r
-                               else if (Top != 0)\r
-                                       Slot.Y = Top;\r
-                               else if (Parent.HIsValid && HIsValid) {\r
+                                       break;\r
+                               }\r
+                               Slot.X = Bounds.X;\r
+                               break;\r
+                       case LayoutingType.Y:\r
+                               if (Bounds.Y == 0) {\r
                                        switch (VerticalAlignment) {\r
                                        case VerticalAlignment.Top:\r
                                                Slot.Y = 0;\r
@@ -469,19 +463,30 @@ namespace go
                                                Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2;\r
                                                break;\r
                                        }\r
-                               } else// if (Parent.getBounds().Height>=0)\r
-                                       yIsValid = false;\r
+                                       break;\r
+                               }\r
+                               Slot.Y = Bounds.Y;\r
+                               break;\r
+                       case LayoutingType.Width:                               \r
+                               if (Width > 0)\r
+                                       Slot.Width = Width;\r
+                               else if (Width < 0)\r
+                                       Slot.Width = measureRawSize ().Width;\r
+                               else\r
+                                       Slot.Width = Parent.ClientRectangle.Width;\r
+                               break;\r
+                       case LayoutingType.Height:\r
+                               if (Height > 0)\r
+                                       Slot.Height = Height;\r
+                               else if (Height < 0)\r
+                                       Slot.Height = measureRawSize ().Height;\r
+                               else\r
+                                       Slot.Height = Parent.ClientRectangle.Height;\r
+                               break;\r
                        }\r
-               }\r
-               public virtual void UpdateLayout ()\r
-               {\r
-                       if (!SizeIsValid)\r
-                               ComputeSize ();\r
-                       if (!PositionIsValid)\r
-                               ComputePosition ();                             \r
-                       if (LayoutIsValid)\r
-                               registerForRedraw ();\r
-\r
+                       //if no layouting remains in queue for item, registre for redraw\r
+                       if (Interface.LayoutingQueue.Where (lq => lq.GraphicObject == this).Count() <= 0)\r
+                               this.registerForRedraw ();\r
                }\r
                protected virtual void onDraw(Context gr)\r
                {\r
index d2c4890412b407c01308bb10601a6221f4ddf0e3..8056f06f791298150ab6a3a8900a8f2e88776929 100644 (file)
@@ -132,67 +132,58 @@ namespace go
                }\r
                protected override Size measureRawSize ()\r
                {\r
-                       Size raw = Bounds.Size;\r
                        Size tmp = new Size ();\r
 \r
-                       if (raw.Width >= 0 && raw.Height >= 0)\r
-                               return raw;\r
-\r
                        foreach (GraphicObject c in Children) {\r
-                               if (raw.Width < 0) {\r
-                                       if (c.WIsValid)\r
-                                               tmp.Width = Math.Max (tmp.Width, c.Slot.Right);\r
-                                       else\r
-                                               return raw;\r
-                               }\r
-                               if (raw.Height < 0) {\r
-                                       if (c.HIsValid)\r
-                                               tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);\r
-                                       else\r
-                                               return raw;\r
-                               }\r
+                               tmp.Width = Math.Max (tmp.Width, c.Slot.Right);\r
+                               tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom);\r
                        }\r
 \r
-                       if (raw.Width < 0)\r
-                               tmp.Width += 2*Margin;\r
-                       if (raw.Height < 0)\r
-                               tmp.Height += 2*Margin;\r
+                       tmp.Width += 2*Margin;\r
+                       tmp.Height += 2*Margin;\r
 \r
                        return tmp;\r
                }\r
-               public override void UpdateLayout()\r
+               public override void RegisterForLayouting ()\r
                {\r
-                       if (LayoutIsValid)\r
-                               return;\r
-\r
-                       bool atLeastOneChildHasWNotDependingOnParent = false;\r
-                       bool atLeastOneChildHasHNotDependingOnParent = false;\r
-\r
-                       foreach (GraphicObject c in Children) {\r
-                               if (c.LayoutIsValid)\r
-                                       continue;\r
+                       base.RegisterForLayouting ();\r
 \r
-                               if (Width < 0 && c.WIsValid) {\r
-                                       if (!atLeastOneChildHasWNotDependingOnParent && !(this is GenericStack))\r
-                                               c.XIsValid = true;\r
-                                       atLeastOneChildHasWNotDependingOnParent = true;\r
-                               }\r
-                               if (Height < 0 && c.HIsValid) {\r
-                                       if (!atLeastOneChildHasHNotDependingOnParent && !(this is GenericStack))\r
-                                               c.YIsValid = true;\r
-                                       atLeastOneChildHasHNotDependingOnParent = true;\r
-                               }\r
-\r
-                               c.UpdateLayout ();\r
-                       }\r
-\r
-//                     if (Width < 0 && !atLeastOneChildHasWNotDependingOnParent)\r
-//                             Debug.WriteLine ("ERROR: no child has fixed width and parent width is set to content!");\r
-//                     if (Height < 0 && !atLeastOneChildHasHNotDependingOnParent)\r
-//                             Debug.WriteLine ("ERROR: no child has fixed height and parent height is set to content!");\r
-\r
-                       base.UpdateLayout ();\r
+                       foreach (GraphicObject g in Children)\r
+                               g.RegisterForLayouting ();                      \r
                }\r
+//             public override void UpdateLayout (LayoutingType layoutType)\r
+//             {\r
+//                     if (LayoutIsValid)\r
+//                             return;\r
+//\r
+//                     bool atLeastOneChildHasWNotDependingOnParent = false;\r
+//                     bool atLeastOneChildHasHNotDependingOnParent = false;\r
+//\r
+////                   foreach (GraphicObject c in Children) {\r
+////                           if (c.LayoutIsValid)\r
+////                                   continue;\r
+////\r
+////                           if (Width < 0 && c.WIsValid) {\r
+////                                   if (!atLeastOneChildHasWNotDependingOnParent && !(this is GenericStack))\r
+////                                           c.XIsValid = true;\r
+////                                   atLeastOneChildHasWNotDependingOnParent = true;\r
+////                           }\r
+////                           if (Height < 0 && c.HIsValid) {\r
+////                                   if (!atLeastOneChildHasHNotDependingOnParent && !(this is GenericStack))\r
+////                                           c.YIsValid = true;\r
+////                                   atLeastOneChildHasHNotDependingOnParent = true;\r
+////                           }\r
+////\r
+////                           c.UpdateLayout ();\r
+////                   }\r
+//\r
+////                   if (Width < 0 && !atLeastOneChildHasWNotDependingOnParent)\r
+////                           Debug.WriteLine ("ERROR: no child has fixed width and parent width is set to content!");\r
+////                   if (Height < 0 && !atLeastOneChildHasHNotDependingOnParent)\r
+////                           Debug.WriteLine ("ERROR: no child has fixed height and parent height is set to content!");\r
+//\r
+//                     //base.UpdateLayout ();\r
+//             }\r
 \r
                public override Rectangle ContextCoordinates(Rectangle r){\r
                        return r + ClientRectangle.Position;\r
@@ -212,7 +203,7 @@ namespace go
 \r
                public override void Paint(ref Context ctx, Rectangles clip = null)\r
                {\r
-                       if ( !(Visible&LayoutIsValid) )\r
+                       if ( !(Visible) )\r
                                return;\r
 \r
                        //                      ctx.Save ();\r
index 1107f825096621f7133732f4426d3178db0926e5..088a4e83742a8a3d037b8ebf48368229a5eaecfb 100644 (file)
@@ -6,14 +6,6 @@ namespace go
        {
                ILayoutable Parent { get; set; }
 
-               bool SizeIsValid { get; set; }
-               bool WIsValid { get; set; }
-               bool HIsValid { get; set; }
-               bool PositionIsValid { get; set; }
-               bool XIsValid { get; set; }
-               bool YIsValid { get; set; }
-               bool LayoutIsValid { get; set; }
-
                Rectangle ClientRectangle { get; }
                Rectangle getSlot();
                Rectangle getBounds();
@@ -21,6 +13,7 @@ namespace go
                IGOLibHost TopContainer { get; }
 
                void InvalidateLayout ();
+               void UpdateLayout(LayoutingType layoutType);
 
 
                Rectangle ContextCoordinates(Rectangle r);
index 45a8a8b36bd06f6741bc1c7d59ba868cabef54aa..74e26c720b045cacb6ff48780db6646f3437f37f 100644 (file)
@@ -115,21 +115,21 @@ namespace go
                {\r
                        TopContainer.redrawClip.AddRectangle (base.ScreenCoordinates(Slot));\r
                }\r
-               public override void UpdateLayout ()\r
+               public override void UpdateLayout (LayoutingType layoutType)\r
                {\r
-                       base.UpdateLayout ();\r
-\r
-                       if (!LayoutIsValid)\r
-                               return;\r
-\r
-                       //override child positionning inside scroller in the \r
-                       //scrolling direction\r
-                       if (child == null)\r
-                               return;\r
-                       if (VerticalScrolling)\r
-                               child.Slot.Y = 0;\r
-                       if (HorizontalScrolling)\r
-                               child.Slot.X = 0;\r
+//                     base.UpdateLayout ();\r
+//\r
+//                     if (!LayoutIsValid)\r
+//                             return;\r
+//\r
+//                     //override child positionning inside scroller in the \r
+//                     //scrolling direction\r
+//                     if (child == null)\r
+//                             return;\r
+//                     if (VerticalScrolling)\r
+//                             child.Slot.Y = 0;\r
+//                     if (HorizontalScrolling)\r
+//                             child.Slot.X = 0;\r
                }\r
                public override void Paint(ref Cairo.Context ctx, Rectangles clip = null)\r
                {\r
index 8f862381a646f5bfb455d8d6ac76132cfa4d3870..8684d8517e4766bef187329f2d70b4fe95588d41 100644 (file)
@@ -35,6 +35,8 @@ namespace go
                public static bool ReplaceTabsWithSpace = false;
                public static bool DesignerMode = false;
 
+               public static LayoutingQueue LayoutingQueue = new LayoutingQueue();
+
                #region Load/Save
 
                internal static List<EventSource> EventsToResolve;
diff --git a/src/LayoutingQueue.cs b/src/LayoutingQueue.cs
new file mode 100644 (file)
index 0000000..9015249
--- /dev/null
@@ -0,0 +1,40 @@
+//
+//  LayoutingQueue.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  Copyright (c) 2015 jp
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+using System;
+using System.Collections.Generic;
+
+namespace go
+{
+       public class LayoutingQueue : List<LayoutingQueueItem>
+       {
+               public LayoutingQueue ()
+               {
+               }
+                       
+               public LayoutingQueueItem Dequeue()
+               {
+                       LayoutingQueueItem tmp = this [0];
+                       this.RemoveAt (0);
+                       return tmp;
+               }
+       }
+}
+
diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs
new file mode 100644 (file)
index 0000000..4005f71
--- /dev/null
@@ -0,0 +1,70 @@
+//
+//  LayoutingQueueItem.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  Copyright (c) 2015 jp
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+using System;
+using System.Diagnostics;
+
+namespace go
+{
+       public enum LayoutingType
+       {
+               X,
+               Y,
+               Width,
+               Height,
+               PositionChildren
+       }
+
+       public class LayoutingQueueItem
+       {
+
+               public ILayoutable GraphicObject;
+               public LayoutingType LayoutType;
+
+               public LayoutingQueueItem (LayoutingType _layoutType, ILayoutable _graphicObject)
+               {
+                       LayoutType = _layoutType;
+                       GraphicObject = _graphicObject;
+               }
+               public void ProcessLayouting()
+               {
+                       Debug.WriteLine ("Layouting => " + this.ToString ());
+                       try {
+                               GraphicObject.UpdateLayout (LayoutType);
+                       } catch (Exception ex) {
+                               Debug.WriteLine ("Layouting error: " + ex.ToString ());
+                       }
+               }
+
+               public static implicit operator GraphicObject(LayoutingQueueItem queueItem)
+               {
+                       return queueItem.GraphicObject as GraphicObject;
+               }
+               public static implicit operator LayoutingType(LayoutingQueueItem lqi)
+               {
+                       return lqi.LayoutType;
+               }
+               public override string ToString ()
+               {
+                       return string.Format ("{0}->{1}", LayoutType,GraphicObject.ToString());
+               }
+       }
+}
+
index 644c65c8db76b8f173d779033e52f6fb6c01c8da..2d491b207d8493fd392490a777229fed0235e3cd 100755 (executable)
@@ -78,6 +78,8 @@ namespace go
                {\r
                        g.Parent = this;\r
                        GraphicObjects.Add (g);\r
+\r
+                       g.RegisterForLayouting ();\r
                }\r
                public void DeleteWidget(GraphicObject g)\r
                {\r
@@ -224,14 +226,18 @@ namespace go
                        GraphicObject[] invGOList = new GraphicObject[GraphicObjects.Count];\r
                        GraphicObjects.CopyTo (invGOList,0);\r
                        invGOList = invGOList.Reverse ().ToArray ();\r
-\r
-                       foreach (GraphicObject p in invGOList) {\r
-                               if (p.Visible) {\r
-                                       layoutTime.Start ();\r
-                                       while(!p.LayoutIsValid)\r
-                                               p.UpdateLayout ();\r
-                                       layoutTime.Stop ();\r
-                               }\r
+//\r
+//                     foreach (GraphicObject p in invGOList) {\r
+//                             if (p.Visible) {\r
+//                                     layoutTime.Start ();\r
+//                                     while(!p.LayoutIsValid)\r
+//                                             p.UpdateLayout ();\r
+//                                     layoutTime.Stop ();\r
+//                             }\r
+//                     }\r
+                       while (Interface.LayoutingQueue.Count > 0) {\r
+                               LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue ();\r
+                               lqi.ProcessLayouting ();\r
                        }\r
 \r
                        //Debug.WriteLine ("otd:" + gobjsToRedraw.Count.ToString () + "-");\r
@@ -457,6 +463,11 @@ namespace go
 \r
                #region ILayoutable implementation\r
 \r
+               public void UpdateLayout (LayoutingType layoutType)\r
+               {\r
+                       throw new NotImplementedException ();\r
+               }\r
+\r
                public Rectangle ContextCoordinates (Rectangle r)\r
                {\r
                        return r;\r