some changes towards fixed height icon lists

This commit is contained in:
rlx 2011-08-06 04:28:38 +00:00
parent 4642b56a95
commit b05be138cc
2 changed files with 17 additions and 6 deletions

View file

@ -1,4 +1,4 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
// vim: et:ts=4:sw=4:sts=4:ft=js
/*@
Ox.IconItem <f:Ox.Element> IconItem Object
@ -6,6 +6,7 @@ Ox.IconItem <f:Ox.Element> IconItem Object
(options) -> <f> IconItem Object
(options, self) -> <f> IconItem Object
options <o> Options object
fixedRatio <b|n|false> if set to a number, icons have a fixed ratio
height <n|128> icon height
id <s> element id
info <s> icon info
@ -23,6 +24,7 @@ Ox.IconItem = function(options, self) {
self = self || {};
var that = Ox.Element({}, self)
.defaults({
fixedRatio: false,
height: 128,
id: '',
info: '',

View file

@ -1,4 +1,4 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
// vim: et:ts=4:sw=4:sts=4:ft=js
/*@
Ox.IconList <f:Ox.Element> IconList Object
() -> <f> IconList Object
@ -6,7 +6,9 @@ Ox.IconList <f:Ox.Element> IconList Object
(options, self) -> <f> IconList Object
options <o> Options object
centerSelection <b|false> scroll list so selection is always centered
defaultRatio <n|1> aspect ratio of icon placeholders
draggable <b|true> can be dragged
fixedRatio <b|n|false> if set to a number, icons have a fixed ratio
id <s|''> element id
item <f|null> called with data, sort, size,
extends data with information needed for constructor
@ -28,7 +30,9 @@ Ox.IconList = function(options, self) {
var that = Ox.Element({}, self)
.defaults({
centerSelection: false,
defaultRatio: 1,
draggable: true,
fixedRatio: false,
id: '',
item: null,
itemConstructor: Ox.IconItem,
@ -43,6 +47,10 @@ Ox.IconList = function(options, self) {
})
.options(options || {});
if (self.options.fixedRatio) {
self.options.defaultRatio = self.options.fixedRatio;
}
$.extend(self, {
itemHeight: self.options.size * 1.5,
itemWidth: self.options.size
@ -78,11 +86,12 @@ Ox.IconList = function(options, self) {
}
function constructItem(data) {
var data = !$.isEmptyObject(data) ?
self.options.item(data, self.options.sort, self.options.size) :
{height: 8, width: 5},
ratio = data.width / data.height;
var isEmpty = Ox.isEmpty(data);
data = !isEmpty ?
self.options.item(data, self.options.sort, self.options.size) : {}
ratio = !isEmpty ? data.width / data.height : self.options.defaultRatio;
return self.options.itemConstructor($.extend(data, {
fixedRatio: self.options.fixedRatio,
height: Math.round(self.options.size / (ratio <= 1 ? 1 : ratio)),
size: self.options.size,
width: Math.round(self.options.size * (ratio >= 1 ? 1 : ratio))