]> O.S.I.I.S - jp/crow.git/commitdiff
tabItem onDraw
authorjpbruyere <jp.bruyere@hotmail.com>
Mon, 15 Feb 2016 11:46:37 +0000 (12:46 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Mon, 15 Feb 2016 11:46:37 +0000 (12:46 +0100)
Templates/TabItem.crow
Tests/GOLIBTests.cs
Tests/Interfaces/testTabView.crow
src/GraphicObjects/TabItem.cs
src/GraphicObjects/TabView.cs

index 683c8e5a58c5edad71cb61f3fc22316c895f9d0e..9e3c02b9ebc2d29bee7922476fa475f4827218d4 100644 (file)
@@ -1,12 +1,13 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<GenericStack Margin="2" Background="DarkRed" Orientation="Vertical"
-               Width="{../../TemplatedWidth}" Height="{../../TemplatedHeight}">
-       <Label Name="TabTitle" Width="-1" Background="BlueCrayola"
+<GenericStack Orientation="Vertical" Spacing="0"
+               Width="{../../WidthPolicy}" Height="{../../HeightPolicy}">
+       <Label Margin="5" Name="TabTitle" Width="-1"
+               HorizontalAlignment="Left"
                Text="{../../Caption}"
                Height="{../../../TabThickness}"
                Left="{../../TabOffset}"
                LayoutChanged="../../../TabTitleLayoutChanged"/>
-       <Container Background="White" Margin="2"
-               Name="Content" Width="{../../../TemplatedWidth}" Height="{../../../TemplatedHeight}"/>
+       <Container
+               Name="Content" Width="{../../../WidthPolicy}" Height="{../../../HeightPolicy}"/>
 </GenericStack>
 
index a12885ffe5fe2f0623212cff016e6d960b87f1a7..c508c0e189b15d058a71055ab570265ed0201494 100644 (file)
@@ -37,7 +37,7 @@ namespace test
                int frameCpt = 0;
                int idx = 0;
                string[] testFiles = {
-//                     "testTabView.crow",
+                       "testTabView.crow",
                        "testExpandable.goml",
                        "0.crow",
                        "testImage.crow",
index 4f829e9d2dd765ea9844714e41c553565f22a6d9..8f25ffcd32bd180b84eb9646726e2d580d51ea24 100644 (file)
@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<TabView Orientation="Horizontal" Background="Gray">
-       <TabItem Caption="tab 1">
+<TabView Orientation="Horizontal" Spacing="20" Margin="0">
+       <TabItem Caption="tab 1" Width="0" Height="0" Margin="0" Background="Gray">
                <Label Text="tab content test 1"/>
        </TabItem>
-       <TabItem Caption="tab 2">
+       <TabItem Caption="tab 2" Width="0" Height="0" Margin="0" Background="Gray">
                <Label Text="tab content test 2"/>
        </TabItem>
 
index 29c682c14fb68b284500027c6be1e54acbc7ad82..1f0389d390640d717ffb42471b5d666a6d658742 100644 (file)
@@ -72,22 +72,48 @@ namespace Crow
                        set {
                                if (tabOffset == value)
                                        return;
-                               tabOffset = value; 
+                               tabOffset = value;
                                NotifyValueChanged ("TabOffset", tabOffset);
                        }
-               } 
+               }
                [XmlAttributeAttribute()][DefaultValue("TabItem")]
                public string Caption {
-                       get { return caption; } 
+                       get { return caption; }
                        set {
                                if (caption == value)
                                        return;
-                               caption = value; 
+                               caption = value;
                                NotifyValueChanged ("Caption", caption);
                        }
-               } 
+               }
+               protected override void onDraw (Cairo.Context gr)
+               {
+                       int spacing = (Parent as TabView).Spacing;
+                       gr.MoveTo (0, TabTitle.Slot.Bottom);
+                       gr.LineTo (TabTitle.Slot.Left - spacing, TabTitle.Slot.Bottom);
+                       gr.CurveTo (
+                               TabTitle.Slot.Left - spacing / 2, TabTitle.Slot.Bottom,
+                               TabTitle.Slot.Left - spacing / 2, 0,
+                               TabTitle.Slot.Left, 0);
+                       gr.LineTo (TabTitle.Slot.Right, 0);
+                       gr.CurveTo (
+                               TabTitle.Slot.Right + spacing / 2, 0,
+                               TabTitle.Slot.Right + spacing / 2, TabTitle.Slot.Bottom,
+                               TabTitle.Slot.Right + spacing, TabTitle.Slot.Bottom);
+                       gr.LineTo (Slot.Width, TabTitle.Slot.Bottom);
 
+                       gr.LineWidth = 1;
+                       Foreground.SetAsSource (gr);
+                       gr.StrokePreserve ();
 
+                       gr.LineTo (Slot.Width, Slot.Height);
+                       gr.LineTo (0, Slot.Height);
+                       gr.ClosePath ();
+                       gr.Save ();
+                       gr.Clip ();
+                       base.onDraw (gr);
+                       gr.Restore ();
+               }
        }
 }
 
