]> O.S.I.I.S - jp/crow.git/commitdiff
debug paged listbox
authorjpbruyere <jp.bruyere@hotmail.com>
Sat, 27 Feb 2016 10:41:39 +0000 (11:41 +0100)
committerjpbruyere <jp.bruyere@hotmail.com>
Sat, 27 Feb 2016 10:41:39 +0000 (11:41 +0100)
Templates/ListBox.goml
Templates/ScrollingListBox.goml
Tests/Interfaces/colorItem.crow
Tests/Interfaces/testColorList.crow
Tests/Interfaces/test_Listbox.goml
src/GraphicObjects/ListBox.cs

index 79d44de35c5ab04576bf85f8e76cf75686a7abd7..72bd8e2ca4f55652864a647f49ca689118f01638 100755 (executable)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<Border BorderWidth="1" Margin="1" MinimumSize="20;20" Height="{../HeightPolicy}" Width="{../WidthPolicy}" >
+<Border BorderWidth="1" Margin="1" MinimumSize="10;10" Height="{../HeightPolicy}" Width="{../WidthPolicy}" >
        <Scroller  Name="scroller1" Margin="1" VerticalScrolling="true"
                Height="{../../HeightPolicy}" Width="{../../WidthPolicy}"
                ValueChanged="../../_scroller_ValueChanged">
index 5f50929f88b4ad21be6fa2d246d83d9a86453c35..7976e3d73b0afe2e6b8ca7b5e40a6999c93a0a96 100644 (file)
@@ -4,7 +4,7 @@
                <Scroller Name="scroller1" Height="{../../../HeightPolicy}" Width="{../../../WidthPolicy}" 
                                Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}"
                                ValueChanged="../../../_scroller_ValueChanged">
-                       <VerticalStack Width="{../../../../WidthPolicy}" Height="-1" MinimumSize="100;100"
+                       <VerticalStack Width="{../../../../WidthPolicy}" Height="-1" MinimumSize="10;10"
                                Name="List" Margin="0" VerticalAlignment="Top"
                                LayoutChanged="../../../../_list_LayoutChanged"/>
                </Scroller>
index 7ed65ab15d1cd8da4c158f82a786e276a9f28213..98c17d5ccb44e30c84756b86c8d88b2c1ea1e8b6 100755 (executable)
@@ -1,8 +1,10 @@
 <?xml version="1.0"?>
-<HorizontalStack Height="-1" Width="150" Margin="1" Focusable="true"
+<HorizontalStack
+                       HorizontalAlignment="Left"
+                       Height="-1" Width="-1" Margin="1" Focusable="true"
                        MouseEnter="{Background=hgradient|0:DarkRed|1:Transparent}"
                        MouseLeave="{Background=Transparent}">
        <GraphicObject Height="12" Width="20" Background="{}" Margin="0" CornerRadius="3"/>
-       <TextRun Text="{Name}" Margin="0"/>
+       <Label Text="{Name}" Margin="0"/>
 </HorizontalStack>
 
index 76bf8d6e593541524f1b3e1814afb3f6da062766..34d32159fb337f7b5e3f352fa87a3b1f40570cdb 100755 (executable)
@@ -10,7 +10,7 @@
                                                <Scroller Name="scroller1" Height="{../../../HeightPolicy}" Width="{../../../WidthPolicy}" 
                                                                Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}"
                                                                ValueChanged="../../../_scroller_ValueChanged">
-                                                       <VerticalStack Width="{../../../../WidthPolicy}" Height="-1" MinimumSize="100;100"
+                                                       <VerticalStack Width="{../../../../WidthPolicy}" Height="-1" MinimumSize="10;10"
                                                                Name="List" Margin="0" VerticalAlignment="Top"
                                                                LayoutChanged="../../../../_list_LayoutChanged"/>
                                                </Scroller>
index 18fe18dc89bfb8b89b17b202afddcb42dcb554ea..64877f57bcb6b2199d33f3dc8c36514df09a364d 100755 (executable)
@@ -1,12 +1,14 @@
 <?xml version="1.0"?>
 <!--<ListBox Data="{TestList}" Focusable="true"/>-->
-<Border BorderWidth="2" Fit="true">
-       <VerticalStack Fit="true" Margin="50">
-               <Label Text="{../ColorList.SelectedItem}" Width="-1" Background="DarkGreen"/>
-               <Label Text="{Hover}" Width="-1" Background="DarkGreen"/>
-               <Button Caption="Clear" Width="150" MouseClick="OnClear"/>
+<Border Margin="50">
+       <VerticalStack >
+               <Label Text="{../ColorList.SelectedItem}" Background="DarkGreen"/>
+               <Label Text="{Hover}" Background="DarkGreen"/>
+               <Button Caption="Clear" Width="0" MouseClick="OnClear"/>
                <ListBox Name="ColorList" Data="{TestList}" Background="0,5;0,5;0,5;0,5"
