]> O.S.I.I.S - jp/crow.git/commitdiff
Templated Groupbox
authorjpbruyere <jp.bruyere@hotmail.com>
Tue, 15 Sep 2015 09:30:06 +0000 (11:30 +0200)
committerjpbruyere <jp.bruyere@hotmail.com>
Tue, 15 Sep 2015 09:30:06 +0000 (11:30 +0200)
GOLib.csproj
Templates/Groupbox.goml [new file with mode: 0755]
Tests/Interfaces/testBorder.goml [new file with mode: 0755]
Tests/Interfaces/testGroupBox.goml [new file with mode: 0755]
Tests/Interfaces/testWindow.goml
src/GraphicObjects/Border.cs
src/GraphicObjects/GroupBox.cs [deleted file]
src/GraphicObjects/Groupbox.cs [new file with mode: 0644]

index 4fac6677a44c9ea1e01f7f372557a9091b3b54c9..8fcc21bb7150a4910474705f69decdd866e78496 100644 (file)
@@ -64,7 +64,6 @@
     <Compile Include="src\GraphicObjects\GraphicObject.cs" />\r
     <Compile Include="src\GraphicObjects\Container.cs" />\r
     <Compile Include="src\GraphicObjects\Group.cs" />\r
-    <Compile Include="src\GraphicObjects\GroupBox.cs" />\r
     <Compile Include="src\GraphicObjects\HorizontalStack.cs" />\r
     <Compile Include="src\GraphicObjects\Image.cs" />\r
     <Compile Include="src\GraphicObjects\Label.cs" />\r
     <Compile Include="src\GraphicObjects\Grid.cs" />\r
     <Compile Include="src\GraphicObjects\TextRun.cs" />\r
     <Compile Include="src\GraphicObjects\MessageBox.cs" />\r
+    <Compile Include="src\GraphicObjects\Groupbox.cs" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <Reference Include="System" />\r
     <EmbeddedResource Include="Images\button.svg" />\r
     <EmbeddedResource Include="Templates\MessageBox.goml" />\r
     <EmbeddedResource Include="Images\Icons\iconInfo.svg" />\r
+    <EmbeddedResource Include="Templates\Groupbox.goml" />\r
   </ItemGroup>\r
   <ItemGroup>\r
     <None Include="Images\Icons\Cursors\hand" />\r
diff --git a/Templates/Groupbox.goml b/Templates/Groupbox.goml
new file mode 100755 (executable)
index 0000000..d804aab
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<Group Height="{TemplatedHeight}" Width="{TemplatedWidth}">
+       <Border CornerRadius="5" BorderWidth="1" Margin="6"
+               Height="{TemplatedHeight}" Width="{TemplatedWidth}">
+               <Container Name="Content" Margin="10"
+                               Height="{TemplatedHeight}" Width="{TemplatedWidth}"/>
+       </Border>
+       <Label Text="{Title}" VerticalAlignment="Top" Left="15"
+               Background="Clear" Margin="1"/>
+</Group>
\ No newline at end of file
diff --git a/Tests/Interfaces/testBorder.goml b/Tests/Interfaces/testBorder.goml
new file mode 100755 (executable)
index 0000000..15ecba3
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>\r
+<GroupBox Width="-1" Height="-1" Background="Red">\r
+       <VerticalStack Margin="0">\r
+               <Checkbox />\r
+\r
+       </VerticalStack>\r
+</GroupBox>\r
diff --git a/Tests/Interfaces/testGroupBox.goml b/Tests/Interfaces/testGroupBox.goml
new file mode 100755 (executable)
index 0000000..712a485
--- /dev/null
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>\r
+<Expandable Title="Test expandable" Width="150" Background="DimGray">\r
+               <VerticalStack Width="100" Height="-1">\r
+                       <Checkbox Name="chk1"/>\r
+                       <Checkbox Name="chk2" IsChecked="true"/>\r
+                       <Checkbox Name="chk3"/>\r
+                       <Checkbox Name="chk4"/>\r
+               </VerticalStack>                \r
+</Expandable>\r
index 1f5cf4e422eabad8094eebaf8dc7d21e7e5b888f..740cfc538b7757f9ef7d5ba1670a2b1ced1752c3 100755 (executable)
                        <GraphicObject Width="0"/>\r
                        <Checkbox Height="-1" Width="80"/>\r
                </HorizontalStack>\r
