From: jpbruyere Date: Wed, 10 Jun 2015 14:10:18 +0000 (+0200) Subject: - template attribute (in xml, and in c# for default one X-Git-Tag: 0.2~84 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=04f0def856c8ff46ad63cd5976a1299c0b91ac44;p=jp%2Fcrow.git - template attribute (in xml, and in c# for default one --- diff --git a/GOLib.csproj b/GOLib.csproj index 28b47450..f4109a94 100644 --- a/GOLib.csproj +++ b/GOLib.csproj @@ -168,5 +168,6 @@ + diff --git a/README.md b/README.md index b549f7aa..ad4155a6 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,14 @@ Graphic Object Library: custom widget library c# version. #####GOLib in action +![GOLib in action](/screenshot2.png?raw=true "golib") + ![GOLib in action](/magic3d.png?raw=true "Magic3d") RoadMap: -v - Implement Vertical and Horizontal layouting queue instead - of testing the whole object tree during layout. - - Implement GL textures backend, as in the c++ version -v - Validate complete drm rendering stack (OpenTK, and Cairo - already have experimental support for drm stack) - - Now the the grobal architecture is ok, develop the common controls existing in every gui lib + - TreeView, templated of course... + Menu, Popper, Combobox, PangoLayouting controls, Improved editor + - Monodevelop addin + - improve inline delegates to handle all conversion and graphic tree parsing with directory navigation syntax + - Make an easyly compilable example of complete application (3d mesh editor for example) diff --git a/Templates/Checkbox2.goml b/Templates/Checkbox2.goml new file mode 100755 index 00000000..c1962c59 --- /dev/null +++ b/Templates/Checkbox2.goml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/Tests/GOLIBTest_4.cs b/Tests/GOLIBTest_4.cs index 796aac66..8b1a9bc0 100644 --- a/Tests/GOLIBTest_4.cs +++ b/Tests/GOLIBTest_4.cs @@ -175,11 +175,11 @@ namespace test } frameCpt++; - if (pb.Value == pb.Maximum) - pb.Value = 0; - pb.Value++; +// if (pb.Value == pb.Maximum) +// pb.Value = 0; +// pb.Value++; pb2.Value = pb.Value; - labPb.Text = pb.Value.ToString (); + //labPb.Text = pb.Value.ToString (); if (FocusedWidget==null) labF.Text = "- none -"; else diff --git a/Tests/Interfaces/test4.goml b/Tests/Interfaces/test4.goml index 8b4f7691..e2fa4643 100755 --- a/Tests/Interfaces/test4.goml +++ b/Tests/Interfaces/test4.goml @@ -19,8 +19,15 @@ - - + + + + @@ -41,6 +48,8 @@ diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 065c6924..d7d19fa1 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -162,7 +162,7 @@ namespace go MemberInfo miDst = dstType.GetMember (binding.MemberName).FirstOrDefault (); MemberInfo miSrc = srcType.GetMember (binding.Value).FirstOrDefault(); - //initialize target with actual value + #region initialize target with actual value object srcVal = null; if (miSrc == null) srcVal = _source;//if no member is provided for binding, source raw value is taken @@ -187,7 +187,8 @@ namespace go fiDst.SetValue (binding.Source, srcVal ); }else throw new Exception("unandled destination member type for binding"); - + #endregion + #region Retrieve EventHandler parameter type EventInfo ei = srcType.GetEvent ("ValueChanged"); if (ei == null) @@ -199,6 +200,7 @@ namespace go #endregion + Type[] args = {typeof(object), handlerArgsType}; DynamicMethod dm = new DynamicMethod("dynHandle_" + dynHandleCpt, typeof(void), @@ -282,8 +284,7 @@ namespace go //Delegate del = dm.CreateDelegate(typeof(System.EventHandler)); addHandler.Invoke(_source, new object[] {del}); } - - + public static FieldInfo getEventHandlerField(Type type, string eventName) { FieldInfo fi; diff --git a/src/GraphicObjects/Checkbox.cs b/src/GraphicObjects/Checkbox.cs index d36f1266..0e20ddb7 100644 --- a/src/GraphicObjects/Checkbox.cs +++ b/src/GraphicObjects/Checkbox.cs @@ -16,6 +16,7 @@ using System.ComponentModel; namespace go { + [DefaultTemplate("#go.Templates.Checkbox.goml")] public class Checkbox : TemplatedControl { Label _caption; @@ -24,13 +25,13 @@ namespace go public Checkbox() : base() { } - + protected override void loadDefaultValues () + { + base.loadDefaultValues (); + } protected override void loadTemplate(GraphicObject template = null) { - if (template == null) - this.SetChild (Interface.Load ("#go.Templates.Checkbox.goml", this)); - else - this.SetChild (template); + base.loadTemplate (template); _caption = this.child.FindByName ("Caption") as Label; _image = this.child.FindByName ("Image") as Image; diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index 6f215b2f..5bf535a4 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -18,6 +18,7 @@ using System.IO; namespace go { + [DefaultTemplate("#go.Templates.Expandable.goml")] public class Expandable : TemplatedControl { bool _isExpanded; @@ -35,10 +36,7 @@ namespace go protected override void loadTemplate(GraphicObject template = null) { - if (template == null) - this.SetChild (Interface.Load ("#go.Templates.Expandable.goml",this)); - else - this.SetChild (template); + base.loadTemplate (template); _caption = this.child.FindByName ("Caption") as Label; Content = this.child.FindByName ("Content") as Container; @@ -47,6 +45,7 @@ namespace go if (_image == null) return; _image.SvgSub = "collapsed"; + this.Expand += (object sender, EventArgs e) => {_image.SvgSub = "expanded";}; this.Collapse += (object sender, EventArgs e) => {_image.SvgSub = "collapsed";}; diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index ce6db79b..a66fe7d4 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -25,6 +25,7 @@ using System.ComponentModel; namespace go { + [DefaultTemplate("#go.Templates.Listbox.goml")] public class ListBox : TemplatedControl { Group _list; @@ -36,11 +37,7 @@ namespace go #region implemented abstract members of TemplatedControl protected override void loadTemplate (GraphicObject template = null) { - if (template == null) - this.SetChild (Interface.Load ("#go.Templates.Listbox.goml")); - else - this.SetChild (template); - + base.loadTemplate (template); _list = this.child.FindByName ("List") as Group; } #endregion diff --git a/src/GraphicObjects/RadioButton.cs b/src/GraphicObjects/RadioButton.cs index 71911d68..8c8000e2 100644 --- a/src/GraphicObjects/RadioButton.cs +++ b/src/GraphicObjects/RadioButton.cs @@ -16,6 +16,7 @@ using System.ComponentModel; namespace go { + [DefaultTemplate("#go.Templates.RadioButton.goml")] public class RadioButton : TemplatedControl { Label _caption; @@ -27,10 +28,7 @@ namespace go protected override void loadTemplate(GraphicObject template = null) { - if (template == null) - this.SetChild (Interface.Load ("#go.Templates.RadioButton.goml")); - else - this.SetChild (template); + base.loadTemplate (template); _caption = this.child.FindByName ("Caption") as Label; _image = this.child.FindByName ("Image") as Image; @@ -38,7 +36,7 @@ namespace go } - [XmlAttributeAttribute()][DefaultValue("RadioButton")] + [XmlAttributeAttribute][DefaultValue("RadioButton")] public string Caption { get { return _caption.Text; } set { diff --git a/src/GraphicObjects/Spinner.cs b/src/GraphicObjects/Spinner.cs index 4bd3a723..048dd849 100644 --- a/src/GraphicObjects/Spinner.cs +++ b/src/GraphicObjects/Spinner.cs @@ -23,10 +23,9 @@ using OpenTK.Input; namespace go { + [DefaultTemplate("#go.Templates.Spinner.goml")] public class Spinner : NumericControl { -// Button butUp; -// Button butDown; Label labCpt; public Spinner (double minimum, double maximum, double step) : @@ -42,11 +41,7 @@ namespace go protected override void loadTemplate (GraphicObject template = null) { - if (template == null) - this.SetChild (Interface.Load ("#go.Templates.Spinner.goml", this)); - else - this.SetChild (template); - + base.loadTemplate (template); labCpt = this.child.FindByName ("labCpt") as Label; } diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index 75d5b54f..7c50a2ea 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -23,9 +23,21 @@ using System.Xml.Serialization; using System.ComponentModel; using System.IO; using System.Xml; +using System.Linq; +using System.Diagnostics; namespace go { + [AttributeUsage(AttributeTargets.Class)] + public class DefaultTemplate : Attribute + { + public string Path = ""; + public DefaultTemplate(string path) + { + Path = path; + } + } + public abstract class TemplatedControl : PrivateContainer, IXmlSerializable { public TemplatedControl () : base() @@ -40,7 +52,14 @@ namespace go // } - protected abstract void loadTemplate(GraphicObject template = null); + protected virtual void loadTemplate(GraphicObject template = null) + { + if (template == null) { + DefaultTemplate dt = (DefaultTemplate)this.GetType ().GetCustomAttributes (typeof(DefaultTemplate), true).FirstOrDefault(); + this.SetChild (Interface.Load (dt.Path, this)); + }else + this.SetChild (template); + } protected override void loadDefaultValues () { @@ -64,37 +83,48 @@ namespace go } public override void ReadXml(System.Xml.XmlReader reader) { + //Template could be either an attribute containing path or expressed inlined + //as a Template Element using (System.Xml.XmlReader subTree = reader.ReadSubtree()) { subTree.Read (); + + string template = reader.GetAttribute ("Template"); string tmp = subTree.ReadOuterXml (); + //Load template from path set as attribute in templated control + if (string.IsNullOrEmpty (template)) { //seek for template tag first - using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) { - //load template first if inlined + using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) { + //load template first if inlined - xr.Read (); //skip current node + xr.Read (); //skip current node - while (!xr.EOF) { - xr.Read (); //read first child - if (!xr.IsStartElement ()) - continue; - if (xr.Name == "Template") { - xr.Read (); + while (!xr.EOF) { + xr.Read (); //read first child + if (!xr.IsStartElement ()) + continue; + if (xr.Name == "Template") { + xr.Read (); - Type t = Type.GetType ("go." + xr.Name); - GraphicObject go = (GraphicObject)Activator.CreateInstance (t); - (go as IXmlSerializable).ReadXml (xr); + Type t = Type.GetType ("go." + xr.Name); + GraphicObject go = (GraphicObject)Activator.CreateInstance (t); + (go as IXmlSerializable).ReadXml (xr); - loadTemplate (go); + loadTemplate (go); - xr.Read ();//go close tag - xr.Read ();//Template close tag - } else { - xr.ReadInnerXml (); + xr.Read ();//go close tag + xr.Read ();//Template close tag + } else { + xr.ReadInnerXml (); + } } - } - } + } + } else + loadTemplate (Interface.Load (template, this)); + + + //normal xml read using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) { xr.Read (); base.ReadXml(xr);