diff options
Diffstat (limited to 'src/GraphicObjects')
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 20 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 47 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 12 | ||||
| -rw-r--r-- | src/GraphicObjects/Label.cs | 7 | ||||
| -rw-r--r-- | src/GraphicObjects/PrivateContainer.cs | 8 | ||||
| -rw-r--r-- | src/GraphicObjects/TextRun.cs | 17 |
6 files changed, 54 insertions, 57 deletions
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 925f908a..455ed928 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -133,10 +133,10 @@ namespace Crow if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width)) return false; cptChildren++; - if (Children [i].Width == 0) { - if (!(stretchedGO == null && Width >= 0)) { + if (Children [i].Width == Measure.Stretched) { + if (!(stretchedGO == null && Width != Measure.Fit)) { //change size policy of other stretched children - Children [i].Width = -1; + Children [i].Width = Measure.Fit; return false; } stretchedGO = Children [i]; @@ -146,7 +146,7 @@ namespace Crow } tmpWidth -= Children [i].Slot.Width + Spacing; } - if (stretchedGO != null && Width >= 0) { + if (stretchedGO != null && Width != Measure.Fit) { tmpWidth += (Spacing - 2 * Margin); if (tmpWidth < MinimumSize.Width) tmpWidth = MinimumSize.Width; @@ -172,9 +172,9 @@ namespace Crow if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height)) return false; cptChildren++; - if (Children [i].Height == 0) { - if (!(stretchedGO == null && Height >= 0)){ - Children [i].Height = -1; + if (Children [i].Height == Measure.Stretched) { + if (!(stretchedGO == null && Height != Measure.Fit)){ + Children [i].Height = Measure.Fit; return false; } stretchedGO = Children [i]; @@ -184,7 +184,7 @@ namespace Crow } tmpHeight -= Children[i].Slot.Height + Spacing; } - if (stretchedGO != null && Height >= 0) { + if (stretchedGO != null && Height != Measure.Fit) { tmpHeight += (Spacing - 2 * Margin); if (tmpHeight < MinimumSize.Height) tmpHeight = MinimumSize.Height; @@ -221,14 +221,14 @@ namespace Crow switch (arg.LayoutType) { case LayoutingType.Width: if (Orientation == Orientation.Horizontal) { - if (Width < 0) + if (Width == Measure.Fit) this.RegisterForLayouting (LayoutingType.Width); this.RegisterForLayouting (LayoutingType.ArrangeChildren); } break; case LayoutingType.Height: if (Orientation == Orientation.Vertical) { - if (Height < 0) + if (Height == Measure.Fit) this.RegisterForLayouting (LayoutingType.Height); this.RegisterForLayouting (LayoutingType.ArrangeChildren); } 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) diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 47795b06..78c5bca3 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -139,7 +139,7 @@ namespace Crow if (largestChild == null){ //if still null, not possible to determine a width //because all children are stretched, force first one to fit - Children[0].Width = -1; + Children[0].Width = Measure.Fit; return -1;//cancel actual sizing to let child computation take place } return maxChildrenWidth + 2 * Margin; @@ -147,7 +147,7 @@ namespace Crow if (tallestChild == null) searchTallestChild (); if (tallestChild == null) { - Children[0].Height = -1; + Children[0].Height = Measure.Fit; return -1; } return maxChildrenHeight + 2 * Margin; @@ -178,14 +178,14 @@ namespace Crow if (g.Slot.Width > maxChildrenWidth) { maxChildrenWidth = g.Slot.Width; largestChild = g; - if (Width < 0) + if (Width == Measure.Fit) this.RegisterForLayouting (LayoutingType.Width); } else if (g == largestChild) { largestChild = null; maxChildrenWidth = 0; - if (Width < 0) + if (Width == Measure.Fit) this.RegisterForLayouting (LayoutingType.Width); } break; @@ -193,14 +193,14 @@ namespace Crow if (g.Slot.Height > maxChildrenHeight) { maxChildrenHeight = g.Slot.Height; tallestChild = g; - if (Height < 0) + if (Height == Measure.Fit) this.RegisterForLayouting (LayoutingType.Height); } else if (g == tallestChild) { tallestChild = null; maxChildrenHeight = 0; - if (Height < 0) + if (Height == Measure.Fit) this.RegisterForLayouting (LayoutingType.Height); } break; diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index c28f090c..0a909b73 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -397,7 +397,8 @@ namespace Crow Rectangle cb = ClientRectangle; //ignore text alignment if size to content = true - if (Width < 0 || Height < 0) + //TODO: split horizontal and vertical logic + if (Width == Measure.Fit || Height == Measure.Fit) { rText.X = cb.X; rText.Y = cb.Y; @@ -406,7 +407,9 @@ namespace Crow widthRatio = (float)cb.Width / rText.Width; if (!verticalStretch) heightRatio = widthRatio; - }if (verticalStretch) { + } + + if (verticalStretch) { heightRatio = (float)cb.Height / rText.Height; if (!horizontalStretch) widthRatio = heightRatio; diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index f3385a88..98e8d4b1 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -108,12 +108,12 @@ namespace Crow //child has stretched size switch (layoutType) { case LayoutingType.Width: - if (Width < 0 && child.Width == 0) - child.Width = -1; + if (Width == Measure.Fit && child.Width.Units == Unit.Percent) + child.Width = Measure.Fit; break; case LayoutingType.Height: - if (Height < 0 && child.Height == 0) - child.Height = -1; + if (Height == Measure.Fit && child.Height.Units == Unit.Percent) + child.Height = Measure.Fit; break; } } diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs index 021d5654..7f50a34e 100644 --- a/src/GraphicObjects/TextRun.cs +++ b/src/GraphicObjects/TextRun.cs @@ -11,6 +11,7 @@ using System.ComponentModel; namespace Crow { [Serializable] + [DefaultStyle("#Crow.Styles.TextRun.style")] public class TextRun : GraphicObject { #region CTOR @@ -127,22 +128,6 @@ namespace Crow } #region GraphicObject overrides - [XmlAttributeAttribute()][DefaultValue(-1)] - public override int Width { - get { return base.Width; } - set { base.Width = value; } - } - [XmlAttributeAttribute()][DefaultValue(-1)] - public override int Height { - get { return base.Height; } - set { base.Height = value; } - } - [XmlAttributeAttribute()][DefaultValue(2)] - public override int Margin { - get { return base.Margin; } - set { base.Margin = value; } - } - protected override int measureRawSize(LayoutingType lt) { if (lines == null) |