From 77f7028debf55a8d6faff8e88c18e33500867774 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Tue, 2 Aug 2016 00:06:25 +0200 Subject: [PATCH] =?utf8?q?Debug=20contentSize=20for=20Stack=20when=20stack?= =?utf8?q?=20sizing=20policy=20changed.=20=09modifi=C3=A9=C2=A0:=20=20=20?= =?utf8?q?=20=20=20=20=20=20src/GraphicObjects/GraphicObject.cs=20queue=20?= =?utf8?q?drawing=20without=20layouting=20when=20not=20required=20=09modif?= =?utf8?q?i=C3=A9=C2=A0:=20=20=20=20=20=20=20=20=20src/GraphicObjects/Labe?= =?utf8?q?l.cs?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/GraphicObjects/GraphicObject.cs | 61 +++++++++++++++++++++-------- src/GraphicObjects/Label.cs | 2 +- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index d610398e..7a2e8ec5 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -241,10 +241,22 @@ namespace Crow if (value < MinimumSize.Width || (value > MaximumSize.Width && MaximumSize.Width > 0)) return; } - + Measure lastWP = WidthPolicy; _width = value; NotifyValueChanged ("Width", _width); - NotifyValueChanged ("WidthPolicy", WidthPolicy); + if (WidthPolicy != lastWP) { + NotifyValueChanged ("WidthPolicy", WidthPolicy); + //contentSize in Stacks are only update on childLayoutChange, and the single stretched + //child of the stack is not counted in contentSize, so when changing size policy of a child + //we should adapt contentSize + //TODO:check case when child become stretched, and another stretched item already exists. + if (_parent is GenericStack) {//TODO:check if I should test Group instead + if (lastWP == Measure.Fit) + (_parent as GenericStack).contentSize.Width -= this.LastSlots.Width; + else + (_parent as GenericStack).contentSize.Width += this.LastSlots.Width; + } + } this.RegisterForLayouting (LayoutingType.Width); } @@ -259,10 +271,18 @@ namespace Crow if (value < MinimumSize.Height || (value > MaximumSize.Height && MaximumSize.Height > 0)) return; } - + Measure lastHP = HeightPolicy; _height = value; NotifyValueChanged ("Height", _height); - NotifyValueChanged ("HeightPolicy", HeightPolicy); + if (HeightPolicy != lastHP) { + NotifyValueChanged ("HeightPolicy", HeightPolicy); + if (_parent is GenericStack) { + if (lastHP == Measure.Fit) + (_parent as GenericStack).contentSize.Height -= this.LastSlots.Height; + else + (_parent as GenericStack).contentSize.Height += this.LastSlots.Height; + } + } this.RegisterForLayouting (LayoutingType.Height); } @@ -497,14 +517,16 @@ namespace Crow Interface.DefaultValuesLoader [Style] (this); return; } - } - if (Interface.DefaultValuesLoader.ContainsKey (thisType.FullName)) { - Interface.DefaultValuesLoader [thisType.FullName] (this); - return; - } - if (Interface.DefaultValuesLoader.ContainsKey (thisType.Name)) { - Interface.DefaultValuesLoader [thisType.Name] (this); - return; + } else { + if (Interface.DefaultValuesLoader.ContainsKey (thisType.FullName)) { + Interface.DefaultValuesLoader [thisType.FullName] (this); + return; + } else if (!Interface.Styling.ContainsKey (thisType.FullName)) { + if (Interface.DefaultValuesLoader.ContainsKey (thisType.Name)) { + Interface.DefaultValuesLoader [thisType.Name] (this); + return; + } + } } List> styling = new List>(); @@ -582,7 +604,10 @@ namespace Crow } } if (styleIndex >= 0){ - defaultValue = styling[styleIndex] [name]; + if (pi.PropertyType.IsEnum)//maybe should be in parser.. + defaultValue = Enum.Parse(pi.PropertyType, (string)styling[styleIndex] [name], true); + else + defaultValue = styling[styleIndex] [name]; }else { DefaultValueAttribute dv = (DefaultValueAttribute)pi.GetCustomAttribute (typeof (DefaultValueAttribute)); if (dv == null) @@ -685,8 +710,12 @@ namespace Crow il.Emit(OpCodes.Ret); #endregion - Interface.DefaultValuesLoader[styleKey] = (Interface.loadDefaultInvoker)dm.CreateDelegate(typeof(Interface.loadDefaultInvoker)); - Interface.DefaultValuesLoader[styleKey] (this); + try { + Interface.DefaultValuesLoader[styleKey] = (Interface.loadDefaultInvoker)dm.CreateDelegate(typeof(Interface.loadDefaultInvoker)); + Interface.DefaultValuesLoader[styleKey] (this); + } catch (Exception ex) { + throw new Exception ("Error applying style <" + styleKey + ">:", ex); + } } public virtual GraphicObject FindByName(string nameToFind){ @@ -723,7 +752,7 @@ namespace Crow get { return layoutingTries; } set { layoutingTries = value; } } - protected Size contentSize; + internal Size contentSize; /// return size of content + margins protected virtual int measureRawSize (LayoutingType lt) { return lt == LayoutingType.Width ? diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index a3343232..2f5798ee 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -101,7 +101,7 @@ namespace Crow if (value == _textAlignment) return; _textAlignment = value; - RegisterForGraphicUpdate (); + RegisterForRedraw (); NotifyValueChanged ("TextAlignment", _textAlignment); } } -- 2.47.3