From: jpbruyere Date: Mon, 8 Feb 2016 10:54:30 +0000 (+0100) Subject: paged ListBox X-Git-Tag: 0.3~33 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=d810ad18dc2a1908211b6967d666c915140f24c9;p=jp%2Fcrow.git paged ListBox --- diff --git a/Crow.csproj b/Crow.csproj index f4474492..fbb6ca24 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -132,6 +132,7 @@ + diff --git a/Templates/ListBox.goml b/Templates/ListBox.goml index ce05400b..0a21be0f 100755 --- a/Templates/ListBox.goml +++ b/Templates/ListBox.goml @@ -5,6 +5,7 @@ - + \ No newline at end of file diff --git a/Tests/GOLIBTests.cs b/Tests/GOLIBTests.cs index 2b2aabd6..f6c33394 100644 --- a/Tests/GOLIBTests.cs +++ b/Tests/GOLIBTests.cs @@ -37,10 +37,10 @@ namespace test int frameCpt = 0; int idx = 0; string[] testFiles = { + "testColorList.crow", "0.crow", "testExpandable.goml", "4.crow", - "testColorList.crow", "5.crow", "testSpinner.goml", "testScrollbar.goml", diff --git a/Tests/Interfaces/testColorList.crow b/Tests/Interfaces/testColorList.crow index a39547f3..fc5e023d 100755 --- a/Tests/Interfaces/testColorList.crow +++ b/Tests/Interfaces/testColorList.crow @@ -8,9 +8,11 @@ + Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}" + ValueChanged="../../../_scroller_ValueChanged"> + Name="List" Margin="0" VerticalAlignment="Top" + LayoutChanged="../../../../_list_LayoutChanged"/> () != null) + continue; + +// object[] att = pi.GetCustomAttributes (false); +// foreach (object o in att) { +// XmlIgnoreAttribute xia = o as XmlIgnoreAttribute; +// if (xia != null) +// continue; +// } + + pi.SetValue(result, pi.GetValue(this)); + } + return result; + } + #endregion } } diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 3822275e..607f6316 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -40,6 +40,7 @@ namespace Crow #endregion Group _list; + GenericStack _gsList; IList data; int _selectedIndex; string _itemTemplate; @@ -51,21 +52,42 @@ namespace Crow { base.loadTemplate (template); _list = this.child.FindByName ("List") as Group; + _gsList = _list as GenericStack; } + + #endregion [XmlAttributeAttribute][DefaultValue("#Crow.Templates.ItemTemplate.goml")] public string ItemTemplate { get { return _itemTemplate; } set { + if (value == _itemTemplate) + return; + + _itemTemplate = value; + + if (templateStream != null) { + templateStream.Dispose (); + templateStream = null; + } + //TODO:reload list with new template? - _itemTemplate = value; + NotifyValueChanged("ItemTemplate", _itemTemplate); } } [XmlAttributeAttribute][DefaultValue(-1)] public int SelectedIndex{ get { return _selectedIndex; } - set { _selectedIndex = value; } + set { + if (value == _selectedIndex) + return; + + _selectedIndex = value; + + NotifyValueChanged ("SelectedIndex", _selectedIndex); + NotifyValueChanged ("SelectedItem", SelectedItem); + } } public object SelectedItem{ get { return data == null ? null : data[_selectedIndex]; } @@ -76,44 +98,112 @@ namespace Crow return data; } set { + if (value == data) + return; data = value; + NotifyValueChanged ("Data", data); + _list.ClearChildren (); if (data == null) return; - - #if DEBUG_LOAD_TIME - Stopwatch loadingTime = new Stopwatch (); - loadingTime.Start (); - #endif - MemoryStream ms = new MemoryStream (); + loadPage (1); + } + } + int itemPerPage = 40; + MemoryStream templateStream = null; + Type templateBaseType = null; + + void loadPage(int pageNum) + { + #if DEBUG_LOAD_TIME + Stopwatch loadingTime = new Stopwatch (); + loadingTime.Start (); + #endif + + if (templateStream == null) { + templateStream = new MemoryStream (); lock (ItemTemplate) { using (Stream stream = Interface.GetStreamFromPath (ItemTemplate)) - stream.CopyTo (ms); + stream.CopyTo (templateStream); } + templateBaseType = Interface.GetTopContainerOfGOMLStream (templateStream); + } - Type t = Interface.GetTopContainerOfGOMLStream (ms); + Group page = _list.Clone () as Group; + page.Name = "page" + pageNum; - foreach (var item in data) { - ms.Seek(0,SeekOrigin.Begin); - GraphicObject g = Interface.Load (ms, t); - g.MouseClick += itemClick; - _list.AddChild (g); - g.DataSource = item; - } - ms.Dispose (); + for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) { + if (i >= data.Count) + break; + templateStream.Seek(0,SeekOrigin.Begin); + GraphicObject g = Interface.Load (templateStream, templateBaseType); + g.MouseClick += itemClick; + page.AddChild (g); + g.DataSource = data [i]; + //g.LogicalParent = this; + } + + _list.AddChild (page); + + #if DEBUG_LOAD_TIME + loadingTime.Stop (); + Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", + loadingTime.ElapsedTicks, + loadingTime.ElapsedMilliseconds, this.ToString()); + #endif + } + void _scroller_ValueChanged (object sender, ValueChangeEventArgs e) + { + if (_gsList == null) + return; + + if (_gsList.Orientation == Orientation.Horizontal) { + } else { + if (!string.Equals (e.MemberName, "ScrollY")) + return; + + double scroll = (double)e.NewValue; + int pageHeight = (int)Math.Ceiling((double)_gsList.getSlot().Height / (double)data.Count * (double)itemPerPage); - #if DEBUG_LOAD_TIME - loadingTime.Stop (); - Debug.WriteLine("Listbox {2} Loading: {0} ticks \t, {1} ms", - loadingTime.ElapsedTicks, - loadingTime.ElapsedMilliseconds, this.ToString()); - #endif + int pagePtr = (int)Math.Ceiling(scroll / (double)pageHeight); + for (int i = _gsList.Children.Count+1; i <= pagePtr+1; i++) { + loadPage (i); + } + } + } + void _list_LayoutChanged (object sender, LayoutingEventArgs e) + { + if (_gsList == null) + return; + + GenericStack page1 = _list.FindByName ("page1") as GenericStack; + if (page1 == null) + return; + + if (_gsList.Orientation == Orientation.Horizontal) { + if (e.LayoutType != LayoutingType.Width) + return; + int tmpWidth = (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)data.Count); + if (_gsList.Slot.Width == tmpWidth) + return; + _gsList.Slot.Width = tmpWidth; + _gsList.OnLayoutChanges (LayoutingType.Width); + _gsList.LastSlots.Width = _gsList.Slot.Width; + } else { + if (e.LayoutType != LayoutingType.Height) + return; + int tmpHeight = (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)data.Count); + if (_gsList.Slot.Height == tmpHeight) + return; + _gsList.Slot.Height = tmpHeight; + _gsList.OnLayoutChanges (LayoutingType.Height); + _gsList.LastSlots.Height = _gsList.Slot.Height; } } diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index 5188baf8..3ac8d66c 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -20,7 +20,7 @@ namespace Crow double _scrollY = 0.0; int scrollSpeed; - + public event EventHandler Scrolled; #region public properties [XmlAttributeAttribute][DefaultValue(false)] diff --git a/src/ScrollingEventArgs.cs b/src/ScrollingEventArgs.cs new file mode 100644 index 00000000..7e04eeb4 --- /dev/null +++ b/src/ScrollingEventArgs.cs @@ -0,0 +1,15 @@ +using System; + +namespace Crow +{ + public class ScrollingEventArgs: EventArgs + { + public Orientation Direction; + + public ScrollingEventArgs (Orientation _direction) : base() + { + Direction = _direction; + } + } +} +