#include "GuiListControlItemArrangers.h"
#include "../Templates/GuiControlTemplates.h"
#include "../Templates/GuiThemeStyleFactory.h"
#include "../GuiButtonControls.h"
namespace
{
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
elements
;
using
namespace
compositions
;
namespace
{
void
::
()
{
if
(
)
{
->
.
(
->
());
}
}
::
(
,
,
)
{
=
/
;
if
(
<
visibleCount
)
{
visibleCount
=
;
}
else
if
(
>
visibleCount
)
{
=
-
*
;
=
-
deltaA
;
if
(
deltaB
<
deltaA
)
{
visibleCount
++;
}
}
return
visibleCount
*
;
}
::
::
(
)
{
*
=
nullptr
;
if
(
->
())
{
backgroundButton
=
new
(
theme
::
::
);
if
(
auto
=
->
TypedControlTemplateObject
(
true
)->
())
{
backgroundButton
->
(
style
);
}
backgroundButton
->
(
false
);
backgroundButton
->
(
false
);
}
auto
=
->
(
,
backgroundButton
->
());
if
(
backgroundButton
)
{
itemStyle
->
(
(
0
,
0
,
0
,
0
));
itemStyle
->
.
([=](
*
,
&
)
{
backgroundButton
->
(
itemStyle
->
());
});
backgroundButton
->
(
itemStyle
->
());
backgroundButton
->
()->
(
itemStyle
);
}
return
{
itemStyle
,
backgroundButton
};
}
void
::
(
)
{
->
(
.
);
if
(
.
)
{
(
.
);
}
}
compositions
::
*
::
(
)
{
return
.
?
.
->
() :
.
;
}
void
::
()
{
=
0
;
if
(
)
{
for
(
=
0
;
i
<
.
();
i
++)
{
(
i
]);
}
}
.
();
(
0
,
0
,
0
,
0
);
();
();
}
void
::
(
,
)
{
=
+
.
() -
1
;
=
0
;
=
->
();
(
true
,
,
newStartIndex
);
if
(
newStartIndex
<
0
)
newStartIndex
=
0
;
;
for
(
=
newStartIndex
;
i
<
itemCount
;
i
++)
{
bool
=
<=
i
&&
i
<=
endIndex
;
auto
=
reuseOldStyle
?
i
-
] :
(
i
);
newVisibleStyles
.
(
style
);
;
;
(
true
, !
reuseOldStyle
,
i
,
style
,
,
bounds
,
alignmentToParent
);
if
(
(
i
,
style
,
bounds
,
))
{
break
;
}
bounds
.
-=
.
;
bounds
.
-=
.
;
bounds
.
-=
.
;
bounds
.
-=
.
;
}
=
newStartIndex
+
newVisibleStyles
.
() -
1
;
for
(
=
0
;
i
<
.
();
i
++)
{
=
+
i
;
if
(
index
<
newStartIndex
||
index
>
newEndIndex
)
{
(
i
]);
}
}
(
,
newVisibleStyles
);
if
(
(
true
,
,
newStartIndex
))
{
->
();
();
}
=
newStartIndex
;
}
void
::
()
{
=
;
(
false
,
,
newStartIndex
);
for
(
=
0
;
i
<
.
();
i
++)
{
auto
=
i
];
;
(-
1
, -
1
, -
1
, -
1
);
(
false
,
false
,
+
i
,
style
,
,
bounds
,
alignmentToParent
);
bounds
.
-=
.
;
bounds
.
-=
.
;
bounds
.
-=
.
;
bounds
.
-=
.
;
->
SetStyleAlignmentToParent
(
(
style
),
alignmentToParent
);
->
(
(
style
),
bounds
);
}
(
false
,
,
);
}
::
()
{
}
::
()
{
}
void
::
(
::
*
)
{
=
;
if
(
)
{
(
0
,
0
,
->
());
}
}
void
::
(
,
,
)
{
if
(
&& !
->
())
{
=
true
;
{
=
.
();
=
->
();
<
>
;
for
(
=
0
;
i
<
visibleCount
;
i
++)
{
=
+
i
;
if
(
index
>=
itemCount
)
{
break
;
}
= -
1
;
if
(
index
<
)
{
oldIndex
=
index
;
}
else
if
(
index
>=
+
)
{
oldIndex
=
index
-
+
;
}
if
(
oldIndex
!= -
1
)
{
if
(
oldIndex
>=
&&
oldIndex
<
+
visibleCount
)
{
auto
=
oldIndex
-
];
reusedStyles
.
(
style
);
.
(
style
);
}
else
{
oldIndex
= -
1
;
}
}
if
(
oldIndex
== -
1
)
{
.
(
(
index
));
}
}
for
(
=
0
;
i
<
visibleCount
;
i
++)
{
auto
=
i
];
if
(!
reusedStyles
.
(
style
))
{
(
style
);
}
}
.
(
0
,
visibleCount
);
for
(
=
0
;
i
<
.
();
i
++)
{
i
].
->
(
+
i
);
}
}
=
false
;
->
();
->
(
.
());
();
}
}
void
::
(
*
)
{
=
;
();
}
void
::
()
{
=
0
;
}
::
*
::
()
{
return
;
}
void
::
(
::
*
)
{
if
(
!=
)
{
();
=
;
}
}
::
()
{
if
(
)
{
return
();
}
else
{
return
(
0
,
0
);
}
}
::
*
::
(
)
{
if
(
<=
&&
<
+
.
())
{
return
-
].
;
}
else
{
return
nullptr
;
}
}
::
(
::
*
)
{
for
(
=
0
;
i
<
.
();
i
++)
{
if
(
i
].
==
)
{
return
i
+
;
}
}
return
-
1
;
}
void
::
()
{
();
}
void
::
(
)
{
if
(!
)
{
=
true
;
=
;
;
if
(
)
{
(
oldBounds
,
);
();
}
=
false
;
}
}
void
::
(
)
{
if
(
.
() ==
0
)
return
;
if
(
==
0
)
{
=
1
;
0
] =
0
;
}
for
(
=
;
i
<
&&
i
<
.
();
i
++)
{
i
] =
i
-
1
] +
i
-
1
];
}
}
void
::
(
bool
,
,
&
)
{
=
false
;
(
.
() -
1
);
if
(
)
{
for
(
=
0
;
i
<
.
();
i
++)
{
if
(
i
] +
i
] >=
.
())
{
=
i
;
break
;
}
}
}
}
void
::
(
bool
,
bool
,
,
,
,
&
,
&
)
{
=
];
{
auto
=
(
);
auto
=
->
(
composition
);
->
(
composition
,
(
.
(),
(
.
(),
.
())));
=
->
(
composition
).
;
->
(
composition
,
currentBounds
);
if
(!
||
styleHeight
<
newStyleHeight
)
{
styleHeight
=
newStyleHeight
;
}
}
if
(
] !=
styleHeight
)
{
] =
styleHeight
;
=
true
;
}
=
==
0
?
0
:
-
1
] +
-
1
];
if
(
<=
||
] !=
styleOffset
)
{
] =
styleOffset
;
=
;
}
(
(
0
,
]),
(
.
(),
]));
}
bool
::
(
,
,
,
)
{
return
.
() >=
.
();
}
bool
::
(
bool
,
,
)
{
if
(
)
{
return
;
}
return
false
;
}
void
::
()
{
=
0
;
for
(
=
0
;
i
<
.
();
i
++)
{
i
] =
1
;
}
}
::
()
{
if
(
.
() ==
0
)
return
(
0
,
0
);
(
.
());
return
(
.
(),
.
() -
1
] +
.
() -
1
]);
}
::
()
{
}
::
()
{
}
void
::
(
::
*
)
{
if
(
)
{
=
->
();
.
(
itemCount
);
.
(
itemCount
);
for
(
=
0
;
i
<
.
();
i
++)
{
i
] =
1
;
}
=
0
;
}
else
{
.
(
0
);
.
(
0
);
=
0
;
}
::
(
);
}
void
::
(
,
,
)
{
=
;
=
.
() +
-
;
if
(
<
)
{
.
(
itemCount
);
if
(
+
<
itemCount
)
{
(&
+
], &
+
],
sizeof
(
) * (
itemCount
-
-
));
}
}
else
if
(
>
)
{
if
(
+
<
itemCount
)
{
(&
+
], &
+
],
sizeof
(
) * (
itemCount
-
-
));
}
.
(
itemCount
);
}
for
(
=
0
;
i
<
;
i
++)
{
+
i
] =
1
;
}
.
(
itemCount
);
::
(
,
,
);
}
::
(
,
compositions
::
)
{
=
->
();
if
(
count
==
0
)
return
-
1
;
switch
(
)
{
case
::
:
--;
break
;
case
::
:
++;
break
;
case
::
:
=
0
;
break
;
case
::
:
=
count
;
break
;
case
::
:
-=
.
();
break
;
case
::
:
+=
.
();
break
;
default
:
return
-
1
;
}
if
(
<
0
)
return
0
;
else
if
(
>=
count
)
return
count
-
1
;
else
return
;
}
::
::
(
)
{
if
(
)
{
bool
=
false
;
while
(
true
)
{
if
(
<
0
||
>=
->
())
{
return
::
::
;
}
(
);
=
.
;
=
];
=
top
+
];
=
.
();
=
.
();
if
(
offset
>
top
)
{
location
.
=
top
;
}
else
if
(
offset
<
bottom
-
height
)
{
location
.
=
bottom
-
height
;
}
else
{
break
;
}
auto
=
.
();
->
(
location
);
moved
|=
.
()
oldLeftTop
;
if
(
.
()
location
)
break
;
}
return
moved
?
::
::
:
::
::
;
}
return
::
::
;
}
::
(
)
{
=
.
*
2
;
if
(
.
<
h
)
.
=
h
;
return
;
}
::
()
{
return
-
1
;
}
::
()
{
return
0
;
}
void
::
(
bool
,
,
&
)
{
=
();
if
(
)
{
=
;
= (
.
() -
()) /
;
}
}
void
::
(
bool
,
bool
,
,
,
,
&
,
&
)
{
=
() +
*
;
if
(
== -
1
)
{
(
0
, -
1
,
0
, -
1
);
(
(
0
,
top
),
(
0
,
));
}
else
{
(-
1
, -
1
, -
1
, -
1
);
(
(
0
,
top
),
(
,
));
}
if
(
)
{
=
->
(
(
)).
;
if
(
<
styleHeight
)
{
=
styleHeight
;
}
}
}
bool
::
(
,
,
,
)
{
return
.
() >=
.
();
}
bool
::
(
bool
,
,
)
{
if
(
)
{
if
(
!=
)
{
= (
-
) *
;
=
;
->
(
(
0
,
.
() +
offset
));
return
true
;
}
}
return
false
;
}
void
::
()
{
=
1
;
}
::
()
{
=
();
if
(
width
<
0
)
width
=
0
;
return
(
width
,
*
->
() +
());
}
::
()
{
}
::
()
{
}
::
(
,
compositions
::
)
{
=
->
();
if
(
count
==
0
)
return
-
1
;
=
.
() /
;
if
(
groupCount
==
0
)
groupCount
=
1
;
switch
(
)
{
case
::
:
--;
break
;
case
::
:
++;
break
;
case
::
:
=
0
;
break
;
case
::
:
=
count
;
break
;
case
::
:
-=
groupCount
;
break
;
case
::
:
+=
groupCount
;
break
;
default
:
return
-
1
;
}
if
(
<
0
)
return
0
;
else
if
(
>=
count
)
return
count
-
1
;
else
return
;
}
::
::
(
)
{
if
(
)
{
if
(
<
0
||
>=
->
())
{
return
::
::
;
}
bool
=
false
;
while
(
true
)
{
=
();
=
*
;
=
top
+
+
yOffset
;
if
(
.
() <
)
{
if
(
.
() <
bottom
&&
top
<
.
())
{
break
;
}
}
=
.
();
if
(
top
<
.
())
{
location
.
=
top
;
}
else
if
(
.
() <
bottom
)
{
location
.
=
bottom
-
.
();
}
else
{
break
;
}
auto
=
.
();
->
(
location
);
moved
|=
.
()
oldLeftTop
;
if
(
.
()
location
)
break
;
}
return
moved
?
::
::
:
::
::
;
}
return
::
::
;
}
::
(
)
{
if
(
)
{
=
();
=
.
-
yOffset
;
=
->
();
return
(
.
,
yOffset
+
(
y
,
itemCount
,
));
}
return
;
}
void
FixedSizeMultiColumnItemArranger
::
(
bool
,
,
&
)
{
if
(
)
{
;
=
.
() /
.
;
if
(
rows
<
0
)
rows
=
0
;
=
.
() /
.
;
if
(
cols
<
1
)
cols
=
1
;
=
rows
*
cols
;
}
}
void
FixedSizeMultiColumnItemArranger
::
(
bool
,
bool
,
,
,
,
&
,
&
)
{
=
.
() /
.
;
if
(
rowItems
<
1
)
rowItems
=
1
;
=
/
rowItems
;
=
%
rowItems
;
(
(
col
*
.
,
row
*
.
),
);
if
(
)
{
=
->
(
(
));
if
(
.
<
styleSize
.
)
.
=
styleSize
.
;
if
(
.
<
styleSize
.
)
.
=
styleSize
.
;
}
}
bool
FixedSizeMultiColumnItemArranger
::
(
,
,
,
)
{
return
.
() >=
.
();
}
bool
FixedSizeMultiColumnItemArranger
::
(
bool
,
,
)
{
if
(
)
{
if
(
)
{
;
return
true
;
}
}
return
false
;
}
void
FixedSizeMultiColumnItemArranger
::
(
,
,
,
&
,
&
)
{
=
.
() /
.
;
if
(
startRow
<
0
)
startRow
=
0
;
= (
.
() -
1
) /
.
;
=
.
() /
.
;
if
(
cols
<
1
)
cols
=
1
;
=
startRow
*
cols
;
= (
endRow
+
1
)*
cols
-
1
;
if
(
>=
)
=
-
1
;
}
void
FixedSizeMultiColumnItemArranger
::
()
{
(
1
,
1
);
}
FixedSizeMultiColumnItemArranger
::
()
{
=
.
() /
.
;
if
(
rowItems
<
1
)
rowItems
=
1
;
=
->
() /
rowItems
;
if
(
->
() %
rowItems
)
rows
++;
return
(
.
*
rowItems
,
.
*
rows
);
}
FixedSizeMultiColumnItemArranger
::
FixedSizeMultiColumnItemArranger
()
{
}
FixedSizeMultiColumnItemArranger
::
~
FixedSizeMultiColumnItemArranger
()
{
}
FixedSizeMultiColumnItemArranger
::
(
,
compositions
::
)
{
=
->
();
=
.
() /
.
;
if
(
columnCount
==
0
)
columnCount
=
1
;
=
.
() /
.
;
if
(
rowCount
==
0
)
rowCount
=
1
;
switch
(
)
{
case
::
:
-=
columnCount
;
break
;
case
::
:
+=
columnCount
;
break
;
case
::
:
--;
break
;
case
::
:
++;
break
;
case
::
:
=
0
;
break
;
case
::
:
=
count
;
break
;
case
::
:
-=
columnCount
*
rowCount
;
break
;
case
::
:
+=
columnCount
*
rowCount
;
break
;
case
::
:
-=
%
columnCount
;
break
;
case
::
:
+=
columnCount
-
%
columnCount
-
1
;
break
;
default
:
return
-
1
;
}
if
(
<
0
)
return
0
;
else
if
(
>=
count
)
return
count
-
1
;
else
return
;
}
::
FixedSizeMultiColumnItemArranger
::
(
)
{
if
(
)
{
if
(
<
0
||
>=
->
())
{
return
::
::
;
}
bool
=
false
;
while
(
true
)
{
=
.
;
=
.
() /
.
;
if
(
columnCount
==
0
)
columnCount
=
1
;
=
/
columnCount
;
=
rowIndex
*
rowHeight
;
=
top
+
rowHeight
;
if
(
.
() <
rowHeight
)
{
if
(
.
() <
bottom
&&
top
<
.
())
{
break
;
}
}
=
.
();
if
(
top
<
.
())
{
location
.
=
top
;
}
else
if
(
.
() <
bottom
)
{
location
.
=
bottom
-
.
();
}
else
{
break
;
}
auto
=
.
();
->
(
location
);
moved
|=
.
()
oldLeftTop
;
if
(
.
()
location
)
break
;
}
return
moved
?
::
::
:
::
::
;
}
return
::
::
;
}
FixedSizeMultiColumnItemArranger
::
(
)
{
if
(
)
{
=
->
();
=
.
() /
.
;
=
.
() /
.
;
return
(
(
.
,
columnCount
,
.
),
(
.
,
rowCount
,
.
)
);
}
return
;
}
void
FixedHeightMultiColumnItemArranger
::
(
,
,
&
,
&
)
{
=
.
() /
;
if
(
<
1
)
=
1
;
=
.
() /
.
();
}
void
FixedHeightMultiColumnItemArranger
::
(
bool
,
,
&
)
{
=
0
;
=
0
;
if
(
)
{
=
;
=
.
() /
;
if
(
rows
<
1
)
rows
=
1
;
=
.
() /
.
();
=
rows
*
columns
;
}
}
void
FixedHeightMultiColumnItemArranger
::
(
bool
,
bool
,
,
,
,
&
,
&
)
{
=
.
() /
;
if
(
rows
<
1
)
rows
=
1
;
=
%
rows
;
if
(
row
==
0
)
{
+=
;
=
0
;
}
=
->
(
(
));
if
(
<
styleSize
.
)
=
styleSize
.
;
(
(
+
.
(),
*
row
),
(
0
,
0
));
if
(
)
{
if
(
<
styleSize
.
)
=
styleSize
.
;
}
}
bool
FixedHeightMultiColumnItemArranger
::
(
,
,
,
)
{
return
.
() >=
.
();
}
bool
FixedHeightMultiColumnItemArranger
::
(
bool
,
,
)
{
if
(
)
{
if
(
!=
)
{
=
;
return
true
;
}
}
return
false
;
}
void
FixedHeightMultiColumnItemArranger
::
()
{
=
1
;
}
FixedHeightMultiColumnItemArranger
::
()
{
=
.
() /
;
if
(
rows
<
1
)
rows
=
1
;
=
->
() /
rows
;
if
(
->
() %
rows
)
columns
+=
1
;
return
(
.
() *
columns
,
0
);
}
FixedHeightMultiColumnItemArranger
::
FixedHeightMultiColumnItemArranger
()
:itemHeight(
1
)
{
}
FixedHeightMultiColumnItemArranger
::
~
FixedHeightMultiColumnItemArranger
()
{
}
FixedHeightMultiColumnItemArranger
::
(
,
compositions
::
)
{
=
->
();
=
.
() /
;
if
(
groupCount
==
0
)
groupCount
=
1
;
switch
(
)
{
case
::
:
--;
break
;
case
::
:
++;
break
;
case
::
:
-=
groupCount
;
break
;
case
::
:
+=
groupCount
;
break
;
case
::
:
=
0
;
break
;
case
::
:
=
count
;
break
;
case
::
:
-=
%
groupCount
;
break
;
case
::
:
+=
groupCount
-
%
groupCount
-
1
;
break
;
default
:
return
-
1
;
}
if
(
<
0
)
return
0
;
else
if
(
>=
count
)
return
count
-
1
;
else
return
;
}
::
FixedHeightMultiColumnItemArranger
::
(
)
{
if
(
)
{
if
(
<
0
||
>=
->
())
{
return
::
::
;
}
bool
=
false
;
while
(
true
)
{
=
.
() /
;
if
(
rowCount
==
0
)
rowCount
=
1
;
=
/
rowCount
;
=
;
=
+
.
() -
1
;
=
.
();
if
(
minIndex
<=
&&
<=
maxIndex
)
{
=
->
(
(
-
]));
if
(
0
<
bounds
.
() &&
bounds
.
() <
.
() &&
bounds
.
() >
.
())
{
break
;
}
else
if
(
bounds
.
() <
0
)
{
location
.
-=
.
();
}
else
if
(
bounds
.
() >
.
())
{
location
.
+=
.
();
}
else
{
break
;
}
}
else
if
(
columnIndex
<
minIndex
/
rowCount
)
{
location
.
-=
.
();
}
else
if
(
columnIndex
>=
maxIndex
/
rowCount
)
{
location
.
+=
.
();
}
else
{
break
;
}
auto
=
.
();
->
(
location
);
moved
|=
.
()
oldLeftTop
;
if
(
.
()
location
)
break
;
}
return
moved
?
::
::
:
::
::
;
}
return
::
::
;
}
FixedHeightMultiColumnItemArranger
::
(
)
{
if
(
)
{
=
->
();
return
(
.
,
(
.
,
count
,
));
}
return
;
}
}
}
}
}