From 4464d8c4d183a963a0c39f5eea393529ebbbc013 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Fri, 21 Aug 2015 16:13:12 +0200 Subject: [PATCH] Item template property for listbox, added ItemTemplate for testTypeViewer --- Tests/GOLIBTest_TypeViewer.cs | 23 ++++++++++++++++++++--- Tests/Interfaces/itemTmp.goml | 8 ++++++++ Tests/Interfaces/testTypeViewer.goml | 17 +++++++++++------ Tests/Interfaces/tmpMembers.goml | 8 ++++++++ Tests/Tests.csproj | 8 +++++++- src/GraphicObjects/ListBox.cs | 12 ++++++++++-- src/GraphicObjects/TemplatedControl.cs | 14 ++++++++++---- 7 files changed, 74 insertions(+), 16 deletions(-) create mode 100755 Tests/Interfaces/itemTmp.goml create mode 100755 Tests/Interfaces/tmpMembers.goml diff --git a/Tests/GOLIBTest_TypeViewer.cs b/Tests/GOLIBTest_TypeViewer.cs index 26f8c7cf..347e06dc 100644 --- a/Tests/GOLIBTest_TypeViewer.cs +++ b/Tests/GOLIBTest_TypeViewer.cs @@ -12,6 +12,7 @@ using System.Diagnostics; //using GGL; using go; using System.Threading; +using System.Reflection; namespace test @@ -22,13 +23,13 @@ namespace test : base(1024, 600,"test") {} - Border g; - Type type; + VerticalStack g; + TypeContainer type; protected override void OnLoad (EventArgs e) { base.OnLoad (e); - type = typeof (GraphicObject); + type = new TypeContainer(typeof (GraphicObject)); this.AddWidget(Interface.Load ("Interfaces/testTypeViewer.goml", type)); //LoadInterface("Interfaces/testTypeViewer.goml", out g); @@ -39,6 +40,9 @@ namespace test GL.Clear (ClearBufferMask.ColorBufferBit); base.OnRenderFrame (e); SwapBuffers (); + + MemberInfo mi; + } [STAThread] @@ -51,4 +55,17 @@ namespace test } } } + public class TypeContainer + { + public Type Type; + public TypeContainer(Type _type){ + Type = _type; + } + public string Name { + get { return Type.Name; } + } + public MemberInfo[] Members { + get { return Type.GetProperties (BindingFlags.Public | BindingFlags.Instance); } + } + } } \ No newline at end of file diff --git a/Tests/Interfaces/itemTmp.goml b/Tests/Interfaces/itemTmp.goml new file mode 100755 index 00000000..5e064e2f --- /dev/null +++ b/Tests/Interfaces/itemTmp.goml @@ -0,0 +1,8 @@ + + + + diff --git a/Tests/Interfaces/testTypeViewer.goml b/Tests/Interfaces/testTypeViewer.goml index c4438c48..7cec7286 100755 --- a/Tests/Interfaces/testTypeViewer.goml +++ b/Tests/Interfaces/testTypeViewer.goml @@ -1,12 +1,17 @@  - - - + + - + + - \ No newline at end of file diff --git a/Tests/Interfaces/tmpMembers.goml b/Tests/Interfaces/tmpMembers.goml new file mode 100755 index 00000000..c86f1574 --- /dev/null +++ b/Tests/Interfaces/tmpMembers.goml @@ -0,0 +1,8 @@ + + + + diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 17d12993..8fa16474 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -8,7 +8,7 @@ Exe Tests Tests - test.GOLIBTest_TypeViewer + test.GOLIBTest_4 v4.5 ..\bin\$(configuration) obj\$(configuration) @@ -131,6 +131,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index a66fe7d4..117dd626 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -26,6 +26,7 @@ using System.ComponentModel; namespace go { [DefaultTemplate("#go.Templates.Listbox.goml")] + //[DefaultTemplate("#go.Templates.ItemTemplate.goml")] public class ListBox : TemplatedControl { Group _list; @@ -44,13 +45,19 @@ namespace go ICollection data; int _selectedIndex; + string _itemTemplate; + [XmlAttributeAttribute][DefaultValue("#go.Templates.ItemTemplate.goml")] + public string ItemTemplate { + get { return _itemTemplate; } + set { _itemTemplate = value; } + } public int SelectedIndex{ get { return _selectedIndex; } set { _selectedIndex = value; } } - [XmlAttributeAttribute()][DefaultValue(null)] + [XmlAttributeAttribute][DefaultValue(null)] public ICollection Data { get { return data; @@ -62,7 +69,8 @@ namespace go if (data == null) return; foreach (var item in data) { - GraphicObject g = Interface.Load ("#go.Templates.ItemTemplate.goml", item); + GraphicObject g = Interface.Load (ItemTemplate, item); + //GraphicObject g = Interface.Load ("#go.Templates.Listbox.goml", item); // g.Tag = item; // g.MouseClick += (object sender, OpenTK.Input.MouseButtonEventArgs e) => { // diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index 7c50a2ea..d8af0bdf 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -37,6 +37,15 @@ namespace go Path = path; } } + [AttributeUsage(AttributeTargets.Class)] + public class DefaultItemTemplate : Attribute + { + public string Path = ""; + public DefaultItemTemplate(string path) + { + Path = path; + } + } public abstract class TemplatedControl : PrivateContainer, IXmlSerializable { @@ -77,10 +86,7 @@ namespace go #region IXmlSerializable - public override System.Xml.Schema.XmlSchema GetSchema() - { - return null; - } + public override System.Xml.Schema.XmlSchema GetSchema(){ return null; } public override void ReadXml(System.Xml.XmlReader reader) { //Template could be either an attribute containing path or expressed inlined -- 2.47.3