our
$VERSION
=
'0.01'
;
sub
new {
my
$class
=
shift
;
my
$rh_items_info
=
shift
;
my
$self
=
bless
{},
$class
;
if
(!
$rh_items_info
) {
die
'no items info hashref was passed in construction to this layout'
;
}
$self
->_layout_items(
$rh_items_info
);
$self
->finalize();
return
$self
;
}
sub
_layout_items {
my
$self
=
shift
;
my
$rh_items_info
=
shift
;
my
@items_id_sorted
=
sort
{
$rh_items_info
->{
$a
}{pathname}
cmp
$rh_items_info
->{
$b
}{pathname}
}
keys
%$rh_items_info
;
my
$x
= 0;
my
$y
= 0;
my
$total_height
= 0;
my
$total_width
= 0;
my
$row_height
= 0;
my
$parentdir_prev
;
for
my
$id
(
@items_id_sorted
) {
my
$w
=
$rh_items_info
->{
$id
}{width};
my
$h
=
$rh_items_info
->{
$id
}{height};
my
$parentdir
=
$rh_items_info
->{
$id
}{parentdir};
if
(
defined
$parentdir_prev
&&
$parentdir
ne
$parentdir_prev
) {
$y
+=
$row_height
;
$x
= 0;
$row_height
= 0;
}
$self
->set_item_coord(
$id
,
$x
,
$y
);
$x
+=
$w
;
$row_height
=
$h
if
$h
>
$row_height
;
$total_width
=
$x
if
$x
>
$total_width
;
$total_height
=
$y
+
$row_height
if
$y
+
$row_height
>
$total_height
;
$parentdir_prev
=
$parentdir
;
}
$self
->{width} =
$total_width
;
$self
->{height} =
$total_height
;
return
;
}
1;