[gnome-shell/wip/aggregate-menu: 62/99] popupMenu: Properly implement all-spanning actors



commit 9f8b65951edf2cbacb43721ca34b59634fb8e217
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Jun 11 17:30:49 2013 -0400

    popupMenu: Properly implement all-spanning actors
    
    All-spanning actors do not have columns, so don't stuff their width
    in the column. Instead, propagate it manually through the API, making
    sure that the menu is never shorter than the greatest spanning actor.

 js/ui/popupMenu.js |   44 ++++++++++++++++++++++++++++++--------------
 1 files changed, 30 insertions(+), 14 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index ad7c95a..65ba0a6 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -204,17 +204,22 @@ const PopupBaseMenuItem = new Lang.Class({
     // This returns column widths in logical order (i.e. from the dot
     // to the image), not in visual order (left to right)
     getColumnWidths: function() {
+        let maxSpan = 0;
         let widths = [];
         for (let i = 0, col = 0; i < this._children.length; i++) {
             let child = this._children[i];
             let [min, natural] = child.actor.get_preferred_width(-1);
-            widths[col++] = natural;
-            if (child.span > 1) {
-                for (let j = 1; j < child.span; j++)
-                    widths[col++] = 0;
+            if (child.span == -1) {
+                maxSpan = Math.max(maxSpan, natural);
+            } else {
+                widths[col++] = natural;
+                if (child.span > 1) {
+                    for (let j = 1; j < child.span; j++)
+                        widths[col++] = 0;
+                }
             }
         }
-        return widths;
+        return [maxSpan, widths];
     },
 
     setColumnWidths: function(widths) {
@@ -224,19 +229,26 @@ const PopupBaseMenuItem = new Lang.Class({
     _getPreferredWidth: function(actor, forHeight, alloc) {
         let width = 0;
         if (this._columnWidths) {
-            for (let i = 0; i < this._columnWidths.length; i++) {
+            let [maxSpan, widths] = this._columnWidths;
+            for (let i = 0; i < widths.length; i++) {
                 if (i > 0)
                     width += this._spacing;
-                width += this._columnWidths[i];
+                width += widths[i];
             }
+            width = Math.max(width, maxSpan);
         } else {
+            let maxSpan = 0;
             for (let i = 0; i < this._children.length; i++) {
                 let child = this._children[i];
                 if (i > 0)
                     width += this._spacing;
                 let [min, natural] = child.actor.get_preferred_width(-1);
-                width += natural;
+                if (child.span == -1)
+                    maxSpan = Math.max(maxSpan, natural);
+                else
+                    width += natural;
             }
+            width = Math.max(width, maxSpan);
         }
         alloc.min_size = alloc.natural_size = width;
     },
@@ -246,12 +258,13 @@ const PopupBaseMenuItem = new Lang.Class({
         for (let i = 0; i < this._children.length; i++) {
             let child = this._children[i];
             if (this._columnWidths) {
+                let [maxSpan, widths] = this._columnWidths;
                 if (child.span == -1) {
                     childWidth = 0;
-                    for (let j = i; j < this._columnWidths.length; j++)
-                        childWidth += this._columnWidths[j]
+                    for (let j = i; j < widths.length; j++)
+                        childWidth += widths[j];
                 } else
-                    childWidth = this._columnWidths[i];
+                    childWidth = widths[i];
             } else {
                 if (child.span == -1)
                     childWidth = forWidth - x;
@@ -305,6 +318,7 @@ const PopupBaseMenuItem = new Lang.Class({
             let [minWidth, naturalWidth] = child.actor.get_preferred_width(-1);
             let availWidth, extraWidth;
             if (this._columnWidths) {
+                let [maxSpan, widths] = this._columnWidths;
                 if (child.span == -1) {
                     if (direction == Clutter.TextDirection.LTR)
                         availWidth = box.x2 - x;
@@ -313,7 +327,7 @@ const PopupBaseMenuItem = new Lang.Class({
                 } else {
                     availWidth = 0;
                     for (let j = 0; j < child.span; j++)
-                        availWidth += this._columnWidths[col++];
+                        availWidth += widths[col++];
                 }
                 extraWidth = availWidth - naturalWidth;
             } else {
@@ -903,6 +917,7 @@ const PopupMenuBase = new Lang.Class({
     },
 
     getColumnWidths: function() {
+        let maxSpan = 0;
         let columnWidths = [];
         let items = this.box.get_children();
         for (let i = 0; i < items.length; i++) {
@@ -910,14 +925,15 @@ const PopupMenuBase = new Lang.Class({
                 !(items[i]._delegate instanceof PopupSubMenu && items[i-1].visible))
                 continue;
             if (items[i]._delegate instanceof PopupBaseMenuItem || items[i]._delegate instanceof 
PopupMenuBase) {
-                let itemColumnWidths = items[i]._delegate.getColumnWidths();
+                let [itemMaxSpan, itemColumnWidths] = items[i]._delegate.getColumnWidths();
+                maxSpan = Math.max(maxSpan, itemMaxSpan);
                 for (let j = 0; j < itemColumnWidths.length; j++) {
                     if (j >= columnWidths.length || itemColumnWidths[j] > columnWidths[j])
                         columnWidths[j] = itemColumnWidths[j];
                 }
             }
         }
-        return columnWidths;
+        return [maxSpan, columnWidths];
     },
 
     setColumnWidths: function(widths) {


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