aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects/GraphicObject.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-04-14 09:36:03 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2016-04-14 12:47:15 +0200
commit7ff5f14fe6b875dff57b335c4eeeb42397a07c91 (patch)
tree23f80be40c98b4d142894a607c8dd2f43112b523 /src/GraphicObjects/GraphicObject.cs
parent0b005fefe69b67bf335c3c00944bbac73e8b4831 (diff)
proportional ui
Diffstat (limited to 'src/GraphicObjects/GraphicObject.cs')
-rw-r--r--src/GraphicObjects/GraphicObject.cs47
1 files changed, 28 insertions, 19 deletions
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index 7b58f652..8877c6b2 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -95,7 +95,8 @@ namespace Crow
/// <summary>
/// Original size and position 0=Stretched; -1=Fit
/// </summary>
- int _width, _height, _left, _top;
+ Measure _width, _height;
+ int _left, _top;
/// <summary>
/// Current size and position computed during layouting pass
/// </summary>
@@ -239,8 +240,8 @@ namespace Crow
this.RegisterForLayouting (LayoutingType.Y);
}
}
- [XmlAttributeAttribute()][DefaultValue(0)]
- public virtual int Width {
+ [XmlAttributeAttribute()][DefaultValue("Stretched")]
+ public virtual Measure Width {
get { return _width; }
set {
if (_width == value)
@@ -253,8 +254,8 @@ namespace Crow
this.RegisterForLayouting (LayoutingType.Width);
}
}
- [XmlAttributeAttribute()][DefaultValue(0)]
- public virtual int Height {
+ [XmlAttributeAttribute()][DefaultValue("Stretched")]
+ public virtual Measure Height {
get { return _height; }
set {
if (_height == value)
@@ -267,17 +268,21 @@ namespace Crow
this.RegisterForLayouting (LayoutingType.Height);
}
}
- [XmlIgnore]public virtual int WidthPolicy { get { return Width < 1 ? Width : 0; } }
- [XmlIgnore]public virtual int HeightPolicy { get { return Height < 1 ? Height : 0; } }
+ [XmlIgnore]public virtual Measure WidthPolicy { get {
+ return Width.Units == Unit.Percent || Width.IsFixed ?
+ Measure.Stretched : Measure.Fit; } }
+ [XmlIgnore]public virtual Measure HeightPolicy { get {
+ return Height.Units == Unit.Percent || Height.IsFixed ?
+ Measure.Stretched : Measure.Fit; } }
[XmlAttributeAttribute()][DefaultValue(false)]
public virtual bool Fit {
- get { return Width < 0 && Height < 0 ? true : false; }
+ get { return Width == Measure.Fit && Height == Measure.Fit ? true : false; }
set {
if (value == Fit)
return;
- Width = Height = -1;
+ Width = Height = Measure.Fit;
}
}
[XmlAttributeAttribute()][DefaultValue(false)]
@@ -800,22 +805,24 @@ namespace Crow
LastSlots.Y = Slot.Y;
break;
case LayoutingType.Width:
- if (Width > 0)
+ if (Width.IsFixed)
Slot.Width = Width;
- else if (Width < 0) {
+ else if (Width == Measure.Fit) {
Slot.Width = measureRawSize (LayoutingType.Width);
} else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width))
return false;
- else
+ else if (Width == Measure.Stretched)
Slot.Width = Parent.ClientRectangle.Width;
+ else
+ Slot.Width = Parent.ClientRectangle.Width * Width / 100;
//size constrain
if (Slot.Width < MinimumSize.Width) {
Slot.Width = MinimumSize.Width;
- NotifyValueChanged ("WidthPolicy", 0);
+ NotifyValueChanged ("WidthPolicy", Measure.Stretched);
} else if (Slot.Width > MaximumSize.Width && MaximumSize.Width > 0) {
Slot.Width = MaximumSize.Width;
- NotifyValueChanged ("WidthPolicy", 0);
+ NotifyValueChanged ("WidthPolicy", Measure.Stretched);
}
if (LastSlots.Width == Slot.Width)
@@ -828,22 +835,24 @@ namespace Crow
LastSlots.Width = Slot.Width;
break;
case LayoutingType.Height:
- if (Height > 0)
+ if (Height.IsFixed)
Slot.Height = Height;
- else if (Height < 0) {
+ else if (Height == Measure.Fit) {
Slot.Height = measureRawSize (LayoutingType.Height);
} else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height))
return false;
- else
+ else if (Height == Measure.Stretched)
Slot.Height = Parent.ClientRectangle.Height;
+ else
+ Slot.Height = Parent.ClientRectangle.Height * Height.Value / 100;
//size constrain
if (Slot.Height < MinimumSize.Height) {
Slot.Height = MinimumSize.Height;
- NotifyValueChanged ("HeightPolicy", 0);
+ NotifyValueChanged ("HeightPolicy", Measure.Stretched);
} else if (Slot.Height > MaximumSize.Height && MaximumSize.Height > 0) {
Slot.Height = MaximumSize.Height;
- NotifyValueChanged ("HeightPolicy", 0);
+ NotifyValueChanged ("HeightPolicy", Measure.Stretched);
}
if (LastSlots.Height == Slot.Height)