From 18e9dca6ea12f3f01a28c08f4b596268d0322a4f Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sun, 7 Jun 2015 11:42:04 +0200 Subject: Allow on child in stack to have streatching size, to occupy remaining space if stack size is fixed or stretched. Usefull in the case of spinner for example. --- src/GraphicObjects/GenericStack.cs | 47 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'src/GraphicObjects/GenericStack.cs') diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 5759bac4..63a70ad3 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -110,12 +110,55 @@ namespace go if ((layoutType & (int)LayoutingType.PositionChildren) > 0) Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this); + } public override void UpdateLayout (LayoutingType layoutType) { - if (layoutType == LayoutingType.PositionChildren) + 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).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.Except (gobjs).Sum (g => g.Slot.Width); + if (sz < Slot.Width) { + gobjs [0].Slot.Width = Slot.Width - sz - Spacing; + 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].LastSlots.Width = gobjs [0].Slot.Width; + } + } + } + } + } else { + if (Height >= 0) { + GraphicObject[] gobjs = Children.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.Except (gobjs).Sum (g => g.Slot.Height); + if (sz < Slot.Height) { + gobjs [0].Slot.Height = Slot.Height - sz; + 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].LastSlots.Height = gobjs [0].Slot.Height; + } + } + } + } + } ComputeChildrenPositions (); - else + }else base.UpdateLayout(layoutType); } #endregion -- cgit v1.3.1-4-g156e