2022-01-29 22:06:43 +00:00
|
|
|
#include "adapter.hpp"
|
|
|
|
|
|
|
|
#include <MyGUI_Gui.h>
|
|
|
|
|
2022-01-29 22:40:31 +00:00
|
|
|
#include "container.hpp"
|
2022-01-29 22:06:43 +00:00
|
|
|
#include "element.hpp"
|
|
|
|
|
|
|
|
namespace LuaUi
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
sol::state luaState;
|
|
|
|
}
|
|
|
|
|
|
|
|
LuaAdapter::LuaAdapter()
|
|
|
|
: mElement(nullptr)
|
2022-01-29 22:43:08 +00:00
|
|
|
, mContainer(nullptr)
|
2022-01-29 22:06:43 +00:00
|
|
|
{
|
2022-01-29 22:43:08 +00:00
|
|
|
mContainer = MyGUI::Gui::getInstancePtr()->createWidget<LuaContainer>(
|
2022-01-29 22:40:31 +00:00
|
|
|
"", MyGUI::IntCoord(), MyGUI::Align::Default, "", "");
|
2023-11-11 12:34:56 +00:00
|
|
|
mContainer->initialize(luaState, mContainer, false);
|
2022-01-29 22:43:08 +00:00
|
|
|
mContainer->onCoordChange([this](WidgetExtension* ext, MyGUI::IntCoord coord) { setSize(coord.size()); });
|
|
|
|
mContainer->widget()->attachToWidget(this);
|
2022-01-29 22:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LuaAdapter::attach(const std::shared_ptr<Element>& element)
|
|
|
|
{
|
|
|
|
detachElement();
|
|
|
|
mElement = element;
|
|
|
|
attachElement();
|
2022-01-29 22:43:08 +00:00
|
|
|
setSize(mContainer->widget()->getSize());
|
2022-01-29 22:06:43 +00:00
|
|
|
|
|
|
|
// 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())
|
2022-01-29 22:43:08 +00:00
|
|
|
mElement->attachToWidget(mContainer);
|
2022-01-29 22:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LuaAdapter::detachElement()
|
|
|
|
{
|
|
|
|
if (mElement.get())
|
|
|
|
mElement->detachFromWidget();
|
|
|
|
mElement = nullptr;
|
|
|
|
}
|
|
|
|
}
|