From d8bb65192d65d4c3cabb09b37a63dab70084d05f Mon Sep 17 00:00:00 2001 From: Rory MacQueen Date: Wed, 18 Sep 2013 11:00:01 -0700 Subject: Renamed TextButton to ListTextButton so that we can have other textbuttons --- wikipedia/widgets/ListTextButton.js | 58 +++++++++++++++++++++++++++++++++++++ wikipedia/widgets/TextButton.js | 58 ------------------------------------- 2 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 wikipedia/widgets/ListTextButton.js delete mode 100644 wikipedia/widgets/TextButton.js (limited to 'wikipedia/widgets') diff --git a/wikipedia/widgets/ListTextButton.js b/wikipedia/widgets/ListTextButton.js new file mode 100644 index 0000000..a3a141b --- /dev/null +++ b/wikipedia/widgets/ListTextButton.js @@ -0,0 +1,58 @@ +const Lang = imports.lang; +const Gdk = imports.gi.Gdk; +const GdkPixbuf = imports.gi.GdkPixbuf; +const Gtk = imports.gi.Gtk; +const Pango = imports.gi.Pango; + +// This is an approximate number of characters that will keep the label from +// going over its specified width +const ARTICLE_LABEL_MAX_WIDTH_CHARS = 24; + +const ListTextButton = new Lang.Class({ + Name: 'EndlessListTextButton', + Extends: Gtk.Button, + + // This is a button for the article list widget. It has a label and an icon image. + // The icon image will only appear on hover or press of button + _init: function(hover_icon_path, label_text, params) { + params.hexpand = true; + this.parent(params); + + this._hover_icon_pixbuf = GdkPixbuf.Pixbuf.new_from_resource(hover_icon_path); + + this._image = new Gtk.Image({ + no_show_all: true + }); + this._image.set_from_pixbuf(this._hover_icon_pixbuf); + + this._box = new Gtk.Box({ + orientation: Gtk.Orientation.HORIZONTAL + }); + + this._label = new Gtk.Label({ + label: label_text.toUpperCase(), + max_width_chars: ARTICLE_LABEL_MAX_WIDTH_CHARS, + ellipsize: Pango.EllipsizeMode.END + }); + + this._box.pack_start(this._label, false, false, 0); + this._box.pack_end(this._image, false, false, 0); + + this.add(this._box); + this.connect('state-changed', Lang.bind(this, this._update_appearance)); + this.show_all(); + }, + + _update_appearance: function(widget, state) { + // If button is hovered over and/or pressed, then show the arrow icon + if (widget.get_state_flags() & Gtk.StateFlags.ACTIVE || + widget.get_state_flags() & Gtk.StateFlags.PRELIGHT) { + this._image.show(); + return false; + } + // If no hover or press, then hide the arrow icon + this._image.hide(); + return false; + } +}); + diff --git a/wikipedia/widgets/TextButton.js b/wikipedia/widgets/TextButton.js deleted file mode 100644 index 834826f..0000000 --- a/wikipedia/widgets/TextButton.js +++ /dev/null @@ -1,58 +0,0 @@ -const Lang = imports.lang; -const Gdk = imports.gi.Gdk; -const GdkPixbuf = imports.gi.GdkPixbuf; -const Gtk = imports.gi.Gtk; -const Pango = imports.gi.Pango; - -// This is an approximate number of characters that will keep the label from -// going over its specified width -const ARTICLE_LABEL_MAX_WIDTH_CHARS = 24; - -const TextButton = new Lang.Class({ - Name: 'EndlessTextButton', - Extends: Gtk.Button, - - // This is a button for the article list widget. It has a label and an icon image. - // The icon image will only appear on hover or press of button - _init: function(hover_icon_path, label_text, params) { - params.hexpand = true; - this.parent(params); - - this._hover_icon_pixbuf = GdkPixbuf.Pixbuf.new_from_resource(hover_icon_path); - - this._image = new Gtk.Image({ - no_show_all: true - }); - this._image.set_from_pixbuf(this._hover_icon_pixbuf); - - this._box = new Gtk.Box({ - orientation: Gtk.Orientation.HORIZONTAL - }); - - this._label = new Gtk.Label({ - label: label_text.toUpperCase(), - max_width_chars: ARTICLE_LABEL_MAX_WIDTH_CHARS, - ellipsize: Pango.EllipsizeMode.END - }); - - this._box.pack_start(this._label, false, false, 0); - this._box.pack_end(this._image, false, false, 0); - - this.add(this._box); - this.connect('state-changed', Lang.bind(this, this._update_appearance)); - this.show_all(); - }, - - _update_appearance: function(widget, state) { - // If button is hovered over and/or pressed, then show the arrow icon - if (widget.get_state_flags() & Gtk.StateFlags.ACTIVE || - widget.get_state_flags() & Gtk.StateFlags.PRELIGHT) { - this._image.show(); - return false; - } - // If no hover or press, then hide the arrow icon - this._image.hide(); - return false; - } -}); - -- cgit v1.2.3