-               <GroupBox Text="test"  Height="-1" Width="0" Margin="5">\r
+               <Groupbox Text="test"  Height="-1" Width="-1" Margin="5">\r
                        <VerticalStack  Height="-1" Width="0" >\r
                                <RadioButton  Caption="Radio 1" Background="Red" />\r
                                <RadioButton  Caption="Radio 2" IsChecked="true" />\r
                                <RadioButton  Caption="Radio 3" />\r
                        </VerticalStack>\r
-               </GroupBox>\r
+               </Groupbox>\r
 <!--           <Checkbox Height="-1" Width="-1" Background="Red" Margin="0" VerticalAlignment="Center" HorizontalAlignment="Right"/>-->\r
        </VerticalStack>\r
 </Window>\r
index 1bc2b7291f3fb2a887a0bd16b8da263351879fa7..84adfc0ab9dc216eca3ad7e49161e9887b5806e2 100644 (file)
@@ -1,6 +1,7 @@
 using System;
 using System.Xml.Serialization;
 using System.ComponentModel;
+using System.Diagnostics;
 
 namespace go
 {
diff --git a/src/GraphicObjects/GroupBox.cs b/src/GraphicObjects/GroupBox.cs
deleted file mode 100644 (file)
index a9c3cc1..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-using System;\r
-using System.Collections.Generic;\r
-using System.ComponentModel;\r
-using System.Text;\r
-using System.Xml.Serialization;\r
-using Cairo;\r
-\r
-namespace go\r
-{\r
-\r
-       public class GroupBox : Border\r
-    {\r
-               #region CTOR\r
-               public GroupBox() : base (){\r
-               }\r
-               public GroupBox(string _title = "GroupBox")\r
-                       : base()\r
-               {\r
-                       Text = _title;            \r
-               }\r
-               #endregion\r
-\r
-               #region private fields\r
-        string _title;\r
-               Font _font;\r
-               #endregion\r
-\r
-               #region public properties\r
-        [XmlAttributeAttribute][DefaultValue("GroupBox")]\r
-        public string Text\r
-        {\r
-            get { return _title; }\r
-            set\r
-            {\r
-                _title = value;\r
-                               NotifyValueChanged ("Text", _title);\r
-                registerForGraphicUpdate();\r
-            }\r
-        }        \r
-               #endregion\r
-\r
-        Size titleSize {\r
-                       get {\r
-#if _WIN32 || _WIN64\r
-            byte[] txt = System.Text.UTF8Encoding.UTF8.GetBytes(_title);\r
-#endif\r
-\r
-                               Size s;\r
-\r
-                               using (ImageSurface img = new ImageSurface (Format.Argb32, 1, 1)) {\r
-                                       using (Context gr = new Context (img)) {\r
-                                               gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);\r
-                                               gr.SetFontSize (Font.Size);\r
-                                               TextExtents te;\r
-#if _WIN32 || _WIN64\r
-                te = gr.TextExtents(txt);\r
-#elif __linux__\r
-                                               te = gr.TextExtents (Text);\r
-#endif\r
-                                               FontExtents fe = gr.FontExtents;\r
-                                               s = new Size ((int)Math.Ceiling (te.XAdvance), (int)Math.Ceiling (fe.Height));\r
-                                       }\r
-                               }\r
-                               return s;// +borderWidth;\r
-                       }\r
-               }\r
-\r
-               #region GraphicObject overrides\r
-               public override Rectangle ClientRectangle {\r
-                       get {\r
-                               Size ts = titleSize;\r
-                               Rectangle cb = Slot.Size;\r
-                               cb.Y = ts.Height;\r
-                               cb.Height -= ts.Height;\r
-                               cb.Inflate ( - Margin);\r
-                               return cb;\r
-                       }\r
-               }                       \r
-               protected override Size measureRawSize ()\r
-               {\r
-                       Size raw = base.measureRawSize ();\r
-                       return raw > 0 ? raw + titleSize : raw;\r
-               }\r
-               protected override void onDraw (Context gr)\r
-               {\r
-                       //base.onDraw (gr);\r
-\r
-                       byte[] txt = System.Text.UTF8Encoding.UTF8.GetBytes(Text);\r
-                       Rectangle r = new Rectangle(Slot.Size);\r
-                       if (BorderWidth > 0) \r
-                               r.Inflate (-BorderWidth / 2);\r
-\r
-                       //gr.Rotate(Math.PI);\r
-                       gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);\r
-                       gr.SetFontSize (Font.Size);\r
-                       FontExtents fe = gr.FontExtents;\r
-                       TextExtents te = gr.TextExtents(Text);\r
-\r
-                       gr.Antialias = Antialias.Subpixel;\r
-                       gr.LineWidth = BorderWidth;\r
-                       gr.Color = Background;\r
-\r
-\r
-\r
-                       Rectangle rTitle = r;\r
-\r
-                       int th = (int)Math.Ceiling(fe.Height / 2);\r
-                       r.Y += th;\r
-                       r.Height -= th;\r
-\r
-                       CairoHelpers.CairoRectangle (gr, r, CornerRadius);\r
-                       gr.Fill();\r
-\r
-                       const int titleGap = 5;\r
-\r
-                       if (BorderWidth > 0)\r
-                       {\r
-                               gr.Color = BorderColor;\r
-\r
-                               rTitle.X = r.X + titleGap;\r
-                               rTitle.Width = (int)Math.Ceiling(te.XAdvance) + 2 * titleGap;\r
-                               rTitle.Height = (int)Math.Ceiling(fe.Height);\r
-                               gr.Save();\r
-                               gr.FillRule = FillRule.EvenOdd;\r
-                               gr.Rectangle(new Rectangle(Slot.Size));\r
-                               gr.Rectangle(rTitle);\r
-                               gr.Clip();\r
-\r
-                               CairoHelpers.CairoRectangle (gr, r, CornerRadius);\r
-\r
-                               gr.Stroke();\r
-                               gr.Restore();\r
-                       }\r
-\r
-                       gr.MoveTo(rTitle.X + titleGap, rTitle.Y + (int)Math.Ceiling(fe.Height - fe.Descent));\r
-\r
-                       #if _WIN32 || _WIN64\r
-                       gr.ShowText(txt);\r
-                       #elif __linux__\r
-                       gr.ShowText(Text);\r
-                       #endif\r
-                       gr.Color = Foreground;\r
-                       gr.Fill();\r
-               }\r
-               #endregion\r
-\r
-        public override string ToString()\r
-        {\r
-                       return base.ToString() + ": " + this.Text;\r
-        }\r
-    }\r
-}\r
-\r
diff --git a/src/GraphicObjects/Groupbox.cs b/src/GraphicObjects/Groupbox.cs
new file mode 100644 (file)
index 0000000..60c2dd0
--- /dev/null
@@ -0,0 +1,68 @@
+using System;\r
+\r
+\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+//using OpenTK.Graphics.OpenGL;\r
+\r
+using Cairo;\r
+\r
+using winColors = System.Drawing.Color;\r
+using System.Diagnostics;\r
+using System.Xml.Serialization;\r
+using OpenTK.Input;\r
+using System.ComponentModel;\r
+using System.Xml;\r
+using System.IO;\r
+\r
+namespace go\r
+{\r
+       [DefaultTemplate("#go.Templates.Groupbox.goml")]\r
+    public class Groupbox : TemplatedContainer\r
+    {          \r
+               string title;\r
+               Container _contentContainer;\r
+\r
+               #region CTOR\r
+               public Groupbox() : base(){}    \r
+               #endregion\r
+\r
+               #region Template overrides\r
+               public override GraphicObject Content {\r
+                       get {\r
+                               return _contentContainer == null ? null : _contentContainer.Child;\r
+                       }\r
+                       set {\r
+                               _contentContainer.SetChild(value);\r
+                       }\r
+               }\r
+               protected override void loadTemplate(GraphicObject template = null)\r
+               {\r
+                       base.loadTemplate (template);\r
+\r
+                       _contentContainer = this.child.FindByName ("Content") as Container;\r
+               }\r
+               #endregion\r
+\r
+               #region GraphicObject overrides\r
+               [XmlAttributeAttribute()][DefaultValue(true)]//overiden to get default to true\r
+               public override bool Focusable\r
+               {\r
+                       get { return base.Focusable; }\r
+                       set { base.Focusable = value; }\r
+               }\r
+               #endregion\r
+\r
+               [XmlAttributeAttribute()][DefaultValue("Groupbox")]\r
+               public string Title {\r
+                       get { return title; } \r
+                       set {\r
+                               if (title == value)\r
+                                       return;\r
+                               title = value; \r
+                               NotifyValueChanged ("Title", title);\r
+                       }\r
+               }        \r
+       }\r
+}\r