diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-05 20:38:00 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2016-02-05 20:38:00 +0100 |
| commit | 9e7f05bfc4a9f47bf11ca44842c0dd92def4d5aa (patch) | |
| tree | 59955d569a318c93851fa107d7ae14da0152407f /src/GraphicObjects | |
| parent | 759f4f39e3fdde1f9ed8b620af51e05d052d8964 (diff) | |
new layouting update through events
Diffstat (limited to 'src/GraphicObjects')
| -rw-r--r-- | src/GraphicObjects/GenericStack.cs | 37 | ||||
| -rw-r--r-- | src/GraphicObjects/GraphicObject.cs | 36 | ||||
| -rw-r--r-- | src/GraphicObjects/Group.cs | 82 | ||||
| -rw-r--r-- | src/GraphicObjects/PrivateContainer.cs | 20 | ||||
| -rw-r--r-- | src/GraphicObjects/Spinner.cs | 17 |
5 files changed, 121 insertions, 71 deletions
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 diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index fe010d6a..53dee9cc 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -565,44 +565,12 @@ namespace Crow switch (layoutType) { case LayoutingType.Width: - if (Parent.getBounds ().Width < 0) { - Group gw = Parent as Group; - if (gw != null) { - if (Slot.Width > gw.maxChildrenWidth) - gw.maxChildrenWidth = Slot.Width; - } - this.Parent.RegisterForLayouting ((int)LayoutingType.Width); - }else if (Width != 0) //update position in parent + if (Width != 0 && Parent.getBounds().Width >=0) //update position in parent this.RegisterForLayouting ((int)LayoutingType.X); - GenericStack gsw = Parent as GenericStack; - if (gsw == null) - break; - if ((Parent as GenericStack).Orientation == Orientation.Horizontal) { -// ulong idx = (ulong)gsw.Children.IndexOf (this); -// if (idx < gsw.stackingUpdateStartIndex) -// gsw.stackingUpdateStartIndex = idx; - this.Parent.RegisterForLayouting ((int)LayoutingType.PositionChildren); - } break; case LayoutingType.Height: - if (Parent.getBounds ().Height < 0) { - Group gh = Parent as Group; - if (gh != null) { - if (Slot.Width > gh.maxChildrenHeight) - gh.maxChildrenHeight = Slot.Height; - } - this.Parent.RegisterForLayouting ((int)LayoutingType.Height); - }else if (Height != 0) //update position in parent + if (Height != 0 && Parent.getBounds().Height >=0) //update position in parent this.RegisterForLayouting ((int)LayoutingType.Y); - GenericStack gsh = Parent as GenericStack; - if (gsh==null) - break; - if (gsh.Orientation == Orientation.Vertical) { -// ulong idx = (ulong)gsh.Children.IndexOf (this); -// if (idx < gsh.stackingUpdateStartIndex) -// gsh.stackingUpdateStartIndex = idx; - this.Parent.RegisterForLayouting ((int)LayoutingType.PositionChildren); - } break; } LayoutChanged.Raise (this, new LayoutChangeEventArgs (layoutType)); diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 7f952ac1..a9870c78 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -25,6 +25,8 @@ namespace Crow internal int maxChildrenWidth = 0; internal int maxChildrenHeight = 0; + internal GraphicObject largestChild = null; + internal GraphicObject tallestChild = null; bool _multiSelect = false; List<GraphicObject> children = new List<GraphicObject>(); @@ -49,10 +51,12 @@ namespace Crow Children.Add(g); g.Parent = this as GraphicObject; g.RegisterForLayouting ((int)LayoutingType.Sizing); + g.LayoutChanged += OnChildLayoutChanges; return (T)child; } public virtual void removeChild(GraphicObject child) - { + { + child.LayoutChanged -= OnChildLayoutChanges; child.ClearBinding (); child.Parent = null; Children.Remove(child); @@ -60,12 +64,14 @@ namespace Crow } public virtual void ClearChildren() { - int lim = children.Count; - for (int i = 0; i < lim; i++) { - GraphicObject g = Children [0]; + int cpt = children.Count; + while(cpt > 0){ + GraphicObject g = children[cpt-1]; + g.LayoutChanged -= OnChildLayoutChanges; g.ClearBinding (); g.Parent = null; - Children.Remove(g); + Children.RemoveAt(cpt-1); + cpt = children.Count; } this.RegisterForLayouting ((int)LayoutingType.Sizing); ChildrenCleared.Raise (this, new EventArgs ()); @@ -86,7 +92,7 @@ namespace Crow Children.Insert(0, w); } } - + #region GraphicObject overrides [XmlIgnore]public override bool DrawingIsValid { get { @@ -136,16 +142,9 @@ namespace Crow { base.OnLayoutChanges (layoutType); - GenericStack gs = this as GenericStack; //position smaller objects in group when group size is fit switch (layoutType) { case LayoutingType.Width: - if (gs != null) { - if (gs.Orientation == Orientation.Horizontal) { - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); - break; - } - } foreach (GraphicObject c in Children.Where(ch => ch.Visible)) { if (c.getBounds ().Width == 0) c.RegisterForLayouting ((int)LayoutingType.Width); @@ -154,12 +153,6 @@ namespace Crow } break; case LayoutingType.Height: - if (gs != null) { - if (gs.Orientation == Orientation.Vertical) { - this.RegisterForLayouting ((int)LayoutingType.PositionChildren); - break; - } - } foreach (GraphicObject c in Children.Where(ch => ch.Visible)) { if (c.getBounds ().Height == 0) c.RegisterForLayouting ((int)LayoutingType.Height); @@ -169,7 +162,56 @@ namespace Crow break; } } - + public virtual void OnChildLayoutChanges (object sender, LayoutChangeEventArgs arg) + { + GraphicObject g = sender as GraphicObject; + switch (arg.LayoutType) { + case LayoutingType.X: + break; + case LayoutingType.Y: + break; + case LayoutingType.Width: + if (g.Slot.Width > maxChildrenWidth) { + maxChildrenWidth = g.Slot.Width; + largestChild = g; + if (this.Bounds.Width < 0) + this.RegisterForLayouting ((int)LayoutingType.Width); + } else if (g == largestChild) { + //search for the new largest child + largestChild = null; + maxChildrenWidth = 0; + for (int i = 0; i < children.Count; i++) { + if (children [i].Slot.Width > maxChildrenWidth) { + maxChildrenWidth = children [i].Slot.Width; + largestChild = children [i]; + } + } + if (this.Bounds.Width < 0) + this.RegisterForLayouting ((int)LayoutingType.Width); + } + break; + case LayoutingType.Height: + if (g.Slot.Height > maxChildrenHeight) { + maxChildrenHeight = g.Slot.Height; + tallestChild = g; + if (this.Bounds.Height < 0) + this.RegisterForLayouting ((int)LayoutingType.Height); + } else if (g == tallestChild) { + //search for the new tallest child + tallestChild = null; + maxChildrenHeight = 0; + for (int i = 0; i < children.Count; i++) { + if (children [i].Slot.Height > maxChildrenHeight) { + maxChildrenHeight = children [i].Slot.Height; + tallestChild = children [i]; + } + } + if (this.Bounds.Height < 0) + this.RegisterForLayouting ((int)LayoutingType.Height); + } + break; + } + } public override Rectangle ContextCoordinates(Rectangle r){ return r + ClientRectangle.Position; } diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index f4190f9b..9b312c14 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -52,6 +52,7 @@ namespace Crow { if (child != null) { + child.LayoutChanged -= OnChildLayoutChanges; this.RegisterForLayouting ((int)LayoutingType.Sizing); child.Parent = null; } @@ -60,6 +61,7 @@ namespace Crow if (child != null) { child.Parent = this; + child.LayoutChanged += OnChildLayoutChanges; child.RegisterForLayouting ((int)LayoutingType.Sizing); } @@ -117,6 +119,24 @@ namespace Crow break; } } + public virtual void OnChildLayoutChanges (object sender, LayoutChangeEventArgs arg) + { + GraphicObject g = sender as GraphicObject; + switch (arg.LayoutType) { + case LayoutingType.X: + break; + case LayoutingType.Y: + break; + case LayoutingType.Width: + if (this.Bounds.Width < 0) + this.RegisterForLayouting ((int)LayoutingType.Width); + break; + case LayoutingType.Height: + if (this.Bounds.Height < 0) + this.RegisterForLayouting ((int)LayoutingType.Height); + break; + } + } public override Rectangle ContextCoordinates (Rectangle r) { diff --git a/src/GraphicObjects/Spinner.cs b/src/GraphicObjects/Spinner.cs index a44abb13..49d323e0 100644 --- a/src/GraphicObjects/Spinner.cs +++ b/src/GraphicObjects/Spinner.cs @@ -35,29 +35,12 @@ namespace Crow { } - #region implemented abstract members of TemplatedControl - - protected override void loadTemplate (GraphicObject template = null) - { - base.loadTemplate (template); - } - - #endregion - void onUp (object sender, MouseButtonEventArgs e) { -// decimal tmp = 0; -// if (!decimal.TryParse (labCpt.Text, out tmp)) -// return; - Value += this.SmallIncrement; } void onDown (object sender, MouseButtonEventArgs e) { -// decimal tmp = 0; -// if (!decimal.TryParse (labCpt.Text, out tmp)) -// return; - Value -= this.SmallIncrement; } |