aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/GraphicObjects
diff options
context:
space:
mode:
authorj-p <jp.bruyere@live.be>2016-06-21 02:02:52 +0200
committerGitHub <noreply@github.com>2016-06-21 02:02:52 +0200
commitaed3905ffee6e07662290f3cf0787044ed95a360 (patch)
treeb245fd7f1454f520a58083fdefffac114e40d5ca /src/GraphicObjects
parentb3c2c1f21e96418d6b3a91ff75a182e84cb5b6a5 (diff)
parent4e3802bba7c4d7fa564cec723ff93d5aa2c1a056 (diff)
Merge pull request #7 from jpbruyere/dynSizing
Dyn sizing
Diffstat (limited to 'src/GraphicObjects')
-rw-r--r--src/GraphicObjects/GenericStack.cs194
-rw-r--r--src/GraphicObjects/GraphicObject.cs169
-rw-r--r--src/GraphicObjects/Group.cs96
-rw-r--r--src/GraphicObjects/IBindable.cs1
-rw-r--r--src/GraphicObjects/ListBox.cs5
-rw-r--r--src/GraphicObjects/PrivateContainer.cs81
-rw-r--r--src/GraphicObjects/Splitter.cs12
7 files changed, 258 insertions, 300 deletions
diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs
index 455ed928..adf428c5 100644
--- a/src/GraphicObjects/GenericStack.cs
+++ b/src/GraphicObjects/GenericStack.cs
@@ -1,14 +1,10 @@
-using System;
+using System.ComponentModel;
using System.Diagnostics;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using System.Xml.Serialization;
-using System.ComponentModel;
namespace Crow
{
- public class GenericStack : Group
+ public class GenericStack : Group
{
#region CTOR
public GenericStack()
@@ -54,41 +50,20 @@ namespace Crow
}
protected override int measureRawSize (LayoutingType lt)
{
- 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;
- }
- return base.measureRawSize (lt);
+ int totSpace = 0;
+ for (int i = 0; i < Children.Count; i++) {
+ if (Children [i].Visible)
+ totSpace += Spacing;
}
-
- return tmp + 2 * Margin;
+ if (totSpace > 0)
+ totSpace -= Spacing;
+ if (lt == LayoutingType.Width) {
+ if (Orientation == Orientation.Horizontal)
+ return contentSize.Width + totSpace + 2 * Margin;
+ }else if (Orientation == Orientation.Vertical)
+ return contentSize.Height + totSpace + 2 * Margin;
+
+ return base.measureRawSize (lt);
}
public virtual void ComputeChildrenPositions()
{
@@ -99,7 +74,6 @@ namespace Crow
continue;
c.Slot.X = d;
d += c.Slot.Width + Spacing;
- c.RegisterForLayouting (LayoutingType.Y);
}
} else {
foreach (GraphicObject c in Children) {
@@ -107,12 +81,11 @@ namespace Crow
continue;
c.Slot.Y = d;
d += c.Slot.Height + Spacing;
- c.RegisterForLayouting (LayoutingType.X);
}
}
bmp = null;
}
-
+ GraphicObject stretchedGO = null;
public override bool UpdateLayout (LayoutingType layoutType)
{
RegisteredLayoutings &= (~layoutType);
@@ -122,86 +95,6 @@ namespace Crow
//this child will occupy remaining space
//if stack size policy is Fit, no child may have stretch enabled
//in the direction of stacking.
- if (Orientation == Orientation.Horizontal) {
- GraphicObject stretchedGO = null;
- int tmpWidth = Slot.Width;
- int cptChildren = 0;
- for (int i = 0; i < Children.Count; i++) {
- if (!Children [i].Visible)
- continue;
- //requeue Positionning if child is not layouted
- if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Width))
- return false;
- cptChildren++;
- if (Children [i].Width == Measure.Stretched) {
- if (!(stretchedGO == null && Width != Measure.Fit)) {
- //change size policy of other stretched children
- Children [i].Width = Measure.Fit;
- return false;
- }
- stretchedGO = Children [i];
- if (i < Children.Count - 1)
- tmpWidth -= Spacing;
- continue;
- }
- tmpWidth -= Children [i].Slot.Width + Spacing;
- }
- if (stretchedGO != null && Width != Measure.Fit) {
- tmpWidth += (Spacing - 2 * Margin);
- if (tmpWidth < MinimumSize.Width)
- tmpWidth = MinimumSize.Width;
- else if (tmpWidth > MaximumSize.Width && MaximumSize.Width > 0)
- tmpWidth = MaximumSize.Width;
- if (stretchedGO.LastSlots.Width != tmpWidth) {
- stretchedGO.Slot.Width = tmpWidth;
- stretchedGO.bmp = null;
- #if DEBUG_LAYOUTING
- Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString());
- #endif
- stretchedGO.OnLayoutChanges (LayoutingType.Width);
- stretchedGO.LastSlots.Width = stretchedGO.Slot.Width;
- }
- }
- } else {
- GraphicObject stretchedGO = null;
- int tmpHeight = Slot.Height;
- int cptChildren = 0;
- for (int i = 0; i < Children.Count; i++) {
- if (!Children [i].Visible)
- continue;
- if (Children [i].RegisteredLayoutings.HasFlag (LayoutingType.Height))
- return false;
- cptChildren++;
- if (Children [i].Height == Measure.Stretched) {
- if (!(stretchedGO == null && Height != Measure.Fit)){
- Children [i].Height = Measure.Fit;
- return false;
- }
- stretchedGO = Children [i];
- if (i < Children.Count - 1)
- tmpHeight -= Spacing;
- continue;
- }
- tmpHeight -= Children[i].Slot.Height + Spacing;
- }
- if (stretchedGO != null && Height != Measure.Fit) {
- tmpHeight += (Spacing - 2 * Margin);
- if (tmpHeight < MinimumSize.Height)
- tmpHeight = MinimumSize.Height;
- else if (tmpHeight > MaximumSize.Height && MaximumSize.Height > 0)
- tmpHeight = MaximumSize.Height;
- if (stretchedGO.LastSlots.Height != tmpHeight) {
- stretchedGO.Slot.Height = tmpHeight;
- stretchedGO.bmp = null;
- #if DEBUG_LAYOUTING
- Debug.WriteLine ("\tAdjusting Height of " + stretchedGO.ToString());
- #endif
- stretchedGO.OnLayoutChanges (LayoutingType.Height);
- stretchedGO.LastSlots.Height = stretchedGO.Slot.Height;
- }
- }
- }
-
ComputeChildrenPositions ();
//if no layouting remains in queue for item, registre for redraw
@@ -216,24 +109,75 @@ namespace Crow
public override void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
{
- base.OnChildLayoutChanges (sender, arg);
-
+ GraphicObject go = sender as GraphicObject;
+ //Debug.WriteLine ("child layout change: " + go.LastSlots.ToString() + " => " + go.Slot.ToString());
switch (arg.LayoutType) {
case LayoutingType.Width:
if (Orientation == Orientation.Horizontal) {
+ if (go.Width == Measure.Stretched) {
+ if (stretchedGO == null && Width != Measure.Fit)
+ stretchedGO = go;
+ else if (stretchedGO != go) {
+ go.Slot.Width = 0;
+ go.Width = Measure.Fit;
+ return;
+ }
+ } else
+ contentSize.Width += go.Slot.Width - go.LastSlots.Width;
+
+ if (stretchedGO != null) {
+ stretchedGO.Slot.Width = this.ClientRectangle.Width - contentSize.Width - Spacing * (Children.Count - 1);
+ stretchedGO.bmp = null;
+#if DEBUG_LAYOUTING
+ Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString());
+#endif
+ stretchedGO.LayoutChanged -= OnChildLayoutChanges;
+ stretchedGO.OnLayoutChanges (LayoutingType.Width);
+ stretchedGO.LayoutChanged += OnChildLayoutChanges;
+ stretchedGO.LastSlots.Width = stretchedGO.Slot.Width;
+ }
+
if (Width == Measure.Fit)
this.RegisterForLayouting (LayoutingType.Width);
+
this.RegisterForLayouting (LayoutingType.ArrangeChildren);
+ return;
}
break;
case LayoutingType.Height:
if (Orientation == Orientation.Vertical) {
+ if (go.Height == Measure.Stretched) {
+ if (stretchedGO == null && Height != Measure.Fit)
+ stretchedGO = go;
+ else if (stretchedGO != go){
+ go.Slot.Height = 0;
+ go.Height = Measure.Fit;
+ return;
+ }
+ } else
+ contentSize.Height += go.Slot.Height - go.LastSlots.Height;
+
+ if (stretchedGO != null) {
+ stretchedGO.Slot.Height = this.ClientRectangle.Height - contentSize.Height - Spacing * (Children.Count -1);
+ stretchedGO.bmp = null;
+#if DEBUG_LAYOUTING
+ Debug.WriteLine ("\tAdjusting Width of " + stretchedGO.ToString());
+#endif
+ stretchedGO.LayoutChanged -= OnChildLayoutChanges;
+ stretchedGO.OnLayoutChanges (LayoutingType.Height);
+ stretchedGO.LayoutChanged += OnChildLayoutChanges;
+ stretchedGO.LastSlots.Height = stretchedGO.Slot.Height;
+ }
+
if (Height == Measure.Fit)
this.RegisterForLayouting (LayoutingType.Height);
+
this.RegisterForLayouting (LayoutingType.ArrangeChildren);
+ return;
}
break;
}
+ base.OnChildLayoutChanges (sender, arg);
}
#endregion
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index 4e230d4f..16371e51 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -22,10 +22,8 @@ namespace Crow
#endregion
- #if DEBUG_LAYOUTING
internal static ulong currentUid = 0;
internal ulong uid = 0;
- #endif
internal int layoutingTries = 0;
@@ -44,10 +42,8 @@ namespace Crow
#region CTOR
public GraphicObject ()
{
- #if DEBUG_LAYOUTING
uid = currentUid;
currentUid++;
- #endif
if (Interface.XmlSerializerInit)
return;
@@ -398,7 +394,8 @@ namespace Crow
if (Parent is GenericStack)
(Parent as GraphicObject).RegisterForLayouting (LayoutingType.ArrangeChildren);
- RegisterForLayouting (LayoutingType.Sizing);
+ if (_isVisible)
+ RegisterForLayouting (LayoutingType.Sizing);
RegisterForGraphicUpdate ();
NotifyValueChanged ("Visible", _isVisible);
@@ -664,15 +661,14 @@ namespace Crow
get { return layoutingTries; }
set { layoutingTries = value; }
}
+ protected Size contentSize;
/// <summary> return size of content + margins </summary>
protected virtual int measureRawSize (LayoutingType lt) {
return lt == LayoutingType.Width ?
- Width == Measure.Fit ? MinimumSize.Width : (int)Width :
- Height == Measure.Fit ? MinimumSize.Height : (int)Height;
+ contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin;
}
/// <summary> By default in groups, LayoutingType.ArrangeChildren is reset </summary>
public virtual void ChildrenLayoutingConstraints(ref LayoutingType layoutType){
-
}
public virtual bool ArrangeChildren { get { return false; } }
public virtual void RegisterForLayouting(LayoutingType layoutType){
@@ -680,9 +676,9 @@ namespace Crow
return;
lock (Interface.CurrentInterface.LayoutMutex) {
//dont set position for stretched item
- if (Width == 0)
+ if (Width == Measure.Stretched)
layoutType &= (~LayoutingType.X);
- if (Height == 0)
+ if (Height == Measure.Stretched)
layoutType &= (~LayoutingType.Y);
if (!ArrangeChildren)
@@ -747,7 +743,7 @@ namespace Crow
if (Left == 0) {
if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width) ||
- RegisteredLayoutings.HasFlag (LayoutingType.Width))
+ RegisteredLayoutings.HasFlag (LayoutingType.Width))
return false;
switch (HorizontalAlignment) {
@@ -763,21 +759,12 @@ namespace Crow
}
} else
Slot.X = Left;
-
- if (LastSlots.X == Slot.X)
- break;
-
- bmp = null;
-
- OnLayoutChanges (layoutType);
-
- LastSlots.X = Slot.X;
break;
case LayoutingType.Y:
if (Top == 0) {
if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height) ||
- RegisteredLayoutings.HasFlag (LayoutingType.Height))
+ RegisteredLayoutings.HasFlag (LayoutingType.Height))
return false;
switch (VerticalAlignment) {
@@ -791,42 +778,97 @@ namespace Crow
Slot.Y = Parent.ClientRectangle.Height / 2 - Slot.Height / 2;
break;
}
- }else
+ } else
Slot.Y = Top;
+ break;
+ case LayoutingType.Width:
+ if (Visible) {
+ if (Width.IsFixed)
+ Slot.Width = Width;
+ else if (Width == Measure.Fit) {
+ Slot.Width = measureRawSize (LayoutingType.Width);
+ } else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width))
+ return false;
+ else if (Width == Measure.Stretched)
+ Slot.Width = Parent.ClientRectangle.Width;
+ else
+ Slot.Width = (int)Math.Round ((double)(Parent.ClientRectangle.Width * Width) / 100.0);
- if (LastSlots.Y == Slot.Y)
+ if (Slot.Width < 0)
+ return false;
+
+ //size constrain
+ if (Slot.Width < MinimumSize.Width) {
+ Slot.Width = MinimumSize.Width;
+ //NotifyValueChanged ("WidthPolicy", Measure.Stretched);
+ } else if (Slot.Width > MaximumSize.Width && MaximumSize.Width > 0) {
+ Slot.Width = MaximumSize.Width;
+ //NotifyValueChanged ("WidthPolicy", Measure.Stretched);
+ }
+ } else
+ Slot.Width = 0;
+ break;
+ case LayoutingType.Height:
+ if (Visible) {
+ if (Height.IsFixed)
+ Slot.Height = Height;
+ else if (Height == Measure.Fit) {
+ Slot.Height = measureRawSize (LayoutingType.Height);
+ } else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height))
+ return false;
+ else if (Height == Measure.Stretched)
+ Slot.Height = Parent.ClientRectangle.Height;
+ else
+ Slot.Height = (int)Math.Round ((double)(Parent.ClientRectangle.Height * Height) / 100.0);
+
+ if (Slot.Height < 0)
+ return false;
+
+ //size constrain
+ if (Slot.Height < MinimumSize.Height) {
+ Slot.Height = MinimumSize.Height;
+ //NotifyValueChanged ("HeightPolicy", Measure.Stretched);
+ } else if (Slot.Height > MaximumSize.Height && MaximumSize.Height > 0) {
+ Slot.Height = MaximumSize.Height;
+ //NotifyValueChanged ("HeightPolicy", Measure.Stretched);
+ }
+ } else
+ Slot.Height = 0;
+ break;
+ }
+
+ updateSlot (layoutType);
+
+ //if no layouting remains in queue for item, registre for redraw
+ if (this.registeredLayoutings == LayoutingType.None && bmp == null)
+ this.AddToRedrawList ();
+
+ return true;
+ }
+ protected void updateSlot(LayoutingType layoutType)
+ {
+ switch (layoutType) {
+ case LayoutingType.X:
+ if (LastSlots.X == Slot.X)
break;
bmp = null;
OnLayoutChanges (layoutType);
- LastSlots.Y = Slot.Y;
+ LastSlots.X = Slot.X;
break;
- case LayoutingType.Width:
- if (Width.IsFixed)
- Slot.Width = Width;
- else if (Width == Measure.Fit) {
- Slot.Width = measureRawSize (LayoutingType.Width);
- } else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width))
- return false;
- else if (Width == Measure.Stretched)
- Slot.Width = Parent.ClientRectangle.Width;
- else
- Slot.Width = (int)Math.Round((double)(Parent.ClientRectangle.Width * Width) / 100.0);
+ case LayoutingType.Y:
+ if (LastSlots.Y == Slot.Y)
+ break;
- if (Slot.Width < 0)
- return false;
+ bmp = null;
- //size constrain
- if (Slot.Width < MinimumSize.Width) {
- Slot.Width = MinimumSize.Width;
- NotifyValueChanged ("WidthPolicy", Measure.Stretched);
- } else if (Slot.Width > MaximumSize.Width && MaximumSize.Width > 0) {
- Slot.Width = MaximumSize.Width;
- NotifyValueChanged ("WidthPolicy", Measure.Stretched);
- }
+ OnLayoutChanges (layoutType);
+ LastSlots.Y = Slot.Y;
+ break;
+ case LayoutingType.Width:
if (LastSlots.Width == Slot.Width)
break;
@@ -834,32 +876,9 @@ namespace Crow
OnLayoutChanges (layoutType);
- LastSlots.Width = Slot.Width;
+ LastSlots.Width = Slot.Width;
break;
case LayoutingType.Height:
- if (Height.IsFixed)
- Slot.Height = Height;
- else if (Height == Measure.Fit) {
- Slot.Height = measureRawSize (LayoutingType.Height);
- } else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height))
- return false;
- else if (Height == Measure.Stretched)
- Slot.Height = Parent.ClientRectangle.Height;
- else
- Slot.Height = (int)Math.Round((double)(Parent.ClientRectangle.Height * Height) / 100.0);
-
- if (Slot.Height < 0)
- return false;
-
- //size constrain
- if (Slot.Height < MinimumSize.Height) {
- Slot.Height = MinimumSize.Height;
- NotifyValueChanged ("HeightPolicy", Measure.Stretched);
- } else if (Slot.Height > MaximumSize.Height && MaximumSize.Height > 0) {
- Slot.Height = MaximumSize.Height;
- NotifyValueChanged ("HeightPolicy", Measure.Stretched);
- }
-
if (LastSlots.Height == Slot.Height)
break;
@@ -867,15 +886,9 @@ namespace Crow
OnLayoutChanges (layoutType);
- LastSlots.Height = Slot.Height;
+ LastSlots.Height = Slot.Height;
break;
}
-
- //if no layouting remains in queue for item, registre for redraw
- if (this.registeredLayoutings == LayoutingType.None && bmp == null)
- this.AddToRedrawList ();
-
- return true;
}
#endregion
@@ -1199,9 +1212,9 @@ namespace Crow
if (!string.IsNullOrEmpty (xaa.AttributeName))
name = xaa.AttributeName;
}
- if (value.StartsWith("{")) {
+ if (value.StartsWith("{",StringComparison.Ordinal)) {
//binding
- if (!value.EndsWith("}"))
+ if (!value.EndsWith("}", StringComparison.Ordinal))
throw new Exception (string.Format("GOML:Malformed binding: {0}", value));
this.Bindings.Add (new Binding (new MemberReference(this, pi), value.Substring (1, value.Length - 2)));
diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs
index 78c5bca3..2b440ac1 100644
--- a/src/GraphicObjects/Group.cs
+++ b/src/GraphicObjects/Group.cs
@@ -21,8 +21,6 @@ namespace Crow
public event EventHandler<EventArgs> ChildrenCleared;
#endregion
- internal int maxChildrenWidth = 0;
- internal int maxChildrenHeight = 0;
internal GraphicObject largestChild = null;
internal GraphicObject tallestChild = null;
@@ -59,9 +57,9 @@ namespace Crow
//child.Parent = null;
Children.Remove(child);
- if (child == largestChild)
+ if (child == largestChild && Width == Measure.Fit)
searchLargestChild ();
- if (child == tallestChild)
+ if (child == tallestChild && Height == Measure.Fit)
searchTallestChild ();
this.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren);
@@ -130,28 +128,26 @@ namespace Crow
}
protected override int measureRawSize (LayoutingType lt)
{
- if (Children.Count == 0)
- return base.measureRawSize (lt);
-
- if (lt == LayoutingType.Width) {
- if (largestChild == null)
- searchLargestChild ();
- 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 = Measure.Fit;
- return -1;//cancel actual sizing to let child computation take place
- }
- return maxChildrenWidth + 2 * Margin;
- }else{
- if (tallestChild == null)
- searchTallestChild ();
- if (tallestChild == null) {
- Children[0].Height = Measure.Fit;
- return -1;
+ if (Children.Count > 0) {
+ if (lt == LayoutingType.Width) {
+ if (largestChild == null)
+ searchLargestChild ();
+ 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 = Measure.Fit;
+ return -1;//cancel actual sizing to let child computation take place
+ }
+ } else {
+ if (tallestChild == null)
+ searchTallestChild ();
+ if (tallestChild == null) {
+ Children [0].Height = Measure.Fit;
+ return -1;
+ }
}
- return maxChildrenHeight + 2 * Margin;
}
+ return base.measureRawSize (lt);
}
public override void OnLayoutChanges (LayoutingType layoutType)
@@ -173,36 +169,29 @@ namespace Crow
public virtual void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
{
GraphicObject g = sender as GraphicObject;
+
switch (arg.LayoutType) {
case LayoutingType.Width:
- if (g.Slot.Width > maxChildrenWidth) {
- maxChildrenWidth = g.Slot.Width;
+ if (Width != Measure.Fit)
+ return;
+ if (g.Slot.Width > contentSize.Width) {
largestChild = g;
- if (Width == Measure.Fit)
- this.RegisterForLayouting (LayoutingType.Width);
- } else if (g == largestChild) {
-
- largestChild = null;
- maxChildrenWidth = 0;
+ contentSize.Width = g.Slot.Width;
+ } else if (g == largestChild)
+ searchLargestChild ();
- if (Width == Measure.Fit)
- this.RegisterForLayouting (LayoutingType.Width);
- }
+ this.RegisterForLayouting (LayoutingType.Width);
break;
case LayoutingType.Height:
- if (g.Slot.Height > maxChildrenHeight) {
- maxChildrenHeight = g.Slot.Height;
+ if (Height != Measure.Fit)
+ return;
+ if (g.Slot.Height > contentSize.Height) {
tallestChild = g;
- if (Height == Measure.Fit)
- this.RegisterForLayouting (LayoutingType.Height);
- } else if (g == tallestChild) {
-
- tallestChild = null;
- maxChildrenHeight = 0;
+ contentSize.Height = g.Slot.Height;
+ } else if (g == tallestChild)
+ searchTallestChild ();
- if (Height == Measure.Fit)
- this.RegisterForLayouting (LayoutingType.Height);
- }
+ this.RegisterForLayouting (LayoutingType.Height);
break;
}
}
@@ -211,22 +200,21 @@ namespace Crow
void resetChildrenMaxSize(){
largestChild = null;
tallestChild = null;
- maxChildrenWidth = 0;
- maxChildrenHeight = 0;
+ contentSize = 0;
}
void searchLargestChild(){
#if DEBUG_LAYOUTING
Debug.WriteLine("\tSearch largest child");
#endif
largestChild = null;
- maxChildrenWidth = 0;
+ contentSize.Width = 0;
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;
+ if (Children [i].Slot.Width > contentSize.Width) {
+ contentSize.Width = Children [i].Slot.Width;
largestChild = Children [i];
}
}
@@ -236,14 +224,14 @@ namespace Crow
Debug.WriteLine("\tSearch tallest child");
#endif
tallestChild = null;
- maxChildrenHeight = 0;
+ contentSize.Height = 0;
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;
+ if (Children [i].Slot.Height > contentSize.Height) {
+ contentSize.Height = Children [i].Slot.Height;
tallestChild = Children [i];
}
}
diff --git a/src/GraphicObjects/IBindable.cs b/src/GraphicObjects/IBindable.cs
index 642c1e9e..45ff5864 100644
--- a/src/GraphicObjects/IBindable.cs
+++ b/src/GraphicObjects/IBindable.cs
@@ -26,6 +26,7 @@ namespace Crow
public interface IBindable
{
List<Binding> Bindings { get; }
+ object DataSource { get; set; }
}
}
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs
index 54871241..34834b8d 100644
--- a/src/GraphicObjects/ListBox.cs
+++ b/src/GraphicObjects/ListBox.cs
@@ -93,7 +93,7 @@ namespace Crow
}
}
public object SelectedItem{
- get { return data == null ? "" : _selectedIndex < 0 ? "" : data[_selectedIndex]; }
+ get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; }
}
[XmlAttributeAttribute]//[DefaultValue(null)]
public IList Data {
@@ -207,6 +207,9 @@ namespace Crow
}
protected void _list_LayoutChanged (object sender, LayoutingEventArgs e)
{
+#if DEBUG_LAYOUTING
+ Debug.WriteLine("list_LayoutChanged");
+#endif
if (_gsList.Orientation == Orientation.Horizontal) {
if (e.LayoutType == LayoutingType.Width)
_gsList.Width = approxSize;
diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs
index 99b85dd2..16a797d7 100644
--- a/src/GraphicObjects/PrivateContainer.cs
+++ b/src/GraphicObjects/PrivateContainer.cs
@@ -51,6 +51,7 @@ namespace Crow
{
if (child != null) {
+ contentSize = new Size (0, 0);
child.LayoutChanged -= OnChildLayoutChanges;
this.RegisterForLayouting (LayoutingType.Sizing);
child.Parent = null;
@@ -61,6 +62,7 @@ namespace Crow
if (child != null) {
child.Parent = this;
child.LayoutChanged += OnChildLayoutChanges;
+ contentSize = child.Slot.Size;
child.RegisterForLayouting (LayoutingType.Sizing);
}
@@ -90,22 +92,17 @@ namespace Crow
return child == goToFind ? true :
child == null ? false : child.Contains(goToFind);
}
- 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 void ChildrenLayoutingConstraints (ref LayoutingType layoutType)
+ {
+ if (Width == Measure.Fit)
+ layoutType &= (~LayoutingType.X);
+ if (Height == Measure.Fit)
+ layoutType &= (~LayoutingType.Y);
}
public override bool UpdateLayout (LayoutingType layoutType)
{
if (child != null) {
- //force sizing to fit if sizing on children and
- //child has stretched size
+ //force sizing to fit if sizing on children and child has stretched size
switch (layoutType) {
case LayoutingType.Width:
if (Width == Measure.Fit && child.Width.Units == Unit.Percent)
@@ -123,34 +120,46 @@ namespace Crow
{
base.OnLayoutChanges (layoutType);
- switch (layoutType) {
- case LayoutingType.Width:
- if (child != null) {
- child.RegisterForLayouting (LayoutingType.X | LayoutingType.Width);
+ if (child == null)
+ return;
+
+ LayoutingType ltChild = LayoutingType.None;
+
+ if (layoutType == LayoutingType.Width) {
+ if (Width == Measure.Fit)
+ return;
+ if (child.Width.Units == Unit.Percent) {
+ ltChild |= LayoutingType.Width;
+ if (child.Width.Value < 100 && child.Left == 0)
+ ltChild |= LayoutingType.X;
}
- break;
- case LayoutingType.Height:
- if (child != null) {
- child.RegisterForLayouting (LayoutingType.Y | LayoutingType.Height);
+ } else if (layoutType == LayoutingType.Height) {
+ if (Height == Measure.Fit)
+ return;
+ if (child.Height.Units == Unit.Percent) {
+ ltChild |= LayoutingType.Height;
+ if (child.Height.Value < 100 && child.Top == 0)
+ ltChild |= LayoutingType.Y;
}
- break;
- }
+ }
+ if (ltChild == LayoutingType.None)
+ return;
+ child.RegisterForLayouting (ltChild);
}
public virtual void OnChildLayoutChanges (object sender, LayoutingEventArgs arg)
- {
- switch (arg.LayoutType) {
- case LayoutingType.X:
- break;
- case LayoutingType.Y:
- break;
- case LayoutingType.Width:
- if (Width < 0)
- this.RegisterForLayouting (LayoutingType.Width);
- break;
- case LayoutingType.Height:
- if (Height < 0)
- this.RegisterForLayouting (LayoutingType.Height);
- break;
+ {
+ GraphicObject g = sender as GraphicObject;
+
+ if (arg.LayoutType == LayoutingType.Width) {
+ if (Width != Measure.Fit)
+ return;
+ contentSize.Width = g.Slot.Width;
+ this.RegisterForLayouting (LayoutingType.Width);
+ }else if (arg.LayoutType == LayoutingType.Height){
+ if (Height != Measure.Fit)
+ return;
+ contentSize.Height = g.Slot.Height;
+ this.RegisterForLayouting (LayoutingType.Height);
}
}
protected override void onDraw (Context gr)
diff --git a/src/GraphicObjects/Splitter.cs b/src/GraphicObjects/Splitter.cs
index 6a1f2254..527b4084 100644
--- a/src/GraphicObjects/Splitter.cs
+++ b/src/GraphicObjects/Splitter.cs
@@ -83,14 +83,14 @@ namespace Crow
if (gs.Orientation == Orientation.Horizontal) {
if (ptrThis >= 0)
- gs.Children [ptrThis - 1].Width = Math.Max(gs.Children [ptrThis - 1].Slot.Width + e.XDelta*2, 1);
+ gs.Children [ptrThis - 1].Width = Math.Max(gs.Children [ptrThis - 1].Slot.Width + e.XDelta, 1);
if (ptrThis < gs.Children.Count - 1)
- gs.Children [ptrThis + 1].Width = Math.Max(gs.Children [ptrThis + 1].Slot.Width - e.XDelta*2, 1);
+ gs.Children [ptrThis + 1].Width = Math.Max(gs.Children [ptrThis + 1].Slot.Width - e.XDelta, 1);
} else {
if (ptrThis >= 0)
- gs.Children [ptrThis - 1].Height = Math.Max(gs.Children [ptrThis - 1].Slot.Height + e.YDelta*2, 1);
+ gs.Children [ptrThis - 1].Height = Math.Max(gs.Children [ptrThis - 1].Slot.Height + e.YDelta, 1);
if (ptrThis < gs.Children.Count - 1)
- gs.Children [ptrThis + 1].Height = Math.Max(gs.Children [ptrThis + 1].Slot.Height - e.YDelta*2, 1);
+ gs.Children [ptrThis + 1].Height = Math.Max(gs.Children [ptrThis + 1].Slot.Height - e.YDelta, 1);
}
}
public override bool UpdateLayout (LayoutingType layoutType)
@@ -100,12 +100,12 @@ namespace Crow
if (gs.Orientation == Orientation.Horizontal)
Width = thickness;
else
- Width = 0;
+ Width = Measure.Stretched;
} else if (layoutType == LayoutingType.Height){
if (gs.Orientation == Orientation.Vertical)
Height = thickness;
else
- Height = 0;
+ Height = Measure.Stretched;
}
return base.UpdateLayout (layoutType);
}