popupMenu: Remove non-all-spanning versions of colspan in popup menus

This simplifies the code considerably, and makes 'expand' behave as expected.

https://bugzilla.gnome.org/show_bug.cgi?id=704336
This commit is contained in:
Jasper St. Pierre 2013-07-15 19:05:46 -04:00
parent a2b499c460
commit 126f0ed95d
2 changed files with 13 additions and 25 deletions

View File

@ -172,14 +172,11 @@ const PopupBaseMenuItem = new Lang.Class({
this.emit('destroy'); this.emit('destroy');
}, },
// adds an actor to the menu item; @params can contain %span // adds an actor to the menu item; @params can contain
// (column span; defaults to 1, -1 means "all the remaining width"),
// %expand (defaults to #false), and %align (defaults to // %expand (defaults to #false), and %align (defaults to
// #St.Align.START) // #St.Align.START)
addActor: function(child, params) { addActor: function(child, params) {
params = Params.parse(params, { span: 1, params = Params.parse(params, { expand: false, align: St.Align.START });
expand: false,
align: St.Align.START });
params.actor = child; params.actor = child;
this._children.push(params); this._children.push(params);
this.actor.connect('destroy', Lang.bind(this, function () { this._removeChild(child); })); this.actor.connect('destroy', Lang.bind(this, function () { this._removeChild(child); }));
@ -226,10 +223,6 @@ const PopupBaseMenuItem = new Lang.Class({
let child = this._children[i]; let child = this._children[i];
let [min, natural] = child.actor.get_preferred_width(-1); let [min, natural] = child.actor.get_preferred_width(-1);
widths[col++] = natural; widths[col++] = natural;
if (child.span > 1) {
for (let j = 1; j < child.span; j++)
widths[col++] = 0;
}
} }
return widths; return widths;
}, },
@ -263,14 +256,14 @@ const PopupBaseMenuItem = new Lang.Class({
for (let i = 0; i < this._children.length; i++) { for (let i = 0; i < this._children.length; i++) {
let child = this._children[i]; let child = this._children[i];
if (this._columnWidths) { if (this._columnWidths) {
if (child.span == -1) { if (child.expand) {
childWidth = 0; childWidth = 0;
for (let j = i; j < this._columnWidths.length; j++) for (let j = i; j < this._columnWidths.length; j++)
childWidth += this._columnWidths[j] childWidth += this._columnWidths[j];
} else } else
childWidth = this._columnWidths[i]; childWidth = this._columnWidths[i];
} else { } else {
if (child.span == -1) if (child.expand)
childWidth = forWidth - x; childWidth = forWidth - x;
else else
[minWidth, childWidth] = child.actor.get_preferred_width(-1); [minWidth, childWidth] = child.actor.get_preferred_width(-1);
@ -316,16 +309,13 @@ const PopupBaseMenuItem = new Lang.Class({
let [minWidth, naturalWidth] = child.actor.get_preferred_width(-1); let [minWidth, naturalWidth] = child.actor.get_preferred_width(-1);
let availWidth; let availWidth;
if (child.span == -1) { if (child.expand) {
availWidth = box.x2 - x; availWidth = box.x2 - x;
} else { } else {
if (this._columnWidths) { if (this._columnWidths)
availWidth = 0; availWidth += this._columnWidths[col++];
for (let j = 0; j < child.span; j++) else
availWidth += this._columnWidths[col++];
} else {
availWidth = naturalWidth; availWidth = naturalWidth;
}
} }
if (direction == Clutter.TextDirection.RTL) if (direction == Clutter.TextDirection.RTL)
@ -375,7 +365,7 @@ const PopupSeparatorMenuItem = new Lang.Class({
can_focus: false}); can_focus: false});
this._box = new St.BoxLayout(); this._box = new St.BoxLayout();
this.addActor(this._box, { span: -1, expand: true }); this.addActor(this._box, { expand: true });
this.label = new St.Label({ text: text || '' }); this.label = new St.Label({ text: text || '' });
this._box.add(this.label); this._box.add(this.label);
@ -558,8 +548,7 @@ const PopupSwitchMenuItem = new Lang.Class({
this.addActor(this.label); this.addActor(this.label);
this._statusBin = new St.Bin({ x_align: St.Align.END }); this._statusBin = new St.Bin({ x_align: St.Align.END });
this.addActor(this._statusBin, this.addActor(this._statusBin, { expand: true, align: St.Align.END });
{ expand: true, span: -1, align: St.Align.END });
this._statusLabel = new St.Label({ text: '', this._statusLabel = new St.Label({ text: '',
style_class: 'popup-status-menu-item' style_class: 'popup-status-menu-item'
@ -1546,8 +1535,7 @@ const PopupComboBoxMenuItem = new Lang.Class({
this.addActor(this._itemBox); this.addActor(this._itemBox);
let expander = new St.Label({ text: '\u2304' }); let expander = new St.Label({ text: '\u2304' });
this.addActor(expander, { align: St.Align.END, this.addActor(expander, { align: St.Align.END });
span: -1 });
this._menu = new PopupComboMenu(this.actor); this._menu = new PopupComboMenu(this.actor);
Main.uiGroup.add_actor(this._menu.actor); Main.uiGroup.add_actor(this._menu.actor);

View File

@ -92,7 +92,7 @@ const IMUserNameItem = new Lang.Class({
Lang.bind(this, this._wrapperGetPreferredHeight)); Lang.bind(this, this._wrapperGetPreferredHeight));
this._wrapper.connect('allocate', this._wrapper.connect('allocate',
Lang.bind(this, this._wrapperAllocate)); Lang.bind(this, this._wrapperAllocate));
this.addActor(this._wrapper, { expand: true, span: -1 }); this.addActor(this._wrapper, { expand: true });
this.label = new St.Label(); this.label = new St.Label();
this.label.clutter_text.set_line_wrap(true); this.label.clutter_text.set_line_wrap(true);