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.cs173
1 files changed, 120 insertions, 53 deletions
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs
index 92e944bb..d2338362 100644
--- a/src/GraphicObjects/GenericStack.cs
+++ b/src/GraphicObjects/GenericStack.cs
@@ -31,13 +31,13 @@ namespace Crow
public override T addChild<T> (T child)
{
T tmp = base.addChild (child);
- this.RegisterForLayouting ((int)LayoutingType.PositionChildren);
+ this.RegisterForLayouting (LayoutingType.PositionChildren);
return tmp;
}
public override void removeChild (GraphicObject child)
{
base.removeChild (child);
- this.RegisterForLayouting ((int)LayoutingType.PositionChildren);
+ this.RegisterForLayouting (LayoutingType.PositionChildren);
}
#region Public Properties
@@ -66,14 +66,18 @@ namespace Crow
Size tmp = new Size ();
if (Orientation == Orientation.Horizontal) {
- foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) {
+ foreach (GraphicObject c in Children) {
+ if (!c.Visible)
+ continue;
tmp.Width += c.Slot.Width + Spacing;
tmp.Height = Math.Max (tmp.Height, Math.Max(c.Slot.Bottom, c.Slot.Height));
}
if (tmp.Width > 0)
tmp.Width -= Spacing;
} else {
- foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) {
+ foreach (GraphicObject c in Children) {
+ if (!c.Visible)
+ continue;
tmp.Width = Math.Max (tmp.Width, Math.Max(c.Slot.Right, c.Slot.Width));
tmp.Height += c.Slot.Height + Spacing;
}
@@ -93,84 +97,147 @@ namespace Crow
#endif
int d = 0;
if (Orientation == Orientation.Horizontal) {
- foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) {
+ foreach (GraphicObject c in Children) {
+ if (!c.Visible)
+ continue;
c.Slot.X = d;
d += c.Slot.Width + Spacing;
- c.RegisterForLayouting ((int)LayoutingType.Y);
+ c.RegisterForLayouting (LayoutingType.Y);
}
} else {
- foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) {
+ foreach (GraphicObject c in Children) {
+ if (!c.Visible)
+ continue;
c.Slot.Y = d;
d += c.Slot.Height + Spacing;
- c.RegisterForLayouting ((int)LayoutingType.X);
+ c.RegisterForLayouting (LayoutingType.X);
}
}
+ bmp = null;
}
+
+ public override bool UpdateLayout (LayoutingType layoutType)
+ {
+ RegisteredLayoutings &= (~layoutType);
- public override void RegisterForLayouting (int layoutType)
- {
- if (Parent == null)
- return;
+ LayoutingType childSizeToCheck;
+ if (Orientation == Orientation.Horizontal)
+ childSizeToCheck = LayoutingType.Width;
+ else
+ childSizeToCheck = LayoutingType.Height;
- base.RegisterForLayouting (layoutType);
+ foreach (GraphicObject g in Children) {
+ if (!g.Visible)
+ continue;
+ if (g.RegisteredLayoutings.HasFlag (childSizeToCheck))
+ return false;
+ }
- if ((layoutType & (int)LayoutingType.PositionChildren) > 0)
- Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this);
-
- }
- public override void UpdateLayout (LayoutingType layoutType)
- {
if (layoutType == LayoutingType.PositionChildren) {
//allow 1 child to have size to 0 if stack has fixed or streched size,
//this child will occupy remaining space
if (Orientation == Orientation.Horizontal) {
if (Width >= 0) {
- GraphicObject[] gobjs = Children.Where (c => c.Width == 0 && c.Visible).ToArray();
- if (gobjs.Length > 1)
- throw new Exception ("Only one child in stack may have size to stretched");
- else if (gobjs.Length == 1) {
- int sz = Children.Where(ch=>ch.Visible).Except (gobjs).Sum (g => g.Slot.Width);
- if (sz < Slot.Width) {
- gobjs [0].Slot.Width = Slot.Width - sz - (Children.Count-1) * Spacing - 2 * Margin;
- int idx = Children.IndexOf (gobjs [0]);
- if (idx > 0 && idx < Children.Count - 1)
- gobjs [0].Slot.Width -= Spacing;
- if (gobjs [0].LastSlots.Width != gobjs [0].Slot.Width) {
- gobjs [0].bmp = null;
- gobjs [0].OnLayoutChanges (LayoutingType.Width);
- gobjs [0].LastSlots.Width = gobjs [0].Slot.Width;
- }
+ GraphicObject stretchedGO = null;
+ int tmpWidth = Slot.Width;
+ int cptChildren = 0;
+ for (int i = 0; i < Children.Count; i++) {
+ if (!Children [i].Visible)
+ continue;
+ cptChildren++;
+ if (Children [i].Width == 0) {
+ if (stretchedGO != null)
+ throw new Exception ("Only one child in stack may have size to stretched");
+ stretchedGO = Children [i];
+ if (i < Children.Count - 1)
+ tmpWidth -= Spacing;
+ continue;
+ }
+ tmpWidth -= Children[i].Slot.Width + Spacing;
+ }
+ if (stretchedGO != null) {
+ 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;
+ stretchedGO.OnLayoutChanges (LayoutingType.Width);
+ stretchedGO.LastSlots.Width = stretchedGO.Slot.Width;
}
}
}
} else {
if (Height >= 0) {
- GraphicObject[] gobjs = Children.Where(ch=>ch.Visible).Where (c => c.Height == 0).ToArray();
- if (gobjs.Length > 1)
- throw new Exception ("Only one child in stack may have size to stretched");
- else if (gobjs.Length == 1) {
- int sz = Children.Where(ch=>ch.Visible).Except (gobjs).Sum (g => g.Slot.Height);
- if (sz < Slot.Height) {
- gobjs [0].Slot.Height = Slot.Height - sz- (Children.Count-1) * Spacing - 2 * Margin;
- int idx = Children.IndexOf (gobjs [0]);
- if (idx > 0 && idx < Children.Count - 1)
- gobjs [0].Slot.Height -= Spacing;
- if (gobjs [0].LastSlots.Height != gobjs [0].Slot.Height) {
- gobjs [0].bmp = null;
- gobjs [0].OnLayoutChanges (LayoutingType.Height);
- gobjs [0].LastSlots.Height = gobjs [0].Slot.Height;
- }
+ GraphicObject stretchedGO = null;
+ int tmpHeight = Slot.Height;
+ int cptChildren = 0;
+ for (int i = 0; i < Children.Count; i++) {
+ if (!Children [i].Visible)
+ continue;
+ cptChildren++;
+ if (Children [i].Height == 0) {
+ if (stretchedGO != null)
+ throw new Exception ("Only one child in stack may have size to stretched");
+ stretchedGO = Children [i];
+ if (i < Children.Count - 1)
+ tmpHeight -= Spacing;
+ continue;
+ }
+ tmpHeight -= Children[i].Slot.Height + Spacing;
+ }
+ if (stretchedGO != null) {
+ 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;
+ stretchedGO.OnLayoutChanges (LayoutingType.Height);
+ stretchedGO.LastSlots.Height = stretchedGO.Slot.Height;
}
}
}
- }
+ }
+
ComputeChildrenPositions ();
+
//if no layouting remains in queue for item, registre for redraw
- if (RegisteredLQINodes.Count () <= 0 && bmp==null)
+ if (RegisteredLayoutings == LayoutingType.None && bmp==null)
this.RegisterForRedraw ();
- }else
- base.UpdateLayout(layoutType);
+
+ return true;
+ }
+
+ return base.UpdateLayout(layoutType);
}
+
+ public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
+ {
+ base.OnChildLayoutChanges (sender, arg);
+
+ GraphicObject g = sender as GraphicObject;
+ switch (arg.LayoutType) {
+ case LayoutingType.Width:
+ if (Orientation == Orientation.Horizontal) {
+ if (this.Bounds.Width < 0)
+ this.RegisterForLayouting (LayoutingType.Width);
+ this.RegisterForLayouting (LayoutingType.PositionChildren);
+ }
+ break;
+ case LayoutingType.Height:
+ if (Orientation == Orientation.Vertical) {
+ if (this.Bounds.Height < 0)
+ this.RegisterForLayouting (LayoutingType.Height);
+ this.RegisterForLayouting (LayoutingType.PositionChildren);
+ }
+ break;
+ }
+ }
#endregion