diff --git a/CHANGELOG.md b/CHANGELOG.md index e615caad3..76d609560 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Bug #3733: Normal maps are inverted on mirrored UVs Bug #3765: DisableTeleporting makes Mark/Recall/Intervention effects undetectable Bug #3778: [Mod] Improved Thrown Weapon Projectiles - weapons have wrong transformation during throw animation + Bug #3812: Wrong multiline tooltips width when word-wrapping is enabled Bug #4329: Removed birthsign abilities are restored after reloading the save Bug #4383: Bow model obscures crosshair when arrow is drawn Bug #4384: Resist Normal Weapons only checks ammunition for ranged weapons diff --git a/components/widgets/box.cpp b/components/widgets/box.cpp index d38410a2c..b76e6d7d5 100644 --- a/components/widgets/box.cpp +++ b/components/widgets/box.cpp @@ -1,5 +1,9 @@ #include "box.hpp" +#if (MYGUI_VERSION >= MYGUI_DEFINE_VERSION(3, 2, 2)) +#include +#endif + namespace Gui { @@ -52,22 +56,54 @@ namespace Gui } } + int AutoSizedEditBox::getWidth() + { + // If the widget has the one short text line, we can shrink widget to avoid a lot of empty space. + // Unfortunately, getLineInfo method is available since MyGUI 3.2.2, so with older MyGUI versions tooltips will just have the fixed width. + int textWidth = mMaxWidth; + +#if (MYGUI_VERSION >= MYGUI_DEFINE_VERSION(3, 2, 2)) + if (mShrink) + { + // MyGUI needs to know the widget size for wordwrapping, but we will know the widget size only after wordwrapping. + // To solve this issue, use the maximum tooltip width first for wordwrapping, then resize widget to its actual used space. + if (mWasResized) + { + int maxLineWidth = 0; + const MyGUI::VectorLineInfo & lines = getSubWidgetText()->castType()->getLineInfo(); + for (unsigned int i = 0; i < lines.size(); ++i) + maxLineWidth = std::max(maxLineWidth, lines[i].width); + + textWidth = std::min(maxLineWidth, textWidth); + } + else + { + mWasResized = true; + } + } +#endif + + return textWidth; + } + MyGUI::IntSize AutoSizedEditBox::getRequestedSize() { if (getAlign().isHStretch()) throw std::runtime_error("AutoSizedEditBox can't have HStretch align (" + getName() + ")"); - return MyGUI::IntSize(getSize().width, getTextSize().height); + return MyGUI::IntSize(getWidth(), getTextSize().height); } void AutoSizedEditBox::setCaption(const MyGUI::UString& _value) { EditBox::setCaption(_value); + mWasResized = false; notifySizeChange (this); } void AutoSizedEditBox::initialiseOverride() { + mMaxWidth = getSize().width; Base::initialiseOverride(); setNeedKeyFocus(false); setEditStatic(true); @@ -79,6 +115,10 @@ namespace Gui { mExpandDirection = MyGUI::Align::parse (_value); } + else if (_key == "Shrink") + { + mShrink = MyGUI::utility::parseValue(_value); + } else { Gui::EditBox::setPropertyOverride (_key, _value); diff --git a/components/widgets/box.hpp b/components/widgets/box.hpp index 9bab575c4..2d9b497db 100644 --- a/components/widgets/box.hpp +++ b/components/widgets/box.hpp @@ -65,7 +65,11 @@ namespace Gui protected: virtual void setPropertyOverride(const std::string& _key, const std::string& _value); + virtual int getWidth(); std::string mFontSize; + bool mShrink = false; + bool mWasResized = false; + int mMaxWidth = 0; }; class AutoSizedButton : public AutoSizedWidget, public Button diff --git a/files/mygui/openmw_tooltips.layout b/files/mygui/openmw_tooltips.layout index bdc224ecd..70246fa4e 100644 --- a/files/mygui/openmw_tooltips.layout +++ b/files/mygui/openmw_tooltips.layout @@ -47,12 +47,14 @@ - + + + @@ -80,18 +82,21 @@ - + + + - + + @@ -125,8 +130,10 @@ + + @@ -137,18 +144,22 @@ + - + + + + @@ -179,19 +190,22 @@ + + - + + - +