[gnome-shell/user-status-update: 11/12] status-menu: Wrap long usernames
- From: Florian MÃllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/user-status-update: 11/12] status-menu: Wrap long usernames
- Date: Thu, 4 Aug 2011 22:28:05 +0000 (UTC)
commit c76b9d74430fb9365330e53d4d6886e8d16cc9f9
Author: Florian MÃllner <fmuellner gnome org>
Date: Tue Aug 2 00:03:43 2011 +0200
status-menu: Wrap long usernames
js/ui/statusMenu.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 52 insertions(+), 3 deletions(-)
---
diff --git a/js/ui/statusMenu.js b/js/ui/statusMenu.js
index 630bd0b..79e13c8 100644
--- a/js/ui/statusMenu.js
+++ b/js/ui/statusMenu.js
@@ -22,6 +22,8 @@ const DISABLE_USER_SWITCH_KEY = 'disable-user-switching';
const DISABLE_LOCK_SCREEN_KEY = 'disable-lock-screen';
const DISABLE_LOG_OUT_KEY = 'disable-log-out';
+const WRAP_WIDTH = 150;
+
const IMStatus = {
AVAILABLE: 0,
BUSY: 1,
@@ -61,6 +63,55 @@ IMStatusItem.prototype = {
}
};
+function IMUserNameItem() {
+ this._init();
+}
+
+IMUserNameItem.prototype = {
+ __proto__: PopupMenu.PopupBaseMenuItem.prototype,
+
+ _init: function() {
+ PopupMenu.PopupBaseMenuItem.prototype._init.call(this,
+ { reactive: false,
+ style_class: 'status-chooser-user-name' });
+
+ this._wrapper = new Shell.GenericContainer();
+ this._wrapper.connect('get-preferred-width',
+ Lang.bind(this, this._wrapperGetPreferredWidth));
+ this._wrapper.connect('get-preferred-height',
+ Lang.bind(this, this._wrapperGetPreferredHeight));
+ this._wrapper.connect('allocate',
+ Lang.bind(this, this._wrapperAllocate));
+ this.addActor(this._wrapper, { expand: true, span: -1 });
+
+ this.label = new St.Label();
+ this.label.clutter_text.set_line_wrap(true);
+ this._wrapper.add_actor(this.label);
+ },
+
+ _wrapperGetPreferredWidth: function(actor, forHeight, alloc) {
+ [alloc.min_size, alloc.natural_size] = this.label.get_preferred_width(-1);
+ if (alloc.natural_size > WRAP_WIDTH)
+ alloc.natural_size = WRAP_WIDTH;
+ },
+
+ _wrapperGetPreferredHeight: function(actor, forWidth, alloc) {
+ let minWidth, natWidth;
+ [alloc.min_size, alloc.natural_size] = this.label.get_preferred_height(forWidth);
+ [minWidth, natWidth] = this.label.get_preferred_width(-1);
+ if (natWidth > WRAP_WIDTH) {
+ alloc.min_size *= 2;
+ alloc.natural_size *= 2;
+ }
+ },
+
+ _wrapperAllocate: function(actor, box, flags) {
+ let availWidth = box.x2 - box.x1;
+ let availHeight = box.y2 - box.y1;
+ this.label.allocate(box, flags);
+ }
+};
+
function IMStatusChooserItem() {
this._init();
}
@@ -84,9 +135,7 @@ IMStatusChooserItem.prototype = {
this._section = new PopupMenu.PopupMenuSection();
this.addActor(this._section.actor);
- this._name = new PopupMenu.PopupMenuItem('',
- { reactive: false,
- style_class: 'status-chooser-user-name' });
+ this._name = new IMUserNameItem();
this._section.addMenuItem(this._name);
this._combo = new PopupMenu.PopupComboBoxMenuItem({ style_class: 'status-chooser-combo' });
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]