-                                        HorizontalAlignment="Center" Width="-1" Height="200" Margin="5">
+                                        HorizontalAlignment="Center" Width="-1" Height="200" Margin="0"
+                                        ItemTemplate="#Tests.Interfaces.colorItem.crow"
+                                        Template="#Crow.Templates.ScrollingListBox.goml">
 <!--                   <Template>
                                <Border BorderWidth="1" Height="{../HeightPolicy}" Width="{../WidthPolicy}">
                                        <HorizontalStack Margin="1" Height="{../../HeightPolicy}" Width="{../../WidthPolicy}" >
@@ -24,6 +26,6 @@
                                </Border>
                        </Template>-->
                </ListBox>
-               <Button Caption="Load list" Width="0" MouseClick="OnLoadList"/>
+               <Button Caption="Load list" Width="0" MouseClick="../../../OnLoadList"/>
        </VerticalStack>
 </Border>
\ No newline at end of file
index 98e302f11ca3186eccd08c6f305fdd11adf3b32e..4a188200e396d6ae9dbbf2a784e9bc83136a0f5d 100644 (file)
@@ -52,6 +52,8 @@ namespace Crow
                {
                        base.loadTemplate (template);
                        _list = this.child.FindByName ("List") as Group;
+                       if (_list == null)
+                               throw new Exception ("ListBox Template MUST contain a Goup named 'List'.");
                        _gsList = _list as GenericStack;
                }
 
@@ -107,6 +109,10 @@ namespace Crow
                                NotifyValueChanged ("Data", data);
 
                                _list.ClearChildren ();
+                               if (_gsList.Orientation == Orientation.Horizontal)
+                                       _gsList.Width = -1;
+                               else
+                                       _gsList.Height = -1;
 
                                if (data == null)
                                        return;
@@ -137,6 +143,13 @@ namespace Crow
                        Group page = _list.Clone () as Group;
                        page.Name = "page" + pageNum;
 
+                       //reset size to fit in the dir of the stacking
+                       //because _list total size is forced to approx size
+                       if (_gsList.Orientation == Orientation.Horizontal)
+                               page.Width = -1;
+                       else
+                               page.Height = -1;                       
+
 
                        for (int i = (pageNum - 1) * itemPerPage; i < pageNum * itemPerPage; i++) {
                                if (i >= data.Count)
@@ -162,6 +175,10 @@ namespace Crow
                {
                        if (_gsList == null)
                                return;
+                       if (data == null)
+                               return;
+                       if (data.Count <= itemPerPage)
+                               return;
 
                        if (_gsList.Orientation == Orientation.Horizontal) {
                        } else {
@@ -170,44 +187,39 @@ namespace Crow
 
                                double scroll = (double)e.NewValue;
                                int pageHeight = (int)Math.Ceiling((double)_gsList.getSlot().Height / (double)data.Count * (double)itemPerPage);
+                               int pagePtr = (int)Math.Ceiling((scroll + (double)pageHeight / 2.0) / (double)pageHeight);
 
-                               int pagePtr = (int)Math.Ceiling(scroll / (double)pageHeight);
-
-                               for (int i = _gsList.Children.Count+1; i <= pagePtr+1; i++) {
+                               for (int i = _gsList.Children.Count+1; i < pagePtr+1; i++) {
                                        loadPage (i);                                   
                                }
                        }
                }
                protected 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;
+                               if (e.LayoutType == LayoutingType.Width)
+                                       _gsList.Width = approxSize;
+                       } else if (e.LayoutType == LayoutingType.Height)
+                               _gsList.Height = approxSize;
+               }
+               int approxSize
+               {
+                       get {
+                               if (data == null)
+                                       return -1;
+                               GenericStack page1 = _list.FindByName ("page1") as GenericStack;
+                               if (page1 == null)
+                                       return - 1;
+                               
+                               return page1.Orientation == Orientation.Horizontal ?
+                                       data.Count < itemPerPage ?
+                                               -1:
+                                       (int)Math.Ceiling ((double)page1.Slot.Width / (double)itemPerPage * (double)(data.Count+1)):
+                                       data.Count < itemPerPage ?
+                                               -1:
+                                       (int)Math.Ceiling ((double)page1.Slot.Height / (double)itemPerPage * (double)(data.Count+1));
                        }
                }
-
                void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){
                        SelectedIndex = data.IndexOf((sender as GraphicObject).DataSource);
                }