#include "GuiGraphicsResponsiveComposition.h"
#include "../Controls/GuiBasicControls.h"
namespace
{
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
controls
;
void
GuiResponsiveCompositionBase
::
()
{
::
();
GuiResponsiveCompositionBase
*
=
nullptr
;
{
auto
=
();
while
(
parent
)
{
if
((
responsive
=
dynamic_cast
<
GuiResponsiveCompositionBase
*>(
parent
)))
{
break
;
}
parent
=
parent
->
();
}
}
if
(
!=
responsive
)
{
if
(
)
{
->
(
this
);
->
OnResponsiveChildLevelUpdated
();
}
=
responsive
;
if
(
)
{
->
OnResponsiveChildInserted
(
this
);
->
OnResponsiveChildLevelUpdated
();
}
}
}
void
GuiResponsiveCompositionBase
::
OnResponsiveChildInserted
(
GuiResponsiveCompositionBase
*
)
{
}
void
GuiResponsiveCompositionBase
::
(
GuiResponsiveCompositionBase
*
)
{
}
void
GuiResponsiveCompositionBase
::
OnResponsiveChildLevelUpdated
()
{
if
(
)
{
->
OnResponsiveChildLevelUpdated
();
}
else
{
InvokeOnCompositionStateChanged
();
}
}
GuiResponsiveCompositionBase
::
GuiResponsiveCompositionBase
()
{
(
LimitToElementAndChildren
);
(
(
1
,
1
));
.
(
this
);
.
(
this
);
}
GuiResponsiveCompositionBase
::
~
GuiResponsiveCompositionBase
()
{
}
GuiResponsiveCompositionBase
::
()
{
return
;
}
void
GuiResponsiveCompositionBase
::
(
)
{
if
(
!=
)
{
=
;
OnResponsiveChildLevelUpdated
();
}
}
void
GuiResponsiveSharedCollection
::
(
,
controls
::
*
const
&
)
{
CHECK_ERROR(!value->GetBoundsComposition()->GetParent(), L"GuiResponsiveSharedCollection::BeforeInsert(vint, GuiResponsiveSharedCollection* const&)#Cannot insert a shared control that is currently in use.");
do
{
if
(!(!
->
()->
()))
throw
(
L"GuiResponsiveSharedCollection::BeforeInsert(vint, GuiResponsiveSharedCollection* const&)#Cannot insert a shared control that is currently in use."
);}
while
(
0
);
}
void
GuiResponsiveSharedCollection
::
(
,
controls
::
*
const
&
)
{
->
OnResponsiveChildLevelUpdated
();
}
void
GuiResponsiveSharedCollection
::
(
,
controls
::
*
const
&
)
{
CHECK_ERROR(!value->GetBoundsComposition()->GetParent(), L"GuiResponsiveSharedCollection::BeforeRemove(vint, GuiResponsiveSharedCollection* const&)#Cannot remove a shared control that is currently in use.");
do
{
if
(!(!
->
()->
()))
throw
(
L"GuiResponsiveSharedCollection::BeforeRemove(vint, GuiResponsiveSharedCollection* const&)#Cannot remove a shared control that is currently in use."
);}
while
(
0
);
}
void
GuiResponsiveSharedCollection
::
(
,
)
{
->
OnResponsiveChildLevelUpdated
();
}
GuiResponsiveSharedCollection
::
GuiResponsiveSharedCollection
(
GuiResponsiveViewComposition
*
)
:view(
)
{
}
GuiResponsiveSharedCollection
::
~
GuiResponsiveSharedCollection
()
{
}
void
GuiResponsiveViewCollection
::
(
,
GuiResponsiveCompositionBase
*
const
&
)
{
CHECK_ERROR(!value->GetParent(), L"GuiResponsiveViewCollection::BeforeRemove(vint, GuiResponsiveCompositionBase* const&)#Cannot insert a view that is currently in use.");
do
{
if
(!(!
->
()))
throw
(
L"GuiResponsiveViewCollection::BeforeRemove(vint, GuiResponsiveCompositionBase* const&)#Cannot insert a view that is currently in use."
);}
while
(
0
);
}
void
GuiResponsiveViewCollection
::
(
,
GuiResponsiveCompositionBase
*
const
&
)
{
if
(!
->
)
{
->
=
true
;
->
=
;
->
->
(
(
0
,
0
,
0
,
0
));
->
(
->
);
->
=
false
;
}
->
OnResponsiveChildLevelUpdated
();
}
void
GuiResponsiveViewCollection
::
(
,
GuiResponsiveCompositionBase
*
const
&
)
{
CHECK_ERROR(!value->GetParent(), L"GuiResponsiveViewCollection::BeforeRemove(vint, GuiResponsiveCompositionBase* const&)#Cannot remove a view that is currently in use.");
do
{
if
(!(!
->
()))
throw
(
L"GuiResponsiveViewCollection::BeforeRemove(vint, GuiResponsiveCompositionBase* const&)#Cannot remove a view that is currently in use."
);}
while
(
0
);
}
void
GuiResponsiveViewCollection
::
(
,
)
{
->
OnResponsiveChildLevelUpdated
();
}
GuiResponsiveViewCollection
::
GuiResponsiveViewCollection
(
GuiResponsiveViewComposition
*
)
:view(
)
{
}
GuiResponsiveViewCollection
::
~
GuiResponsiveViewCollection
()
{
}
void
GuiResponsiveSharedComposition
::
()
{
if
(
&&
&& !
->
)
{
auto
=
->
()->
();
CHECK_ERROR(view->sharedControls.Contains(shared), L"GuiResponsiveSharedComposition::SetSharedControl()#The specified shared control is not in GuiResponsiveViewComposition::GetSharedControls().");
do
{
if
(!(
->
.
(
)))
throw
(
L"GuiResponsiveSharedComposition::SetSharedControl()#The specified shared control is not in GuiResponsiveViewComposition::GetSharedControls()."
);}
while
(
0
);
CHECK_ERROR(!sharedParent || sharedParent == this, L"GuiResponsiveSharedComposition::SetSharedControl()#The specified shared control has not been released. This usually means this control is not in GuiResponsiveViewComposition::GetSharedControls().");
do
{
if
(!(!
sharedParent
||
sharedParent
==
this
))
throw
(
L"GuiResponsiveSharedComposition::SetSharedControl()#The specified shared control has not been released. This usually means this control is not in GuiResponsiveViewComposition::GetSharedControls()."
);}
while
(
0
);
if
(!
sharedParent
)
{
->
()->
(
(
0
,
0
,
0
,
0
));
(
->
());
->
.
(
);
}
}
}
void
GuiResponsiveSharedComposition
::
()
{
::
();
if
(
&&
->
)
{
return
;
}
GuiResponsiveViewComposition
*
=
nullptr
;
{
auto
=
();
while
(
parent
)
{
if
((
currentView
=
dynamic_cast
<
GuiResponsiveViewComposition
*>(
parent
)))
{
break
;
}
parent
=
parent
->
();
}
}
if
(
currentView
!=
&&
&&
)
{
(
->
());
->
.
(
);
}
=
currentView
;
();
}
GuiResponsiveSharedComposition
::
GuiResponsiveSharedComposition
()
{
(
LimitToElementAndChildren
);
}
GuiResponsiveSharedComposition
::
~
GuiResponsiveSharedComposition
()
{
}
controls
::
*
GuiResponsiveSharedComposition
::
()
{
return
;
}
void
GuiResponsiveSharedComposition
::
(
controls
::
*
)
{
if
(
!=
)
{
CHECK_ERROR(!shared || !shared->GetBoundsComposition()->GetParent(), L"GuiResponsiveSharedComposition::SetShared(GuiControl*)#Cannot replace a shared control that is currently in use.");
do
{
if
(!(!
|| !
->
()->
()))
throw
(
L"GuiResponsiveSharedComposition::SetShared(GuiControl*)#Cannot replace a shared control that is currently in use."
);}
while
(
0
);
=
;
();
}
}
bool
GuiResponsiveViewComposition
::
()
{
=
;
if
(
.
() ==
0
)
{
=
1
;
}
else
{
=
0
;
for
(
=
0
;
i
<
.
();
i
++)
{
auto
=
i
];
if
(((
)
& (
)
view
->
()) !=
0
)
{
+=
view
->
();
}
else
{
+=
1
;
}
}
}
if
(
old
!=
)
{
.
(
(
this
));
return
true
;
}
return
false
;
}
bool
GuiResponsiveViewComposition
::
()
{
=
;
=
0
;
for
(
=
.
() -
1
;
i
>=
0
;
i
--)
{
auto
=
i
];
if
(((
)
& (
)
view
->
()) !=
0
)
{
if
(
==
view
)
{
+=
view
->
() +
1
;
break
;
}
else
{
+=
view
->
();
}
}
else
{
++;
}
}
--;
if
(
old
!=
)
{
.
(
(
this
));
return
true
;
}
return
false
;
}
void
GuiResponsiveViewComposition
::
OnResponsiveChildLevelUpdated
()
{
if
(!
)
{
();
();
GuiResponsiveCompositionBase
::
OnResponsiveChildLevelUpdated
();
}
}
GuiResponsiveViewComposition
::
GuiResponsiveViewComposition
()
:sharedControls(
this
)
, views(
this
)
{
.
(
this
);
}
GuiResponsiveViewComposition
::
~
GuiResponsiveViewComposition
()
{
=
true
;
FOREACH(GuiResponsiveCompositionBase*, view, views)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
GuiResponsiveCompositionBase
*>&
= ::
vl
::
collections
::
(
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
GuiResponsiveCompositionBase
*
;
__foreach_iterator__
.
(
view
);)
{
if
(
view
!=
)
{
(
view
);
}
}
FOREACH(GuiControl*, shared, From(sharedControls).Except(usedSharedControls))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
*>&
= ::
vl
::
collections
::
(
(
).Except(
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
*
;
__foreach_iterator__
.
(
shared
);)
{
(
shared
);
}
}
GuiResponsiveViewComposition
::
()
{
return
;
}
GuiResponsiveViewComposition
::
()
{
return
;
}
bool
GuiResponsiveViewComposition
::
()
{
=
true
;
if
(((
)
& (
)
->
()) !=
0
&& !
->
())
{
=
.
(
);
if
(
index
<
.
() -
1
)
{
(
);
=
index
+
1
];
->
(
(
0
,
0
,
0
,
0
));
{
(
this
);
arguments
.
=
.
(
);
.
(
arguments
);
}
(
);
}
}
=
false
;
auto
=
();
auto
=
();
if
(!
x
&& !
y
)
return
false
;
InvokeOnCompositionStateChanged
();
return
true
;
}
bool
GuiResponsiveViewComposition
::
()
{
=
true
;
if
(((
)
& (
)
->
()) !=
0
&& !
->
())
{
=
.
(
);
if
(
index
>
0
)
{
(
);
=
index
-
1
];
->
(
(
0
,
0
,
0
,
0
));
{
(
this
);
arguments
.
=
.
(
);
.
(
arguments
);
}
(
);
}
}
=
false
;
auto
=
();
auto
=
();
if
(!
x
&& !
y
)
return
false
;
InvokeOnCompositionStateChanged
();
return
true
;
}
GuiResponsiveCompositionBase
*
GuiResponsiveViewComposition
::
()
{
return
;
}
collections
::
<
controls
::
*>&
GuiResponsiveViewComposition
::
()
{
return
;
}
collections
::
<
GuiResponsiveCompositionBase
*>&
GuiResponsiveViewComposition
::
()
{
return
;
}
void
GuiResponsiveFixedComposition
::
OnResponsiveChildLevelUpdated
()
{
InvokeOnCompositionStateChanged
();
}
GuiResponsiveFixedComposition
::
GuiResponsiveFixedComposition
()
{
}
GuiResponsiveFixedComposition
::
~
GuiResponsiveFixedComposition
()
{
}
GuiResponsiveFixedComposition
::
()
{
return
1
;
}
GuiResponsiveFixedComposition
::
()
{
return
0
;
}
bool
GuiResponsiveFixedComposition
::
()
{
return
false
;
}
bool
GuiResponsiveFixedComposition
::
()
{
return
false
;
}
#define DEFINE_AVAILABLE \
auto availables = From(responsiveChildren) \
.Where([=](GuiResponsiveCompositionBase* child) \
{ \
return ((vint)direction & (vint)child->GetDirection()) != 0; \
}) \
bool
GuiResponsiveStackComposition
::
()
{
=
;
DEFINE_AVAILABLE;
auto
=
(
) .Where([=](
GuiResponsiveCompositionBase
*
) {
return
((
)
& (
)
child
->
()) !=
0
; });
if
(
availables
.IsEmpty())
{
=
1
;
}
else
{
=
availables
.Select([](
GuiResponsiveCompositionBase
*
)
{
return
child
->
() -
1
;
})
.Aggregate([](
,
)
{
return
a
+
b
;
}) +
1
;
}
if
(
old
!=
)
{
.
(
(
this
));
return
true
;
}
return
false
;
}
bool
GuiResponsiveStackComposition
::
()
{
=
;
DEFINE_AVAILABLE;
auto
=
(
) .Where([=](
GuiResponsiveCompositionBase
*
) {
return
((
)
& (
)
child
->
()) !=
0
; });
if
(
availables
.IsEmpty())
{
=
0
;
}
else
{
=
availables
.Select([](
GuiResponsiveCompositionBase
*
)
{
return
child
->
();
})
.Aggregate([](
,
)
{
return
a
+
b
;
});
}
if
(
old
!=
)
{
.
(
(
this
));
return
true
;
}
return
false
;
}
void
GuiResponsiveStackComposition
::
OnResponsiveChildInserted
(
GuiResponsiveCompositionBase
*
)
{
.
(
);
}
void
GuiResponsiveStackComposition
::
(
GuiResponsiveCompositionBase
*
)
{
.
(
);
}
void
GuiResponsiveStackComposition
::
OnResponsiveChildLevelUpdated
()
{
();
();
GuiResponsiveCompositionBase
::
OnResponsiveChildLevelUpdated
();
}
bool
GuiResponsiveStackComposition
::
(
bool
)
{
DEFINE_AVAILABLE;
auto
=
(
) .Where([=](
GuiResponsiveCompositionBase
*
) {
return
((
)
& (
)
child
->
()) !=
0
; });
<
GuiResponsiveCompositionBase
*>
;
while
(
true
)
{
GuiResponsiveCompositionBase
*
=
nullptr
;
=
0
;
FOREACH(GuiResponsiveCompositionBase*, child, availables)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
GuiResponsiveCompositionBase
*>&
= ::
vl
::
collections
::
(
availables
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
GuiResponsiveCompositionBase
*
;
__foreach_iterator__
.
(
child
);)
{
if
(!
ignored
.
(
child
))
{
=
child
->
().
();
=
==
::
?
childSize
.
:
==
::
?
childSize
.
:
childSize
.
*
childSize
.
;
if
(!
selected
|| (
?
size
<
childSizeToCompare
:
size
>
childSizeToCompare
))
{
selected
=
child
;
size
=
childSizeToCompare
;
}
}
}
if
(!
selected
)
{
break
;
}
else
if
(
?
selected
->
() :
selected
->
())
{
break
;
}
else
{
ignored
.
(
selected
);
}
}
if
(!
())
return
false
;
InvokeOnCompositionStateChanged
();
return
true
;
}
GuiResponsiveStackComposition
::
GuiResponsiveStackComposition
()
{
}
GuiResponsiveStackComposition
::
~
GuiResponsiveStackComposition
()
{
}
GuiResponsiveStackComposition
::
()
{
return
;
}
GuiResponsiveStackComposition
::
()
{
return
;
}
bool
GuiResponsiveStackComposition
::
()
{
return
(
true
);
}
bool
GuiResponsiveStackComposition
::
()
{
return
(
false
);
}
bool
GuiResponsiveGroupComposition
::
()
{
=
;
DEFINE_AVAILABLE;
auto
=
(
) .Where([=](
GuiResponsiveCompositionBase
*
) {
return
((
)
& (
)
child
->
()) !=
0
; });
if
(
availables
.IsEmpty())
{
=
1
;
}
else
{
=
availables
.Select([](
GuiResponsiveCompositionBase
*
)
{
return
child
->
();
})
.Max();
}
if
(
old
!=
)
{
.
(
(
this
));
return
true
;
}
return
false
;
}
bool
GuiResponsiveGroupComposition
::
()
{
=
;
DEFINE_AVAILABLE;
auto
=
(
) .Where([=](
GuiResponsiveCompositionBase
*
) {
return
((
)
& (
)
child
->
()) !=
0
; });
if
(
availables
.IsEmpty())
{
=
0
;
}
else
{
=
availables
.Select([](
GuiResponsiveCompositionBase
*
)
{
return
child
->
();
})
.Max();
}
if
(
old
!=
)
{
.
(
(
this
));
return
true
;
}
return
false
;
}
void
GuiResponsiveGroupComposition
::
OnResponsiveChildInserted
(
GuiResponsiveCompositionBase
*
)
{
.
(
);
}
void
GuiResponsiveGroupComposition
::
(
GuiResponsiveCompositionBase
*
)
{
.
(
);
}
void
GuiResponsiveGroupComposition
::
OnResponsiveChildLevelUpdated
()
{
();
();
GuiResponsiveCompositionBase
::
OnResponsiveChildLevelUpdated
();
}
GuiResponsiveGroupComposition
::
GuiResponsiveGroupComposition
()
{
}
GuiResponsiveGroupComposition
::
~
GuiResponsiveGroupComposition
()
{
}
GuiResponsiveGroupComposition
::
()
{
return
;
}
GuiResponsiveGroupComposition
::
()
{
return
;
}
bool
GuiResponsiveGroupComposition
::
()
{
DEFINE_AVAILABLE;
auto
=
(
) .Where([=](
GuiResponsiveCompositionBase
*
) {
return
((
)
& (
)
child
->
()) !=
0
; });
=
;
FOREACH(GuiResponsiveCompositionBase*, child, availables)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
GuiResponsiveCompositionBase
*>&
= ::
vl
::
collections
::
(
availables
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
GuiResponsiveCompositionBase
*
;
__foreach_iterator__
.
(
child
);)
{
if
(
child
->
() >=
level
)
{
if
(!
child
->
())
{
break
;
}
}
}
if
(!
())
return
false
;
InvokeOnCompositionStateChanged
();
return
true
;
}
bool
GuiResponsiveGroupComposition
::
()
{
DEFINE_AVAILABLE;
auto
=
(
) .Where([=](
GuiResponsiveCompositionBase
*
) {
return
((
)
& (
)
child
->
()) !=
0
; });
=
;
FOREACH(GuiResponsiveCompositionBase*, child, availables)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
GuiResponsiveCompositionBase
*>&
= ::
vl
::
collections
::
(
availables
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
GuiResponsiveCompositionBase
*
;
__foreach_iterator__
.
(
child
);)
{
while
(
child
->
() <=
level
)
{
if
(!
child
->
())
{
break
;
}
}
}
if
(!
())
return
false
;
InvokeOnCompositionStateChanged
();
return
true
;
}
#undef DEFINE_AVAILABLE
#define RESPONSIVE_INVALID_SIZE Size(-1, -1)
void
GuiResponsiveContainerComposition
::
()
{
if
(!
)
return
;
const
=
().
();
const
=
->
().
();
const
bool
= (
)
->
() & (
)
::
;
const
bool
= (
)
->
() & (
)
::
;
#define RESPONSIVE_IF_CONTAINER(OP, SIZE) ((testX && (containerSize).x OP SIZE.x) || (testY && (containerSize).y OP SIZE.y))
if (upperLevelSize != RESPONSIVE_INVALID_SIZE && RESPONSIVE_IF_CONTAINER(>=, upperLevelSize))
if
(
(-
1
, -
1
) && ((
testX
&& (
containerSize
).
>=
.
) || (
testY
&& (
containerSize
).
>=
.
)))
{
upperLevelSize = RESPONSIVE_INVALID_SIZE;
}
if (upperLevelSize == RESPONSIVE_INVALID_SIZE && RESPONSIVE_IF_CONTAINER(>=, responsiveOriginalSize))
if
(
(-
1
, -
1
) && ((
testX
&& (
containerSize
).
>=
responsiveOriginalSize
.
) || (
testY
&& (
containerSize
).
>=
responsiveOriginalSize
.
)))
{
while
(
true
)
{
if
(
->
() ==
->
() -
1
)
{
break
;
}
else
if
(
->
())
{
->
ForceCalculateSizeImmediately
();
auto
=
->
().
();
if (RESPONSIVE_IF_CONTAINER(<, currentSize))
if
(((
testX
&& (
containerSize
).
<
currentSize
.
) || (
testY
&& (
containerSize
).
<
currentSize
.
)))
{
currentSize
;
->
();
break
;
}
}
else
{
break
;
}
}
}
else
{
while
(
true
)
{
->
ForceCalculateSizeImmediately
();
auto
=
->
().
();
if (RESPONSIVE_IF_CONTAINER(>=, currentSize))
if
(((
testX
&& (
containerSize
).
>=
currentSize
.
) || (
testY
&& (
containerSize
).
>=
currentSize
.
)))
{
break
;
}
if
(
->
() ==
0
)
{
break
;
}
else
if
(
->
())
{
currentSize
;
}
else
{
break
;
}
}
}
#undef RESPONSIVE_IF_CONTAINER
}
void
GuiResponsiveContainerComposition
::
(
*
,
&
)
{
auto
=
();
if
(
control
)
{
control
->
([=]()
{
();
});
}
else
{
();
}
}
GuiResponsiveContainerComposition
::
GuiResponsiveContainerComposition
()
:upperLevelSize(RESPONSIVE_INVALID_SIZE)
:upperLevelSize(
(-
1
, -
1
))
{
.
(
this
, &
GuiResponsiveContainerComposition
::
);
}
GuiResponsiveContainerComposition
::
~
GuiResponsiveContainerComposition
()
{
}
GuiResponsiveCompositionBase
*
GuiResponsiveContainerComposition
::
()
{
return
;
}
void
GuiResponsiveContainerComposition
::
(
GuiResponsiveCompositionBase
*
)
{
if
(
!=
)
{
if
(
)
{
(
);
}
=
;
upperLevelSize = RESPONSIVE_INVALID_SIZE;
if
(
)
{
->
(
(
0
,
0
,
0
,
0
));
while
(
->
());
(
);
(
this
);
(
this
,
arguments
);
}
}
}
#undef RESPONSIVE_INVALID_SIZE
}
}
}