aboutsummaryrefslogtreecommitdiffstatsci
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-02-08 11:54:30 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2016-02-08 11:54:30 +0100
commitd810ad18dc2a1908211b6967d666c915140f24c9 (patch)
tree13a031d1eab76d1be985ae2aa2cbffcd99ba4516
parent10b0b2b477b926ea4084a1a38c9b822d2c4a8846 (diff)
paged ListBox
-rw-r--r--Crow.csproj1
-rwxr-xr-xTemplates/ListBox.goml3
-rw-r--r--Tests/GOLIBTests.cs2
-rwxr-xr-xTests/Interfaces/testColorList.crow6
-rw-r--r--src/GraphicObjects/GraphicObject.cs29
-rw-r--r--src/GraphicObjects/ListBox.cs138
-rw-r--r--src/GraphicObjects/Scroller.cs2
-rw-r--r--src/ScrollingEventArgs.cs15
8 files changed, 165 insertions, 31 deletions
diff --git a/Crow.csproj b/Crow.csproj
index f4474492..fbb6ca24 100644
--- a/Crow.csproj
+++ b/Crow.csproj
@@ -132,6 +132,7 @@
<Compile Include="src\Gradient.cs" />
<Compile Include="src\Fill\Fill.cs" />
<Compile Include="src\LayoutingEventArgs.cs" />
+ <Compile Include="src\ScrollingEventArgs.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
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 @@
<Border BorderWidth="1" Margin="1" MinimumSize="20;20" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}" >
<Scroller Name="scroller1" Margin="1" VerticalScrolling="true"
Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}">
- <VerticalStack Height="-1" Width="{../../../TemplatedWidth}" Name="List" Margin="0" VerticalAlignment="Top"/>
+ <VerticalStack LayoutChanged="../../../_list_LayoutChanged"
+ Height="-1" Width="{../../../TemplatedWidth}" Name="List" Margin="0" VerticalAlignment="Top"/>
</Scroller>
</Border> \ 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 @@
<Border BorderWidth="1" Height="{../TemplatedHeight}" Width="{../TemplatedWidth}">
<HorizontalStack Margin="1" Height="{../../TemplatedHeight}" Width="{../../TemplatedWidth}" >
<Scroller Name="scroller1" Height="{../../../TemplatedHeight}" Width="{../../../TemplatedWidth}"
- Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}">
+ Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}"
+ ValueChanged="../../../_scroller_ValueChanged">
<VerticalStack Width="{../../../../TemplatedWidth}" Height="-1" MinimumSize="100;100"
- Name="List" Margin="0" VerticalAlignment="Top" />
+ Name="List" Margin="0" VerticalAlignment="Top"
+ LayoutChanged="../../../../_list_LayoutChanged"/>
</Scroller>
<ScrollBar Name="scrollbar1" Value="{../scroller1.ScrollY}"
Maximum="{../scroller1.MaximumScroll}" Orientation="Vertical"
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index d7567659..43b9a725 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -21,7 +21,7 @@ using System.Reflection.Emit;
namespace Crow
{
- public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange
+ public class GraphicObject : IXmlSerializable, ILayoutable, IValueChange, ICloneable
{
#if DEBUG_LAYOUTING
internal static ulong currentUid = 0;
@@ -462,7 +462,7 @@ namespace Crow
}
public virtual GraphicObject FindByName(string nameToFind){
- return nameToFind == _name ? this : null;
+ return string.Equals(nameToFind, _name, StringComparison.Ordinal) ? this : null;
}
public virtual bool Contains(GraphicObject goToFind){
return false;
@@ -1381,5 +1381,30 @@ namespace Crow
}
#endregion
+ #region ICloneable implementation
+ public object Clone ()
+ {
+ Type type = this.GetType ();
+ GraphicObject result = (GraphicObject)Activator.CreateInstance (type);
+
+ foreach (PropertyInfo pi in type.GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
+ if (pi.GetSetMethod () == null)
+ continue;
+
+ if (pi.GetCustomAttribute<XmlIgnoreAttribute> () != 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<ScrollingEventArgs> 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;
+ }
+ }
+}
+