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

77 lines
2.5 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->setFontHeight(propertyValue("textSize", 10));
mEditBox->setTextColour(propertyValue("textColor", MyGUI::Colour(0, 0, 0, 1)));
mEditBox->setEditWordWrap(propertyValue("wordWrap", false));
Alignment horizontal(propertyValue("textAlignH", Alignment::Start));
Alignment vertical(propertyValue("textAlignV", Alignment::Start));
mEditBox->setTextAlign(alignmentToMyGui(horizontal, vertical));
mMultiline = propertyValue("multiline", false);
mEditBox->setEditMultiLine(mMultiline);
bool readOnly = propertyValue("readOnly", false);
mEditBox->setEditStatic(readOnly);
mAutoSize = (readOnly || !mMultiline) && propertyValue("autoSize", false);
// change caption last, for multiline and wordwrap to apply
mEditBox->setCaption(propertyValue("text", std::string()));
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();
mEditBox->setSize(widget()->getSize());
}
void LuaTextEdit::updateChildren()
{
WidgetExtension::updateChildren();
// otherwise it won't be focusable
mEditBox->detachFromWidget();
mEditBox->attachToWidget(this);
}
MyGUI::IntSize LuaTextEdit::calculateSize()
{
MyGUI::IntSize normalSize = WidgetExtension::calculateSize();
if (mAutoSize)
{
mEditBox->setSize(normalSize);
int targetHeight = mMultiline ? mEditBox->getTextSize().height : mEditBox->getFontHeight();
normalSize.height = std::max(normalSize.height, targetHeight);
}
return normalSize;
}
3 years ago
}