mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-22 06:05:38 +00:00
Added horizontal margins to textlist.
Updated and corrected documentation (center -> alignment for textlist, not text!).
This commit is contained in:
parent
fa8e60b7b5
commit
ea009315e9
10
THEMES.md
10
THEMES.md
|
@ -331,8 +331,8 @@ Can be created as an extra.
|
|||
- Path to a truetype font (.ttf).
|
||||
* `fontSize` - type: FLOAT.
|
||||
- Size of the font as a percentage of screen height (e.g. for a value of `0.1`, the text's height would be 10% of the screen height).
|
||||
* `alignment` - type: STRING.
|
||||
- Valid values are "left", "center", or "right". Controls alignment on the X axis.
|
||||
* `center` - type: BOOLEAN.
|
||||
- True to center, false to left-align.
|
||||
|
||||
#### textlist
|
||||
|
||||
|
@ -350,8 +350,10 @@ Can be created as an extra.
|
|||
* `fontSize` - type: FLOAT.
|
||||
* `scrollSound` - type: PATH.
|
||||
- Sound that is played when the list is scrolled.
|
||||
* `center` - type: BOOLEAN.
|
||||
- True to center, false to left-align.
|
||||
* `alignment` - type: STRING.
|
||||
- Valid values are "left", "center", or "right". Controls alignment on the X axis.
|
||||
* `horizontalMargin` - type: FLOAT.
|
||||
- Horizontal offset for text from the alignment point. If `alignment` is "left", offsets the text to the right. If `alignment` is "right", offsets text to the left. No effect if `alignment` is "center". Given as a percentage of the element's parent's width (same unit as `size`'s X value).
|
||||
|
||||
#### ninepatch
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@ std::map< std::string, std::map<std::string, ThemeData::ElementPropertyType> > T
|
|||
("fontPath", PATH)
|
||||
("fontSize", FLOAT)
|
||||
("scrollSound", PATH)
|
||||
("alignment", STRING))
|
||||
("alignment", STRING)
|
||||
("horizontalMargin", FLOAT))
|
||||
("container", boost::assign::map_list_of
|
||||
("pos", NORMALIZED_PAIR)
|
||||
("size", NORMALIZED_PAIR))
|
||||
|
|
|
@ -96,6 +96,7 @@ private:
|
|||
int mMarqueeTime;
|
||||
|
||||
Alignment mAlignment;
|
||||
float mHorizontalMargin;
|
||||
|
||||
std::vector<ListRow> mRowVector;
|
||||
int mCursor;
|
||||
|
@ -121,6 +122,7 @@ TextListComponent<T>::TextListComponent(Window* window) :
|
|||
mMarqueeOffset = 0;
|
||||
mMarqueeTime = -MARQUEE_DELAY;
|
||||
|
||||
mHorizontalMargin = 0;
|
||||
mAlignment = ALIGN_CENTER;
|
||||
|
||||
mFont = Font::get(FONT_SIZE_MEDIUM);
|
||||
|
@ -202,20 +204,25 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
|||
switch(mAlignment)
|
||||
{
|
||||
case ALIGN_LEFT:
|
||||
offset[0] = 0;
|
||||
offset[0] = mHorizontalMargin;
|
||||
break;
|
||||
case ALIGN_CENTER:
|
||||
offset[0] = (mSize.x() - row.textCache->metrics.size.x()) / 2;
|
||||
if(offset[0] < 0)
|
||||
offset[0] = 0;
|
||||
break;
|
||||
case ALIGN_RIGHT:
|
||||
offset[0] = (mSize.x() - row.textCache->metrics.size.x());
|
||||
offset[0] -= mHorizontalMargin;
|
||||
if(offset[0] < 0)
|
||||
offset[0] = 0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if(offset[0] < 0)
|
||||
offset[0] = 0;
|
||||
offset[0] += (float)(mCursor == i ? -mMarqueeOffset : 0);
|
||||
|
||||
if(mCursor == i)
|
||||
offset[0] -= mMarqueeOffset;
|
||||
|
||||
Eigen::Affine3f drawTrans = trans;
|
||||
drawTrans.translate(offset);
|
||||
Renderer::setMatrix(drawTrans);
|
||||
|
@ -312,7 +319,7 @@ void TextListComponent<T>::update(int deltaTime)
|
|||
Eigen::Vector2f textSize = mFont->sizeText(text);
|
||||
|
||||
//it's long enough to marquee
|
||||
if(textSize.x() - mMarqueeOffset > getSize().x() - 12)
|
||||
if(textSize.x() - mMarqueeOffset > getSize().x() - 12 - (mAlignment != ALIGN_CENTER ? mHorizontalMargin : 0))
|
||||
{
|
||||
mMarqueeTime += deltaTime;
|
||||
while(mMarqueeTime > MARQUEE_SPEED)
|
||||
|
@ -453,17 +460,24 @@ void TextListComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme, c
|
|||
if(properties & SOUND && elem->has("scrollSound"))
|
||||
setSound(Sound::get(elem->get<std::string>("scrollSound")));
|
||||
|
||||
if(properties & ALIGNMENT && elem->has("alignment"))
|
||||
if(properties & ALIGNMENT)
|
||||
{
|
||||
const std::string& str = elem->get<std::string>("alignment");
|
||||
if(str == "left")
|
||||
setAlignment(ALIGN_LEFT);
|
||||
else if(str == "center")
|
||||
setAlignment(ALIGN_CENTER);
|
||||
else if(str == "right")
|
||||
setAlignment(ALIGN_RIGHT);
|
||||
else
|
||||
LOG(LogError) << "Unknown TextListComponent alignment \"" << str << "\"!";
|
||||
if(elem->has("alignment"))
|
||||
{
|
||||
const std::string& str = elem->get<std::string>("alignment");
|
||||
if(str == "left")
|
||||
setAlignment(ALIGN_LEFT);
|
||||
else if(str == "center")
|
||||
setAlignment(ALIGN_CENTER);
|
||||
else if(str == "right")
|
||||
setAlignment(ALIGN_RIGHT);
|
||||
else
|
||||
LOG(LogError) << "Unknown TextListComponent alignment \"" << str << "\"!";
|
||||
}
|
||||
if(elem->has("horizontalMargin"))
|
||||
{
|
||||
mHorizontalMargin = elem->get<float>("horizontalMargin") * (mParent ? mParent->getSize().x() : (float)Renderer::getScreenWidth());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue