diff options
author | Matt Watson <mattdangerw@gmail.com> | 2013-08-07 14:06:58 -0700 |
---|---|---|
committer | Matt Watson <mattdangerw@gmail.com> | 2013-08-07 14:06:58 -0700 |
commit | 8c8fe4fb9dc3eeb8b042fbf7a31e95aadc34d41f (patch) | |
tree | 2932c82a49fd6442f6eba220161e9d5d7b6c90c3 /wikipedia | |
parent | 1ef4cee0962e3172b21a98c7be1d2897bb7fae45 (diff) |
Fixed the sizing of pixbufs in the wikipedia first page
They are now always sized to cover the allocation they need too. Right
now we are double loading the image, once to get its size, which we
should change in the future
[endlessm/eos-sdk#234]
Diffstat (limited to 'wikipedia')
-rw-r--r-- | wikipedia/views/title_label_view.js | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/wikipedia/views/title_label_view.js b/wikipedia/views/title_label_view.js index 15b3085..ccedc8e 100644 --- a/wikipedia/views/title_label_view.js +++ b/wikipedia/views/title_label_view.js @@ -91,17 +91,25 @@ const TitleLabelView = new Lang.Class({ // PRIVATE - _updateImage: function(res_path, width, height) { - let [source_width, source_height] = [width, height]; - if(width > height) + _updateImage: function(res_path, dest_width, dest_height) { + let [source_width, source_height] = [dest_width, dest_height]; + // TODO: We need to get the size of the source image, so right now we + // are loading the image twice, once to get the size, and the again at + // the proper size. We should eventually use a GdkPixbuf.Loader and + // connect to the size-prepared signal, as described in the + // documentation + let temp_pixbuf = GdkPixbuf.Pixbuf.new_from_resource(res_path); + let source_aspect = temp_pixbuf.width / temp_pixbuf.height; + let dest_aspect = dest_width / dest_height; + if(dest_aspect > source_aspect) source_height = -1; else source_width = -1; let source_pixbuf = GdkPixbuf.Pixbuf.new_from_resource_at_scale(res_path, source_width, source_height, true); let cropped_pixbuf = source_pixbuf; - if(width < source_pixbuf.width || height < source_pixbuf.height) - cropped_pixbuf = source_pixbuf.new_subpixbuf(0, 0, width, height); + if(dest_width < source_pixbuf.width || dest_height < source_pixbuf.height) + cropped_pixbuf = source_pixbuf.new_subpixbuf(0, 0, dest_width, dest_height); this._image.set_from_pixbuf(cropped_pixbuf); } }); |