[gnome-shell/wip/aggregate-menu: 6/57] popupMenu: Remove column widths
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/wip/aggregate-menu: 6/57] popupMenu: Remove column widths
- Date: Wed, 17 Jul 2013 06:35:33 +0000 (UTC)
commit 0053aede3112c6d1938001b8a13ad6bc9364ac31
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Jul 15 18:58:00 2013 -0400
popupMenu: Remove column widths
This code is too complicated to keep, and the last straw came after the
fixed width menu in the aggregate menu design.
This will break some existing popup menus that rely on the fixed width,
but this will soon be replaced with the aggregate menu. We'll also soon
clean this up further by replacing PopupBaseMenuItem's custom layout code
with an StBoxLayout.
js/ui/popupMenu.js | 130 ++++++----------------------------------------------
1 files changed, 14 insertions(+), 116 deletions(-)
---
diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js
index f7f3b9d..9614f9f 100644
--- a/js/ui/popupMenu.js
+++ b/js/ui/popupMenu.js
@@ -61,7 +61,6 @@ const PopupBaseMenuItem = new Lang.Class({
this._ornament = Ornament.NONE;
this._ornamentLabel = new St.Label({ style_class: 'popup-menu-ornament' });
this.actor.add_actor(this._ornamentLabel);
- this._columnWidths = null;
this._spacing = 0;
this.active = false;
this._activatable = params.reactive && params.activate;
@@ -215,38 +214,14 @@ 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 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;
- }
- return widths;
- },
-
- setColumnWidths: function(widths) {
- this._columnWidths = widths;
- },
-
_getPreferredWidth: function(actor, forHeight, alloc) {
let width = 0;
- if (this._columnWidths) {
- for (let i = 0; i < this._columnWidths.length; i++) {
- if (i > 0)
- width += this._spacing;
- width += this._columnWidths[i];
- }
- } else {
- 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;
- }
+ 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;
}
alloc.min_size = alloc.natural_size = width;
},
@@ -255,19 +230,10 @@ const PopupBaseMenuItem = new Lang.Class({
let height = 0, x = 0, minWidth, childWidth;
for (let i = 0; i < this._children.length; i++) {
let child = this._children[i];
- if (this._columnWidths) {
- if (child.expand) {
- childWidth = 0;
- for (let j = i; j < this._columnWidths.length; j++)
- childWidth += this._columnWidths[j];
- } else
- childWidth = this._columnWidths[i];
- } else {
- if (child.expand)
- childWidth = forWidth - x;
- else
- [minWidth, childWidth] = child.actor.get_preferred_width(-1);
- }
+ if (child.expand)
+ childWidth = forWidth - x;
+ else
+ [minWidth, childWidth] = child.actor.get_preferred_width(-1);
x += childWidth;
let [min, natural] = child.actor.get_preferred_height(childWidth);
@@ -309,14 +275,10 @@ const PopupBaseMenuItem = new Lang.Class({
let [minWidth, naturalWidth] = child.actor.get_preferred_width(-1);
let availWidth;
- if (child.expand) {
+ if (child.expand)
availWidth = box.x2 - x;
- } else {
- if (this._columnWidths)
- availWidth += this._columnWidths[col++];
- else
- availWidth = naturalWidth;
- }
+ else
+ availWidth = naturalWidth;
if (direction == Clutter.TextDirection.RTL)
childBox.x1 = width - x - availWidth;
@@ -647,7 +609,6 @@ const PopupMenuBase = new Lang.Class({
} else {
this.box = new St.BoxLayout({ vertical: true });
}
- this.box.connect_after('queue-relayout', Lang.bind(this, this._menuQueueRelayout));
this.length = 0;
this.isOpen = false;
@@ -914,48 +875,6 @@ const PopupMenuBase = new Lang.Class({
this.length++;
},
- getColumnWidths: function() {
- let columnWidths = [];
- let items = this.box.get_children();
- for (let i = 0; i < items.length; i++) {
- if (!items[i].visible)
- continue;
-
- if (items[i]._delegate instanceof PopupSubMenu)
- continue;
-
- if (items[i]._delegate instanceof PopupBaseMenuItem || items[i]._delegate instanceof
PopupMenuBase) {
- let itemColumnWidths = items[i]._delegate.getColumnWidths();
- for (let j = 0; j < itemColumnWidths.length; j++) {
- if (j >= columnWidths.length || itemColumnWidths[j] > columnWidths[j])
- columnWidths[j] = itemColumnWidths[j];
- }
- }
- }
- return columnWidths;
- },
-
- setColumnWidths: function(widths) {
- let items = this.box.get_children();
- for (let i = 0; i < items.length; i++) {
- if (items[i]._delegate instanceof PopupSubMenu)
- continue;
-
- if (items[i]._delegate instanceof PopupBaseMenuItem || items[i]._delegate instanceof
PopupMenuBase)
- items[i]._delegate.setColumnWidths(widths);
- }
- },
-
- // Because of the above column-width funniness, we need to do a
- // queue-relayout on every item whenever the menu itself changes
- // size, to force clutter to drop its cached size requests. (The
- // menuitems will in turn call queue_relayout on their parent, the
- // menu, but that call will be a no-op since the menu already
- // has a relayout queued, so we won't get stuck in a loop.
- _menuQueueRelayout: function() {
- this.box.get_children().map(function (actor) { actor.queue_relayout(); });
- },
-
addActor: function(actor) {
this.box.add(actor);
},
@@ -1026,12 +945,7 @@ const PopupMenu = new Lang.Class({
this.actor._delegate = this;
this.actor.style_class = 'popup-menu-boxpointer';
- this._boxWrapper = new Shell.GenericContainer();
- this._boxWrapper.connect('get-preferred-width', Lang.bind(this, this._boxGetPreferredWidth));
- this._boxWrapper.connect('get-preferred-height', Lang.bind(this, this._boxGetPreferredHeight));
- this._boxWrapper.connect('allocate', Lang.bind(this, this._boxAllocate));
- this._boxPointer.bin.set_child(this._boxWrapper);
- this._boxWrapper.add_actor(this.box);
+ this._boxPointer.bin.set_child(this.box);
this.actor.add_style_class_name('popup-menu');
global.focus_manager.add_group(this.actor);
@@ -1048,22 +962,6 @@ const PopupMenu = new Lang.Class({
this._openedSubMenu = submenu;
},
- _boxGetPreferredWidth: function (actor, forHeight, alloc) {
- let columnWidths = this.getColumnWidths();
- this.setColumnWidths(columnWidths);
-
- // Now they will request the right sizes
- [alloc.min_size, alloc.natural_size] = this.box.get_preferred_width(forHeight);
- },
-
- _boxGetPreferredHeight: function (actor, forWidth, alloc) {
- [alloc.min_size, alloc.natural_size] = this.box.get_preferred_height(forWidth);
- },
-
- _boxAllocate: function (actor, box, flags) {
- this.box.allocate(box, flags);
- },
-
setArrowOrigin: function(origin) {
this._boxPointer.setArrowOrigin(origin);
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]