From: jpbruyere Date: Sun, 14 Feb 2016 18:27:00 +0000 (+0100) Subject: testing tabview, ChildLayoutConstraints X-Git-Tag: v0.4~127^2~26 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=3ee26688eedb549a81b7846eac4698cf9a589519;p=jp%2Fcrow.git testing tabview, ChildLayoutConstraints --- diff --git a/Crow.csproj b/Crow.csproj index 9490cde5..8c35fe4e 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -45,7 +45,7 @@ bin\Debug - DEBUG_LAYOUTING0;TRACE;DEBUG;__linux__;MEASURE_TIME;DEBUG_LOAD_TIME0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0 + DEBUG_LAYOUTING0;TRACE;DEBUG;__linux__;MEASURE_TIME;DEBUG_LOAD_TIME0;DEBUG_BINDING;DEBUG_CLIP_RECTANGLE0 + + + + + diff --git a/Templates/TreeViewItem.crow b/Templates/TreeViewItem.crow deleted file mode 100644 index 0cb44176..00000000 --- a/Templates/TreeViewItem.crow +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - diff --git a/Tests/GOLIBTests.cs b/Tests/GOLIBTests.cs index 832cf151..a12885ff 100644 --- a/Tests/GOLIBTests.cs +++ b/Tests/GOLIBTests.cs @@ -37,11 +37,13 @@ namespace test int frameCpt = 0; int idx = 0; string[] testFiles = { +// "testTabView.crow", + "testExpandable.goml", + "0.crow", "testImage.crow", "testOutOfClipUpdate.crow", "test_Listbox.goml", "testTreeView.crow", - "0.crow", "1.crow", "testWindow.goml", "clip4.crow", @@ -55,7 +57,6 @@ namespace test "testTextBox.crow", "testColorList.crow", - "testExpandable.goml", "4.crow", "testSpinner.goml", "testScrollbar.goml", diff --git a/Tests/Interfaces/0.crow b/Tests/Interfaces/0.crow index 011148a7..d067f4ff 100755 --- a/Tests/Interfaces/0.crow +++ b/Tests/Interfaces/0.crow @@ -1,9 +1,10 @@  - - - diff --git a/Tests/Interfaces/testTabView.crow b/Tests/Interfaces/testTabView.crow new file mode 100644 index 00000000..4f829e9d --- /dev/null +++ b/Tests/Interfaces/testTabView.crow @@ -0,0 +1,11 @@ + + + + + + + + + diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 1d7bbe18..91ebc43a 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -244,6 +244,9 @@ PreserveNewest + + PreserveNewest + diff --git a/src/GraphicObjects/GenericStack.cs b/src/GraphicObjects/GenericStack.cs index c8282988..ed90486d 100644 --- a/src/GraphicObjects/GenericStack.cs +++ b/src/GraphicObjects/GenericStack.cs @@ -10,12 +10,6 @@ namespace Crow { public class GenericStack : Group { - internal class Page - { - public byte[] bmp; - public int Size; - } - #region CTOR public GenericStack() : base() @@ -28,18 +22,6 @@ namespace Crow Orientation _orientation; #endregion - public override T AddChild (T child) - { - T tmp = base.AddChild (child); - this.RegisterForLayouting (LayoutingType.PositionChildren); - return tmp; - } - public override void RemoveChild (GraphicObject child) - { - base.RemoveChild (child); - this.RegisterForLayouting (LayoutingType.PositionChildren); - } - #region Public Properties [XmlAttributeAttribute()][DefaultValue(2)] public int Spacing @@ -60,6 +42,15 @@ namespace Crow } #endregion + public override void ChildrenLayoutingConstraints (ref LayoutingType layoutType) + { + //Prevent child repositionning in the direction of stacking + if (Orientation == Orientation.Horizontal) + layoutType &= (~LayoutingType.X); + else + layoutType &= (~LayoutingType.Y); + } + #region GraphicObject Overrides protected override Size measureRawSize () { @@ -120,7 +111,7 @@ namespace Crow { RegisteredLayoutings &= (~layoutType); - if (layoutType == LayoutingType.PositionChildren) { + if (layoutType == LayoutingType.ArrangeChildren) { //allow 1 child to have size to 0 if stack has fixed or streched size policy, //this child will occupy remaining space //if stack size policy is Fit, no child may have stretch enabled @@ -221,14 +212,14 @@ namespace Crow if (Orientation == Orientation.Horizontal) { if (this.Bounds.Width < 0) this.RegisterForLayouting (LayoutingType.Width); - this.RegisterForLayouting (LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.ArrangeChildren); } break; case LayoutingType.Height: if (Orientation == Orientation.Vertical) { if (this.Bounds.Height < 0) this.RegisterForLayouting (LayoutingType.Height); - this.RegisterForLayouting (LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.ArrangeChildren); } break; } diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index ba11bd77..f2c50e6f 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -376,20 +376,17 @@ namespace Crow if (!_isVisible && this.Contains (HostContainer.hoverWidget)) HostContainer.hoverWidget = null; + if (Parent is GraphicObject) + Parent.RegisterForLayouting (LayoutingType.Sizing); if (Parent is GenericStack) - Parent.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.PositionChildren); - + Parent.RegisterForLayouting (LayoutingType.ArrangeChildren); RegisterForLayouting (LayoutingType.Sizing); RegisterForRedraw (); + NotifyValueChanged ("Visible", _isVisible); } } - //TODO: only used in group, should be removed from base go object - [XmlIgnore]public virtual bool DrawingIsValid - { get { return bmp == null ? - false : - true; } } [XmlAttributeAttribute()][DefaultValue("0;0")] public virtual Size MaximumSize { get { return _maximumSize; } @@ -623,12 +620,14 @@ namespace Crow get { return layoutingTries; } set { layoutingTries = value; } } - /// return size of content + margins protected virtual Size measureRawSize () { return Bounds.Size; } - + /// By default in groups, LayoutingType.ArrangeChildren is reset + public virtual void ChildrenLayoutingConstraints(ref LayoutingType layoutType){ + layoutType &= (~LayoutingType.ArrangeChildren); + } public virtual void RegisterForLayouting(LayoutingType layoutType){ if (Parent == null) return; @@ -638,15 +637,9 @@ namespace Crow if (Height == 0) layoutType &= (~LayoutingType.Y); - //Prevent child repositionning in a stack - //TODO:this should be done inside GenericStack - GenericStack gs = Parent as GenericStack; - if (gs != null) { - if (gs.Orientation == Orientation.Horizontal) - layoutType &= (~LayoutingType.X); - else - layoutType &= (~LayoutingType.Y); - } + //apply constraints depending on parent type + if (Parent is GraphicObject) + (Parent as GraphicObject).ChildrenLayoutingConstraints (ref layoutType); //prevent queueing same LayoutingType for this layoutType &= (~RegisteredLayoutings); @@ -667,8 +660,8 @@ namespace Crow Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.X, this)); if (layoutType.HasFlag (LayoutingType.Y)) Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.Y, this)); - if (layoutType.HasFlag (LayoutingType.PositionChildren)) - Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.PositionChildren, this)); + if (layoutType.HasFlag (LayoutingType.ArrangeChildren)) + Interface.LayoutingQueue.Enqueue (new LayoutingQueueItem (LayoutingType.ArrangeChildren, this)); } /// trigger dependant sizing component update @@ -1009,11 +1002,11 @@ namespace Crow #region Binding public virtual void ResolveBindings() { + if (Bindings.Count == 0) + return; #if DEBUG_BINDING Debug.WriteLine ("ResolveBinding => " + this.ToString ()); #endif - if (Bindings.Count == 0) - return; Dictionary> resolved = new Dictionary>(); foreach (Binding b in Bindings) { if (b.Resolved) @@ -1024,12 +1017,14 @@ namespace Crow continue; } } - if (!b.FindTarget ()) + if (!b.FindTarget ()) { + Debug.WriteLine ("BINDING ERROR: target not found => " + b.ToString()); continue; + } if (b.Source.Member.MemberType == MemberTypes.Event) { //register handler for event if (b.Target.Method == null) { - Debug.WriteLine ("Handler Method not found: " + b.Expression); + Debug.WriteLine ("Handler Method not found: " + b.ToString()); continue; } @@ -1037,6 +1032,9 @@ namespace Crow Delegate del = Delegate.CreateDelegate (b.Source.Event.EventHandlerType, b.Target.Instance, b.Target.Method); addHandler.Invoke (this, new object[] { del }); b.Resolved = true; + #if DEBUG_BINDING + Debug.WriteLine ("\tHandler binded => " + b.ToString()); + #endif continue; } List bindings = null; @@ -1046,6 +1044,9 @@ namespace Crow } bindings.Add (b); b.Resolved = true; + #if DEBUG_BINDING + Debug.WriteLine ("\tmarked as resolved => " + b.ToString()); + #endif } MethodInfo stringEquals = typeof(string).GetMethod @@ -1332,6 +1333,9 @@ namespace Crow addHandler.Invoke(this, new object[] {del}); binding.Resolved = true; + #if DEBUG_BINDING + Debug.WriteLine ("\tCompiled Event Source => " + binding.ToString()); + #endif } /// /// Remove dynamic delegates by ids from dataSource diff --git a/src/GraphicObjects/Grid.cs b/src/GraphicObjects/Grid.cs index c242899f..281f4ae0 100644 --- a/src/GraphicObjects/Grid.cs +++ b/src/GraphicObjects/Grid.cs @@ -32,13 +32,13 @@ namespace Crow public override T AddChild (T child) { T tmp = base.AddChild (child); - this.RegisterForLayouting (LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.ArrangeChildren); return tmp; } public override void RemoveChild (GraphicObject child) { base.RemoveChild (child); - this.RegisterForLayouting (LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.ArrangeChildren); } #region Public Properties @@ -59,7 +59,7 @@ namespace Crow _columnCount = value; NotifyValueChanged ("ColumnCount", ColumnCount); - this.RegisterForLayouting (LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.ArrangeChildren); } } [XmlAttributeAttribute()][DefaultValue(1)] @@ -73,7 +73,7 @@ namespace Crow _rowCount = value; NotifyValueChanged ("RowCount", RowCount); - this.RegisterForLayouting (LayoutingType.PositionChildren); + this.RegisterForLayouting (LayoutingType.ArrangeChildren); } } public virtual int CaseWidth { @@ -130,7 +130,7 @@ namespace Crow { RegisteredLayoutings &= (~layoutType); - if (layoutType == LayoutingType.PositionChildren) { + if (layoutType == LayoutingType.ArrangeChildren) { ComputeChildrenPositions (); diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index 32e45fef..cb9ac846 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -45,7 +45,7 @@ namespace Crow GraphicObject g = child as GraphicObject; Children.Add(g); g.Parent = this as GraphicObject; - g.RegisterForLayouting (LayoutingType.Sizing); + g.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); g.LayoutChanged += OnChildLayoutChanges; return (T)child; } @@ -55,7 +55,13 @@ namespace Crow child.ClearBinding (); child.Parent = null; Children.Remove(child); - this.RegisterForLayouting (LayoutingType.Sizing); + + if (child == largestChild) + searchLargestChild (); + if (child == tallestChild) + searchTallestChild (); + + this.RegisterForLayouting (LayoutingType.Sizing | LayoutingType.ArrangeChildren); } public virtual void ClearChildren() { @@ -66,9 +72,13 @@ namespace Crow g.Parent = null; Children.RemoveAt(Children.Count-1); } + + resetChildrenMaxSize (); + this.RegisterForLayouting (LayoutingType.Sizing); ChildrenCleared.Raise (this, new EventArgs ()); } + public void putWidgetOnTop(GraphicObject w) { if (Children.Contains(w)) @@ -87,17 +97,6 @@ namespace Crow } #region GraphicObject overrides - [XmlIgnore]public override bool DrawingIsValid { - get { - if (!base.DrawingIsValid) - return false; - foreach (GraphicObject g in Children) { - if (!g.DrawingIsValid) - return false; - } - return true; - } - } public override void ResolveBindings () { base.ResolveBindings (); @@ -163,15 +162,9 @@ namespace Crow if (this.Bounds.Width < 0) this.RegisterForLayouting (LayoutingType.Width); } else if (g == largestChild) { - //search for the new largest child - largestChild = null; - maxChildrenWidth = 0; - for (int i = 0; i < Children.Count; i++) { - if (Children [i].Slot.Width > maxChildrenWidth) { - maxChildrenWidth = Children [i].Slot.Width; - largestChild = Children [i]; - } - } + + searchLargestChild (); + if (this.Bounds.Width < 0) this.RegisterForLayouting (LayoutingType.Width); } @@ -183,15 +176,9 @@ namespace Crow if (this.Bounds.Height < 0) this.RegisterForLayouting (LayoutingType.Height); } else if (g == tallestChild) { - //search for the new tallest child - tallestChild = null; - maxChildrenHeight = 0; - for (int i = 0; i < Children.Count; i++) { - if (Children [i].Slot.Height > maxChildrenHeight) { - maxChildrenHeight = Children [i].Slot.Height; - tallestChild = Children [i]; - } - } + + searchTallestChild (); + if (this.Bounds.Height < 0) this.RegisterForLayouting (LayoutingType.Height); } @@ -199,6 +186,37 @@ namespace Crow } } + void resetChildrenMaxSize(){ + largestChild = null; + tallestChild = null; + maxChildrenWidth = 0; + maxChildrenHeight = 0; + } + void searchLargestChild(){ + largestChild = null; + maxChildrenWidth = 0; + for (int i = 0; i < Children.Count; i++) { + if (!Children [i].Visible) + continue; + if (Children [i].Slot.Width > maxChildrenWidth) { + maxChildrenWidth = Children [i].Slot.Width; + largestChild = Children [i]; + } + } + } + void searchTallestChild(){ + tallestChild = null; + maxChildrenHeight = 0; + for (int i = 0; i < Children.Count; i++) { + if (!Children [i].Visible) + continue; + if (Children [i].Slot.Height > maxChildrenHeight) { + maxChildrenHeight = Children [i].Slot.Height; + tallestChild = Children [i]; + } + } + } + protected override void onDraw (Context gr) { base.onDraw (gr); diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs new file mode 100644 index 00000000..29c682c1 --- /dev/null +++ b/src/GraphicObjects/TabItem.cs @@ -0,0 +1,93 @@ +// +// TabItem.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2016 jp +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using System.Xml.Serialization; +using System.ComponentModel; + +namespace Crow +{ + [DefaultTemplate("#Crow.Templates.TabItem.crow")] + public class TabItem : TemplatedContainer + { + string caption; + Container _contentContainer; + GraphicObject _tabTitle; + + public TabItem () : base() + { + } + public override GraphicObject Content { + get { + return _contentContainer == null ? null : _contentContainer.Child; + } + set { + _contentContainer.SetChild(value); + } + } + public override void ResolveBindings () + { + base.ResolveBindings (); + if (_contentContainer != null) + _contentContainer.ResolveBindings (); + } + protected override void loadTemplate(GraphicObject template = null) + { + base.loadTemplate (template); + + _contentContainer = this.child.FindByName ("Content") as Container; + _tabTitle = this.child.FindByName ("TabTitle"); + } + internal GraphicObject TabTitle { get { return _tabTitle; }} + + #region GraphicObject overrides + [XmlAttributeAttribute()][DefaultValue(true)] + public override bool Focusable + { + get { return base.Focusable; } + set { base.Focusable = value; } + } + #endregion + int tabOffset; + [XmlAttributeAttribute()][DefaultValue(0)] + public virtual int TabOffset { + get { return tabOffset; } + set { + if (tabOffset == value) + return; + tabOffset = value; + NotifyValueChanged ("TabOffset", tabOffset); + } + } + [XmlAttributeAttribute()][DefaultValue("TabItem")] + public string Caption { + get { return caption; } + set { + if (caption == value) + return; + caption = value; + NotifyValueChanged ("Caption", caption); + } + } + + + } +} + diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index f9f44754..6a18cf26 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -19,13 +19,121 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System; +using System.Xml.Serialization; +using System.ComponentModel; namespace Crow { - public class TabView + public class TabView : Group { - public TabView () + Orientation _orientation; + int selectedTab = 0; + + public TabView () : base() + { + } + + [XmlAttributeAttribute()][DefaultValue(Orientation.Horizontal)] + public virtual Orientation Orientation + { + get { return _orientation; } + set { + if (_orientation == value) + return; + _orientation = value; + NotifyValueChanged ("Orientation", _orientation); + if (_orientation == Orientation.Horizontal) + NotifyValueChanged ("TabOrientation", Orientation.Vertical); + else + NotifyValueChanged ("TabOrientation", Orientation.Horizontal); + } + } + [XmlAttributeAttribute()][DefaultValue(0)] + public virtual int SelectedTab { + get { return selectedTab; } + set { + if (selectedTab == value) + return; + selectedTab = value; + NotifyValueChanged ("SelectedTab", selectedTab); + } + } + int tabThickness; + [XmlAttributeAttribute()][DefaultValue(20)] + public virtual int TabThickness { + get { return tabThickness; } + set { + if (tabThickness == value) + return; + tabThickness = value; + NotifyValueChanged ("TabThickness", tabThickness); + } + } + public override T AddChild (T child) + { + 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 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; + for (int i = 0; i < Children.Count; i++) { + if (!Children [i].Visible) + continue; + TabItem ti = Children [i] as TabItem; + ti.TabOffset = curOffset; + if (Orientation == Orientation.Horizontal) { + if (ti.TabTitle.RegisteredLayoutings.HasFlag (LayoutingType.Width)) + return false; + curOffset += ti.TabTitle.Slot.Width; + } else { + if (ti.TabTitle.RegisteredLayoutings.HasFlag (LayoutingType.Height)) + return false; + curOffset += ti.TabTitle.Slot.Height; + } + } + + //if no layouting remains in queue for item, registre for redraw + if (RegisteredLayoutings == LayoutingType.None && bmp==null) + this.RegisterForRedraw (); + + return true; + } + + return base.UpdateLayout(layoutType); + } + + 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); + + } } } diff --git a/src/LayoutingQueueItem.cs b/src/LayoutingQueueItem.cs index 03a39c5c..50dbe391 100644 --- a/src/LayoutingQueueItem.cs +++ b/src/LayoutingQueueItem.cs @@ -32,8 +32,7 @@ namespace Crow Width = 0x04, Height = 0x08, Sizing = 0x0C, - PositionChildren = 0x10, - ChildAddition = 0x20, + ArrangeChildren = 0x10, All = 0xFF } diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs index 72d8fb9c..97695657 100644 --- a/src/OpenTKGameWindow.cs +++ b/src/OpenTKGameWindow.cs @@ -169,6 +169,8 @@ namespace Crow { int i = 0; while (GraphicObjects.Count>0) { + //TODO:parent is not reset to null because object will be added + //to ObjectToRedraw list, and without parent, it fails GraphicObject g = GraphicObjects [i]; g.Visible = false; g.ClearBinding ();