aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-02-17 00:53:59 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2016-02-17 00:53:59 +0100
commita8a5562df0358b314197f3685fc7622ecfd307d0 (patch)
tree02cdd70b6b0f999dd2a2eab7bf8018da03ffdd9f /src
parent61d1d07d37a5cc9d6ae1c4fcc333ec8ae644aca3 (diff)
splitted measure with fault checking, changing default template sizing to 0, lots of bugs.
Diffstat (limited to 'src')
-rw-r--r--src/GraphicObjects/Border.cs5
-rw-r--r--src/GraphicObjects/DummyTemplate.cs33
-rw-r--r--src/GraphicObjects/GenericStack.cs57
-rw-r--r--src/GraphicObjects/GraphicObject.cs32
-rw-r--r--src/GraphicObjects/Group.cs29
-rw-r--r--src/GraphicObjects/Image.cs9
-rw-r--r--src/GraphicObjects/Label.cs31
-rw-r--r--src/GraphicObjects/PrivateContainer.cs13
-rw-r--r--src/GraphicObjects/TemplatedControl.cs61
-rw-r--r--src/GraphicObjects/TextRun.cs39
10 files changed, 202 insertions, 107 deletions
diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs
index 7011690e..be08a7d8 100644
--- a/src/GraphicObjects/Border.cs
+++ b/src/GraphicObjects/Border.cs
@@ -40,9 +40,10 @@ namespace Crow
}
}
- protected override Size measureRawSize ()
+ protected override int measureRawSize (LayoutingType lt)
{
- return child == null ? Bounds.Size : child.Slot.Size + 2 * (Margin + BorderWidth);
+ int tmp = base.measureRawSize (lt);
+ return tmp < 0 ? tmp : tmp + 2 * BorderWidth;
}
protected override void onDraw (Cairo.Context gr)
{
diff --git a/src/GraphicObjects/DummyTemplate.cs b/src/GraphicObjects/DummyTemplate.cs
new file mode 100644
index 00000000..68597d18
--- /dev/null
+++ b/src/GraphicObjects/DummyTemplate.cs
@@ -0,0 +1,33 @@
+//
+// DummyTemplate.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// Copyright (c) 2016 jp
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+using System;
+
+namespace Crow
+{
+ [DefaultTemplate("#Crow.Templates.Dummy.goml")]
+ public class DummyTemplate : TemplatedControl
+ {
+ public DummyTemplate () : base()
+ {
+ }
+ }
+}
+
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs
index bbbc52ec..2a1da6c3 100644
--- a/src/GraphicObjects/GenericStack.cs
+++ b/src/GraphicObjects/GenericStack.cs
@@ -52,34 +52,43 @@ namespace Crow
else
layoutType &= (~LayoutingType.Y);
}
- protected override Size measureRawSize ()
+ protected override int measureRawSize (LayoutingType lt)
{
- Size tmp = new Size ();
-
- if (Orientation == Orientation.Horizontal) {
- foreach (GraphicObject c in Children) {
- if (!c.Visible)
- continue;
- tmp.Width += c.Slot.Width + Spacing;
- tmp.Height = Math.Max (tmp.Height, Math.Max(c.Slot.Bottom, c.Slot.Height));
- }
- if (tmp.Width > 0)
- tmp.Width -= Spacing;
- } else {
- foreach (GraphicObject c in Children) {
- if (!c.Visible)
- continue;
- tmp.Width = Math.Max (tmp.Width, Math.Max(c.Slot.Right, c.Slot.Width));
- tmp.Height += c.Slot.Height + Spacing;
+ int tmp = 0;
+ switch (lt) {
+ case LayoutingType.Width:
+ if (Orientation == Orientation.Horizontal) {
+ if (Children.Count > 0) {
+ foreach (GraphicObject c in Children) {
+ if (!c.Visible)
+ continue;
+ if (c.RegisteredLayoutings.HasFlag (LayoutingType.Width))
+ return -1;
+ tmp += c.Slot.Width + Spacing;
+ }
+ tmp -= Spacing;
+ }
+ break;
+ }
+ return base.measureRawSize (lt);
+ case LayoutingType.Height:
+ if (Orientation == Orientation.Vertical) {
+ if (Children.Count > 0) {
+ foreach (GraphicObject c in Children) {
+ if (!c.Visible)
+ continue;
+ if (c.RegisteredLayoutings.HasFlag (LayoutingType.Height))
+ return -1;
+ tmp += c.Slot.Height + Spacing;
+ }
+ tmp -= Spacing;
+ }
+ break;
}
- if (tmp.Height > 0)
- tmp.Height -= Spacing;
+ return base.measureRawSize (lt);
}
- tmp.Width += 2 * Margin;
- tmp.Height += 2 * Margin;
-
- return tmp;
+ return tmp + 2 * Margin;
}
public virtual void ComputeChildrenPositions()
{
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index f10f2244..9f20fca9 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -262,12 +262,12 @@ namespace Crow
[XmlAttributeAttribute()][DefaultValue(false)]
public virtual bool Fit {
- get { return Bounds.Width < 0 && Bounds.Height < 0 ? true : false; }
+ get { return Width < 0 && Height < 0 ? true : false; }
set {
if (value == Fit)
return;
- Bounds.Width = Bounds.Height = -1;
+ Width = Height = -1;
}
}
[XmlAttributeAttribute()][DefaultValue(false)]
@@ -626,8 +626,8 @@ namespace Crow
set { layoutingTries = value; }
}
/// <summary> return size of content + margins </summary>
- protected virtual Size measureRawSize () {
- return Bounds.Size;
+ protected virtual int measureRawSize (LayoutingType lt) {
+ return lt == LayoutingType.Width ? Bounds.Size.Width : Bounds.Size.Height;
}
/// <summary> By default in groups, LayoutingType.ArrangeChildren is reset </summary>
public virtual void ChildrenLayoutingConstraints(ref LayoutingType layoutType){
@@ -704,7 +704,8 @@ namespace Crow
case LayoutingType.X:
if (Bounds.X == 0) {
- if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width))
+ if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width) ||
+ RegisteredLayoutings.HasFlag (LayoutingType.Width))
return false;
switch (HorizontalAlignment) {
@@ -733,7 +734,8 @@ namespace Crow
case LayoutingType.Y:
if (Bounds.Y == 0) {
- if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height))
+ if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height) ||
+ RegisteredLayoutings.HasFlag (LayoutingType.Height))
return false;
switch (VerticalAlignment) {
@@ -762,9 +764,12 @@ namespace Crow
case LayoutingType.Width:
if (Width > 0)
Slot.Width = Width;
- else if (Width < 0)
- Slot.Width = measureRawSize ().Width;
- else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width))
+ else if (Width < 0) {
+ int tmp = measureRawSize (LayoutingType.Width);
+ if (tmp < 0)
+ return false;
+ Slot.Width = tmp;
+ }else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width))
return false;
else
Slot.Width = Parent.ClientRectangle.Width;
@@ -787,9 +792,12 @@ namespace Crow
case LayoutingType.Height:
if (Height > 0)
Slot.Height = Height;
- else if (Height < 0)
- Slot.Height = measureRawSize ().Height;
- else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height))
+ else if (Height < 0){
+ int tmp = measureRawSize (LayoutingType.Height);
+ if (tmp < 0)
+ return false;
+ Slot.Height = tmp;
+ }else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height))
return false;
else
Slot.Height = Parent.ClientRectangle.Height;
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs
index ba65ba0c..2a960029 100644
--- a/src/GraphicObjects/Group.cs
+++ b/src/GraphicObjects/Group.cs
@@ -125,9 +125,21 @@ namespace Crow
}
return false;
}
- protected override Size measureRawSize ()
+ protected override int measureRawSize (LayoutingType lt)
{
- return new Size(maxChildrenWidth + 2 * Margin, maxChildrenHeight + 2 * Margin);
+ if (lt == LayoutingType.Width) {
+ if (largestChild == null)
+ searchLargestChild ();
+ if (largestChild == null)//if still null, not possible to determine a width
+ return -1;
+ return maxChildrenWidth + 2 * Margin;
+ }else{
+ if (tallestChild == null)
+ searchTallestChild ();
+ if (tallestChild == null)
+ return -1;
+ return maxChildrenHeight + 2 * Margin;
+ }
}
public override void OnLayoutChanges (LayoutingType layoutType)
@@ -162,8 +174,9 @@ namespace Crow
if (this.Bounds.Width < 0)
this.RegisterForLayouting (LayoutingType.Width);
} else if (g == largestChild) {
-
- searchLargestChild ();
+
+ largestChild = null;
+ maxChildrenWidth = 0;
if (this.Bounds.Width < 0)
this.RegisterForLayouting (LayoutingType.Width);
@@ -177,7 +190,8 @@ namespace Crow
this.RegisterForLayouting (LayoutingType.Height);
} else if (g == tallestChild) {
- searchTallestChild ();
+ tallestChild = null;
+ maxChildrenHeight = 0;
if (this.Bounds.Height < 0)
this.RegisterForLayouting (LayoutingType.Height);
@@ -186,6 +200,7 @@ namespace Crow
}
}
+ //TODO: x,y position should be taken in account for computation of width and height
void resetChildrenMaxSize(){
largestChild = null;
tallestChild = null;
@@ -198,6 +213,8 @@ namespace Crow
for (int i = 0; i < Children.Count; i++) {
if (!Children [i].Visible)
continue;
+ if (children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width))
+ continue;
if (Children [i].Slot.Width > maxChildrenWidth) {
maxChildrenWidth = Children [i].Slot.Width;
largestChild = Children [i];
@@ -210,6 +227,8 @@ namespace Crow
for (int i = 0; i < Children.Count; i++) {
if (!Children [i].Visible)
continue;
+ if (children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height))
+ continue;
if (Children [i].Slot.Height > maxChildrenHeight) {
maxChildrenHeight = Children [i].Slot.Height;
tallestChild = Children [i];
diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs
index bd6a57c9..6755653e 100644
--- a/src/GraphicObjects/Image.cs
+++ b/src/GraphicObjects/Image.cs
@@ -94,12 +94,15 @@ namespace Crow
#endregion
#region GraphicObject overrides
- protected override Size measureRawSize ()
+ protected override int measureRawSize (LayoutingType lt)
{
if (_pic == null)
_pic = "#Crow.Images.Icons.IconAlerte.svg";
-
- return _pic.Dimensions + Margin * 2;
+ //TODO:take scalling in account
+ if (lt == LayoutingType.Width)
+ return _pic.Dimensions.Width + 2 * Margin;
+ else
+ return _pic.Dimensions.Height + 2 * Margin;
}
protected override void onDraw (Context gr)
{
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs
index 4c7e7006..dd5b89e2 100644
--- a/src/GraphicObjects/Label.cs
+++ b/src/GraphicObjects/Label.cs
@@ -319,13 +319,11 @@ namespace Crow
set { base.Height = value; }
}
- protected override Size measureRawSize()
- {
- Size size;
-
+ protected override int measureRawSize(LayoutingType lt)
+ {
if (lines == null)
lines = getLines;
-
+
using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) {
using (Context gr = new Context (img)) {
//Cairo.FontFace cf = gr.GetContextFontFace ();
@@ -333,8 +331,19 @@ namespace Crow
gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
gr.SetFontSize (Font.Size);
+
+ fe = gr.FontExtents;
te = new TextExtents();
+ if (lt == LayoutingType.Height){
+ int lc = lines.Count;
+ //ensure minimal height = text line height
+ if (lc == 0)
+ lc = 1;
+
+ return (int)(fe.Height * lc) + Margin * 2;
+ }
+
foreach (string s in lines) {
string l = s.Replace("\t", new String (' ', Interface.TabSize));
@@ -346,16 +355,9 @@ namespace Crow
if (tmp.XAdvance > te.XAdvance)
te = tmp;
}
- fe = gr.FontExtents;
- int lc = lines.Count;
- //ensure minimal height = text line height
- if (lc == 0)
- lc = 1;
- size = new Size ((int)Math.Ceiling (te.XAdvance) + Margin * 2, (int)(fe.Height * lc) + Margin*2);
+ return (int)Math.Ceiling (te.XAdvance) + Margin * 2;
}
}
-
- return size;;
}
protected override void onDraw (Context gr)
{
@@ -368,7 +370,8 @@ namespace Crow
//gr.FontOptions.Antialias = Antialias.Subpixel;
//gr.FontOptions.HintMetrics = HintMetrics.On;
- rText = new Rectangle(measureRawSize());
+ rText = new Rectangle(
+ measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height));
rText.Width -= 2 * Margin;
rText.Height -= 2 * Margin;
diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs
index f3c9f43d..640e8d0b 100644
--- a/src/GraphicObjects/PrivateContainer.cs
+++ b/src/GraphicObjects/PrivateContainer.cs
@@ -91,9 +91,16 @@ namespace Crow
return child == goToFind ? true :
child == null ? false : child.Contains(goToFind);
}
- protected override Size measureRawSize ()
- {
- return child == null ? Bounds.Size : child.Slot.Size + 2 * Margin;
+ protected override int measureRawSize (LayoutingType lt)
+ {
+ if (child == null)
+ return base.measureRawSize (lt);
+ if (lt == LayoutingType.Width)
+ return child.RegisteredLayoutings.HasFlag(LayoutingType.Width) ?
+ -1 : child.Slot.Size.Width + 2 * Margin;
+ else
+ return child.RegisteredLayoutings.HasFlag(LayoutingType.Height) ?
+ -1 : child.Slot.Size.Height + 2 * Margin;
}
public override bool UpdateLayout (LayoutingType layoutType)
{
diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs
index dd7c742d..75176c34 100644
--- a/src/GraphicObjects/TemplatedControl.cs
+++ b/src/GraphicObjects/TemplatedControl.cs
@@ -71,38 +71,47 @@ namespace Crow
string _template;
- [XmlAttributeAttribute][DefaultValue("#Crow.Templates.Template.goml")]
+ [XmlAttributeAttribute][DefaultValue(null)]
public string Template {
get { return _template; }
- set { _template = value; }
- }
+ set {
+ if (Template == value)
+ return;
+ _template = value;
- #region GraphicObject overrides
- [XmlAttributeAttribute()][DefaultValue(-1)]
- public override int Width {
- get { return base.Width; }
- set {
- base.Width = value;
- //PropertyLess binding for sizing policy in template
- if (base.Width < 1) //send size policy to template elements
- NotifyValueChanged ("TemplatedWidth", base.Width);
- else //stretched in control if size is fixed
- NotifyValueChanged ("TemplatedWidth", 0);
+ if (string.IsNullOrEmpty(_template))
+ loadTemplate ();
+ else
+ loadTemplate (Interface.Load (_template, this));
}
}
- [XmlAttributeAttribute()][DefaultValue(-1)]
- public override int Height {
- get { return base.Height; }
- set {
- base.Height = value;
- //PropertyLess binding for sizing policy in template
- if (base.Height < 1) //send size policy to template elements
- NotifyValueChanged ("TemplatedHeight", base.Height);
- else //stretched in control if size is fixed
- NotifyValueChanged ("TemplatedHeight", 0);
- }
- }
+ #region GraphicObject overrides
+// [XmlAttributeAttribute()][DefaultValue(-1)]
+// public override int Width {
+// get { return base.Width; }
+// set {
+// base.Width = value;
+// //PropertyLess binding for sizing policy in template
+// if (base.Width < 1) //send size policy to template elements
+// NotifyValueChanged ("TemplatedWidth", base.Width);
+// else //stretched in control if size is fixed
+// NotifyValueChanged ("TemplatedWidth", 0);
+// }
+// }
+// [XmlAttributeAttribute()][DefaultValue(-1)]
+// public override int Height {
+// get { return base.Height; }
+// set {
+// base.Height = value;
+//
+// //PropertyLess binding for sizing policy in template
+// if (base.Height < 1) //send size policy to template elements
+// NotifyValueChanged ("TemplatedHeight", base.Height);
+// else //stretched in control if size is fixed
+// NotifyValueChanged ("TemplatedHeight", 0);
+// }
+// }
public override GraphicObject FindByName (string nameToFind)
{
//prevent name searching in template
diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs
index a426bdee..ef19cb04 100644
--- a/src/GraphicObjects/TextRun.cs
+++ b/src/GraphicObjects/TextRun.cs
@@ -144,13 +144,11 @@ namespace Crow
set { base.Margin = value; }
}
- protected override Size measureRawSize()
- {
- Size size;
-
+ protected override int measureRawSize(LayoutingType lt)
+ {
if (lines == null)
lines = getLines;
-
+
using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) {
using (Context gr = new Context (img)) {
//Cairo.FontFace cf = gr.GetContextFontFace ();
@@ -158,30 +156,34 @@ namespace Crow
gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
gr.SetFontSize (Font.Size);
+
+ fe = gr.FontExtents;
te = new TextExtents();
+ if (lt == LayoutingType.Height){
+ int lc = lines.Count;
+ //ensure minimal height = text line height
+ if (lc == 0)
+ lc = 1;
+
+ return (int)(fe.Height * lc) + Margin * 2;
+ }
+
foreach (string s in lines) {
string l = s.Replace("\t", new String (' ', Interface.TabSize));
-#if _WIN32 || _WIN64
+ #if _WIN32 || _WIN64
TextExtents tmp = gr.TextExtents(str.ToUtf8());
-#elif __linux__
+ #elif __linux__
TextExtents tmp = gr.TextExtents (l);
-#endif
+ #endif
if (tmp.XAdvance > te.XAdvance)
te = tmp;
}
- fe = gr.FontExtents;
- int lc = lines.Count;
- //ensure minimal height = text line height
- if (lc == 0)
- lc = 1;
- size = new Size ((int)Math.Ceiling (te.XAdvance) + Margin * 2, (int)(fe.Height * lc) + Margin*2);
+ return (int)Math.Ceiling (te.XAdvance) + Margin * 2;
}
}
-
- return size;;
- }
+ }
protected override void onDraw (Context gr)
{
base.onDraw (gr);
@@ -193,7 +195,8 @@ namespace Crow
//gr.FontOptions.Antialias = Antialias.Subpixel;
//gr.FontOptions.HintMetrics = HintMetrics.On;
- rText = new Rectangle(measureRawSize());
+ rText = new Rectangle(
+ measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height));
rText.Width -= 2 * Margin;
rText.Height -= 2 * Margin;