From a7363d1f7e4eb1611e4ab522c8cf381b70570b7e Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Wed, 3 Jun 2015 17:05:51 +0200 Subject: [PATCH] - min and max dimensions for objects --- GOLib.csproj | 1 + Templates/ComboListOverlay.goml | 6 +++++ Templates/Listbox.goml | 5 ++-- Tests/GOLIBTest_Listbox.cs | 8 +++++- Tests/Interfaces/test_Listbox.goml | 4 +-- src/GraphicObjects/GraphicObject.cs | 32 +++++++++++++++++++++++- src/Size.cs | 38 +++++++++++++++++++++++------ 7 files changed, 79 insertions(+), 15 deletions(-) create mode 100755 Templates/ComboListOverlay.goml diff --git a/GOLib.csproj b/GOLib.csproj index a89eeb50..c281a642 100644 --- a/GOLib.csproj +++ b/GOLib.csproj @@ -346,5 +346,6 @@ + diff --git a/Templates/ComboListOverlay.goml b/Templates/ComboListOverlay.goml new file mode 100755 index 00000000..65bac62b --- /dev/null +++ b/Templates/ComboListOverlay.goml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Templates/Listbox.goml b/Templates/Listbox.goml index 43f8425b..4a661db0 100755 --- a/Templates/Listbox.goml +++ b/Templates/Listbox.goml @@ -1,5 +1,4 @@  - - - + + \ No newline at end of file diff --git a/Tests/GOLIBTest_Listbox.cs b/Tests/GOLIBTest_Listbox.cs index 624bc2c7..815acfd2 100644 --- a/Tests/GOLIBTest_Listbox.cs +++ b/Tests/GOLIBTest_Listbox.cs @@ -66,7 +66,13 @@ namespace test { "string 1", "string 2", - "string 3" +// "string 3", +// "string 4", +// "string 5", +// "string 6", +// "string 7", +// "string 8", + "string 9" }); // string[] TestList = new string[] // { diff --git a/Tests/Interfaces/test_Listbox.goml b/Tests/Interfaces/test_Listbox.goml index d336ae3c..2263793a 100755 --- a/Tests/Interfaces/test_Listbox.goml +++ b/Tests/Interfaces/test_Listbox.goml @@ -1,3 +1,3 @@  - - + + diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 72fccfba..0a402f12 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -47,6 +47,8 @@ namespace go protected bool _isVisible = true; VerticalAlignment _verticalAlignment; HorizontalAlignment _horizontalAlignment; + Size _maximumSize; + Size _minimumSize; Picture _backgroundImage; string _template; @@ -264,7 +266,18 @@ namespace go registerForGraphicUpdate (); } } + [XmlAttributeAttribute()][DefaultValue("0;0")] + public Size MaximumSize { + get { return _maximumSize; } + set { _maximumSize = value; } + } + [XmlAttributeAttribute()][DefaultValue("0;0")] + public Size MinimumSize { + get { return _minimumSize; } + set { _minimumSize = value; } + } #endregion + public string BackImgSub = null; /// @@ -307,6 +320,8 @@ namespace go pi.SetValue (this, Font.Parse ((string)dv.Value), null); else if (pi.PropertyType == typeof(Picture)) pi.SetValue (this, Picture.Parse ((string)dv.Value), null); + else if (pi.PropertyType == typeof(Size)) + pi.SetValue (this, Size.Parse ((string)dv.Value), null); else pi.SetValue (this, dv.Value, null); continue; @@ -354,7 +369,7 @@ namespace go TopContainer.redrawClip.AddRectangle (ScreenCoordinates(Slot)); } protected virtual Size measureRawSize () - { + { return Bounds.Size; } @@ -489,6 +504,12 @@ namespace go else Slot.Width = Parent.ClientRectangle.Width; + //size constrain + if (Slot.Width < MinimumSize.Width) + Slot.Width = MinimumSize.Width; + else if (Slot.Width > MaximumSize.Width && MaximumSize.Width > 0) + Slot.Width = MaximumSize.Width; + if (LastSlots.Width == Slot.Width) break; @@ -506,6 +527,13 @@ namespace go else Slot.Height = Parent.ClientRectangle.Height; + //size constrain + if (Slot.Height < MinimumSize.Height) + Slot.Height = MinimumSize.Height; + else if (Slot.Height > MaximumSize.Height && MaximumSize.Height > 0) + Slot.Height = MaximumSize.Height; + + if (LastSlots.Height == Slot.Height) break; @@ -728,6 +756,8 @@ namespace go pi.SetValue (this, Font.Parse ((string)defaultValue), null); else if (pi.PropertyType == typeof(Picture)) pi.SetValue (this, Picture.Parse ((string)defaultValue), null); + else if (pi.PropertyType == typeof(Size)) + pi.SetValue (this, Size.Parse ((string)defaultValue), null); else pi.SetValue (this, defaultValue, null); } else { diff --git a/src/Size.cs b/src/Size.cs index 72f8fff1..c2231576 100755 --- a/src/Size.cs +++ b/src/Size.cs @@ -9,16 +9,20 @@ namespace go { public static Size Zero { get { return new Size(0, 0); } } + int _width; int _height; - //public Size() - //{ } public Size(int width, int height) { _width = width; _height = height; } + public Size(int size) + { + _width = size; + _height = size; + } public int Width { get { return _width; } @@ -29,10 +33,7 @@ namespace go get { return _height; } set { _height = value; } } - public override string ToString() - { - return string.Format("({0},{1})", Width, Height); - } + #region operators public static implicit operator Rectangle(Size s) { return new Rectangle (s); @@ -41,7 +42,15 @@ namespace go { return new Size(i, i); } - public static bool operator ==(Size s1, Size s2) + public static implicit operator string(Size s) + { + return s.ToString (); + } + public static implicit operator Size(string s) + { + return string.IsNullOrEmpty (s) ? Size.Zero : Parse (s); + } + public static bool operator ==(Size s1, Size s2) { if (s1.Width == s2.Width && s1.Height == s2.Height) return true; @@ -118,6 +127,19 @@ namespace go { return new Size(s.Width + i, s.Height + i); } - } + #endregion + + public override string ToString() + { + return string.Format("{0},{1}", Width, Height); + } + public static Size Parse(string s) + { + string[] d = s.Split(new char[] { ';' }); + return d.Length == 1 ? new Size(int.Parse(d[0])) : new Size( + int.Parse(d[0]), + int.Parse(d[1])); + } + } } -- 2.47.3