mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-01-31 04:25:40 +00:00
Changed "center" property of textlist to "alignment".
TextListComponent can now be aligned either left, right, or center.
This commit is contained in:
parent
49130464ba
commit
fa8e60b7b5
|
@ -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).
|
||||
* `center` - type: BOOLEAN.
|
||||
- If true, center the text on the x-axis.
|
||||
* `alignment` - type: STRING.
|
||||
- Valid values are "left", "center", or "right". Controls alignment on the X axis.
|
||||
|
||||
#### textlist
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ std::map< std::string, std::map<std::string, ThemeData::ElementPropertyType> > T
|
|||
("fontPath", PATH)
|
||||
("fontSize", FLOAT)
|
||||
("scrollSound", PATH)
|
||||
("center", BOOLEAN))
|
||||
("alignment", STRING))
|
||||
("container", boost::assign::map_list_of
|
||||
("pos", NORMALIZED_PAIR)
|
||||
("size", NORMALIZED_PAIR))
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace ThemeFlags
|
|||
FONT_PATH = 32,
|
||||
FONT_SIZE = 64,
|
||||
SOUND = 128,
|
||||
CENTER = 256,
|
||||
ALIGNMENT = 256,
|
||||
TEXT = 512,
|
||||
|
||||
ALL = 0xFFFFFFFF
|
||||
|
|
|
@ -172,7 +172,7 @@ void TextComponent::applyTheme(const std::shared_ptr<ThemeData>& theme, const st
|
|||
if(properties & COLOR && elem->has("color"))
|
||||
setColor(elem->get<unsigned int>("color"));
|
||||
|
||||
if(properties & CENTER && elem->has("center"))
|
||||
if(properties & ALIGNMENT && elem->has("center"))
|
||||
setCentered(elem->get<bool>("center"));
|
||||
|
||||
if(properties & TEXT && elem->has("text"))
|
||||
|
|
|
@ -48,14 +48,21 @@ public:
|
|||
void stopScrolling();
|
||||
inline bool isScrolling() const { return mScrollDir != 0; }
|
||||
|
||||
inline void setCentered(bool centered) { mCentered = centered; }
|
||||
|
||||
enum CursorState
|
||||
{
|
||||
CURSOR_STOPPED,
|
||||
CURSOR_SCROLLING
|
||||
};
|
||||
|
||||
enum Alignment
|
||||
{
|
||||
ALIGN_LEFT,
|
||||
ALIGN_CENTER,
|
||||
ALIGN_RIGHT
|
||||
};
|
||||
|
||||
inline void setAlignment(Alignment align) { mAlignment = align; }
|
||||
|
||||
inline void setCursorChangedCallback(const std::function<void(CursorState state)>& func) { mCursorChangedCallback = func; }
|
||||
|
||||
inline void setFont(const std::shared_ptr<Font>& font)
|
||||
|
@ -88,7 +95,7 @@ private:
|
|||
int mMarqueeOffset;
|
||||
int mMarqueeTime;
|
||||
|
||||
bool mCentered;
|
||||
Alignment mAlignment;
|
||||
|
||||
std::vector<ListRow> mRowVector;
|
||||
int mCursor;
|
||||
|
@ -114,7 +121,7 @@ TextListComponent<T>::TextListComponent(Window* window) :
|
|||
mMarqueeOffset = 0;
|
||||
mMarqueeTime = -MARQUEE_DELAY;
|
||||
|
||||
mCentered = true;
|
||||
mAlignment = ALIGN_CENTER;
|
||||
|
||||
mFont = Font::get(FONT_SIZE_MEDIUM);
|
||||
mSelectorColor = 0x000000FF;
|
||||
|
@ -179,8 +186,6 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
|||
|
||||
ListRow& row = mRowVector.at((unsigned int)i);
|
||||
|
||||
float x = (float)(mCursor == i ? -mMarqueeOffset : 0);
|
||||
|
||||
unsigned int color;
|
||||
if(mCursor == i && mSelectedColor)
|
||||
color = mSelectedColor;
|
||||
|
@ -192,10 +197,24 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
|
|||
|
||||
row.textCache->setColor(color);
|
||||
|
||||
Eigen::Vector3f offset(x, y, 0);
|
||||
Eigen::Vector3f offset(0, y, 0);
|
||||
|
||||
if(mCentered)
|
||||
offset[0] += (mSize.x() - row.textCache->metrics.size.x()) / 2;
|
||||
switch(mAlignment)
|
||||
{
|
||||
case ALIGN_LEFT:
|
||||
offset[0] = 0;
|
||||
break;
|
||||
case ALIGN_CENTER:
|
||||
offset[0] = (mSize.x() - row.textCache->metrics.size.x()) / 2;
|
||||
break;
|
||||
case ALIGN_RIGHT:
|
||||
offset[0] = (mSize.x() - row.textCache->metrics.size.x());
|
||||
break;
|
||||
}
|
||||
|
||||
if(offset[0] < 0)
|
||||
offset[0] = 0;
|
||||
offset[0] += (float)(mCursor == i ? -mMarqueeOffset : 0);
|
||||
|
||||
Eigen::Affine3f drawTrans = trans;
|
||||
drawTrans.translate(offset);
|
||||
|
@ -434,8 +453,18 @@ 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 & CENTER && elem->has("center"))
|
||||
mCentered = elem->get<bool>("center");
|
||||
if(properties & ALIGNMENT && 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 << "\"!";
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,7 @@ DetailedGameListView::DetailedGameListView(Window* window, FileData* root) :
|
|||
|
||||
mList.setPosition(mSize.x() * (0.50f + padding), mList.getPosition().y());
|
||||
mList.setSize(mSize.x() * (0.50f - 2*padding), mList.getSize().y());
|
||||
mList.setCentered(false);
|
||||
mList.setAlignment(TextListComponent<FileData*>::ALIGN_LEFT);
|
||||
mList.setCursorChangedCallback([&](TextListComponent<FileData*>::CursorState state) { updateInfoPanel(); });
|
||||
|
||||
// image
|
||||
|
|
Loading…
Reference in a new issue