1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-18 04:10:06 +00:00
OpenMW/components/lua_ui/textedit.cpp

63 lines
2.1 KiB
C++
Raw Normal View History

2021-11-18 15:19:54 +00:00
#include "textedit.hpp"
#include "alignment.hpp"
2021-11-18 15:19:54 +00:00
namespace LuaUi
{
void LuaTextEdit::initialize()
{
2022-05-14 10:27:30 +00:00
mEditBox = createWidget<MyGUI::EditBox>("LuaTextEdit", MyGUI::IntCoord(0, 0, 0, 0), MyGUI::Align::Default);
mEditBox->eventEditTextChange += MyGUI::newDelegate(this, &LuaTextEdit::textChange);
registerEvents(mEditBox);
WidgetExtension::initialize();
}
void LuaTextEdit::deinitialize()
{
2022-05-14 10:27:30 +00:00
mEditBox->eventEditTextChange -= MyGUI::newDelegate(this, &LuaTextEdit::textChange);
clearEvents(mEditBox);
WidgetExtension::deinitialize();
}
2022-01-28 09:31:45 +00:00
void LuaTextEdit::updateProperties()
2021-11-18 15:19:54 +00:00
{
2022-05-14 10:27:30 +00:00
mEditBox->setCaption(propertyValue("text", std::string()));
mEditBox->setFontHeight(propertyValue("textSize", 10));
mEditBox->setTextColour(propertyValue("textColor", MyGUI::Colour(0, 0, 0, 1)));
mEditBox->setEditMultiLine(propertyValue("multiline", false));
mEditBox->setEditWordWrap(propertyValue("wordWrap", false));
Alignment horizontal(propertyValue("textAlignH", Alignment::Start));
Alignment vertical(propertyValue("textAlignV", Alignment::Start));
2022-05-14 10:27:30 +00:00
mEditBox->setTextAlign(alignmentToMyGui(horizontal, vertical));
2022-05-14 10:27:30 +00:00
mEditBox->setEditStatic(propertyValue("readOnly", false));
2022-01-28 09:31:45 +00:00
WidgetExtension::updateProperties();
2021-11-18 15:19:54 +00:00
}
void LuaTextEdit::textChange(MyGUI::EditBox*)
{
2022-05-14 10:27:30 +00:00
triggerEvent("textChanged", sol::make_object(lua(), mEditBox->getCaption().asUTF8()));
}
void LuaTextEdit::updateCoord()
{
WidgetExtension::updateCoord();
{
MyGUI::IntSize slotSize = slot()->calculateSize();
MyGUI::IntPoint slotPosition = slot()->widget()->getAbsolutePosition() - widget()->getAbsolutePosition();
MyGUI::IntCoord slotCoord(slotPosition, slotSize);
mEditBox->setCoord(slotCoord);
}
}
void LuaTextEdit::updateChildren()
{
WidgetExtension::updateChildren();
// otherwise it won't be focusable
mEditBox->detachFromWidget();
mEditBox->attachToWidget(this);
}
2021-11-18 15:19:54 +00:00
}