]> O.S.I.I.S - jp/crow.git/commitdiff
- template attribute (in xml, and in c# for default one
authorjpbruyere <jp.bruyere@hotmail.com>
Wed, 10 Jun 2015 14:10:18 +0000 (16:10 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Wed, 10 Jun 2015 14:10:18 +0000 (16:10 +0200)
12 files changed:
GOLib.csproj
README.md
Templates/Checkbox2.goml [new file with mode: 0755]
Tests/GOLIBTest_4.cs
Tests/Interfaces/test4.goml
src/CompilerServices/CompilerServices.cs
src/GraphicObjects/Checkbox.cs
src/GraphicObjects/Expandable.cs
src/GraphicObjects/ListBox.cs
src/GraphicObjects/RadioButton.cs
src/GraphicObjects/Spinner.cs
src/GraphicObjects/TemplatedControl.cs

index 28b47450458348b16c575f1218a15f0b61da23fe..f4109a94918dc0ff77b08aaf67ef5009c2dc099b 100644 (file)
     <EmbeddedResource Include="Templates\ComboListOverlay.goml" />\r
     <EmbeddedResource Include="Templates\Expandable.goml" />\r
     <EmbeddedResource Include="Images\Icons\expandable.svg" />\r
+    <EmbeddedResource Include="Templates\Checkbox2.goml" />\r
   </ItemGroup>\r
 </Project>\r
index b549f7aa3dfa3d3441e64dedf403bd621568d929..ad4155a6e4d271cb5868fef01baca398547b0f34 100644 (file)
--- 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 (executable)
index 0000000..c1962c5
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0"?>\r
+<HorizontalStack Margin="0" Spacing="1" Focusable="false">\r
+       <Image Name="Image" Width="16" Height="16" Path="#go.Images.Icons.checkbox.svg"/>\r
+       <Label Name="Caption" Background="Red"/>\r
+</HorizontalStack>
\ No newline at end of file
index 796aac6627d6c2cb03ddc25676809fd29773c8e2..8b1a9bc0e1c2d04a5df16b746e1df46f0b45e8a1 100644 (file)
@@ -175,11 +175,11 @@ namespace test
                        }\r
                        frameCpt++;\r
 \r
-                       if (pb.Value == pb.Maximum)\r
-                               pb.Value = 0;\r
-                       pb.Value++;\r
+//                     if (pb.Value == pb.Maximum)\r
+//                             pb.Value = 0;\r
+//                     pb.Value++;\r
                        pb2.Value = pb.Value;\r
-                       labPb.Text = pb.Value.ToString ();\r
+                       //labPb.Text = pb.Value.ToString ();\r
                        if (FocusedWidget==null)\r
                                labF.Text = "- none -";\r
                        else\r
index 8b4f769121711a5221685e8ba62f4a8d234a24dc..e2fa4643f072e6829259512e4024716373e4fd77 100755 (executable)
                                        <VerticalStack Width="100">\r
                                                <Checkbox Name="chk1"/>\r
                                                <Checkbox Name="chk2" IsChecked="true"/>\r
-                                               <Checkbox Name="chk3"/>\r
-                                               <Checkbox Name="chk4"/>\r
+                                               <Checkbox Name="chk3" Template="#go.Templates.Checkbox2.goml"/>\r
+                                               <Checkbox Name="chk4">\r
+                                                       <Template>\r
+                                                               <HorizontalStack Margin="0" Spacing="1" Focusable="false">\r
+                                                                       <Image Name="Image" Width="16" Height="16" Path="#go.Images.Icons.checkbox.svg"/>\r
+                                                                       <Label Name="Caption" Foreground="Black" Background="Yellow"/>\r
+                                                               </HorizontalStack>\r
+                                                       </Template>\r
+                                               </Checkbox>\r
                                        </VerticalStack>\r
                                        <VerticalStack Width="100">\r
                                                <RadioButton IsChecked="true"/>\r
@@ -41,6 +48,8 @@
                                <HorizontalStack Name="hsPbar" Margin="5">\r
                                        <ProgressBar Name="pbBar" \r
                                                Width="100" Height="20"\r
+                                               Minimum="0"\r
+                                               Maximum="200"\r
                                                Value="50"\r
                                                Foreground="BlueCrayola" Background="DarkGray"\r
                                                BorderWidth="2" BorderColor="White"/>\r
index 065c6924e2fadeeb0c7ff7d7144df68ba283680a..d7d19fa1b7c7db9ec1a8b15522a80b49696cd92c 100644 (file)
@@ -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;
index d36f1266f5c72ddc812953456e50763aed3743ba..0e20ddb700373757aafa34f8d3d3d79996bb137e 100644 (file)
@@ -16,6 +16,7 @@ using System.ComponentModel;
 \r
 namespace go\r
 {\r
+       [DefaultTemplate("#go.Templates.Checkbox.goml")]\r
     public class Checkbox : TemplatedControl\r
     {                  \r
                Label _caption;\r
@@ -24,13 +25,13 @@ namespace go
                public Checkbox() : base()\r
                {\r
                }       \r
-\r
+               protected override void loadDefaultValues ()\r
+               {\r
+                       base.loadDefaultValues ();\r
+               }\r
                protected override void loadTemplate(GraphicObject template = null)\r
                {                       \r
-                       if (template == null)\r
-                               this.SetChild (Interface.Load ("#go.Templates.Checkbox.goml", this));\r
-                       else\r
-                               this.SetChild (template);\r
+                       base.loadTemplate (template);\r
 \r
                        _caption = this.child.FindByName ("Caption") as Label;\r
                        _image = this.child.FindByName ("Image") as Image;\r
index 6f215b2fe8e126aa8a6d407ca3c506cdfacc7da2..5bf535a45ff128cc1c527ef8bc292010b1714ac5 100644 (file)
@@ -18,6 +18,7 @@ using System.IO;
 \r
 namespace go\r
 {\r
+       [DefaultTemplate("#go.Templates.Expandable.goml")]\r
     public class Expandable : TemplatedControl\r
     {          \r
                bool _isExpanded;\r
@@ -35,10 +36,7 @@ namespace go
 \r
                protected override void loadTemplate(GraphicObject template = null)\r
                {\r
-                       if (template == null)\r
-                               this.SetChild (Interface.Load ("#go.Templates.Expandable.goml",this));\r
-                       else\r
-                               this.SetChild (template);\r
+                       base.loadTemplate (template);\r
 \r
                        _caption = this.child.FindByName ("Caption") as Label;\r
                        Content = this.child.FindByName ("Content") as Container;\r
@@ -47,6 +45,7 @@ namespace go
                        if (_image == null)\r
                                return;\r
                        _image.SvgSub = "collapsed";\r
+\r
                        this.Expand += (object sender, EventArgs e) => {_image.SvgSub = "expanded";};\r
                        this.Collapse += (object sender, EventArgs e) => {_image.SvgSub = "collapsed";};\r
 \r
index ce6db79b078beefbe5aad3b0c1a6c7029ee7f975..a66fe7d4efd5e2b7ff18584abcdf6b24c07fa325 100644 (file)
@@ -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
index 71911d6801312d91832fdadcd30568161f582aab..8c8000e28017df5bb87655bdcc93797871944e4d 100644 (file)
@@ -16,6 +16,7 @@ using System.ComponentModel;
 \r
 namespace go\r
 {\r
+       [DefaultTemplate("#go.Templates.RadioButton.goml")]\r
     public class RadioButton : TemplatedControl\r
     {                  \r
                Label _caption;\r
@@ -27,10 +28,7 @@ namespace go
 \r
                protected override void loadTemplate(GraphicObject template = null)\r
                {\r
-                       if (template == null)\r
-                               this.SetChild (Interface.Load ("#go.Templates.RadioButton.goml"));\r
-                       else\r
-                               this.SetChild (template);\r
+                       base.loadTemplate (template);\r
 \r
                        _caption = this.child.FindByName ("Caption") as Label;\r
                        _image = this.child.FindByName ("Image") as Image;\r
@@ -38,7 +36,7 @@ namespace go
                }\r
                        \r
 \r
-               [XmlAttributeAttribute()][DefaultValue("RadioButton")]\r
+               [XmlAttributeAttribute][DefaultValue("RadioButton")]\r
                public string Caption {\r
                        get { return _caption.Text; } \r
                        set { \r
index 4bd3a723b005b45e68ed9ec9e71648effdc589d4..048dd84996b1a9f1e3ace82778b8e564377c07d7 100644 (file)
@@ -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;
                }
 
index 75d5b54ffb23287c9b06d4f3e55a5141e901d55f..7c50a2ea8c67725f002900684443c2239c4e43cd 100644 (file)
@@ -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);