You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by ca...@apache.org on 2020/04/14 11:07:27 UTC

[royale-asjs] branch develop updated: jewel-list: add scrollToIndex function

This is an automated email from the ASF dual-hosted git repository.

carlosrovira pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-asjs.git


The following commit(s) were added to refs/heads/develop by this push:
     new e626fcb  jewel-list: add scrollToIndex function
e626fcb is described below

commit e626fcb4c0dfe47e17f8af7cda2b6dfc55da5f47
Author: Carlos Rovira <ca...@apache.org>
AuthorDate: Tue Apr 14 13:07:18 2020 +0200

    jewel-list: add scrollToIndex function
---
 .../projects/Jewel/src/main/royale/JewelClasses.as |  2 +
 .../beads/controls/list/HorizontalListScroll.as    |  3 -
 .../jewel/beads/controls/list/scrollToIndex.as     | 96 ++++++++++++++++++++++
 .../jewel/beads/models/ListPresentationModel.as    |  3 +-
 .../supportClasses/datagrid/DataGridColumnList.as  |  3 +-
 5 files changed, 102 insertions(+), 5 deletions(-)

diff --git a/frameworks/projects/Jewel/src/main/royale/JewelClasses.as b/frameworks/projects/Jewel/src/main/royale/JewelClasses.as
index 7f8068a..7fd876b 100644
--- a/frameworks/projects/Jewel/src/main/royale/JewelClasses.as
+++ b/frameworks/projects/Jewel/src/main/royale/JewelClasses.as
@@ -141,5 +141,7 @@ package
         import org.apache.royale.jewel.beads.itemRenderers.NavigationItemRendererInitializer; NavigationItemRendererInitializer;
         import org.apache.royale.jewel.beads.itemRenderers.DropDownListItemRendererInitializer; DropDownListItemRendererInitializer;
 
+        import org.apache.royale.jewel.beads.controls.list.scrollToIndex; scrollToIndex;
+
     }
 }
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/list/HorizontalListScroll.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/list/HorizontalListScroll.as
index d9da370..57213ad 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/list/HorizontalListScroll.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/list/HorizontalListScroll.as
@@ -20,9 +20,6 @@ package org.apache.royale.jewel.beads.controls.list
 {
 	import org.apache.royale.core.IBead;
 	import org.apache.royale.core.IStrand;
-	import org.apache.royale.events.Event;
-	import org.apache.royale.jewel.DropDownList;
-	import org.apache.royale.jewel.beads.models.IDropDownListModel;
 	import org.apache.royale.jewel.List;
 	
 	/**
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/list/scrollToIndex.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/list/scrollToIndex.as
new file mode 100644
index 0000000..4e19168
--- /dev/null
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/controls/list/scrollToIndex.as
@@ -0,0 +1,96 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.royale.jewel.beads.controls.list
+{
+	import org.apache.royale.jewel.List;
+	import org.apache.royale.html.beads.IListView;
+	import org.apache.royale.core.IItemRendererOwnerView;
+	import org.apache.royale.jewel.beads.models.ListPresentationModel;
+	import org.apache.royale.core.IIndexedItemRenderer;
+	import org.apache.royale.html.supportClasses.StyledDataItemRenderer;
+	import org.apache.royale.core.IItemRenderer;
+	
+	/**
+     *  Ensures that the data provider item at the given index is visible.
+     *  
+     *  If the item is visible, the <code>verticalScrollPosition</code>
+     *  property is left unchanged even if the item is not the first visible
+     *  item. If the item is not currently visible, the 
+     *  <code>verticalScrollPosition</code>
+     *  property is changed make the item the first visible item, unless there
+     *  aren't enough rows to do so because the 
+     *  <code>verticalScrollPosition</code> value is limited by the 
+     *  <code>maxVerticalScrollPosition</code> property.
+     *
+     *  @param index The index of the item in the data provider.
+     *
+     *  @return <code>true</code> if <code>verticalScrollPosition</code> changed.
+     *  
+     *  @langversion 3.0
+     *  @playerversion Flash 9
+     *  @playerversion AIR 1.1
+     *  @productversion Royale 0.9.7
+     */
+    public function scrollToIndex(list:List, index:int):Boolean
+    {
+        COMPILE::SWF
+        {
+            // to implement
+
+            return false;
+        }
+
+		COMPILE::JS
+		{
+        var scrollArea:HTMLElement = list.element;
+        var oldScroll:Number = scrollArea.scrollTop;
+
+        var totalHeight:Number = 0;
+        
+        if(list.variableRowHeight)
+        {
+            var listView:IListView = list.getBeadByType(IListView) as IListView;
+            var dataGroup:IItemRendererOwnerView = listView.dataGroup;
+
+            //each item render can have its own height
+            var n:int = list.dataProvider.length;
+            var irHeights:Array = [];
+            for (var i:int = 0; i < n; i++)
+            {
+                var ir:IItemRenderer = dataGroup.getItemRendererForIndex(i) as IItemRenderer;
+                irHeights.push(totalHeight + ir.element.clientHeight);
+                totalHeight += ir.element.clientHeight;
+            }
+
+            scrollArea.scrollTop = irHeights[index-1];
+
+        } else 
+        {
+            var rowHeight:Number;
+            // all items renderers with same height
+            rowHeight = isNaN(list.rowHeight) ? ListPresentationModel.DEFAULT_ROW_HEIGHT : list.rowHeight;
+            totalHeight = list.dataProvider.length * rowHeight - scrollArea.clientHeight;
+            
+            scrollArea.scrollTop = Math.min(index * rowHeight, totalHeight);
+        }
+
+        return oldScroll != scrollArea.scrollTop; 
+		}
+    } 
+}
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/models/ListPresentationModel.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/models/ListPresentationModel.as
index 6b689b1..295228c 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/models/ListPresentationModel.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/beads/models/ListPresentationModel.as
@@ -37,6 +37,7 @@ package org.apache.royale.jewel.beads.models
 	 */
 	public class ListPresentationModel extends EventDispatcher implements IListPresentationModel
 	{
+		public static const DEFAULT_ROW_HEIGHT:Number = 34;
 		/**
 		 *  constructor.
 		 *
@@ -51,7 +52,7 @@ package org.apache.royale.jewel.beads.models
 		}
 
 		
-		private var _rowHeight:Number = 34;
+		private var _rowHeight:Number = DEFAULT_ROW_HEIGHT;
 		/**
 		 *  The height of each row.
 		 *
diff --git a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/datagrid/DataGridColumnList.as b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/datagrid/DataGridColumnList.as
index c790f52..3a42af4 100644
--- a/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/datagrid/DataGridColumnList.as
+++ b/frameworks/projects/Jewel/src/main/royale/org/apache/royale/jewel/supportClasses/datagrid/DataGridColumnList.as
@@ -21,6 +21,7 @@ package org.apache.royale.jewel.supportClasses.datagrid
     import org.apache.royale.jewel.DataGrid;
     import org.apache.royale.jewel.List;
     import org.apache.royale.jewel.supportClasses.datagrid.IDataGridColumnList;
+    import org.apache.royale.jewel.beads.models.ListPresentationModel;
     
     //--------------------------------------
     //  Events
@@ -60,7 +61,7 @@ package org.apache.royale.jewel.supportClasses.datagrid
 			super();
 			typeNames = "jewel list column";
             // rowHeight need to be set to a default value to avoid potential different column heights
-			rowHeight = 34;
+			rowHeight = ListPresentationModel.DEFAULT_ROW_HEIGHT;
 		}
 		
         /**