aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-06-07 11:42:04 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-06-07 11:42:05 +0200
commit18e9dca6ea12f3f01a28c08f4b596268d0322a4f (patch)
treee59d9d645b0cc09eca7e656ad790fde3a0f1ae7f
parentd54616114dc1a3a3ca269e067c62fda2cde70202 (diff)
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.
-rwxr-xr-xTemplates/Spinner.goml6
-rwxr-xr-xTests/Interfaces/testSpinner.goml2
-rw-r--r--src/GraphicObjects/GenericStack.cs47
3 files changed, 49 insertions, 6 deletions
diff --git a/Templates/Spinner.goml b/Templates/Spinner.goml
index 8f61f0b1..c537f977 100755
--- a/Templates/Spinner.goml
+++ b/Templates/Spinner.goml
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
-<Border CornerRadius="0" Margin="0" BorderWidth="1" Fit="True">
- <HorizontalStack Name="hstack" Margin="0" Spacing="5">
- <Label Width="30" Name="labCpt" Text="55" Margin="1" TextAlignment="RightCenter"/>
+<Border CornerRadius="0" Margin="0" BorderWidth="1" Width="0" Height="-1">
+ <HorizontalStack Name="hstack" Margin="0" Spacing="5" Width="0" Height="-1">
+ <Label Width="0" Name="labCpt" Text="55" Margin="1" TextAlignment="RightCenter"/>
<VerticalStack Spacing="1" Name="vstack">
<Button Width="10" Height="8" MouseClick="onUp">
<Image Margin="1" Path="#go.Images.Icons.updown.svg" SvgSub="up"/>
diff --git a/Tests/Interfaces/testSpinner.goml b/Tests/Interfaces/testSpinner.goml
index 12a72991..9767d546 100755
--- a/Tests/Interfaces/testSpinner.goml
+++ b/Tests/Interfaces/testSpinner.goml
@@ -2,5 +2,5 @@
<Container Name="TopContainer" Width="400" Height="350"
Margin="20" Focusable="True" Background="DarkGray">
- <Spinner Width="50"></Spinner>
+ <Spinner Width="100"></Spinner>
</Container> \ No newline at end of file
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