diff --git a/components/lua_ui/textedit.cpp b/components/lua_ui/textedit.cpp index 0441eb4e5d..9a98920bb7 100644 --- a/components/lua_ui/textedit.cpp +++ b/components/lua_ui/textedit.cpp @@ -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; + } } diff --git a/components/lua_ui/textedit.hpp b/components/lua_ui/textedit.hpp index 1158e91e2c..c26292416b 100644 --- a/components/lua_ui/textedit.hpp +++ b/components/lua_ui/textedit.hpp @@ -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; }; } diff --git a/docs/source/reference/lua-scripting/widgets/textedit.rst b/docs/source/reference/lua-scripting/widgets/textedit.rst index 16e640d1b0..f0b31b6971 100644 --- a/docs/source/reference/lua-scripting/widgets/textedit.rst +++ b/docs/source/reference/lua-scripting/widgets/textedit.rst @@ -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 ------ diff --git a/files/data/scripts/omw/mwui/init.lua b/files/data/scripts/omw/mwui/init.lua index b0d7e4346d..7f1fec7f59 100644 --- a/files/data/scripts/omw/mwui/init.lua +++ b/files/data/scripts/omw/mwui/init.lua @@ -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) --- diff --git a/files/data/scripts/omw/mwui/text.lua b/files/data/scripts/omw/mwui/text.lua index 8fc1133000..93ccba94cc 100644 --- a/files/data/scripts/omw/mwui/text.lua +++ b/files/data/scripts/omw/mwui/text.lua @@ -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 \ No newline at end of file diff --git a/files/data/scripts/omw/mwui/textEdit.lua b/files/data/scripts/omw/mwui/textEdit.lua index 4f86aa356f..99a42190c8 100644 --- a/files/data/scripts/omw/mwui/textEdit.lua +++ b/files/data/scripts/omw/mwui/textEdit.lua @@ -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 \ No newline at end of file diff --git a/files/data/scripts/omw/settings/render.lua b/files/data/scripts/omw/settings/render.lua index c57d8fb838..8aebf76661 100644 --- a/files/data/scripts/omw/settings/render.lua +++ b/files/data/scripts/omw/settings/render.lua @@ -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 diff --git a/files/data/scripts/omw/settings/renderers.lua b/files/data/scripts/omw/settings/renderers.lua index 9f7a46eb2e..2b1739e5a3 100644 --- a/files/data/scripts/omw/settings/renderers.lua +++ b/files/data/scripts/omw/settings/renderers.lua @@ -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(),