[gnome-shell/wip/paging-release: 8/90] AllView, indicator layout, paginationScrollView: fixed allocation cycle hidding actors of indicators



commit 7f290806fd842c1a88afcb6050c3b2c8129ea691
Author: Carlos Soriano <carlos soriano89 gmail com>
Date:   Mon Aug 12 17:37:46 2013 +0200

    AllView, indicator layout, paginationScrollView: fixed allocation cycle hidding actors of indicators

 js/ui/appDisplay.js |   70 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 49 insertions(+), 21 deletions(-)
---
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 1567f6b..ae3411c 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -303,9 +303,6 @@ const PaginationScrollView = new Lang.Class({
         
         this._pages.setGridParentSize([availWidth, availHeight]);
         child.allocate(childBox, flags);
-        if(this._pages.nPages() > 0) {
-            this._parent.goToPage(0);
-       }
     },
     
     goToPage: function(pageNumber) {
@@ -343,11 +340,6 @@ const PaginationScrollView = new Lang.Class({
                     this._eventBlocker.reactive = isOpen;
                     this._currentPopup = isOpen ? popup : null;
                     this._updateIconOpacities(isOpen);
-                    if (isOpen) {
-                        this._pages._grid.actor.y = popup.parentOffset;
-                    } else {
-                        this._pages._grid.actor.y = 0;
-                    }
                 }));
     },
     
@@ -399,20 +391,62 @@ const PaginationIconIndicator = new Lang.Class({
     }
 });
 
+const IndicatorLayout = Lang.Class({
+    Name:'IndicatorLayout',
+    Extends: Clutter.BoxLayout,
+
+    vfunc_get_preferred_width: function(container, forHeight) {
+        let childWidth = container.get_children()[0].get_preferred_width(forHeight);
+        let totalWidth = childWidth + this.spacing * 2;
+        return [totalWidth, totalWidth];
+    },
+
+    vfunc_allocate: function(container, box, flags) {
+        let children = container.get_children();
+        if(!this._nPages || this._nPages < 2)
+            return;
+        let availHeight = box.y2 - box.y1;
+        let availWidth = box.x2 - box.x1;
+        let [minHeight, natHeight] = children[0].get_preferred_height(availWidth);
+        let totalUsedHeight = (this._nPages - 1) * this.spacing * 2 + this._nPages * natHeight;
+        let heightPerChild = totalUsedHeight / this._nPages;
+        let [minWidth, natWidth] = children[0].get_preferred_width(natHeight);
+        let widthPerChild = natWidth + this.spacing * 2;
+        let firstPosition = [this.spacing, availHeight / 2 - totalUsedHeight / 2];
+
+        for(let i = 0; i < this._nPages; i++) {
+            let childBox = new Clutter.ActorBox();
+            childBox.x1 = box.x2 - widthPerChild;
+            childBox.x2 = box.x2;
+            childBox.y1 = firstPosition[1] + i * heightPerChild;
+            childBox.y2 = childBox.y1 + heightPerChild;
+            children[i].allocate(childBox, flags);
+        }
+    },
+
+    vfunc_set_container: function(container) {
+        if(this._styleChangedId) {
+            this._container.disconnect(this._styleChangedId);
+            this._styleChangedId = 0;
+        }
+        if(container != null)
+            this._styleChangedId = container.connect('style-changed', Lang.bind(this,
+                    function() { this.spacing = this._container.get_theme_node().get_length('spacing'); }));
+        this._container = container;
+    }
+});
 
 const AllView = new Lang.Class({
     Name: 'AllView',
    
     _init: function() {
         this._paginationView = new PaginationScrollView(this);
-        let paginationIndicatorLayout = new Clutter.BoxLayout({orientation: Clutter.Orientation.VERTICAL});
-        //FIXME: hardcoded spacing
-        paginationIndicatorLayout.spacing = 40;
-        this._paginationIndicator = new St.Widget({ layout_manager: paginationIndicatorLayout,
-                                                    x_align:3, y_align: 2,
+        this._paginationIndicatorLayout = new IndicatorLayout({orientation: Clutter.Orientation.VERTICAL});
+
+        this._paginationIndicator = new St.Widget({ x_align:3, y_align: 2,
                                                     x_expand:true, y_expand:true,
                                                     style_class: 'pages-indicator' });
-        
+        this._paginationIndicator.set_layout_manager(this._paginationIndicatorLayout);
         let layout = new Clutter.BinLayout();
         this.actor = new Shell.GenericContainer({ layout_manager: layout,
                                                   x_expand:true, y_expand:true });
@@ -426,7 +460,6 @@ const AllView = new Lang.Class({
             if(i == 0) {
                 indicatorIcon.setChecked(true);
             }
-            indicatorIcon.actor.hide();
             this._paginationIndicator.add_actor(indicatorIcon.actor);
         }
         this.actor.connect('allocate', Lang.bind(this, this._allocate));
@@ -437,12 +470,7 @@ const AllView = new Lang.Class({
         this._paginationView.allocate(box, flags);
         
         let nPages = this._paginationView.nPages();
-        
-        if(nPages > 1) {
-            for(let i = 0; i < nPages; i++) {
-                this._paginationIndicator.get_child_at_index(i).show();
-            }         
-        }
+        this._paginationIndicatorLayout._nPages = nPages;
         this._paginationIndicator.allocate(box, flags);
     },
     


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]