Right aligned DateTimeEditComponent and made some minor adjustments in GuiMetaDataEd.

This commit is contained in:
Leon Styhre 2021-03-20 10:26:18 +01:00
parent d65ecd6a50
commit 9d9aaa30d7
2 changed files with 21 additions and 7 deletions

View file

@ -144,6 +144,10 @@ GuiMetaDataEd::GuiMetaDataEd(
ed->setSize(0, height); ed->setSize(0, height);
row.addElement(ed, false, true); row.addElement(ed, false, true);
auto ratingSpacer = std::make_shared<GuiComponent>(mWindow);
ratingSpacer->setSize(Renderer::getScreenWidth() * 0.001f, 0);
row.addElement(ratingSpacer, false);
// Pass input to the actual RatingComponent instead of the spacer. // Pass input to the actual RatingComponent instead of the spacer.
row.input_handler = std::bind(&GuiComponent::input, row.input_handler = std::bind(&GuiComponent::input,
ed.get(), std::placeholders::_1, std::placeholders::_2); ed.get(), std::placeholders::_1, std::placeholders::_2);
@ -159,6 +163,10 @@ GuiMetaDataEd::GuiMetaDataEd(
ed->setChangedColor(TEXTCOLOR_USERMARKED); ed->setChangedColor(TEXTCOLOR_USERMARKED);
row.addElement(ed, false); row.addElement(ed, false);
auto dateSpacer = std::make_shared<GuiComponent>(mWindow);
dateSpacer->setSize(Renderer::getScreenWidth() * 0.0035f, 0);
row.addElement(dateSpacer, false);
// Pass input to the actual DateTimeEditComponent instead of the spacer. // Pass input to the actual DateTimeEditComponent instead of the spacer.
row.input_handler = std::bind(&GuiComponent::input, ed.get(), row.input_handler = std::bind(&GuiComponent::input, ed.get(),
std::placeholders::_1, std::placeholders::_2); std::placeholders::_1, std::placeholders::_2);

View file

@ -160,14 +160,22 @@ void DateTimeEditComponent::render(const Transform4x4f& parentTrans)
Transform4x4f trans = parentTrans * getTransform(); Transform4x4f trans = parentTrans * getTransform();
if (mTextCache) { if (mTextCache) {
std::shared_ptr<Font> font = getFont();
float referenceSize;
if (mTime != 0)
referenceSize = font->sizeText("ABCDEFG").x();
else
referenceSize = font->sizeText("ABCDEIJ").x();
// Vertically center. // Vertically center.
Vector3f off(0, (mSize.y() - mTextCache->metrics.size.y()) / 2, 0); Vector3f off(0, (mSize.y() - mTextCache->metrics.size.y()) / 2.0f, 0.0f);
// Right align.
off.x() += referenceSize - mTextCache->metrics.size.x();
trans.translate(off); trans.translate(off);
Renderer::setMatrix(trans); Renderer::setMatrix(trans);
std::shared_ptr<Font> font = getFont();
mTextCache->setColor((mColor & 0xFFFFFF00) | getOpacity()); mTextCache->setColor((mColor & 0xFFFFFF00) | getOpacity());
font->renderTextCache(mTextCache.get()); font->renderTextCache(mTextCache.get());
@ -211,14 +219,12 @@ std::string DateTimeEditComponent::getDisplayString(DisplayMode mode) const
switch (mode) { switch (mode) {
case DISP_DATE: { case DISP_DATE: {
if (mTime.getTime() == 0) if (mTime.getTime() == 0)
// The extra blankspaces are for visual alignment.
return "unknown"; return "unknown";
fmt = "%Y-%m-%d"; fmt = "%Y-%m-%d";
break; break;
} }
case DISP_DATE_TIME: { case DISP_DATE_TIME: {
if (mTime.getTime() == 0) if (mTime.getTime() == 0)
// The extra blankspaces are for visual alignment.
return "unknown"; return "unknown";
fmt = "%Y-%m-%d %H:%M:%S"; fmt = "%Y-%m-%d %H:%M:%S";
break; break;