Lua UI: Enable autoSize for single line text edit

combined_windows_build
uramer 3 years ago
parent f8a6001e87
commit 6d2dcaea50

@ -29,12 +29,13 @@ namespace LuaUi
Alignment vertical(propertyValue("textAlignV", Alignment::Start));
mEditBox->setTextAlign(alignmentToMyGui(horizontal, vertical));
mEditBox->setEditMultiLine(propertyValue("multiline", false));
mMultiline = propertyValue("multiline", false);
mEditBox->setEditMultiLine(mMultiline);
bool readOnly = propertyValue("readOnly", false);
mEditBox->setEditStatic(readOnly);
mAutoSize = readOnly && propertyValue("autoSize", false);
mAutoSize = (readOnly || !mMultiline) && propertyValue("autoSize", false);
// change caption last, for multiline and wordwrap to apply
mEditBox->setCaption(propertyValue("text", std::string()));
@ -67,8 +68,8 @@ namespace LuaUi
if (mAutoSize)
{
mEditBox->setSize(normalSize);
MyGUI::IntSize textSize = mEditBox->getTextSize();
normalSize.height = std::max(normalSize.height, textSize.height);
int targetHeight = mMultiline ? mEditBox->getTextSize().height : mEditBox->getFontHeight();
normalSize.height = std::max(normalSize.height, targetHeight);
}
return normalSize;
}

@ -23,6 +23,7 @@ namespace LuaUi
void textChange(MyGUI::EditBox*);
MyGUI::EditBox* mEditBox = nullptr;
bool mMultiline;
bool mAutoSize;
};
}

@ -38,7 +38,7 @@ Properties
* - autoSize
- boolean (false)
- | Automatically changes widget height to fix all the text.
| Only applies for readOnly = true.
| Only applies when readOnly = true or multiline = false.
Events
------

@ -7,7 +7,8 @@ return function(templates)
templates.textEditLine = {
type = ui.TYPE.TextEdit,
props = {
size = util.vector2(150, constants.textNormalSize),
size = util.vector2(150, 0),
autoSize = true,
textSize = constants.textNormalSize,
textColor = constants.normalColor,
multiline = false,

Loading…
Cancel
Save