[sushi] all: factor out common code for fallback/folder renderer allocation
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sushi] all: factor out common code for fallback/folder renderer allocation
- Date: Wed, 27 Apr 2011 21:41:02 +0000 (UTC)
commit c1b03f9acb68b57435442bf83373a4148d8516c1
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Apr 27 17:40:21 2011 -0400
all: factor out common code for fallback/folder renderer allocation
src/js/ui/fallbackRenderer.js | 17 ++++++-----------
src/js/ui/utils.js | 30 +++++++++++++++++++++++++++++-
src/js/viewers/folder.js | 15 +++++----------
3 files changed, 40 insertions(+), 22 deletions(-)
---
diff --git a/src/js/ui/fallbackRenderer.js b/src/js/ui/fallbackRenderer.js
index 64c8607..b106271 100644
--- a/src/js/ui/fallbackRenderer.js
+++ b/src/js/ui/fallbackRenderer.js
@@ -4,6 +4,7 @@ let Gettext = imports.gettext.domain("sushi");
let Sushi = imports.gi.Sushi;
let Constants = imports.util.constants;
+let Utils = imports.ui.utils;
function FallbackRenderer(args) {
this._init(args);
@@ -16,6 +17,9 @@ FallbackRenderer.prototype = {
render : function(file, mainWindow) {
this._mainWindow = mainWindow;
+ this.lastWidth = 0;
+ this.lastHeight = 0;
+
this._fileLoader = new Sushi.FileLoader();
this._fileLoader.connect("notify::size",
Lang.bind(this, this._onFileInfoChanged));
@@ -38,7 +42,7 @@ FallbackRenderer.prototype = {
spacing: 1,
"margin-top": 48,
"margin-left": 12,
- "margin-right": 12 });
+ "margin-right": 6 });
this._box.pack_start(vbox, false, false, 0);
let hbox = new Gtk.Box({ orientation: Gtk.Orientation.HORIZONTAL,
@@ -123,15 +127,6 @@ FallbackRenderer.prototype = {
},
getSizeForAllocation : function(allocation) {
- let width = this._box.get_preferred_width();
- let height = this._box.get_preferred_height();
-
- if (width[1] < Constants.VIEW_MIN &&
- height[1] < Constants.VIEW_MIN) {
- width[1] = Constants.VIEW_MIN;
- }
-
- /* return the natural */
- return [ width[1], height[1] ];
+ return Utils.getStaticSize(this, this._box);
}
}
diff --git a/src/js/ui/utils.js b/src/js/ui/utils.js
index 7b87f33..1331756 100644
--- a/src/js/ui/utils.js
+++ b/src/js/ui/utils.js
@@ -1,3 +1,5 @@
+let Constants = imports.util.constants;
+
function getScaledSize(baseSize, allocSize, upscale) {
let allocW = allocSize[0];
let allocH = allocSize[1];
@@ -26,4 +28,30 @@ function getScaledSize(baseSize, allocSize, upscale) {
height *= scale;
return [ Math.floor(width), Math.floor(height) ];
-}
\ No newline at end of file
+}
+
+function getStaticSize(renderer, widget) {
+ let width = widget.get_preferred_width()[1];
+ let height = widget.get_preferred_height()[1];
+
+ if (width < Constants.VIEW_MIN &&
+ height < Constants.VIEW_MIN) {
+ width = Constants.VIEW_MIN;
+ }
+
+ /* never make it shrink; this could happen when the
+ * spinner hides.
+ */
+ if (width < renderer.lastWidth)
+ width = renderer.lastWidth;
+ else
+ renderer.lastWidth = width;
+
+ if (height < renderer.lastHeight)
+ height = renderer.lastHeight;
+ else
+ renderer.lastHeight = height;
+
+ /* return the natural */
+ return [ width, height ];
+}
diff --git a/src/js/viewers/folder.js b/src/js/viewers/folder.js
index 0d8f05f..dccecb6 100644
--- a/src/js/viewers/folder.js
+++ b/src/js/viewers/folder.js
@@ -4,6 +4,7 @@ let Gettext = imports.gettext.domain("sushi");
let Sushi = imports.gi.Sushi;
let Constants = imports.util.constants;
+let Utils = imports.ui.utils;
function FolderRenderer(args) {
this._init(args);
@@ -16,6 +17,9 @@ FolderRenderer.prototype = {
render : function(file, mainWindow) {
this._mainWindow = mainWindow;
+ this.lastWidth = 0;
+ this.lastHeight = 0;
+
this._folderLoader = new Sushi.FileLoader();
this._folderLoader.connect("notify::size",
Lang.bind(this, this._onFolderInfoChanged));
@@ -111,16 +115,7 @@ FolderRenderer.prototype = {
},
getSizeForAllocation : function(allocation) {
- let width = this._box.get_preferred_width();
- let height = this._box.get_preferred_height();
-
- if (width[1] < Constants.VIEW_MIN &&
- height[1] < Constants.VIEW_MIN) {
- width[1] = Constants.VIEW_MIN;
- }
-
- /* return the natural */
- return [ width[1], height[1] ];
+ return Utils.getStaticSize(this, this._box);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]