From 413cc890b171f24691ec8d62d30634c2972d1234 Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Mon, 15 Feb 2016 12:46:37 +0100 Subject: [PATCH] tabItem onDraw --- Templates/TabItem.crow | 11 ++++--- Tests/GOLIBTests.cs | 2 +- Tests/Interfaces/testTabView.crow | 6 ++-- src/GraphicObjects/TabItem.cs | 36 +++++++++++++++++++--- src/GraphicObjects/TabView.cs | 51 ++++++++++++++++--------------- 5 files changed, 68 insertions(+), 38 deletions(-) diff --git a/Templates/TabItem.crow b/Templates/TabItem.crow index 683c8e5a..9e3c02b9 100644 --- a/Templates/TabItem.crow +++ b/Templates/TabItem.crow @@ -1,12 +1,13 @@  - - diff --git a/Tests/GOLIBTests.cs b/Tests/GOLIBTests.cs index a12885ff..c508c0e1 100644 --- a/Tests/GOLIBTests.cs +++ b/Tests/GOLIBTests.cs @@ -37,7 +37,7 @@ namespace test int frameCpt = 0; int idx = 0; string[] testFiles = { -// "testTabView.crow", + "testTabView.crow", "testExpandable.goml", "0.crow", "testImage.crow", diff --git a/Tests/Interfaces/testTabView.crow b/Tests/Interfaces/testTabView.crow index 4f829e9d..8f25ffcd 100644 --- a/Tests/Interfaces/testTabView.crow +++ b/Tests/Interfaces/testTabView.crow @@ -1,9 +1,9 @@  - - + + - + diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs index 29c682c1..1f0389d3 100644 --- a/src/GraphicObjects/TabItem.cs +++ b/src/GraphicObjects/TabItem.cs @@ -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 (); + } } } diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index 3fa3f706..c9017e49 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -21,13 +21,18 @@ 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); - - - } } } -- 2.47.3