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