]> O.S.I.I.S - jp/crow.git/commitdiff
wrapper widget
authorjpbruyere <jp.bruyere@hotmail.com>
Sat, 13 Aug 2016 00:13:22 +0000 (02:13 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Sat, 13 Aug 2016 00:13:22 +0000 (02:13 +0200)
Crow.csproj
Tests/Interfaces/basicTests/0.crow
src/GraphicObjects/Group.cs
src/GraphicObjects/Wrapper.cs [new file with mode: 0644]
src/LayoutingQueueItem.cs

index 0de00b5c65b998c7f1a058a122328df0c076ab18..c85557b9ea75348f67f1ec043c74eab28d1050d7 100644 (file)
     <Compile Include="src\IMLReader.cs" />
     <Compile Include="src\ItemTemplate.cs" />
     <Compile Include="Style.cs" />
+    <Compile Include="src\GraphicObjects\Wrapper.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
index d180fa821a6dfc7be3ce32748128d61e052daee0..798b8ff141428a694268e28ce944a77c88846fd2 100755 (executable)
@@ -1,2 +1,13 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<MessageBox/>
+<?xml version="1.0"?>
+<Window Width="50%" Height="50%">      
+       <Wrapper Margin="10" Background="Teal" Spacing="30" Width="50%">
+               <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"/>
+       </Wrapper>
+</Window>
\ No newline at end of file
index e87ca41c112634022c324bd231d2b73773fec458..3782640c53c398947bad0c670d3fdc94c914fe89 100644 (file)
@@ -164,6 +164,56 @@ namespace Crow
                                break;
                        }
                }
+               protected override void onDraw (Context gr)
+               {
+                       base.onDraw (gr);
+
+                       gr.Save ();
+                       //clip to client zone
+                       CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
+                       gr.Clip ();
+                       lock (children) {
+                               foreach (GraphicObject g in Children) {
+                                       g.Paint (ref gr);
+                               }
+                       }
+                       gr.Restore ();
+               }
+               protected override void UpdateCache (Context ctx)
+               {
+                       Rectangle rb = Slot + Parent.ClientRectangle.Position;
+
+                       using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) {
+                               Context gr = new Context (cache);
+
+                               if (Clipping.count > 0) {
+                                       Clipping.clearAndClip (gr);
+                                       base.onDraw (gr);
+
+                                       //clip to client zone
+                                       CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
+                                       gr.Clip ();
+
+                                       foreach (GraphicObject c in Children) {
+                                               if (!c.Visible)
+                                                       continue;
+                                               if (Clipping.intersect(c.Slot + ClientRectangle.Position))
+                                                       c.Paint (ref gr);
+                                       }
+
+                                       #if DEBUG_CLIP_RECTANGLE
+                                       Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8));
+                                       #endif
+                               }
+                               gr.Dispose ();
+
+                               ctx.SetSourceSurface (cache, rb.X, rb.Y);
+                               ctx.Paint ();
+                       }
+                       Clipping.Reset();
+               }
+               #endregion
+
                public virtual void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
                {
                        GraphicObject g = sender as GraphicObject;
@@ -193,7 +243,6 @@ namespace Crow
                                break;
                        }
                }
-
                //TODO: x,y position should be taken in account for computation of width and height
                void resetChildrenMaxSize(){
                        largestChild = null;
@@ -235,56 +284,6 @@ namespace Crow
                        }
                }
 
-               protected override void onDraw (Context gr)
-               {
-                       base.onDraw (gr);
-
-                       gr.Save ();
-                       //clip to client zone
-                       CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
-                       gr.Clip ();
-                       lock (children) {
-                               foreach (GraphicObject g in Children) {
-                                       g.Paint (ref gr);
-                               }
-                       }
-                       gr.Restore ();
-               }
-               protected override void UpdateCache (Context ctx)
-               {
-                       Rectangle rb = Slot + Parent.ClientRectangle.Position;
-
-                       using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) {
-                               Context gr = new Context (cache);
-
-                               if (Clipping.count > 0) {
-                                       Clipping.clearAndClip (gr);
-                                       base.onDraw (gr);
-
-                                       //clip to client zone
-                                       CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
-                                       gr.Clip ();
-
-                                       foreach (GraphicObject c in Children) {
-                                               if (!c.Visible)
-                                                       continue;
-                                               if (Clipping.intersect(c.Slot + ClientRectangle.Position))
-                                                       c.Paint (ref gr);
-                                       }
-
-                                       #if DEBUG_CLIP_RECTANGLE
-                                       Clipping.stroke (gr, Color.Amaranth.AdjustAlpha (0.8));
-                                       #endif
-                               }
-                               gr.Dispose ();
-
-                               ctx.SetSourceSurface (cache, rb.X, rb.Y);
-                               ctx.Paint ();
-                       }
-                       Clipping.Reset();
-               }
-               #endregion
-
        
                #region Mouse handling
                public override void checkHoverWidget (MouseMoveEventArgs e)
