From b05be138ccc03b6156758ddcad8586e1ae9240ca Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 6 Aug 2011 04:28:38 +0000 Subject: [PATCH] some changes towards fixed height icon lists --- source/Ox.UI/js/List/Ox.IconItem.js | 4 +++- source/Ox.UI/js/List/Ox.IconList.js | 19 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/source/Ox.UI/js/List/Ox.IconItem.js b/source/Ox.UI/js/List/Ox.IconItem.js index adcf67db..3e673814 100644 --- a/source/Ox.UI/js/List/Ox.IconItem.js +++ b/source/Ox.UI/js/List/Ox.IconItem.js @@ -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 IconItem Object @@ -6,6 +6,7 @@ Ox.IconItem IconItem Object (options) -> IconItem Object (options, self) -> IconItem Object options Options object + fixedRatio if set to a number, icons have a fixed ratio height icon height id element id info 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: '', diff --git a/source/Ox.UI/js/List/Ox.IconList.js b/source/Ox.UI/js/List/Ox.IconList.js index 33459549..ee13fc03 100644 --- a/source/Ox.UI/js/List/Ox.IconList.js +++ b/source/Ox.UI/js/List/Ox.IconList.js @@ -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 IconList Object () -> IconList Object @@ -6,7 +6,9 @@ Ox.IconList IconList Object (options, self) -> IconList Object options Options object centerSelection scroll list so selection is always centered + defaultRatio aspect ratio of icon placeholders draggable can be dragged + fixedRatio if set to a number, icons have a fixed ratio id element id item 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))