index 3fa3f706734b2d6bc3b718b6951236b076d0ac86..c9017e4958b89117e400d5a504e804cbb13e90f9 100644 (file)
 using System;
 using System.Xml.Serialization;
 using System.ComponentModel;
+using Cairo;
+using System.Diagnostics;
 
 namespace Crow
 {
        public class TabView : Group
        {
+               #region Private fields
+               int _spacing;
                Orientation _orientation;
                int selectedTab = 0;
+               #endregion
 
                public TabView () : base()
                {
@@ -37,10 +42,10 @@ namespace Crow
                public virtual Orientation Orientation
                {
                        get { return _orientation; }
-                       set { 
+                       set {
                                if (_orientation == value)
                                        return;
-                               _orientation = value; 
+                               _orientation = value;
                                NotifyValueChanged ("Orientation", _orientation);
                                if (_orientation == Orientation.Horizontal)
                                        NotifyValueChanged ("TabOrientation", Orientation.Vertical);
@@ -48,14 +53,26 @@ namespace Crow
                                        NotifyValueChanged ("TabOrientation", Orientation.Horizontal);
                        }
                }
+               [XmlAttributeAttribute()][DefaultValue(2)]
+               public int Spacing
+               {
+                       get { return _spacing; }
+                       set {
+                               if (_spacing == value)
+                                       return;
+                               _spacing = value;
+                               NotifyValueChanged ("Spacing", Spacing);
+                       }
+               }
                [XmlAttributeAttribute()][DefaultValue(0)]
                public virtual int SelectedTab {
                        get { return selectedTab; }
                        set {
                                if (selectedTab == value)
                                        return;
-                               selectedTab = value; 
+                               selectedTab = value;
                                NotifyValueChanged ("SelectedTab", selectedTab);
+                               registerForGraphicUpdate ();
                        }
                }
                int tabThickness;
@@ -65,7 +82,7 @@ namespace Crow
                        set {
                                if (tabThickness == value)
                                        return;
-                               tabThickness = value; 
+                               tabThickness = value;
                                NotifyValueChanged ("TabThickness", tabThickness);
                        }
                }
@@ -74,26 +91,18 @@ namespace Crow
                        TabItem ti = child as TabItem;
                        if (ti == null)
                                throw new Exception ("TabView control accept only TabItem as child.");
-                       
+
                        ti.MouseDown += Ti_MouseDown;
 
                        return base.AddChild (child);
                }
                public override bool ArrangeChildren { get { return true; } }
-               public override void ChildrenLayoutingConstraints (ref LayoutingType layoutType)
-               {
-//                     //Prevent child repositionning in the direction of 
-//                     if (Orientation == Orientation.Horizontal)
-//                             layoutType &= (~LayoutingType.X);
-//                     else
-//                             layoutType &= (~LayoutingType.Y);                       
-               }
                public override bool UpdateLayout (LayoutingType layoutType)
                {
                        RegisteredLayoutings &= (~layoutType);
 
-                       if (layoutType == LayoutingType.ArrangeChildren) {                       
-                               int curOffset = 0;
+                       if (layoutType == LayoutingType.ArrangeChildren) {
+                               int curOffset = Spacing;
                                for (int i = 0; i < Children.Count; i++) {
                                        if (!Children [i].Visible)
                                                continue;
@@ -102,11 +111,11 @@ namespace Crow
                                        if (Orientation == Orientation.Horizontal) {
                                                if (ti.TabTitle.RegisteredLayoutings.HasFlag (LayoutingType.Width))
                                                        return false;
-                                               curOffset += ti.TabTitle.Slot.Width;
+                                               curOffset += ti.TabTitle.Slot.Width + Spacing;
                                        } else {
                                                if (ti.TabTitle.RegisteredLayoutings.HasFlag (LayoutingType.Height))
                                                        return false;
-                                               curOffset += ti.TabTitle.Slot.Height;
+                                               curOffset += ti.TabTitle.Slot.Height + Spacing;
                                        }
                                }
 
@@ -122,19 +131,13 @@ namespace Crow
 
                void TabTitleLayoutChanged (object sender, LayoutingEventArgs e)
                {
-                       
+
                }
 
                void Ti_MouseDown (object sender, OpenTK.Input.MouseButtonEventArgs e)
                {
                        SelectedTab = Children.IndexOf (sender as GraphicObject);
                }
-               protected override void onDraw (Cairo.Context gr)
-               {
-                       base.onDraw (gr);
-
-
-               }
        }
 }