From 9e7f05bfc4a9f47bf11ca44842c0dd92def4d5aa Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Fri, 5 Feb 2016 20:38:00 +0100 Subject: new layouting update through events --- src/GraphicObjects/GenericStack.cs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/GraphicObjects/GenericStack.cs') diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index 92e944bb..d4e3ae5d 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -105,6 +105,7 @@ namespace Crow c.RegisterForLayouting ((int)LayoutingType.X); } } + bmp = null; } public override void RegisterForLayouting (int layoutType) @@ -171,6 +172,42 @@ namespace Crow }else base.UpdateLayout(layoutType); } + public override void OnLayoutChanges (LayoutingType layoutType) + { + base.OnLayoutChanges (layoutType); + + if (Orientation == Orientation.Horizontal){ + if(layoutType == LayoutingType.Width) + this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + }else if (layoutType == LayoutingType.Height) + this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + } + public override void OnChildLayoutChanges (object sender, LayoutChangeEventArgs arg) + { + base.OnChildLayoutChanges (sender, arg); + + GraphicObject g = sender as GraphicObject; + switch (arg.LayoutType) { + case LayoutingType.X: + break; + case LayoutingType.Y: + break; + case LayoutingType.Width: + if (Orientation == Orientation.Horizontal) { + if (this.Bounds.Width < 0) + this.RegisterForLayouting ((int)LayoutingType.Width); + this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + } + break; + case LayoutingType.Height: + if (Orientation == Orientation.Vertical) { + if (this.Bounds.Height < 0) + this.RegisterForLayouting ((int)LayoutingType.Height); + this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + } + break; + } + } #endregion -- cgit v1.3.1-4-g156e From 643d44f381962d6814d3676cee322c41018406eb Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sat, 6 Feb 2016 07:11:22 +0100 Subject: 2 step, 1=> Simple Register, 2=> Enqueue with priority checking --- src/GraphicObjects/GenericStack.cs | 7 +++---- src/GraphicObjects/GraphicObject.cs | 19 +++++++++++++------ src/GraphicObjects/Grid.cs | 6 +++--- src/Interface.cs | 1 + src/LayoutingQueueItem.cs | 1 + src/OpenTKGameWindow.cs | 16 ++++++++-------- 6 files changed, 29 insertions(+), 21 deletions(-) (limited to 'src/GraphicObjects/GenericStack.cs') diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index d4e3ae5d..e2bdcf7a 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -108,16 +108,15 @@ namespace Crow bmp = null; } - public override void RegisterForLayouting (int layoutType) + public override void EnqueueForLayouting () { if (Parent == null) return; - base.RegisterForLayouting (layoutType); + base.EnqueueForLayouting (); - if ((layoutType & (int)LayoutingType.PositionChildren) > 0) + if (RegisteredLayoutings.HasFlag(LayoutingType.PositionChildren)) Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this); - } public override void UpdateLayout (LayoutingType layoutType) { diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 53dee9cc..97afaa7e 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -509,9 +509,16 @@ namespace Crow RegisteredLQINodes.Remove (lqis [i]); } } + public LayoutingType RegisteredLayoutings = 0; + + public virtual void RegisterForLayouting(int layoutType){ + if (RegisteredLayoutings == LayoutingType.None) + Interface.RegisteredGOForLayouting.Enqueue (this); + RegisteredLayoutings |= (LayoutingType)layoutType; + } /// clear current layoutingQueue items for object and /// trigger a new layouting pass for a layoutType - public virtual void RegisterForLayouting(int layoutType) + public virtual void EnqueueForLayouting() { if (Parent == null) return; @@ -519,8 +526,8 @@ namespace Crow Debug.WriteLine ("RegisterForLayouting => {1}->{0}", layoutType, this.ToString()); #endif - deleteLQI (layoutType); - if ((layoutType & (int)LayoutingType.Width) > 0) { + //deleteLQI (RegisteredLayoutings); + if (RegisteredLayoutings.HasFlag(LayoutingType.Width)) { if (Bounds.Width == 0) //stretch in parent Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Width, this); else if (Bounds.Width < 0) //fit @@ -531,7 +538,7 @@ namespace Crow new LayoutingQueueItem (LayoutingType.Width, this))); } - if ((layoutType & (int)LayoutingType.Height) > 0) { + if (RegisteredLayoutings.HasFlag(LayoutingType.Height)) { if (Bounds.Height == 0) //stretch in parent Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Height, this); else if (Bounds.Height < 0) //fit @@ -544,11 +551,11 @@ namespace Crow } } - if ((layoutType & (int)LayoutingType.X) > 0) + if (RegisteredLayoutings.HasFlag(LayoutingType.X)) //for x positionning, sizing of parent and this have to be done Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.X, this); - if ((layoutType & (int)LayoutingType.Y) > 0) + if (RegisteredLayoutings.HasFlag(LayoutingType.Y)) //for x positionning, sizing of parent and this have to be done Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.Y, this); } diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index 1981fc60..571fdc0f 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -125,11 +125,11 @@ namespace Crow } } - public override void RegisterForLayouting (int layoutType) + public override void EnqueueForLayouting () { - base.RegisterForLayouting (layoutType); + base.EnqueueForLayouting (); - if ((layoutType & (int)LayoutingType.PositionChildren) > 0) + if (RegisteredLayoutings.HasFlag(LayoutingType.PositionChildren)) Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this); } public override void UpdateLayout (LayoutingType layoutType) diff --git a/src/Interface.cs b/src/Interface.cs index c96dffa0..cf86ecf3 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -54,6 +54,7 @@ namespace Crow public static int BorderThreshold = 5; public static LayoutingQueue LayoutingQueue = new LayoutingQueue (); + public static Queue RegisteredGOForLayouting = new Queue(); #region Load/Save //internal static List Bindings; diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index 80d04dc6..7153429b 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -26,6 +26,7 @@ namespace Crow { public enum LayoutingType { + None = 0x00, X = 0x01, Y = 0x02, Width = 0x04, diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 89df8ee4..23d3e814 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -261,18 +261,18 @@ namespace Crow #endif //Debug.WriteLine ("======= Layouting queue start ======="); + while (Interface.RegisteredGOForLayouting.Count > 0){ + while (Interface.RegisteredGOForLayouting.Count > 0){ + GraphicObject go = Interface.RegisteredGOForLayouting.Dequeue (); + go.EnqueueForLayouting (); + go.RegisteredLayoutings = LayoutingType.None; + } while (Interface.LayoutingQueue.First != null) { -// Stopwatch lqiProcTime = new Stopwatch (); -// lqiProcTime.Start (); LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue (); lqi.ProcessLayouting (); -// lqiProcTime.Stop (); -// if (lqiProcTime.ElapsedMilliseconds > 10) { -// Debug.WriteLine("lqi {2}: {0} ticks \t, {1} ms", -// updateTime.ElapsedTicks, -// updateTime.ElapsedMilliseconds, lqi.ToString()); -// } } + } + #if MEASURE_TIME layoutTime.Stop (); #endif -- cgit v1.3.1-4-g156e From 6577bc6e136c7440117bd7bb49cb4a4fd3fbcfa3 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sat, 6 Feb 2016 08:01:25 +0100 Subject: use LayoutingType Enum everywhere instead of casting to (int) --- MonoDevelop.GOLib/src/GOLibGtkHost.cs | 4 ++-- UnitTest/NUnitCrowWindow.cs | 2 +- src/GraphicObjects/GenericStack.cs | 20 ++++++++++---------- src/GraphicObjects/GraphicObject.cs | 16 ++++++++-------- src/GraphicObjects/Grid.cs | 8 ++++---- src/GraphicObjects/Group.cs | 22 +++++++++++----------- src/GraphicObjects/ILayoutable.cs | 2 +- src/GraphicObjects/Label.cs | 2 +- src/GraphicObjects/Popper.cs | 4 ++-- src/GraphicObjects/PrivateContainer.cs | 16 ++++++++-------- src/GraphicObjects/Slider.cs | 4 ++-- src/GraphicObjects/TextBox.cs | 4 ++-- src/GraphicObjects/TextRun.cs | 2 +- src/LayoutingQueueItem.cs | 2 +- src/OpenTKGameWindow.cs | 6 +++--- 15 files changed, 57 insertions(+), 57 deletions(-) (limited to 'src/GraphicObjects/GenericStack.cs') diff --git a/MonoDevelop.GOLib/src/GOLibGtkHost.cs b/MonoDevelop.GOLib/src/GOLibGtkHost.cs index f9e7e599..905d9d26 100644 --- a/MonoDevelop.GOLib/src/GOLibGtkHost.cs +++ b/MonoDevelop.GOLib/src/GOLibGtkHost.cs @@ -170,7 +170,7 @@ namespace MonoDevelop.GOLib g.Parent = this; GraphicObjects.Insert (0, g); - g.RegisterForLayouting ((int)LayoutingType.Sizing); + g.RegisterForLayouting (LayoutingType.Sizing); } public void DeleteWidget(GraphicObject g) { @@ -262,7 +262,7 @@ namespace MonoDevelop.GOLib Crow.Size newSize = this.ClientRectangle.Size; if (lastSize != newSize) { foreach (GraphicObject g in GraphicObjects) - g.RegisterForLayouting ((int)LayoutingType.All); + g.RegisterForLayouting (LayoutingType.All); lastSize = newSize; } diff --git a/UnitTest/NUnitCrowWindow.cs b/UnitTest/NUnitCrowWindow.cs index 1325dcaf..40f79480 100644 --- a/UnitTest/NUnitCrowWindow.cs +++ b/UnitTest/NUnitCrowWindow.cs @@ -58,7 +58,7 @@ namespace Crow g.Parent = this; GraphicObjects.Insert (0, g); - g.RegisterForLayouting ((int)LayoutingType.Sizing); + g.RegisterForLayouting (LayoutingType.Sizing); } public void DeleteWidget(GraphicObject g) { diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index e2bdcf7a..7bdb3b56 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -31,13 +31,13 @@ namespace Crow public override T addChild (T child) { T tmp = base.addChild (child); - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.PositionChildren); return tmp; } public override void removeChild (GraphicObject child) { base.removeChild (child); - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.PositionChildren); } #region Public Properties @@ -96,13 +96,13 @@ namespace Crow foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) { c.Slot.X = d; d += c.Slot.Width + Spacing; - c.RegisterForLayouting ((int)LayoutingType.Y); + c.RegisterForLayouting (LayoutingType.Y); } } else { foreach (GraphicObject c in Children.Where(ch=>ch.Visible)) { c.Slot.Y = d; d += c.Slot.Height + Spacing; - c.RegisterForLayouting ((int)LayoutingType.X); + c.RegisterForLayouting (LayoutingType.X); } } bmp = null; @@ -177,9 +177,9 @@ namespace Crow if (Orientation == Orientation.Horizontal){ if(layoutType == LayoutingType.Width) - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.PositionChildren); }else if (layoutType == LayoutingType.Height) - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.PositionChildren); } public override void OnChildLayoutChanges (object sender, LayoutChangeEventArgs arg) { @@ -194,15 +194,15 @@ namespace Crow case LayoutingType.Width: if (Orientation == Orientation.Horizontal) { if (this.Bounds.Width < 0) - this.RegisterForLayouting ((int)LayoutingType.Width); - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.Width); + this.RegisterForLayouting (LayoutingType.PositionChildren); } break; case LayoutingType.Height: if (Orientation == Orientation.Vertical) { if (this.Bounds.Height < 0) - this.RegisterForLayouting ((int)LayoutingType.Height); - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.Height); + this.RegisterForLayouting (LayoutingType.PositionChildren); } break; } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 97afaa7e..19002a5d 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -219,7 +219,7 @@ namespace Crow Bounds.X = value; NotifyValueChanged ("Left", Bounds.X); - this.RegisterForLayouting ((int)LayoutingType.X); + this.RegisterForLayouting (LayoutingType.X); } } [XmlAttributeAttribute()][DefaultValue(0)] @@ -231,7 +231,7 @@ namespace Crow Bounds.Y = value; NotifyValueChanged ("Top", Bounds.Y); - this.RegisterForLayouting ((int)LayoutingType.Y); + this.RegisterForLayouting (LayoutingType.Y); } } [XmlAttributeAttribute()][DefaultValue(0)] @@ -243,7 +243,7 @@ namespace Crow Bounds.Width = value; NotifyValueChanged ("Width", Bounds.Width); - this.RegisterForLayouting ((int)LayoutingType.Width); + this.RegisterForLayouting (LayoutingType.Width); } } [XmlAttributeAttribute()][DefaultValue(0)] @@ -255,7 +255,7 @@ namespace Crow Bounds.Height = value; NotifyValueChanged ("Height", Bounds.Height); - this.RegisterForLayouting ((int)LayoutingType.Height); + this.RegisterForLayouting (LayoutingType.Height); } } [XmlAttributeAttribute()][DefaultValue(false)] @@ -371,7 +371,7 @@ namespace Crow if (this.Contains (HostContainer.hoverWidget)) HostContainer.hoverWidget = null; if (Parent is GenericStack) - Parent.RegisterForLayouting ((int)LayoutingType.Sizing | (int)LayoutingType.PositionChildren); + Parent.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.PositionChildren); NotifyValueChanged ("Visible", _isVisible); } @@ -511,7 +511,7 @@ namespace Crow } public LayoutingType RegisteredLayoutings = 0; - public virtual void RegisterForLayouting(int layoutType){ + public virtual void RegisterForLayouting(LayoutingType layoutType){ if (RegisteredLayoutings == LayoutingType.None) Interface.RegisteredGOForLayouting.Enqueue (this); RegisteredLayoutings |= (LayoutingType)layoutType; @@ -573,11 +573,11 @@ namespace Crow switch (layoutType) { case LayoutingType.Width: if (Width != 0 && Parent.getBounds().Width >=0) //update position in parent - this.RegisterForLayouting ((int)LayoutingType.X); + this.RegisterForLayouting (LayoutingType.X); break; case LayoutingType.Height: if (Height != 0 && Parent.getBounds().Height >=0) //update position in parent - this.RegisterForLayouting ((int)LayoutingType.Y); + this.RegisterForLayouting (LayoutingType.Y); break; } LayoutChanged.Raise (this, new LayoutChangeEventArgs (layoutType)); diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index 571fdc0f..171abd61 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -32,13 +32,13 @@ namespace Crow public override T addChild (T child) { T tmp = base.addChild (child); - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.PositionChildren); return tmp; } public override void removeChild (GraphicObject child) { base.removeChild (child); - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.PositionChildren); } #region Public Properties @@ -59,7 +59,7 @@ namespace Crow _columnCount = value; NotifyValueChanged ("ColumnCount", ColumnCount); - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.PositionChildren); } } [XmlAttributeAttribute()][DefaultValue(1)] @@ -73,7 +73,7 @@ namespace Crow _rowCount = value; NotifyValueChanged ("RowCount", RowCount); - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.PositionChildren); } } public virtual int CaseWidth { diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index a9870c78..e8632fea 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -50,7 +50,7 @@ namespace Crow GraphicObject g = child as GraphicObject; Children.Add(g); g.Parent = this as GraphicObject; - g.RegisterForLayouting ((int)LayoutingType.Sizing); + g.RegisterForLayouting (LayoutingType.Sizing); g.LayoutChanged += OnChildLayoutChanges; return (T)child; } @@ -60,7 +60,7 @@ namespace Crow child.ClearBinding (); child.Parent = null; Children.Remove(child); - this.RegisterForLayouting ((int)LayoutingType.Sizing); + this.RegisterForLayouting (LayoutingType.Sizing); } public virtual void ClearChildren() { @@ -73,7 +73,7 @@ namespace Crow Children.RemoveAt(cpt-1); cpt = children.Count; } - this.RegisterForLayouting ((int)LayoutingType.Sizing); + this.RegisterForLayouting (LayoutingType.Sizing); ChildrenCleared.Raise (this, new EventArgs ()); } public void putWidgetOnTop(GraphicObject w) @@ -147,17 +147,17 @@ namespace Crow case LayoutingType.Width: foreach (GraphicObject c in Children.Where(ch => ch.Visible)) { if (c.getBounds ().Width == 0) - c.RegisterForLayouting ((int)LayoutingType.Width); + c.RegisterForLayouting (LayoutingType.Width); else - c.RegisterForLayouting ((int)LayoutingType.X); + c.RegisterForLayouting (LayoutingType.X); } break; case LayoutingType.Height: foreach (GraphicObject c in Children.Where(ch => ch.Visible)) { if (c.getBounds ().Height == 0) - c.RegisterForLayouting ((int)LayoutingType.Height); + c.RegisterForLayouting (LayoutingType.Height); else - c.RegisterForLayouting ((int)LayoutingType.Y); + c.RegisterForLayouting (LayoutingType.Y); } break; } @@ -175,7 +175,7 @@ namespace Crow maxChildrenWidth = g.Slot.Width; largestChild = g; if (this.Bounds.Width < 0) - this.RegisterForLayouting ((int)LayoutingType.Width); + this.RegisterForLayouting (LayoutingType.Width); } else if (g == largestChild) { //search for the new largest child largestChild = null; @@ -187,7 +187,7 @@ namespace Crow } } if (this.Bounds.Width < 0) - this.RegisterForLayouting ((int)LayoutingType.Width); + this.RegisterForLayouting (LayoutingType.Width); } break; case LayoutingType.Height: @@ -195,7 +195,7 @@ namespace Crow maxChildrenHeight = g.Slot.Height; tallestChild = g; if (this.Bounds.Height < 0) - this.RegisterForLayouting ((int)LayoutingType.Height); + this.RegisterForLayouting (LayoutingType.Height); } else if (g == tallestChild) { //search for the new tallest child tallestChild = null; @@ -207,7 +207,7 @@ namespace Crow } } if (this.Bounds.Height < 0) - this.RegisterForLayouting ((int)LayoutingType.Height); + this.RegisterForLayouting (LayoutingType.Height); } break; } diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs index 7bb30bce..01d62365 100644 --- a/src/GraphicObjects/ILayoutable.cs +++ b/src/GraphicObjects/ILayoutable.cs @@ -14,7 +14,7 @@ namespace Crow IGOLibHost HostContainer { get; } List> RegisteredLQINodes { get; } - void RegisterForLayouting(int layoutType); + void RegisterForLayouting(LayoutingType layoutType); void UpdateLayout(LayoutingType layoutType); diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index d8d214c7..08e7211a 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -105,7 +105,7 @@ namespace Crow lines = getLines; this.registerForGraphicUpdate (); - this.RegisterForLayouting ((int)LayoutingType.Sizing); + this.RegisterForLayouting (LayoutingType.Sizing); NotifyValueChanged ("Text", _text); } } diff --git a/src/GraphicObjects/Popper.cs b/src/GraphicObjects/Popper.cs index a7e1290c..d213fd6d 100644 --- a/src/GraphicObjects/Popper.cs +++ b/src/GraphicObjects/Popper.cs @@ -66,7 +66,7 @@ namespace Crow if (tc == null) return; Rectangle r = this.ScreenCoordinates (this.Slot); - if (((int)e.LayoutType & (int)LayoutingType.Width) > 0) { + if (e.LayoutType.HasFlag(LayoutingType.Width)) { if (Content.Slot.Width < tc.ClientRectangle.Width) { if (r.Left + Content.Slot.Width > tc.ClientRectangle.Right) Content.Left = tc.ClientRectangle.Right - Content.Slot.Width; @@ -75,7 +75,7 @@ namespace Crow } else Content.Left = 0; } - if (((int)e.LayoutType & (int)LayoutingType.Height) > 0) { + if (e.LayoutType.HasFlag(LayoutingType.Height)) { if (Content.Slot.Height < tc.ClientRectangle.Height) { if (r.Bottom + Content.Slot.Height > tc.ClientRectangle.Bottom) Content.Top = r.Top - Content.Slot.Height; diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index 9b312c14..b7651d76 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -53,7 +53,7 @@ namespace Crow if (child != null) { child.LayoutChanged -= OnChildLayoutChanges; - this.RegisterForLayouting ((int)LayoutingType.Sizing); + this.RegisterForLayouting (LayoutingType.Sizing); child.Parent = null; } @@ -62,7 +62,7 @@ namespace Crow if (child != null) { child.Parent = this; child.LayoutChanged += OnChildLayoutChanges; - child.RegisterForLayouting ((int)LayoutingType.Sizing); + child.RegisterForLayouting (LayoutingType.Sizing); } return (T)_child; @@ -104,17 +104,17 @@ namespace Crow case LayoutingType.Width: if (child != null) { if (child.getBounds ().Width == 0) - child.RegisterForLayouting ((int)LayoutingType.Width); + child.RegisterForLayouting (LayoutingType.Width); else - child.RegisterForLayouting ((int)LayoutingType.X); + child.RegisterForLayouting (LayoutingType.X); } break; case LayoutingType.Height: if (child != null) { if (child.getBounds ().Height == 0) - child.RegisterForLayouting ((int)LayoutingType.Height); + child.RegisterForLayouting (LayoutingType.Height); else - child.RegisterForLayouting ((int)LayoutingType.Y); + child.RegisterForLayouting (LayoutingType.Y); } break; } @@ -129,11 +129,11 @@ namespace Crow break; case LayoutingType.Width: if (this.Bounds.Width < 0) - this.RegisterForLayouting ((int)LayoutingType.Width); + this.RegisterForLayouting (LayoutingType.Width); break; case LayoutingType.Height: if (this.Bounds.Height < 0) - this.RegisterForLayouting ((int)LayoutingType.Height); + this.RegisterForLayouting (LayoutingType.Height); break; } } diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs index 495683d2..a9bb5b8e 100644 --- a/src/GraphicObjects/Slider.cs +++ b/src/GraphicObjects/Slider.cs @@ -58,7 +58,7 @@ namespace Crow if (_cursorSize == value) return; _cursorSize = value; - RegisterForLayouting ((int)LayoutingType.Sizing); + RegisterForLayouting (LayoutingType.Sizing); registerForGraphicUpdate (); NotifyValueChanged ("CursorSize", _cursorSize); } @@ -72,7 +72,7 @@ namespace Crow return; _orientation = value; - RegisterForLayouting ((int)LayoutingType.All); + RegisterForLayouting (LayoutingType.All); NotifyValueChanged ("Orientation", _orientation); } } diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs index 143d148f..91122523 100644 --- a/src/GraphicObjects/TextBox.cs +++ b/src/GraphicObjects/TextBox.cs @@ -199,9 +199,9 @@ namespace Crow break; } if (Width < 0) - RegisterForLayouting ((int)LayoutingType.Width); + RegisterForLayouting (LayoutingType.Width); if (Height < 0) - RegisterForLayouting ((int)LayoutingType.Height); + RegisterForLayouting (LayoutingType.Height); registerForGraphicUpdate(); } #endregion diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs index bee580b3..76dde9a8 100644 --- a/src/GraphicObjects/TextRun.cs +++ b/src/GraphicObjects/TextRun.cs @@ -60,7 +60,7 @@ namespace Crow return; registerForGraphicUpdate(); - this.RegisterForLayouting ((int)LayoutingType.Sizing); + this.RegisterForLayouting (LayoutingType.Sizing); _text = value; diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index 7153429b..8fbd95ca 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -24,7 +24,7 @@ using System.Collections.Generic; namespace Crow { - public enum LayoutingType + public enum LayoutingType : byte { None = 0x00, X = 0x01, diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 23d3e814..bb5b67e6 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -76,7 +76,7 @@ namespace Crow g.Parent = this; GraphicObjects.Insert (0, g); - g.RegisterForLayouting ((int)LayoutingType.Sizing); + g.RegisterForLayouting (LayoutingType.Sizing); } public void DeleteWidget(GraphicObject g) { @@ -408,7 +408,7 @@ namespace Crow base.OnResize (e); createContext (); foreach (GraphicObject g in GraphicObjects) { - g.RegisterForLayouting ((int)LayoutingType.All); + g.RegisterForLayouting (LayoutingType.All); //g.registerForGraphicUpdate(); } } @@ -554,7 +554,7 @@ namespace Crow //TODO:uneeded list, should be removed public List> RegisteredLQINodes { get; } = new List>(); - public void RegisterForLayouting (int layoutType) { throw new NotImplementedException (); } + public void RegisterForLayouting (LayoutingType layoutType) { throw new NotImplementedException (); } public void UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } public Rectangle ContextCoordinates (Rectangle r) { -- cgit v1.3.1-4-g156e From 95e936cad1d7e5e666c633d8ba132b0d54fdf3b5 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sat, 6 Feb 2016 09:03:15 +0100 Subject: rename LayoutChangeEventArgs=>LayoutingEventArgs --- Crow.csproj | 4 ++-- src/GraphicObjects/ComboBox.cs | 2 +- src/GraphicObjects/GenericStack.cs | 2 +- src/GraphicObjects/GraphicObject.cs | 6 +++--- src/GraphicObjects/Group.cs | 2 +- src/GraphicObjects/Popper.cs | 4 ++-- src/GraphicObjects/PrivateContainer.cs | 2 +- src/GraphicObjects/Scroller.cs | 2 +- src/LayoutChangeEventArgs.cs | 15 --------------- src/LayoutingEventArgs.cs | 15 +++++++++++++++ 10 files changed, 27 insertions(+), 27 deletions(-) delete mode 100644 src/LayoutChangeEventArgs.cs create mode 100644 src/LayoutingEventArgs.cs (limited to 'src/GraphicObjects/GenericStack.cs') diff --git a/Crow.csproj b/Crow.csproj index a3dbc710..851f75e1 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -46,7 +46,7 @@ bin\Debug - TRACE;DEBUG;__linux__;MEASURE_TIME;DEBUG_LOAD_TIME0;DEBUG_LAYOUTING0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0 + TRACE;DEBUG;__linux__;MEASURE_TIME;DEBUG_LOAD_TIME0;DEBUG_LAYOUTING;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0 - - - - - - - - - - - - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/src/GraphicObjects/ComboBox.cs b/src/GraphicObjects/ComboBox.cs index 181131b4..aee7da9b 100644 --- a/src/GraphicObjects/ComboBox.cs +++ b/src/GraphicObjects/ComboBox.cs @@ -164,11 +164,7 @@ namespace Crow } } - public override void UpdateLayout (LayoutingType layoutType) - { - CheckPendingChildrenAddition (); - base.UpdateLayout (layoutType); - } + internal void CheckPendingChildrenAddition() { if (pendingChildrenAddition == null) diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index c49c5307..5de21fac 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -109,19 +109,11 @@ namespace Crow } bmp = null; } + + public override bool UpdateLayout (LayoutingType layoutType) + { + RegisteredLayoutings &= (~layoutType); - public override void EnqueueForLayouting () - { - if (Parent == null) - return; - - base.EnqueueForLayouting (); - - if (RegisteredLayoutings.HasFlag(LayoutingType.PositionChildren)) - Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this); - } - public override void UpdateLayout (LayoutingType layoutType) - { if (layoutType == LayoutingType.PositionChildren) { //allow 1 child to have size to 0 if stack has fixed or streched size, //this child will occupy remaining space @@ -165,13 +157,18 @@ namespace Crow } } } - } + } + ComputeChildrenPositions (); + //if no layouting remains in queue for item, registre for redraw - if (RegisteredLQINodes.Count () <= 0 && bmp==null) + if (RegisteredLayoutings == LayoutingType.None && bmp==null) this.RegisterForRedraw (); - }else - base.UpdateLayout(layoutType); + + return true; + } + + return base.UpdateLayout(layoutType); } public override void OnLayoutChanges (LayoutingType layoutType) { diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 1f437021..4d00b99a 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -64,6 +64,7 @@ namespace Crow #endregion #region private fields + LayoutingType registeredLayoutings = LayoutingType.None; ILayoutable _parent; string _name = "unamed"; Fill _background = Color.Transparent; @@ -111,8 +112,7 @@ namespace Crow #endregion #region ILayoutable - - public List> RegisteredLQINodes { get; } = new List>(); + [XmlIgnore]public LayoutingType RegisteredLayoutings { get { return registeredLayoutings; } set { registeredLayoutings = value; } } //TODO: it would save the recurent cost of a cast in event bubbling if parent type was GraphicObject // or we could add to the interface the mouse events /// @@ -501,21 +501,14 @@ namespace Crow protected virtual Size measureRawSize () { return Bounds.Size; } - - void deleteLQI(int lt){ - LinkedListNode[] lqis = this.RegisteredLQINodes.Where (n => (lt & (int)n.Value.LayoutType) > 0).ToArray (); - for (int i = 0; i < lqis.Length; i++) { - Interface.LayoutingQueue.Remove (lqis [i]); - RegisteredLQINodes.Remove (lqis [i]); - } - } - public LayoutingType RegisteredLayoutings = 0; - + public virtual void RegisterForLayouting(LayoutingType layoutType){ + //dont set position for stretched item if (Width == 0) layoutType &= (~LayoutingType.X); if (Height == 0) layoutType &= (~LayoutingType.Y); + //Prevent child repositionning in a stack //TODO:this should be done inside GenericStack GenericStack gs = Parent as GenericStack; @@ -525,66 +518,36 @@ namespace Crow else layoutType &= (~LayoutingType.Y); } + + //prevent queueing same LayoutingType for this + layoutType &= (~RegisteredLayoutings); + if (layoutType == LayoutingType.None) return; - if (RegisteredLayoutings == LayoutingType.None) - Interface.RegisteredGOForLayouting.Enqueue (this); - RegisteredLayoutings |= (LayoutingType)layoutType; - } - /// clear current layoutingQueue items for object and - /// trigger a new layouting pass for a layoutType - public virtual void EnqueueForLayouting() - { - if (Parent == null) - return; + #if DEBUG_LAYOUTING - Debug.WriteLine ("RegisterForLayouting => {1}->{0}", RegisteredLayoutings.ToString(), this.ToString()); + Debug.WriteLine ("RegisterForLayouting => {1}->{0}", layoutType, this.ToString()); #endif - //deleteLQI (RegisteredLayoutings); - if (RegisteredLayoutings.HasFlag(LayoutingType.Width)) { - if (Bounds.Width == 0) //stretch in parent - Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Width, this); - else if (Bounds.Width < 0) //fit - Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Width, this); - else - RegisteredLQINodes.Add( - Interface.LayoutingQueue.AddFirst ( - new LayoutingQueueItem (LayoutingType.Width, this))); - } - - if (RegisteredLayoutings.HasFlag(LayoutingType.Height)) { - if (Bounds.Height == 0) //stretch in parent - Interface.LayoutingQueue.EnqueueAfterParentSizing (LayoutingType.Height, this); - else if (Bounds.Height < 0) //fit - Interface.LayoutingQueue.EnqueueBeforeParentSizing (LayoutingType.Height, this); - else{ - RegisteredLQINodes.Add( - Interface.LayoutingQueue.AddFirst ( - new LayoutingQueueItem (LayoutingType.Height, this))); - - } - } - - if (RegisteredLayoutings.HasFlag(LayoutingType.X)) - //for x positionning, sizing of parent and this have to be done - Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.X, this); - - if (RegisteredLayoutings.HasFlag(LayoutingType.Y)) - //for x positionning, sizing of parent and this have to be done - Interface.LayoutingQueue.EnqueueAfterThisAndParentSizing (LayoutingType.Y, this); + if (layoutType.HasFlag (LayoutingType.Width)) + Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Width, this)); + if (layoutType.HasFlag (LayoutingType.Height)) + Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Height, this)); + if (layoutType.HasFlag (LayoutingType.X)) + Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this)); + if (layoutType.HasFlag (LayoutingType.Y)) + Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this)); + if (layoutType.HasFlag (LayoutingType.PositionChildren)) + Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.PositionChildren, this)); } - /// trigger dependant sizing component update public virtual void OnLayoutChanges(LayoutingType layoutType) { - if (Parent==null) - return; #if DEBUG_LAYOUTING Debug.WriteLine ("Layout change: " + this.ToString () + ":" + LastSlots.ToString() + "=>" + Slot.ToString ()); #endif - + switch (layoutType) { case LayoutingType.Width: if (Width != 0 && Parent.getBounds().Width >=0) //update position in parent @@ -597,13 +560,23 @@ namespace Crow } LayoutChanged.Raise (this, new LayoutingEventArgs (layoutType)); } + /// Update layout component, this is where the computation of alignement /// and size take place - public virtual void UpdateLayout (LayoutingType layoutType) - { + /// true, if layouting was possible, false if conditions were not + /// met and LQI has to be re-queued + public virtual bool UpdateLayout (LayoutingType layoutType) + { + //unset bit, it would be reset if LQI is re-queued + registeredLayoutings &= (~layoutType); + switch (layoutType) { case LayoutingType.X: if (Bounds.X == 0) { + + if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width)) + return false; + switch (HorizontalAlignment) { case HorizontalAlignment.Left: Slot.X = 0; @@ -629,8 +602,12 @@ namespace Crow break; case LayoutingType.Y: if (Bounds.Y == 0) { + + if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Height)) + return false; + switch (VerticalAlignment) { - case VerticalAlignment.Top: + case VerticalAlignment.Top://this could be processed even if parent Height is not known Slot.Y = 0; break; case VerticalAlignment.Bottom: @@ -662,6 +639,8 @@ namespace Crow Slot.Width = Width; else if (Width < 0) Slot.Width = measureRawSize ().Width; + else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width)) + return false; else Slot.Width = Parent.ClientRectangle.Width; @@ -689,6 +668,8 @@ namespace Crow Slot.Height = Height; else if (Height < 0) Slot.Height = measureRawSize ().Height; + else if (Parent.RegisteredLayoutings.HasFlag (LayoutingType.Width)) + return false; else Slot.Height = Parent.ClientRectangle.Height; @@ -698,7 +679,6 @@ namespace Crow else if (Slot.Height > MaximumSize.Height && MaximumSize.Height > 0) Slot.Height = MaximumSize.Height; - if (LastSlots.Height == Slot.Height) break; @@ -709,9 +689,12 @@ namespace Crow LastSlots.Height = Slot.Height; break; } + //if no layouting remains in queue for item, registre for redraw - if (this.RegisteredLQINodes.Count () <= 0 && bmp == null) + if (this.registeredLayoutings == LayoutingType.None && bmp == null) this.RegisterForRedraw (); + + return true; } #endregion diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index 171abd61..fc3d8988 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -125,22 +125,23 @@ namespace Crow } } - public override void EnqueueForLayouting () - { - base.EnqueueForLayouting (); - if (RegisteredLayoutings.HasFlag(LayoutingType.PositionChildren)) - Interface.LayoutingQueue.Enqueue (LayoutingType.PositionChildren, this); - } - public override void UpdateLayout (LayoutingType layoutType) - { + public override bool UpdateLayout (LayoutingType layoutType) + { + RegisteredLayoutings &= (~layoutType); + if (layoutType == LayoutingType.PositionChildren) { + ComputeChildrenPositions (); + //if no layouting remains in queue for item, registre for redraw - if (RegisteredLQINodes.Count () <= 0 && bmp==null) + if (RegisteredLayoutings == LayoutingType.None && bmp==null) this.RegisterForRedraw (); - }else - base.UpdateLayout(layoutType); + + return true; + } + + return base.UpdateLayout(layoutType); } #endregion diff --git a/src/GraphicObjects/ILayoutable.cs b/src/GraphicObjects/ILayoutable.cs index 01d62365..b9a97b0e 100644 --- a/src/GraphicObjects/ILayoutable.cs +++ b/src/GraphicObjects/ILayoutable.cs @@ -13,9 +13,9 @@ namespace Crow IGOLibHost HostContainer { get; } - List> RegisteredLQINodes { get; } + LayoutingType RegisteredLayoutings { get; set; } void RegisterForLayouting(LayoutingType layoutType); - void UpdateLayout(LayoutingType layoutType); + bool UpdateLayout(LayoutingType layoutType); Rectangle ContextCoordinates(Rectangle r); diff --git a/src/Interface.cs b/src/Interface.cs index cf86ecf3..5ecd7a88 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -53,12 +53,9 @@ namespace Crow /// Threshold to catch borders for sizing public static int BorderThreshold = 5; - public static LayoutingQueue LayoutingQueue = new LayoutingQueue (); - public static Queue RegisteredGOForLayouting = new Queue(); + public static Queue LayoutingQueue = new Queue(); #region Load/Save - //internal static List Bindings; - public static void Save (string file, T graphicObject) { diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index 8fbd95ca..d5ad7fcc 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -46,6 +46,7 @@ namespace Crow { LayoutType = _layoutType; GraphicObject = _graphicObject; + GraphicObject.RegisteredLayoutings |= LayoutType; } public void ProcessLayouting() @@ -53,12 +54,14 @@ namespace Crow #if DEBUG_LAYOUTING Debug.WriteLine ("Layouting => " + this.ToString ()); #endif + try { if (GraphicObject.Parent == null){ Debug.WriteLine("ERROR: processLayouting, no parent for: " + GraphicObject.ToString()); return; } - GraphicObject.UpdateLayout (LayoutType); + if (!GraphicObject.UpdateLayout (LayoutType)) + Interface.LayoutingQueue.Enqueue(this); } catch (Exception ex) { Debug.WriteLine ("Layouting error: " + ex.ToString ()); } diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index bb5b67e6..12099e48 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -261,16 +261,9 @@ namespace Crow #endif //Debug.WriteLine ("======= Layouting queue start ======="); - while (Interface.RegisteredGOForLayouting.Count > 0){ - while (Interface.RegisteredGOForLayouting.Count > 0){ - GraphicObject go = Interface.RegisteredGOForLayouting.Dequeue (); - go.EnqueueForLayouting (); - go.RegisteredLayoutings = LayoutingType.None; - } - while (Interface.LayoutingQueue.First != null) { - LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue (); - lqi.ProcessLayouting (); - } + while (Interface.LayoutingQueue.Count > 0) { + LayoutingQueueItem lqi = Interface.LayoutingQueue.Dequeue (); + lqi.ProcessLayouting (); } #if MEASURE_TIME @@ -551,11 +544,12 @@ namespace Crow #endregion #region ILayoutable implementation - - //TODO:uneeded list, should be removed - public List> RegisteredLQINodes { get; } = new List>(); + public LayoutingType RegisteredLayoutings { + get { return LayoutingType.None; } + set { throw new NotImplementedException (); } + } public void RegisterForLayouting (LayoutingType layoutType) { throw new NotImplementedException (); } - public void UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } + public bool UpdateLayout (LayoutingType layoutType) { throw new NotImplementedException (); } public Rectangle ContextCoordinates (Rectangle r) { return r; -- cgit v1.3.1-4-g156e From 1c7f2d63a7230cb487faf915b9431784653f48ef Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Sat, 6 Feb 2016 17:01:28 +0100 Subject: resolved Checkbox bug (template was modified), adjust several layout registering --- Templates/CheckBox.goml | 6 ++-- Tests/Interfaces/testWindow.goml | 14 +++++++++ src/GraphicObjects/GenericStack.cs | 55 +++++++++++++++++++++++----------- src/GraphicObjects/GraphicObject.cs | 8 ++--- src/GraphicObjects/Group.cs | 19 +++++------- src/GraphicObjects/PrivateContainer.cs | 12 +++----- 6 files changed, 69 insertions(+), 45 deletions(-) (limited to 'src/GraphicObjects/GenericStack.cs') diff --git a/Templates/CheckBox.goml b/Templates/CheckBox.goml index 799bde1e..b1b224d8 100755 --- a/Templates/CheckBox.goml +++ b/Templates/CheckBox.goml @@ -3,8 +3,8 @@