From 7b8ff62e3ee75e19d9eeeabd31bedef371215554 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 27 Apr 2015 14:58:27 +0200 Subject: Layouting queue --- src/GraphicObjects/GenericStack.cs | 103 +++++++++---------------------------- 1 file changed, 24 insertions(+), 79 deletions(-) (limited to 'src/GraphicObjects/GenericStack.cs') diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index a36cd7b1..36d41f99 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -18,7 +18,6 @@ namespace go #endregion #region Private fields - bool childrenArePositionned = false; int _spacing; Orientation _orientation; #endregion @@ -49,49 +48,25 @@ namespace go get { return base.Height; } set { base.Height = value; } } - [XmlIgnore]public override bool LayoutIsValid { - get { return childrenArePositionned && base.LayoutIsValid; } - set { base.LayoutIsValid = value; } - } - public override void InvalidateLayout () - { - childrenArePositionned = false; - base.InvalidateLayout (); - } protected override Size measureRawSize () { - Size raw = Bounds.Size; Size tmp = new Size (); - if (raw.Width >= 0 && raw.Height >= 0) - return raw; - - foreach (GraphicObject c in Children) { - if (raw.Width < 0) { - if (c.WIsValid) { - if (Orientation == Orientation.Horizontal && c.Bounds.Width != 0) - tmp.Width += c.Slot.Width + Spacing; - else - tmp.Width = Math.Max (tmp.Width, c.Slot.Right); - }else - return raw; + if (Orientation == Orientation.Horizontal) { + foreach (GraphicObject c in Children) { + tmp.Width += c.Slot.Width + Spacing; + tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom); } - if (raw.Height < 0) { - if (c.HIsValid) { - if (Orientation == Orientation.Vertical && c.Bounds.Height != 0) - tmp.Height += c.Slot.Height + Spacing; - else - tmp.Height = Math.Max (tmp.Height, c.Slot.Bottom); - }else - return raw; + } else { + foreach (GraphicObject c in Children) { + tmp.Width = Math.Max (tmp.Width, c.Slot.Right); + tmp.Height += c.Slot.Height + Spacing; } } - if (raw.Width < 0) - tmp.Width += 2*Margin; - if (raw.Height < 0) - tmp.Height += 2*Margin; + tmp.Width += 2*Margin; + tmp.Height += 2*Margin; return tmp; } @@ -100,66 +75,36 @@ namespace go int d = 0; if (Orientation == Orientation.Horizontal) { foreach (GraphicObject c in Children) { - if (c.Bounds.Width == 0) - continue; - c.Slot.X = d; - c.XIsValid = true; d += c.Slot.Width + Spacing; } } else { foreach (GraphicObject c in Children) { - if (c.Bounds.Height == 0) - continue; - c.Slot.Y = d; - c.YIsValid = true; d += c.Slot.Height + Spacing; } } - childrenArePositionned = true; } + public override void RegisterForLayouting () + { + base.RegisterForLayouting (); - public override void UpdateLayout() + int idx = Interface.LayoutingQueue.IndexOf (Interface.LayoutingQueue.Where (lq => lq.GraphicObject.Parent == this).LastOrDefault ()); + if (idx < 0) + return; + Interface.LayoutingQueue.Insert ( + idx+1, + new LayoutingQueueItem (LayoutingType.PositionChildren, this)); + } + public override void UpdateLayout (LayoutingType layoutType) { - base.UpdateLayout(); - - ComputeChildrenPositions (); + if (layoutType == LayoutingType.PositionChildren) + ComputeChildrenPositions (); - if (LayoutIsValid) - registerForRedraw(); + base.UpdateLayout(layoutType); } #endregion - // -// bool enoughtSpaceForWidget(GraphicObject w) -// { -// if (!SizeToContent) -// { -// int nextXForWidget = 0; -// int nextYForWidget = 0; -// -// if (Orientation == Orientation.Horizontal) -// nextXForWidget = currentXForWidget + w.Slot.Width; -// else -// nextYForWidget = nextYForWidget + w.Slot.Height; -// -// -// if (nextXForWidget > ClientRectangle.Right ) -// return false; -// if (currentYForWidget > ClientRectangle.Bottom ) -// return false; -// } -// return true; -// } -// void advance(GraphicObject w) -// { -// if (Orientation == Orientation.Horizontal) -// currentXForWidget = currentXForWidget + WidgetSpacing + w.Slot.Width; -// else -// currentYForWidget = currentYForWidget + WidgetSpacing + w.Slot.Height; -// -// } } } -- cgit v1.3.1-4-g156e