mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-16 14:59:54 +00:00
Allow to shrink tooltip width to its actual text width (bug #3812)
This commit is contained in:
parent
0fac28563c
commit
7e0bf40dbe
4 changed files with 66 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#include "box.hpp"
|
||||
|
||||
#if (MYGUI_VERSION >= MYGUI_DEFINE_VERSION(3, 2, 2))
|
||||
#include <MyGUI_EditText.h>
|
||||
#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<MyGUI::EditText>()->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<bool>(_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Gui::EditBox::setPropertyOverride (_key, _value);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -47,12 +47,14 @@
|
|||
<Property key="Padding" value="8"/>
|
||||
<Property key="Spacing" value="8"/>
|
||||
|
||||
<Widget type="AutoSizedTextBox" skin="NormalText" position="8 8 284 18" align="Left Top" name="CenteredCaption">
|
||||
<Widget type="AutoSizedTextBox" skin="NormalText" position="8 8 0 18" align="Left Top" name="CenteredCaption">
|
||||
<Property key="TextAlign" value="Center"/>
|
||||
<UserString key="HStretch" value="true"/>
|
||||
</Widget>
|
||||
|
||||
<Widget type="AutoSizedEditBox" skin="SandText" position="8 30 430 18" align="Left Top" name="CenteredCaptionText">
|
||||
<Property key="MultiLine" value="true"/>
|
||||
<Property key="Shrink" value="true"/>
|
||||
<Property key="WordWrap" value="true"/>
|
||||
<Property key="TextAlign" value="Left Top"/>
|
||||
</Widget>
|
||||
|
@ -80,18 +82,21 @@
|
|||
<Property key="Padding" value="8"/>
|
||||
<Property key="Spacing" value="8"/>
|
||||
|
||||
<Widget type="AutoSizedTextBox" skin="NormalText" position="8 8 284 18" align="Left Top" name="ClassName">
|
||||
<Widget type="AutoSizedTextBox" skin="NormalText" position="8 8 0 18" align="Left Top HStretch" name="ClassName">
|
||||
<Property key="TextAlign" value="Center"/>
|
||||
<UserString key="HStretch" value="true"/>
|
||||
</Widget>
|
||||
|
||||
<Widget type="AutoSizedEditBox" skin="SandText" position="8 30 430 18" align="Left Top" name="ClassDescription">
|
||||
<Property key="MultiLine" value="true"/>
|
||||
<Property key="Shrink" value="true"/>
|
||||
<Property key="WordWrap" value="true"/>
|
||||
<Property key="TextAlign" value="Left Top"/>
|
||||
</Widget>
|
||||
|
||||
<Widget type="AutoSizedEditBox" skin="SandText" position="8 52 284 18" align="Left Bottom" name="ClassSpecialisation">
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" position="8 52 0 18" align="Left Bottom" name="ClassSpecialisation">
|
||||
<Property key="TextAlign" value="Center"/>
|
||||
<UserString key="HStretch" value="true"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
|
@ -125,8 +130,10 @@
|
|||
|
||||
<Widget type="AutoSizedEditBox" skin="SandText" position="44 8 392 0" align="Left Top" name="HealthDescription">
|
||||
<Property key="MultiLine" value="true"/>
|
||||
<Property key="Shrink" value="true"/>
|
||||
<Property key="WordWrap" value="true"/>
|
||||
<Property key="TextAlign" value="Left Top"/>
|
||||
<UserString key="HStretch" value="true"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
|
@ -137,18 +144,22 @@
|
|||
<Property key="Spacing" value="8"/>
|
||||
|
||||
<Widget type="HBox">
|
||||
<UserString key="HStretch" value="true"/>
|
||||
<Property key="Spacing" value="8"/>
|
||||
<Widget type="ImageBox" skin="ImageBox" position="8 8 32 32" align="Left Top" name="AttributeImage"/>
|
||||
|
||||
<Widget type="AutoSizedEditBox" skin="NormalText" position="44 8 392 32" align="Left Top" name="AttributeName">
|
||||
<Widget type="AutoSizedTextBox" skin="NormalText" position="44 8 0 32" align="Left Top" name="AttributeName">
|
||||
<Property key="TextAlign" value="Left VCenter"/>
|
||||
<UserString key="HStretch" value="true"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
<Widget type="AutoSizedEditBox" skin="SandText" position="8 44 436 248" align="Left Top" name="AttributeDescription">
|
||||
<Property key="MultiLine" value="true"/>
|
||||
<Property key="Shrink" value="true"/>
|
||||
<Property key="WordWrap" value="true"/>
|
||||
<Property key="TextAlign" value="Left Top"/>
|
||||
<UserString key="HStretch" value="true"/>
|
||||
</Widget>
|
||||
</Widget>
|
||||
|
||||
|
@ -179,19 +190,22 @@
|
|||
|
||||
<Widget type="AutoSizedEditBox" skin="SandText" position="8 44 430 0" align="Left Top" name="SkillDescription">
|
||||
<Property key="MultiLine" value="true"/>
|
||||
<Property key="Shrink" value="true"/>
|
||||
<Property key="WordWrap" value="true"/>
|
||||
<Property key="TextAlign" value="Left Top"/>
|
||||
<Property key="Spacing" value="28"/>
|
||||
<UserString key="HStretch" value="true"/>
|
||||
</Widget>
|
||||
|
||||
<Widget type="Widget" skin="" position="0 0 0 2" align="Left Top" />
|
||||
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" position="8 48 444 18" align="Left Bottom" name="SkillMaxed">
|
||||
<Widget type="AutoSizedTextBox" skin="SandText" position="8 48 200 18" align="Left Bottom" name="SkillMaxed">
|
||||
<Property key="Caption" value="#{sSkillMaxReached}"/>
|
||||
<Property key="TextAlign" value="Center"/>
|
||||
<UserString key="HStretch" value="true"/>
|
||||
</Widget>
|
||||
<Widget type="VBox" name="SkillProgressVBox">
|
||||
<Widget type="AutoSizedTextBox" skin="NormalText" position="8 48 444 18" align="Left Bottom">
|
||||
<Widget type="AutoSizedTextBox" skin="NormalText" position="8 48 200 18" align="Left Bottom">
|
||||
<Property key="Caption" value="#{sSkillProgress}"/>
|
||||
<Property key="TextAlign" value="Center"/>
|
||||
</Widget>
|
||||
|
|
Loading…
Reference in a new issue