2022-01-29 22:06:43 +00:00
|
|
|
#include "adapter.hpp"
|
|
|
|
|
|
|
|
#include <MyGUI_Gui.h>
|
|
|
|
|
|
|
|
#include "element.hpp"
|
2022-01-29 22:40:31 +00:00
|
|
|
#include "container.hpp"
|
2022-01-29 22:06:43 +00:00
|
|
|
|
|
|
|
namespace LuaUi
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
sol::state luaState;
|
|
|
|
}
|
|
|
|
|
|
|
|
LuaAdapter::LuaAdapter()
|
|
|
|
: mElement(nullptr)
|
|
|
|
, mContent(nullptr)
|
|
|
|
{
|
2022-01-29 22:40:31 +00:00
|
|
|
mContent = MyGUI::Gui::getInstancePtr()->createWidget<LuaContainer>(
|
|
|
|
"", MyGUI::IntCoord(), MyGUI::Align::Default, "", "");
|
|
|
|
mContent->initialize(luaState, mContent);
|
|
|
|
mContent->onCoordChange([this](WidgetExtension* ext, MyGUI::IntCoord coord)
|
2022-01-29 22:06:43 +00:00
|
|
|
{
|
2022-01-29 22:40:31 +00:00
|
|
|
setSize(coord.size());
|
2022-01-29 22:06:43 +00:00
|
|
|
});
|
|
|
|
mContent->widget()->attachToWidget(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaAdapter::attach(const std::shared_ptr<Element>& element)
|
|
|
|
{
|
|
|
|
detachElement();
|
|
|
|
mElement = element;
|
|
|
|
attachElement();
|
|
|
|
setSize(mContent->widget()->getSize());
|
|
|
|
|
|
|
|
// workaround for MyGUI bug
|
|
|
|
// parent visibility doesn't affect added children
|
|
|
|
setVisible(!getVisible());
|
|
|
|
setVisible(!getVisible());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaAdapter::detach()
|
|
|
|
{
|
|
|
|
detachElement();
|
|
|
|
setSize({ 0, 0 });
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaAdapter::attachElement()
|
|
|
|
{
|
|
|
|
if (mElement.get())
|
|
|
|
mElement->attachToWidget(mContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LuaAdapter::detachElement()
|
|
|
|
{
|
|
|
|
if (mElement.get())
|
|
|
|
mElement->detachFromWidget();
|
|
|
|
mElement = nullptr;
|
|
|
|
}
|
|
|
|
}
|