mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 04:45: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()
|
void LuaTextEdit::updateProperties()
|
||||||
{
|
{
|
||||||
mEditBox->setCaption(propertyValue("text", std::string()));
|
|
||||||
mEditBox->setFontHeight(propertyValue("textSize", 10));
|
mEditBox->setFontHeight(propertyValue("textSize", 10));
|
||||||
mEditBox->setTextColour(propertyValue("textColor", MyGUI::Colour(0, 0, 0, 1)));
|
mEditBox->setTextColour(propertyValue("textColor", MyGUI::Colour(0, 0, 0, 1)));
|
||||||
mEditBox->setEditMultiLine(propertyValue("multiline", false));
|
|
||||||
mEditBox->setEditWordWrap(propertyValue("wordWrap", false));
|
mEditBox->setEditWordWrap(propertyValue("wordWrap", false));
|
||||||
|
|
||||||
Alignment horizontal(propertyValue("textAlignH", Alignment::Start));
|
Alignment horizontal(propertyValue("textAlignH", Alignment::Start));
|
||||||
Alignment vertical(propertyValue("textAlignV", Alignment::Start));
|
Alignment vertical(propertyValue("textAlignV", Alignment::Start));
|
||||||
mEditBox->setTextAlign(alignmentToMyGui(horizontal, vertical));
|
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();
|
WidgetExtension::updateProperties();
|
||||||
}
|
}
|
||||||
|
@ -44,12 +50,7 @@ namespace LuaUi
|
||||||
void LuaTextEdit::updateCoord()
|
void LuaTextEdit::updateCoord()
|
||||||
{
|
{
|
||||||
WidgetExtension::updateCoord();
|
WidgetExtension::updateCoord();
|
||||||
{
|
mEditBox->setSize(widget()->getSize());
|
||||||
MyGUI::IntSize slotSize = slot()->calculateSize();
|
|
||||||
MyGUI::IntPoint slotPosition = slot()->widget()->getAbsolutePosition() - widget()->getAbsolutePosition();
|
|
||||||
MyGUI::IntCoord slotCoord(slotPosition, slotSize);
|
|
||||||
mEditBox->setCoord(slotCoord);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaTextEdit::updateChildren()
|
void LuaTextEdit::updateChildren()
|
||||||
|
@ -59,4 +60,16 @@ namespace LuaUi
|
||||||
mEditBox->detachFromWidget();
|
mEditBox->detachFromWidget();
|
||||||
mEditBox->attachToWidget(this);
|
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 updateProperties() override;
|
||||||
void updateCoord() override;
|
void updateCoord() override;
|
||||||
void updateChildren() override;
|
void updateChildren() override;
|
||||||
|
MyGUI::IntSize calculateSize() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void textChange(MyGUI::EditBox*);
|
void textChange(MyGUI::EditBox*);
|
||||||
|
|
||||||
MyGUI::EditBox* mEditBox;
|
MyGUI::EditBox* mEditBox = nullptr;
|
||||||
|
bool mAutoSize;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,10 @@ Properties
|
||||||
* - readOnly
|
* - readOnly
|
||||||
- boolean (false)
|
- boolean (false)
|
||||||
- Whether the text can be edited.
|
- Whether the text can be edited.
|
||||||
|
* - autoSize
|
||||||
|
- boolean (false)
|
||||||
|
- | Automatically changes widget height to fix all the text.
|
||||||
|
| Only applies for readOnly = true.
|
||||||
|
|
||||||
Events
|
Events
|
||||||
------
|
------
|
||||||
|
|
|
@ -85,6 +85,14 @@ require('scripts.omw.mwui.borders')(templates)
|
||||||
---
|
---
|
||||||
-- Standard "sand" colored text
|
-- Standard "sand" colored text
|
||||||
-- @field [parent=#Templates] openmw.ui#Layout textNormal
|
-- @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)
|
require('scripts.omw.mwui.text')(templates)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
local ui = require('openmw.ui')
|
local ui = require('openmw.ui')
|
||||||
|
local util = require('openmw.util')
|
||||||
|
|
||||||
local constants = require('scripts.omw.mwui.constants')
|
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)
|
return function(templates)
|
||||||
templates.textNormal = textNormal
|
templates.textNormal = textNormal
|
||||||
templates.textHeader = textHeader
|
templates.textHeader = textHeader
|
||||||
|
templates.textParagraph = textParagraph
|
||||||
end
|
end
|
|
@ -3,49 +3,25 @@ local ui = require('openmw.ui')
|
||||||
|
|
||||||
local constants = require('scripts.omw.mwui.constants')
|
local constants = require('scripts.omw.mwui.constants')
|
||||||
|
|
||||||
local borderOffset = util.vector2(1, 1) * constants.border
|
|
||||||
|
|
||||||
return function(templates)
|
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 = {
|
templates.textEditLine = {
|
||||||
type = ui.TYPE.TextEdit,
|
type = ui.TYPE.TextEdit,
|
||||||
props = {
|
props = {
|
||||||
size = util.vector2(150, constants.textNormalSize) + borderOffset * 4,
|
size = util.vector2(150, constants.textNormalSize),
|
||||||
textSize = constants.textNormalSize,
|
textSize = constants.textNormalSize,
|
||||||
textColor = constants.normalColor,
|
textColor = constants.normalColor,
|
||||||
multiline = false,
|
multiline = false,
|
||||||
},
|
},
|
||||||
content = borderContent,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
templates.textEditBox = {
|
templates.textEditBox = {
|
||||||
type = ui.TYPE.TextEdit,
|
type = ui.TYPE.TextEdit,
|
||||||
props = {
|
props = {
|
||||||
size = util.vector2(150, 5 * constants.textNormalSize) + borderOffset * 4,
|
size = util.vector2(150, 5 * constants.textNormalSize),
|
||||||
textSize = constants.textNormalSize,
|
textSize = constants.textNormalSize,
|
||||||
textColor = constants.normalColor,
|
textColor = constants.normalColor,
|
||||||
multiline = true,
|
multiline = true,
|
||||||
wordWrap = true,
|
wordWrap = true,
|
||||||
},
|
},
|
||||||
content = borderContent,
|
|
||||||
}
|
}
|
||||||
end
|
end
|
|
@ -94,10 +94,9 @@ local function renderSetting(group, setting, value, global)
|
||||||
type = ui.TYPE.Flex,
|
type = ui.TYPE.Flex,
|
||||||
content = ui.content {
|
content = ui.content {
|
||||||
{
|
{
|
||||||
template = I.MWUI.templates.textNormal,
|
template = I.MWUI.templates.textHeader,
|
||||||
props = {
|
props = {
|
||||||
text = l10n(setting.name),
|
text = l10n(setting.name),
|
||||||
textSize = 18,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -105,10 +104,10 @@ local function renderSetting(group, setting, value, global)
|
||||||
if setting.description then
|
if setting.description then
|
||||||
titleLayout.content:add(interval)
|
titleLayout.content:add(interval)
|
||||||
titleLayout.content:add {
|
titleLayout.content:add {
|
||||||
template = I.MWUI.templates.textNormal,
|
template = I.MWUI.templates.textParagraph,
|
||||||
props = {
|
props = {
|
||||||
text = l10n(setting.description),
|
text = l10n(setting.description),
|
||||||
textSize = 16,
|
size = util.vector2(300, 0),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -191,10 +190,10 @@ local function renderGroup(group, global)
|
||||||
if group.description then
|
if group.description then
|
||||||
titleLayout.content:add(interval)
|
titleLayout.content:add(interval)
|
||||||
titleLayout.content:add {
|
titleLayout.content:add {
|
||||||
template = I.MWUI.templates.textHeader,
|
template = I.MWUI.templates.textParagraph,
|
||||||
props = {
|
props = {
|
||||||
text = l10n(group.description),
|
text = l10n(group.description),
|
||||||
textSize = 18,
|
size = util.vector2(300, 0),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -301,10 +300,10 @@ local function renderPage(page)
|
||||||
}
|
}
|
||||||
if page.description then
|
if page.description then
|
||||||
titleLayout.content:add {
|
titleLayout.content:add {
|
||||||
template = I.MWUI.templates.textNormal,
|
template = I.MWUI.templates.textParagraph,
|
||||||
props = {
|
props = {
|
||||||
text = l10n(page.description),
|
text = l10n(page.description),
|
||||||
textSize = 20,
|
size = util.vector2(300, 0),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,18 @@ local function applyDefaults(argument, defaults)
|
||||||
return argument
|
return argument
|
||||||
end
|
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)
|
local function disable(disabled, layout)
|
||||||
if disabled then
|
if disabled then
|
||||||
return {
|
return {
|
||||||
|
@ -39,7 +51,7 @@ return function(registerRenderer)
|
||||||
}
|
}
|
||||||
registerRenderer('textLine', function(value, set, argument)
|
registerRenderer('textLine', function(value, set, argument)
|
||||||
argument = applyDefaults(argument, defaultArgument)
|
argument = applyDefaults(argument, defaultArgument)
|
||||||
return disable(argument.disabled, {
|
return disable(argument.disabled, paddedBox {
|
||||||
template = I.MWUI.templates.textEditLine,
|
template = I.MWUI.templates.textEditLine,
|
||||||
props = {
|
props = {
|
||||||
text = tostring(value),
|
text = tostring(value),
|
||||||
|
@ -61,24 +73,19 @@ return function(registerRenderer)
|
||||||
registerRenderer('checkbox', function(value, set, argument)
|
registerRenderer('checkbox', function(value, set, argument)
|
||||||
argument = applyDefaults(argument, defaultArgument)
|
argument = applyDefaults(argument, defaultArgument)
|
||||||
local l10n = core.l10n(argument.l10n)
|
local l10n = core.l10n(argument.l10n)
|
||||||
return disable(argument.disabled, {
|
return disable(argument.disabled, paddedBox {
|
||||||
template = I.MWUI.templates.box,
|
template = I.MWUI.templates.padding,
|
||||||
content = ui.content {
|
content = ui.content {
|
||||||
{
|
{
|
||||||
template = I.MWUI.templates.padding,
|
template = I.MWUI.templates.textNormal,
|
||||||
content = ui.content {
|
props = {
|
||||||
{
|
text = l10n(value and argument.trueLabel or argument.falseLabel)
|
||||||
template = I.MWUI.templates.textNormal,
|
},
|
||||||
props = {
|
events = {
|
||||||
text = l10n(value and argument.trueLabel or argument.falseLabel)
|
mouseClick = async:callback(function() set(not value) end),
|
||||||
},
|
|
||||||
events = {
|
|
||||||
mouseClick = async:callback(function() set(not value) end),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
})
|
})
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
@ -101,7 +108,7 @@ return function(registerRenderer)
|
||||||
registerRenderer('number', function(value, set, argument)
|
registerRenderer('number', function(value, set, argument)
|
||||||
argument = applyDefaults(argument, defaultArgument)
|
argument = applyDefaults(argument, defaultArgument)
|
||||||
local lastInput = nil
|
local lastInput = nil
|
||||||
return disable(argument.disabled, {
|
return disable(argument.disabled, paddedBox {
|
||||||
template = I.MWUI.templates.textEditLine,
|
template = I.MWUI.templates.textEditLine,
|
||||||
props = {
|
props = {
|
||||||
text = tostring(value),
|
text = tostring(value),
|
||||||
|
@ -173,6 +180,7 @@ return function(registerRenderer)
|
||||||
end),
|
end),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{ template = I.MWUI.templates.interval },
|
||||||
{
|
{
|
||||||
template = I.MWUI.templates.textNormal,
|
template = I.MWUI.templates.textNormal,
|
||||||
props = {
|
props = {
|
||||||
|
@ -182,6 +190,7 @@ return function(registerRenderer)
|
||||||
grow = 1,
|
grow = 1,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{ template = I.MWUI.templates.interval },
|
||||||
{
|
{
|
||||||
type = ui.TYPE.Image,
|
type = ui.TYPE.Image,
|
||||||
props = {
|
props = {
|
||||||
|
@ -197,17 +206,7 @@ return function(registerRenderer)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return disable(argument.disabled, {
|
return disable(argument.disabled, paddedBox(body))
|
||||||
template = I.MWUI.templates.box,
|
|
||||||
content = ui.content {
|
|
||||||
{
|
|
||||||
template = I.MWUI.templates.padding,
|
|
||||||
content = ui.content {
|
|
||||||
body,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -233,7 +232,7 @@ return function(registerRenderer)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
local lastInput = nil
|
local lastInput = nil
|
||||||
local hexInput = {
|
local hexInput = paddedBox {
|
||||||
template = I.MWUI.templates.textEditLine,
|
template = I.MWUI.templates.textEditLine,
|
||||||
props = {
|
props = {
|
||||||
text = value:asHex(),
|
text = value:asHex(),
|
||||||
|
|
Loading…
Reference in a new issue