aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/GenericStack.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/GraphicObjects/GenericStack.cs')
-rw-r--r--src/GraphicObjects/GenericStack.cs189
1 files changed, 62 insertions, 127 deletions
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs
index dd385201..d5ff81c6 100644
--- a/src/GraphicObjects/GenericStack.cs
+++ b/src/GraphicObjects/GenericStack.cs
@@ -1,14 +1,10 @@
-using System;
+using System.ComponentModel;
using System.Diagnostics;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Xml.Serialization;
-using System.ComponentModel;
namespace Crow
{
- public class GenericStack : Group
+ public class GenericStack : Group
{
#region CTOR
public GenericStack()
@@ -54,41 +50,13 @@ namespace Crow
}
protected override int measureRawSize (LayoutingType lt)
{
- int tmp = 0;
- switch (lt) {
- case LayoutingType.Width:
- if (Orientation == Orientation.Horizontal) {
- if (Children.Count > 0) {
- foreach (GraphicObject c in Children) {
- if (!c.Visible)
- continue;
- if (c.RegisteredLayoutings.HasFlag (LayoutingType.Width))
- return -1;
- tmp += c.Slot.Width + Spacing;
- }
- tmp -= Spacing;
- }
- break;
- }
- return base.measureRawSize (lt);
- case LayoutingType.Height:
- if (Orientation == Orientation.Vertical) {
- if (Children.Count > 0) {
- foreach (GraphicObject c in Children) {
- if (!c.Visible)
- continue;
- if (c.RegisteredLayoutings.HasFlag (LayoutingType.Height))
- return -1;
- tmp += c.Slot.Height + Spacing;
- }
- tmp -= Spacing;
- }
- break;
- }
- return base.measureRawSize (lt);
- }
-
- return tmp + 2 * Margin;
+ if (lt == LayoutingType.Width) {
+ if (Orientation == Orientation.Horizontal)
+ return contentSize.Width + (Children.Count - 1) * Spacing + 2 * Margin;
+ }else if (Orientation == Orientation.Vertical)
+ return contentSize.Height + (Children.Count - 1) * Spacing + 2 * Margin;
+
+ return base.measureRawSize (lt);
}
public virtual void ComputeChildrenPositions()
{
@@ -99,7 +67,6 @@ namespace Crow
continue;
c.Slot.X = d;
d += c.Slot.Width + Spacing;
- c.RegisterForLayouting (LayoutingType.Y);
}
} else {
foreach (GraphicObject c in Children) {
@@ -107,12 +74,11 @@ namespace Crow
continue;
c.Slot.Y = d;
d += c.Slot.Height + Spacing;
- c.RegisterForLayouting (LayoutingType.X);
}
}
bmp = null;
}
-
+ GraphicObject stretchedGO = null;
public override bool UpdateLayout (LayoutingType layoutType)
{
RegisteredLayoutings &= (~layoutType);
@@ -122,86 +88,6 @@ namespace Crow
//this child will occupy remaining space
//if stack size policy is Fit, no child may have stretch enabled
//in the direction of stacking.
- if (Orientation == Orientation.Horizontal) {
- GraphicObject stretchedGO = null;
- int tmpWidth = Slot.Width;
- int cptChildren = 0;
- for (int i = 0; i < Children.Count; i++) {
- if (!Children [i].Visible)
- continue;
- //requeue Positionning if child is not layouted
- if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width))
- return false;
- cptChildren++;
- if (Children [i].Width == Measure.Stretched) {
- if (!(stretchedGO == null && Width != Measure.Fit)) {
- //change size policy of other stretched children
- Children [i].Width = Measure.Fit;
- return false;
- }
- stretchedGO = Children [i];
- if (i < Children.Count - 1)
- tmpWidth -= Spacing;
- continue;
- }
- tmpWidth -= Children [i].Slot.Width + Spacing;
- }
- if (stretchedGO != null && Width != Measure.Fit) {
- tmpWidth += (Spacing - 2 * Margin);
- if (tmpWidth < MinimumSize.Width)
- tmpWidth = MinimumSize.Width;
- else if (tmpWidth > MaximumSize.Width && MaximumSize.Width > 0)
- tmpWidth = MaximumSize.Width;
- if (stretchedGO.LastSlots.Width != tmpWidth) {
- stretchedGO.Slot.Width = tmpWidth;
- stretchedGO.bmp = null;
- #if DEBUG_LAYOUTING
- Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString());
- #endif
- stretchedGO.OnLayoutChanges (LayoutingType.Width);
- stretchedGO.LastSlots.Width = stretchedGO.Slot.Width;
- }
- }
- } else {
- GraphicObject stretchedGO = null;
- int tmpHeight = Slot.Height;
- int cptChildren = 0;
- for (int i = 0; i < Children.Count; i++) {
- if (!Children [i].Visible)
- continue;
- if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height))
- return false;
- cptChildren++;
- if (Children [i].Height == Measure.Stretched) {
- if (!(stretchedGO == null && Height != Measure.Fit)){
- Children [i].Height = Measure.Fit;
- return false;
- }
- stretchedGO = Children [i];
- if (i < Children.Count - 1)
- tmpHeight -= Spacing;
- continue;
- }
- tmpHeight -= Children[i].Slot.Height + Spacing;
- }
- if (stretchedGO != null && Height != Measure.Fit) {
- tmpHeight += (Spacing - 2 * Margin);
- if (tmpHeight < MinimumSize.Height)
- tmpHeight = MinimumSize.Height;
- else if (tmpHeight > MaximumSize.Height && MaximumSize.Height > 0)
- tmpHeight = MaximumSize.Height;
- if (stretchedGO.LastSlots.Height != tmpHeight) {
- stretchedGO.Slot.Height = tmpHeight;
- stretchedGO.bmp = null;
- #if DEBUG_LAYOUTING
- Debug.WriteLine ("\tAdjusting Height of " + stretchedGO.ToString());
- #endif
- stretchedGO.OnLayoutChanges (LayoutingType.Height);
- stretchedGO.LastSlots.Height = stretchedGO.Slot.Height;
- }
- }
- }
-
ComputeChildrenPositions ();
//if no layouting remains in queue for item, registre for redraw
@@ -216,26 +102,75 @@ namespace Crow
public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
{
- base.OnChildLayoutChanges (sender, arg);
-
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.Horizontal) {
+ if (go.Width == Measure.Stretched) {
+ if (stretchedGO == null && Width != Measure.Fit)
+ stretchedGO = go;
+ else if (stretchedGO != go) {
+ go.Slot.Width = 0;
+ go.Width = Measure.Fit;
+ return;
+ }
+ } else
+ contentSize.Width += go.Slot.Width - go.LastSlots.Width;
+
+ if (stretchedGO != null) {
+ stretchedGO.Slot.Width = this.ClientRectangle.Width - contentSize.Width - Spacing * (Children.Count - 1);
+ stretchedGO.bmp = null;
+#if DEBUG_LAYOUTING
+ Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString());
+#endif
+ stretchedGO.LayoutChanged -= OnChildLayoutChanges;
+ stretchedGO.OnLayoutChanges (LayoutingType.Width);
+ stretchedGO.LayoutChanged += OnChildLayoutChanges;
+ stretchedGO.LastSlots.Width = stretchedGO.Slot.Width;
+ }
+
if (Width == Measure.Fit)
this.RegisterForLayouting (LayoutingType.Width);
+
this.RegisterForLayouting (LayoutingType.ArrangeChildren);
+ return;
}
break;
case LayoutingType.Height:
if (Orientation == Orientation.Vertical) {
+ if (go.Height == Measure.Stretched) {
+ if (stretchedGO == null && Height != Measure.Fit)
+ stretchedGO = go;
+ else if (stretchedGO != go){
+ go.Slot.Height = 0;
+ go.Height = Measure.Fit;
+ return;
+ }
+ } else
+ contentSize.Height += go.Slot.Height - go.LastSlots.Height;
+
+ if (stretchedGO != null) {
+ stretchedGO.Slot.Height = this.ClientRectangle.Height - contentSize.Height - Spacing * (Children.Count -1);
+ stretchedGO.bmp = null;
+#if DEBUG_LAYOUTING
+ Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString());
+#endif
+ stretchedGO.LayoutChanged -= OnChildLayoutChanges;
+ stretchedGO.OnLayoutChanges (LayoutingType.Height);
+ stretchedGO.LayoutChanged += OnChildLayoutChanges;
+ stretchedGO.LastSlots.Height = stretchedGO.Slot.Height;
+ }
+
if (Height == Measure.Fit)
this.RegisterForLayouting (LayoutingType.Height);
+
this.RegisterForLayouting (LayoutingType.ArrangeChildren);
+ return;
}
break;
}
+ base.OnChildLayoutChanges (sender, arg);
}
#endregion