diff --git a/src/GraphicObjects/Wrapper.cs b/src/GraphicObjects/Wrapper.cs
new file mode 100644 (file)
index 0000000..cfd7452
--- /dev/null
@@ -0,0 +1,164 @@
+//
+//  Wrapper.cs
+//
+//  Author:
+//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+//  Copyright (c) 2016 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;
+
+namespace Crow
+{
+       public class Wrapper : GenericStack
+       {
+               public Wrapper () : base()
+               {}
+
+               #region Group Overrides
+               public override void ChildrenLayoutingConstraints (ref LayoutingType layoutType)
+               {
+                       layoutType &= (~LayoutingType.Positioning);
+               }
+               public override void ComputeChildrenPositions()
+               {
+                       int dx = 0;
+                       int dy = 0;
+
+                       if (Orientation == Orientation.Horizontal) {
+                               int tallestChild = 0;
+                               foreach (GraphicObject c in Children) {
+                                       if (!c.Visible)
+                                               continue;
+                                       if (dx + c.Slot.Width > ClientRectangle.Width) {
+                                               dx = 0;
+                                               dy += tallestChild + Spacing;
+                                               c.Slot.X = dx;
+                                               c.Slot.Y = dy;
+                                               tallestChild = c.Slot.Height;
+                                       } else {
+                                               if (tallestChild < c.Slot.Height)
+                                                       tallestChild = c.Slot.Height;
+                                               c.Slot.X = dx;
+                                               c.Slot.Y = dy;
+                                       }
+                                       dx += c.Slot.Width + Spacing;
+                               }
+                       } else {
+                               int largestChild = 0;
+                               foreach (GraphicObject c in Children) {
+                                       if (!c.Visible)
+                                               continue;
+                                       if (dy + c.Slot.Height > ClientRectangle.Height) {
+                                               dy = 0;
+                                               dx += largestChild + Spacing;
+                                               c.Slot.X = dx;
+                                               c.Slot.Y = dy;
+                                               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;
+                                       }
+                               }
+                       }
+                       bmp = null;
+               }
+               public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
+               {
+                       //children can't stretch in a wrapper
+                       GraphicObject go = sender as GraphicObject;
+                       //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) {
+                                       go.Width = Measure.Fit;
+                                       return;
+                               }
+                               break;
+                       case LayoutingType.Height:
+                               if (Orientation == Orientation.Horizontal && go.Height == Measure.Stretched) {
+                                       go.Height = Measure.Fit;
+                                       return;
+                               }
+                               break;
+                       default:
+                               return;
+                       }
+                       this.RegisterForLayouting (LayoutingType.ArrangeChildren);
+               }
+               #endregion
+
+               #region GraphicObject Overrides
+               protected override int measureRawSize (LayoutingType lt)
+               {
+                       //Wrapper can't fit
+                       if (lt == LayoutingType.Width)
+                               Width = Measure.Stretched;
+                       else
+                               Height = Measure.Stretched;
+                       return -1;                              
+               }
+
+               public override bool UpdateLayout (LayoutingType layoutType)
+               {
+                       RegisteredLayoutings &= (~layoutType);
+
+                       if (layoutType == LayoutingType.ArrangeChildren) {
+                               if ((RegisteredLayoutings & LayoutingType.Sizing) != 0)
+                                       return false;
+
+                               ComputeChildrenPositions ();
+
+                               //if no layouting remains in queue for item, registre for redraw
+                               if (RegisteredLayoutings == LayoutingType.None && bmp == null)
+                                       Interface.CurrentInterface.EnqueueForRepaint (this);
+
+                               return true;
+                       }
+
+                       return base.UpdateLayout(layoutType);
+               }
+               public override void OnLayoutChanges (LayoutingType layoutType)
+               {
+                       #if DEBUG_LAYOUTING
+                       LayoutingQueueItem.currentLQI.Slot = LastSlots;
+                       LayoutingQueueItem.currentLQI.Slot = Slot;
+                       #endif
+
+                       switch (layoutType) {
+                       case LayoutingType.Width:
+                               foreach (GraphicObject c in Children) {
+                                       if (c.Width.Units == Unit.Percent)
+                                               c.RegisterForLayouting (LayoutingType.Width);
+                               }
+                               break;
+                       case LayoutingType.Height:
+                               foreach (GraphicObject c in Children) {
+                                       if (c.Height.Units == Unit.Percent)
+                                               c.RegisterForLayouting (LayoutingType.Height);
+                               }
+                               break;
+                       default:
+                               return;
+                       }
+                       RegisterForLayouting (LayoutingType.ArrangeChildren);
+                       //LayoutChanged.Raise (this, new LayoutingEventArgs (layoutType));
+               }
+               #endregion
+       }
+}
+
index a7909022354ee835bda44192401a5ce6560ec36c..e33d209c53c61da2b859f0654d77138d3142ef79 100644 (file)
@@ -31,6 +31,7 @@ namespace Crow
                None = 0x00,
                X = 0x01,
                Y = 0x02,
+               Positioning = 0x03,
                Width = 0x04,
                Height = 0x08,
                Sizing = 0x0C,