You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openmw/components/lua_ui/textedit.cpp

63 lines
2.1 KiB
C++

3 years ago
#include "textedit.hpp"
#include "alignment.hpp"
3 years ago
namespace LuaUi
{
void LuaTextEdit::initialize()
{
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()
{
mEditBox->eventEditTextChange -= MyGUI::newDelegate(this, &LuaTextEdit::textChange);
clearEvents(mEditBox);
WidgetExtension::deinitialize();
}
3 years ago
void LuaTextEdit::updateProperties()
3 years ago
{
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));
mEditBox->setTextAlign(alignmentToMyGui(horizontal, vertical));
mEditBox->setEditStatic(propertyValue("readOnly", false));
3 years ago
WidgetExtension::updateProperties();
3 years ago
}
void LuaTextEdit::textChange(MyGUI::EditBox*)
{
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);
}
3 years ago
}