diff options
| author | j-p <jp.bruyere@live.be> | 2016-06-21 02:02:52 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-21 02:02:52 +0200 |
| commit | aed3905ffee6e07662290f3cf0787044ed95a360 (patch) | |
| tree | b245fd7f1454f520a58083fdefffac114e40d5ca /src/GraphicObjects/GenericStack.cs | |
| parent | b3c2c1f21e96418d6b3a91ff75a182e84cb5b6a5 (diff) | |
| parent | 4e3802bba7c4d7fa564cec723ff93d5aa2c1a056 (diff) | |
Merge pull request #7 from jpbruyere/dynSizing
Dyn sizing
Diffstat (limited to 'src/GraphicObjects/GenericStack.cs')
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 194 |
1 files changed, 69 insertions, 125 deletions
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 455ed928..adf428c5 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,20 @@ 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); + int totSpace = 0; + for (int i = 0; i < Children.Count; i++) { + if (Children [i].Visible) + totSpace += Spacing; } - - return tmp + 2 * Margin; + if (totSpace > 0) + totSpace -= Spacing; + if (lt == LayoutingType.Width) { + if (Orientation == Orientation.Horizontal) + return contentSize.Width + totSpace + 2 * Margin; + }else if (Orientation == Orientation.Vertical) + return contentSize.Height + totSpace + 2 * Margin; + + return base.measureRawSize (lt); } public virtual void ComputeChildrenPositions() { @@ -99,7 +74,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 +81,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 +95,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,24 +109,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 |