mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-26 08:05:38 +00:00
Added margin support to TextComponent for abbreviated text.
This commit is contained in:
parent
dc9c49438f
commit
8ecc50b4ce
|
@ -23,6 +23,7 @@ TextComponent::TextComponent(
|
|||
mVerticalAlignment(ALIGN_CENTER),
|
||||
mLineSpacing(1.5f),
|
||||
mBgColor(0),
|
||||
mMargin(0.0f),
|
||||
mRenderBackground(false)
|
||||
{
|
||||
}
|
||||
|
@ -35,7 +36,8 @@ TextComponent::TextComponent(
|
|||
Alignment align,
|
||||
Vector3f pos,
|
||||
Vector2f size,
|
||||
unsigned int bgcolor)
|
||||
unsigned int bgcolor,
|
||||
float margin)
|
||||
: GuiComponent(window),
|
||||
mFont(nullptr),
|
||||
mUppercase(false),
|
||||
|
@ -45,6 +47,7 @@ TextComponent::TextComponent(
|
|||
mVerticalAlignment(ALIGN_CENTER),
|
||||
mLineSpacing(1.5f),
|
||||
mBgColor(0),
|
||||
mMargin(margin),
|
||||
mRenderBackground(false)
|
||||
{
|
||||
setFont(font);
|
||||
|
@ -230,8 +233,10 @@ void TextComponent::onTextChanged()
|
|||
// Abbreviate text.
|
||||
const std::string abbrev = "...";
|
||||
Vector2f abbrevSize = f->sizeText(abbrev);
|
||||
// mMargin adds a margin around the text if it's abbreviated.
|
||||
float marginAdjustedSize = mSize.x() - (mSize.x() * mMargin);
|
||||
|
||||
while (text.size() && size.x() + abbrevSize.x() > mSize.x()) {
|
||||
while (text.size() && size.x() + abbrevSize.x() > marginAdjustedSize) {
|
||||
size_t newSize = Utils::String::prevCursor(text, text.size());
|
||||
text.erase(newSize, text.size() - newSize);
|
||||
size = f->sizeText(text);
|
||||
|
|
|
@ -33,7 +33,8 @@ public:
|
|||
Alignment align = ALIGN_LEFT,
|
||||
Vector3f pos = Vector3f::Zero(),
|
||||
Vector2f size = Vector2f::Zero(),
|
||||
unsigned int bgcolor = 0x00000000);
|
||||
unsigned int bgcolor = 0x00000000,
|
||||
float margin = 0.0f);
|
||||
|
||||
void setFont(const std::shared_ptr<Font>& font);
|
||||
void setUppercase(bool uppercase);
|
||||
|
@ -80,6 +81,7 @@ private:
|
|||
unsigned int mBgColor;
|
||||
unsigned char mColorOpacity;
|
||||
unsigned char mBgColorOpacity;
|
||||
float mMargin;
|
||||
bool mRenderBackground;
|
||||
|
||||
bool mUppercase;
|
||||
|
|
Loading…
Reference in a new issue