mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 04:15:33 +00:00
Merge branch 'text_edit_autosize' into 'master'
Lua UI: Support autosized multiline text See merge request OpenMW/openmw!1977
This commit is contained in:
commit
aac32f2de5
8 changed files with 88 additions and 72 deletions
|
@ -21,17 +21,23 @@ namespace LuaUi
|
|||
|
||||
void LuaTextEdit::updateProperties()
|
||||
{
|
||||
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));
|
||||
mEditBox->setEditMultiLine(propertyValue("multiline", false));
|
||||
|
||||
bool readOnly = propertyValue("readOnly", false);
|
||||
mEditBox->setEditStatic(readOnly);
|
||||
|
||||
mAutoSize = readOnly && propertyValue("autoSize", false);
|
||||
|
||||
// change caption last, for multiline and wordwrap to apply
|
||||
mEditBox->setCaption(propertyValue("text", std::string()));
|
||||
|
||||
WidgetExtension::updateProperties();
|
||||
}
|
||||
|
@ -44,12 +50,7 @@ namespace LuaUi
|
|||
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);
|
||||
}
|
||||
mEditBox->setSize(widget()->getSize());
|
||||
}
|
||||
|
||||
void LuaTextEdit::updateChildren()
|
||||
|
@ -59,4 +60,16 @@ namespace LuaUi
|
|||
mEditBox->detachFromWidget();
|
||||
mEditBox->attachToWidget(this);
|
||||
}
|
||||
|
||||
MyGUI::IntSize LuaTextEdit::calculateSize()
|
||||
{
|
||||
MyGUI::IntSize normalSize = WidgetExtension::calculateSize();
|
||||
if (mAutoSize)
|
||||
{
|
||||
mEditBox->setSize(normalSize);
|
||||
MyGUI::IntSize textSize = mEditBox->getTextSize();
|
||||
normalSize.height = std::max(normalSize.height, textSize.height);
|
||||
}
|
||||
return normalSize;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,11 +17,13 @@ namespace LuaUi
|
|||
void updateProperties() override;
|
||||
void updateCoord() override;
|
||||
void updateChildren() override;
|
||||
MyGUI::IntSize calculateSize() override;
|
||||
|
||||
private:
|
||||
void textChange(MyGUI::EditBox*);
|
||||
|
||||
MyGUI::EditBox* mEditBox;
|
||||
MyGUI::EditBox* mEditBox = nullptr;
|
||||
bool mAutoSize;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,10 @@ Properties
|
|||
* - readOnly
|
||||
- boolean (false)
|
||||
- Whether the text can be edited.
|
||||
* - autoSize
|
||||
- boolean (false)
|
||||
- | Automatically changes widget height to fix all the text.
|
||||
| Only applies for readOnly = true.
|
||||
|
||||
Events
|
||||
------
|
||||
|
|
|
@ -85,6 +85,14 @@ require('scripts.omw.mwui.borders')(templates)
|
|||
---
|
||||
-- Standard "sand" colored text
|
||||
-- @field [parent=#Templates] openmw.ui#Layout textNormal
|
||||
|
||||
---
|
||||
-- Header white colored text
|
||||
-- @field [parent=#Templates] openmw.ui#Layout textHeader
|
||||
|
||||
---
|
||||
-- Standard "sand" colored multiline text
|
||||
-- @field [parent=#Templates] openmw.ui#Layout textParagraph
|
||||
require('scripts.omw.mwui.text')(templates)
|
||||
|
||||
---
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
local ui = require('openmw.ui')
|
||||
local util = require('openmw.util')
|
||||
|
||||
local constants = require('scripts.omw.mwui.constants')
|
||||
|
||||
|
@ -18,7 +19,21 @@ local textHeader = {
|
|||
},
|
||||
}
|
||||
|
||||
local textParagraph = {
|
||||
type = ui.TYPE.TextEdit,
|
||||
props = {
|
||||
textSize = constants.textNormalSize,
|
||||
textColor = constants.normalColor,
|
||||
autoSize = true,
|
||||
readOnly = true,
|
||||
multiline = true,
|
||||
wordWrap = true,
|
||||
size = util.vector2(100, 0),
|
||||
},
|
||||
}
|
||||
|
||||
return function(templates)
|
||||
templates.textNormal = textNormal
|
||||
templates.textHeader = textHeader
|
||||
templates.textParagraph = textParagraph
|
||||
end
|
|
@ -3,49 +3,25 @@ local ui = require('openmw.ui')
|
|||
|
||||
local constants = require('scripts.omw.mwui.constants')
|
||||
|
||||
local borderOffset = util.vector2(1, 1) * constants.border
|
||||
|
||||
return function(templates)
|
||||
local borderContent = ui.content {
|
||||
{
|
||||
template = templates.borders,
|
||||
props = {
|
||||
relativeSize = util.vector2(1, 1),
|
||||
},
|
||||
content = ui.content {
|
||||
{
|
||||
props = {
|
||||
position = borderOffset,
|
||||
relativeSize = util.vector2(1, 1),
|
||||
},
|
||||
external = {
|
||||
slot = true,
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
templates.textEditLine = {
|
||||
type = ui.TYPE.TextEdit,
|
||||
props = {
|
||||
size = util.vector2(150, constants.textNormalSize) + borderOffset * 4,
|
||||
size = util.vector2(150, constants.textNormalSize),
|
||||
textSize = constants.textNormalSize,
|
||||
textColor = constants.normalColor,
|
||||
multiline = false,
|
||||
},
|
||||
content = borderContent,
|
||||
}
|
||||
|
||||
templates.textEditBox = {
|
||||
type = ui.TYPE.TextEdit,
|
||||
props = {
|
||||
size = util.vector2(150, 5 * constants.textNormalSize) + borderOffset * 4,
|
||||
size = util.vector2(150, 5 * constants.textNormalSize),
|
||||
textSize = constants.textNormalSize,
|
||||
textColor = constants.normalColor,
|
||||
multiline = true,
|
||||
wordWrap = true,
|
||||
},
|
||||
content = borderContent,
|
||||
}
|
||||
end
|
|
@ -94,10 +94,9 @@ local function renderSetting(group, setting, value, global)
|
|||
type = ui.TYPE.Flex,
|
||||
content = ui.content {
|
||||
{
|
||||
template = I.MWUI.templates.textNormal,
|
||||
template = I.MWUI.templates.textHeader,
|
||||
props = {
|
||||
text = l10n(setting.name),
|
||||
textSize = 18,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -105,10 +104,10 @@ local function renderSetting(group, setting, value, global)
|
|||
if setting.description then
|
||||
titleLayout.content:add(interval)
|
||||
titleLayout.content:add {
|
||||
template = I.MWUI.templates.textNormal,
|
||||
template = I.MWUI.templates.textParagraph,
|
||||
props = {
|
||||
text = l10n(setting.description),
|
||||
textSize = 16,
|
||||
size = util.vector2(300, 0),
|
||||
},
|
||||
}
|
||||
end
|
||||
|
@ -191,10 +190,10 @@ local function renderGroup(group, global)
|
|||
if group.description then
|
||||
titleLayout.content:add(interval)
|
||||
titleLayout.content:add {
|
||||
template = I.MWUI.templates.textHeader,
|
||||
template = I.MWUI.templates.textParagraph,
|
||||
props = {
|
||||
text = l10n(group.description),
|
||||
textSize = 18,
|
||||
size = util.vector2(300, 0),
|
||||
},
|
||||
}
|
||||
end
|
||||
|
@ -301,10 +300,10 @@ local function renderPage(page)
|
|||
}
|
||||
if page.description then
|
||||
titleLayout.content:add {
|
||||
template = I.MWUI.templates.textNormal,
|
||||
template = I.MWUI.templates.textParagraph,
|
||||
props = {
|
||||
text = l10n(page.description),
|
||||
textSize = 20,
|
||||
size = util.vector2(300, 0),
|
||||
},
|
||||
}
|
||||
end
|
||||
|
|
|
@ -19,6 +19,18 @@ local function applyDefaults(argument, defaults)
|
|||
return argument
|
||||
end
|
||||
|
||||
local function paddedBox(layout)
|
||||
return {
|
||||
template = I.MWUI.templates.box,
|
||||
content = ui.content {
|
||||
{
|
||||
template = I.MWUI.templates.padding,
|
||||
content = ui.content { layout },
|
||||
},
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
local function disable(disabled, layout)
|
||||
if disabled then
|
||||
return {
|
||||
|
@ -39,7 +51,7 @@ return function(registerRenderer)
|
|||
}
|
||||
registerRenderer('textLine', function(value, set, argument)
|
||||
argument = applyDefaults(argument, defaultArgument)
|
||||
return disable(argument.disabled, {
|
||||
return disable(argument.disabled, paddedBox {
|
||||
template = I.MWUI.templates.textEditLine,
|
||||
props = {
|
||||
text = tostring(value),
|
||||
|
@ -61,24 +73,19 @@ return function(registerRenderer)
|
|||
registerRenderer('checkbox', function(value, set, argument)
|
||||
argument = applyDefaults(argument, defaultArgument)
|
||||
local l10n = core.l10n(argument.l10n)
|
||||
return disable(argument.disabled, {
|
||||
template = I.MWUI.templates.box,
|
||||
return disable(argument.disabled, paddedBox {
|
||||
template = I.MWUI.templates.padding,
|
||||
content = ui.content {
|
||||
{
|
||||
template = I.MWUI.templates.padding,
|
||||
content = ui.content {
|
||||
{
|
||||
template = I.MWUI.templates.textNormal,
|
||||
props = {
|
||||
text = l10n(value and argument.trueLabel or argument.falseLabel)
|
||||
},
|
||||
events = {
|
||||
mouseClick = async:callback(function() set(not value) end),
|
||||
},
|
||||
},
|
||||
template = I.MWUI.templates.textNormal,
|
||||
props = {
|
||||
text = l10n(value and argument.trueLabel or argument.falseLabel)
|
||||
},
|
||||
events = {
|
||||
mouseClick = async:callback(function() set(not value) end),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
@ -101,7 +108,7 @@ return function(registerRenderer)
|
|||
registerRenderer('number', function(value, set, argument)
|
||||
argument = applyDefaults(argument, defaultArgument)
|
||||
local lastInput = nil
|
||||
return disable(argument.disabled, {
|
||||
return disable(argument.disabled, paddedBox {
|
||||
template = I.MWUI.templates.textEditLine,
|
||||
props = {
|
||||
text = tostring(value),
|
||||
|
@ -173,6 +180,7 @@ return function(registerRenderer)
|
|||
end),
|
||||
},
|
||||
},
|
||||
{ template = I.MWUI.templates.interval },
|
||||
{
|
||||
template = I.MWUI.templates.textNormal,
|
||||
props = {
|
||||
|
@ -182,6 +190,7 @@ return function(registerRenderer)
|
|||
grow = 1,
|
||||
},
|
||||
},
|
||||
{ template = I.MWUI.templates.interval },
|
||||
{
|
||||
type = ui.TYPE.Image,
|
||||
props = {
|
||||
|
@ -197,17 +206,7 @@ return function(registerRenderer)
|
|||
},
|
||||
},
|
||||
}
|
||||
return disable(argument.disabled, {
|
||||
template = I.MWUI.templates.box,
|
||||
content = ui.content {
|
||||
{
|
||||
template = I.MWUI.templates.padding,
|
||||
content = ui.content {
|
||||
body,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
return disable(argument.disabled, paddedBox(body))
|
||||
end)
|
||||
end
|
||||
|
||||
|
@ -233,7 +232,7 @@ return function(registerRenderer)
|
|||
},
|
||||
}
|
||||
local lastInput = nil
|
||||
local hexInput = {
|
||||
local hexInput = paddedBox {
|
||||
template = I.MWUI.templates.textEditLine,
|
||||
props = {
|
||||
text = value:asHex(),
|
||||
|
|
Loading…
Reference in a new issue