diff options
author | P. F. Chimento <philip.chimento@gmail.com> | 2013-11-06 16:38:14 -0800 |
---|---|---|
committer | P. F. Chimento <philip.chimento@gmail.com> | 2013-11-06 16:38:14 -0800 |
commit | 0da08f1c39c7f2fdbf2f359c2380e17c61e825ce (patch) | |
tree | b6876789daaf3e3a4707a2a27db09a97709df137 /wikipedia | |
parent | d3744dfc7275e8f78a406a427e996e56b1e113a9 (diff) | |
parent | ddcbb17728b8b22b6d204259b8e97918ac690b0d (diff) |
Merge pull request #392 from endlessm/issues/349
#349 Only load category button images when needed
Diffstat (limited to 'wikipedia')
-rw-r--r-- | wikipedia/widgets/category_button.js | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/wikipedia/widgets/category_button.js b/wikipedia/widgets/category_button.js index 54f0b79..4ca1d90 100644 --- a/wikipedia/widgets/category_button.js +++ b/wikipedia/widgets/category_button.js @@ -61,8 +61,8 @@ const CategoryButton = new Lang.Class({ this._category_title = null; this._clickable_category = null; this._is_main_category = null; + this._pixbuf = null; - this._overlay = new Gtk.Overlay(); this._eventbox = new Gtk.EventBox({ expand: true }); @@ -92,22 +92,15 @@ const CategoryButton = new Lang.Class({ context.add_class(EndlessWikipedia.STYLE_CLASS_TITLE); context.add_class(EndlessWikipedia.STYLE_CLASS_CATEGORY); context.add_class(EndlessWikipedia.STYLE_CLASS_FRONT_PAGE); - this._image = new Gtk.Image({ - expand: true, - halign: Gtk.Align.FILL, - valign: Gtk.Align.FILL - }); // Parent constructor sets all properties this.parent(props); // Put widgets together - this.add(this._overlay); - this._overlay.add(this._image); this._eventbox_grid.add(this._label); this._eventbox_grid.add(this._arrow); this._eventbox.add(this._eventbox_grid); - this._overlay.add_overlay(this._eventbox); + this.add(this._eventbox); this.show_all(); // Connect signals @@ -121,12 +114,6 @@ const CategoryButton = new Lang.Class({ set image_uri(value) { this._image_uri = value; - if(this._image) { - let allocation = this.get_allocation(); - let new_pixbuf = Utils.load_pixbuf_cover(Utils.resourceUriToPath(this._image_uri), - allocation.width, allocation.height); - this._image.set_from_pixbuf(new_pixbuf); - } }, get category_title() { @@ -189,13 +176,24 @@ const CategoryButton = new Lang.Class({ } }, - vfunc_size_allocate: function(allocation) { - this.parent(allocation); - if(this._image_uri !== "" && this._image_uri != null) { - let new_pixbuf = Utils.load_pixbuf_cover(Utils.resourceUriToPath(this._image_uri), - allocation.width, allocation.height); - this._image.set_from_pixbuf(new_pixbuf); + // Reloads the pixbuf from the gresource at the proper size if necessary + _update_pixbuf: function () { + if (this._image_uri === "" || this._image_uri === null) + return; + let allocation = this.get_allocation(); + if (this._pixbuf === null || this._pixbuf.get_width() !== allocation.width || + this._pixbuf.get_height() !== allocation.height) + this._pixbuf = Utils.load_pixbuf_cover(Utils.resourceUriToPath(this._image_uri), + allocation.width, allocation.height); + }, + + vfunc_draw: function (cr) { + this._update_pixbuf(); + if (this._pixbuf !== null) { + Gdk.cairo_set_source_pixbuf(cr, this._pixbuf, 0, 0); + cr.paint(); } + this.parent(cr); }, // HANDLERS |