[gnome-shell/wip/paging-release: 6/39] Indicator with Shell.GenericContainer



commit 597f05f5c7915ad986a62abfe58e50af0bf2dd4e
Author: Carlos Soriano <carlos soriano89 gmail com>
Date:   Wed Jul 17 15:20:40 2013 +0200

    Indicator with Shell.GenericContainer
    
    testing allocation issues with visual glitchs
    
    yeah....Shell.GenericContainer works fine for skipping painting
    actors...
    
    fixed frequent apps css spacing calculation, since the box passed didn't
    take into account the grid spacing in updateDisplaySize, which is the
    widget which has the right padding

 data/theme/gnome-shell.css |    4 +-
 js/ui/appDisplay.js        |  131 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 100 insertions(+), 35 deletions(-)
---
diff --git a/data/theme/gnome-shell.css b/data/theme/gnome-shell.css
index ae633a0..e08b954 100644
--- a/data/theme/gnome-shell.css
+++ b/data/theme/gnome-shell.css
@@ -900,9 +900,9 @@ StScrollBar StButton#vhandle:active {
 
 .search-display > StBoxLayout,
 .all-apps,
-.frequent-apps > StBoxLayout {
+.frequent-apps > StBoxLayout{
     /* horizontal padding to make sure scrollbars or dash don't overlap content */
-    padding: 8px 88px;
+    padding: 10px 88px;
 }
 
 .pages-indicator {
diff --git a/js/ui/appDisplay.js b/js/ui/appDisplay.js
index 05460b7..e67dea9 100644
--- a/js/ui/appDisplay.js
+++ b/js/ui/appDisplay.js
@@ -463,7 +463,7 @@ const PaginationIconIndicator = new Lang.Class({
         this.actor.set_child(this._icon);
         this.actor._delegate = this;
         this._parent = parent;
-        this._index = index;
+        this.actor._index = index;
     },
 
     _createIcon: function(size) {
@@ -474,8 +474,8 @@ const PaginationIconIndicator = new Lang.Class({
         return this._icon;
     },
 
-    _onClicked: function(actor, button) {
-        this._parent.goToPage(this._index); 
+    _onClicked: function(actor, button) {        
+        this._parent.goToPage(this.actor._index); 
         return false;
     },
     
@@ -484,29 +484,55 @@ const PaginationIconIndicator = new Lang.Class({
     }
 });
 
-const IndicatorLayout = Lang.Class({
-    Name:'IndicatorLayout',
-    Extends: Clutter.BoxLayout,
-
-    vfunc_get_preferred_width: function(container, forHeight) {
-        let [minWidth, natWidth] = container.get_children()[0].get_preferred_width(forHeight);
-        let totalWidth = natWidth + this.spacing * 2;
-        return [totalWidth, totalWidth];
+const PaginationIndicator = new Lang.Class({
+    Name:'PaginationIndicator',
+    
+    _init: function(params) {
+        params['y_expand'] = true;
+        this.actor = new Shell.GenericContainer(params);
+        this.actor.connect('get-preferred-height', Lang.bind(this, this._getPreferredHeight));
+        this.actor.connect('get-preferred-width', Lang.bind(this, this._getPreferredWidth));
+        this.actor.connect('allocate', Lang.bind(this, this._allocate));
+        this.actor.connect('style-changed', Lang.bind(this, this._styleChanged));
+        this._spacing = 0;
+    },
+    
+    _getPreferredHeight: function(actor, forWidth, alloc) {
+        let [minHeight, natHeight] = this.actor.get_children()[0].get_preferred_height(forWidth);
+        if(this._nPages) {
+            let natHeightPerChild = natHeight + this._spacing;
+            let totalUsedHeight =  this._nPages * natHeightPerChild - this._spacing;
+            let minHeightPerChild = minHeight + this._spacing;
+            minHeight = this._nPages * minHeightPerChild - this._spacing;
+            natHeight = this._nPages * natHeightPerChild - this._spacing;
+        } else
+            minHeight = natHeight = 0;
+        alloc.min_size = minHeight;
+        alloc.natural_size = natHeight;
+    },
+    
+    _getPreferredWidth: function(actor, forHeight, alloc) {
+        let [minWidth, natWidth] = this.actor.get_children()[0].get_preferred_width(forHeight);
+        let totalWidth = natWidth + this._spacing;
+        alloc.min_size = totalWidth;
+        alloc.natural_size = totalWidth;
     },
 
-    vfunc_allocate: function(container, box, flags) {
-        let children = container.get_children();
+    _allocate: function(actor, box, flags) {
+        let children = this.actor.get_children();
+        for(let i in children)
+            this.actor.set_skip_paint(children[i], true);
         if(children.length < 1)
             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  * this.spacing * 2  - this.spacing + this._nPages * natHeight;
-        let heightPerChild = totalUsedHeight / this._nPages;
+        let heightPerChild = natHeight + this._spacing;
+        let totalUsedHeight =  this._nPages * heightPerChild - this._spacing;
+        
         let [minWidth, natWidth] = children[0].get_preferred_width(natHeight);
-        let widthPerChild = natWidth + this.spacing * 2;
-        let firstPosition = [this.spacing, availHeight / 2 - totalUsedHeight / 2];
-
+        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 = 0;
@@ -514,6 +540,7 @@ const IndicatorLayout = Lang.Class({
             childBox.y1 = firstPosition[1] + i * heightPerChild;
             childBox.y2 = childBox.y1 + heightPerChild;
             children[i].allocate(childBox, flags);
+            this.actor.set_skip_paint(children[i], false);
         }
     },
 
@@ -536,25 +563,24 @@ const AllView = new Lang.Class({
         let paginationScrollViewParams = {style_class: 'all-apps'};
         this._paginationView = new PaginationScrollView(this, paginationScrollViewParams);
 
-        this._paginationIndicatorLayout = new IndicatorLayout({orientation: Clutter.Orientation.VERTICAL});
-        this._paginationIndicatorLayout._nPages = 0;
-
-        this._paginationIndicator = new St.Widget({ x_align:3, y_align: 2,
-                                                    style_class: 'pages-indicator' });
-        this._paginationIndicator.set_layout_manager(this._paginationIndicatorLayout);
+        this._paginationIndicator = new PaginationIndicator({style_class: 'pages-indicator'});
+        this._paginationIndicator._nPages = 0;
         let layout = new Clutter.BinLayout();
         this.actor = new Shell.GenericContainer({ layout_manager: layout, 
                                                   x_expand:true, y_expand:true });
         
         layout.add(this._paginationView, 2,2);
-        layout.add(this._paginationIndicator, 3,2);
+        if(Clutter.get_default_text_direction() == Clutter.TextDirection.RTL)
+            layout.add(this._paginationIndicator.actor, 2,2);
+        else
+            layout.add(this._paginationIndicator.actor, 3,2);
         for(let i = 0; i < MAX_APPS_PAGES; i++) {
 
             let indicatorIcon = new PaginationIconIndicator(this, i);
             if(i == 0) {
                 indicatorIcon.setChecked(true);
             }
-            this._paginationIndicator.add_child(indicatorIcon.actor);
+            this._paginationIndicator.actor.add_actor(indicatorIcon.actor);
         }
         this.actor.connect('allocate', Lang.bind(this, this._allocate));
     },
@@ -580,8 +606,9 @@ const AllView = new Lang.Class({
 
     _updatedNPages: function(iconGrid, nPages) {
         // We don't need a relayout because we already done it at iconGrid
-        // when pages are calculated (and then the signal is emitted before that)
-        this._paginationIndicatorLayout._nPages = nPages;        
+        // when pages are calculated (and then the signal is emitted before that)");
+        this._paginationIndicator._nPages = nPages;
+        this._paginationView.invalidatePagination = true;
     },
 
     _onKeyRelease: function(actor, event) {
@@ -632,10 +659,22 @@ const AllView = new Lang.Class({
         this._paginationView._pages.loadGrid();
     },
     
-    goToPage: function(index) {
-        this._paginationIndicator.get_child_at_index(this._paginationView.currentPage()).set_checked(false);
-        this._paginationView.goToPage(index);
-        this._paginationIndicator.get_child_at_index(this._paginationView.currentPage()).set_checked(true);
+    goToPage: function(index, action) {
+        
this._paginationIndicator.actor.get_child_at_index(this._paginationView.currentPage()).set_checked(false);
+        this._paginationView.goToPage(index, action);
+        
this._paginationIndicator.actor.get_child_at_index(this._paginationView.currentPage()).set_checked(true);
+    },
+    
+    onUpdatedDisplaySize: function(width, height) {
+        let box = new Clutter.ActorBox();
+        box.x1 = 0;
+        box.x2 = width;
+        box.y1 = 0;
+        box.y2 = height;
+        box = this.actor.get_theme_node().get_content_box(box);
+        let availWidth = box.x2 - box.x1;
+        let availHeight = box.y2 - box.y1;
+        this._paginationView.onUpdatedDisplaySize(availWidth, availHeight);
     }
 });
 
@@ -664,7 +703,26 @@ const FrequentView = new Lang.Class({
                 continue;
             let appIcon = new AppIcon(mostUsed[i]);
             this._grid.addItem(appIcon.actor, -1);
-        }    }
+        }
+    },
+    
+    onUpdatedDisplaySize: function(width, height) {
+        let box = new Clutter.ActorBox();
+        box.x1 = 0;
+        box.x2 = width;
+        box.y1 = 0;
+        box.y2 = height;
+        box = this.actor.get_theme_node().get_content_box(box);
+        box = this._grid.actor.get_theme_node().get_content_box(box);
+        let availWidth = box.x2 - box.x1;
+        let availHeight = box.y2 - box.y1;
+        let spacing = this._grid.maxSpacingForWidthHeight(availWidth, availHeight, MIN_COLUMNS, MIN_ROWS, 
true);
+        this._grid.top_padding = spacing;
+        this._grid.bottom_padding = spacing;
+        this._grid.left_padding = spacing;
+        this._grid.right_padding = spacing;
+        this._grid.setSpacing(spacing);
+    }
 });
 
 const Views = {
@@ -845,6 +903,13 @@ const AppDisplay = new Lang.Class({
             if (focused)
                 this.actor.navigate_focus(null, Gtk.DirectionType.TAB_FORWARD, false);
         }
+    },
+    
+    _onUpdatedDisplaySize: function(actor, width, height) {
+        //FIXME
+        for (let i = 0; i < this._views.length; i++) {
+            this._views[i].view.onUpdatedDisplaySize(width, height);
+        }
     }
 });
 


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