Fixed some alignment issues in CarouselComponent.

This commit is contained in:
Leon Styhre 2022-10-14 18:14:15 +02:00
parent 5f6bd48022
commit 16c4fb6d17
2 changed files with 22 additions and 22 deletions

View file

@ -183,7 +183,8 @@ CarouselComponent<T>::CarouselComponent()
, mMaxItemCount {3.0f} , mMaxItemCount {3.0f}
, mItemsBeforeCenter {8} , mItemsBeforeCenter {8}
, mItemsAfterCenter {8} , mItemsAfterCenter {8}
, mItemSize {Renderer::getScreenWidth() * 0.25f, Renderer::getScreenHeight() * 0.155f} , mItemSize {glm::round(
glm::vec2 {Renderer::getScreenWidth() * 0.25f, Renderer::getScreenHeight() * 0.155f})}
, mLinearInterpolation {false} , mLinearInterpolation {false}
, mInstantItemTransitions {false} , mInstantItemTransitions {false}
, mItemAxisHorizontal {false} , mItemAxisHorizontal {false}
@ -226,7 +227,7 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
auto item = std::make_shared<ImageComponent>(false, dynamic); auto item = std::make_shared<ImageComponent>(false, dynamic);
item->setLinearInterpolation(mLinearInterpolation); item->setLinearInterpolation(mLinearInterpolation);
item->setMipmapping(true); item->setMipmapping(true);
item->setMaxSize(mItemSize * mItemScale); item->setMaxSize(glm::round(mItemSize * mItemScale));
item->applyTheme(theme, "system", "image_logo", item->applyTheme(theme, "system", "image_logo",
ThemeFlags::PATH | ThemeFlags::COLOR); ThemeFlags::PATH | ThemeFlags::COLOR);
item->setRotateByTargetSize(true); item->setRotateByTargetSize(true);
@ -240,7 +241,7 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
auto item = std::make_shared<ImageComponent>(false, dynamic); auto item = std::make_shared<ImageComponent>(false, dynamic);
item->setLinearInterpolation(mLinearInterpolation); item->setLinearInterpolation(mLinearInterpolation);
item->setMipmapping(true); item->setMipmapping(true);
item->setMaxSize(mItemSize * mItemScale); item->setMaxSize(glm::round(mItemSize * mItemScale));
item->setImage(entry.data.itemPath); item->setImage(entry.data.itemPath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL); item->applyTheme(theme, "system", "", ThemeFlags::ALL);
item->setRotateByTargetSize(true); item->setRotateByTargetSize(true);
@ -251,7 +252,7 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
auto defaultItem = std::make_shared<ImageComponent>(false, dynamic); auto defaultItem = std::make_shared<ImageComponent>(false, dynamic);
defaultItem->setLinearInterpolation(mLinearInterpolation); defaultItem->setLinearInterpolation(mLinearInterpolation);
defaultItem->setMipmapping(true); defaultItem->setMipmapping(true);
defaultItem->setMaxSize(mItemSize * mItemScale); defaultItem->setMaxSize(glm::round(mItemSize * mItemScale));
defaultItem->setImage(entry.data.defaultItemPath); defaultItem->setImage(entry.data.defaultItemPath);
defaultItem->applyTheme(theme, "system", "", ThemeFlags::ALL); defaultItem->applyTheme(theme, "system", "", ThemeFlags::ALL);
defaultItem->setRotateByTargetSize(true); defaultItem->setRotateByTargetSize(true);
@ -275,7 +276,7 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
auto text = std::make_shared<TextComponent>( auto text = std::make_shared<TextComponent>(
nameEntry, mFont, 0x000000FF, mItemHorizontalAlignment, mItemVerticalAlignment, nameEntry, mFont, 0x000000FF, mItemHorizontalAlignment, mItemVerticalAlignment,
glm::vec3 {0.0f, 0.0f, 0.0f}, mItemSize * mItemScale, 0x00000000); glm::vec3 {0.0f, 0.0f, 0.0f}, glm::round(mItemSize * mItemScale), 0x00000000);
if (legacyMode) { if (legacyMode) {
text->applyTheme(theme, "system", "text_logoText", text->applyTheme(theme, "system", "text_logoText",
ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE | ThemeFlags::COLOR | ThemeFlags::FONT_PATH | ThemeFlags::FONT_SIZE | ThemeFlags::COLOR |
@ -310,7 +311,7 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
else else
entry.data.item->setOrigin(entry.data.item->getOrigin().x, 0.5f); entry.data.item->setOrigin(entry.data.item->getOrigin().x, 0.5f);
glm::vec2 denormalized {mItemSize * entry.data.item->getOrigin()}; glm::vec2 denormalized {glm::round(mItemSize * entry.data.item->getOrigin())};
entry.data.item->setPosition(glm::vec3 {denormalized.x, denormalized.y, 0.0f}); entry.data.item->setPosition(glm::vec3 {denormalized.x, denormalized.y, 0.0f});
List::add(entry); List::add(entry);
@ -323,7 +324,7 @@ void CarouselComponent<T>::updateEntry(Entry& entry, const std::shared_ptr<Theme
auto item = std::make_shared<ImageComponent>(false, true); auto item = std::make_shared<ImageComponent>(false, true);
item->setLinearInterpolation(mLinearInterpolation); item->setLinearInterpolation(mLinearInterpolation);
item->setMipmapping(true); item->setMipmapping(true);
item->setMaxSize(mItemSize * mItemScale); item->setMaxSize(glm::round(mItemSize * mItemScale));
item->setImage(entry.data.itemPath); item->setImage(entry.data.itemPath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL); item->applyTheme(theme, "system", "", ThemeFlags::ALL);
item->setRotateByTargetSize(true); item->setRotateByTargetSize(true);
@ -348,7 +349,7 @@ void CarouselComponent<T>::updateEntry(Entry& entry, const std::shared_ptr<Theme
else else
entry.data.item->setOrigin(entry.data.item->getOrigin().x, 0.5f); entry.data.item->setOrigin(entry.data.item->getOrigin().x, 0.5f);
glm::vec2 denormalized {mItemSize * entry.data.item->getOrigin()}; glm::vec2 denormalized {glm::round(mItemSize * entry.data.item->getOrigin())};
entry.data.item->setPosition(glm::vec3 {denormalized.x, denormalized.y, 0.0f}); entry.data.item->setPosition(glm::vec3 {denormalized.x, denormalized.y, 0.0f});
} }
@ -609,7 +610,7 @@ template <typename T> void CarouselComponent<T>::render(const glm::mat4& parentT
float scaleSize {mItemSize.x * mItemScale - mItemSize.x}; float scaleSize {mItemSize.x * mItemScale - mItemSize.x};
if (isWheel) { if (isWheel) {
xOff = (mSize.x - mItemSize.x) / 2.0f - (camOffset * itemSpacing.y); xOff = (mSize.x - mItemSize.x) / 2.0f;
yOff = (mSize.y - mItemSize.y) / 2.0f; yOff = (mSize.y - mItemSize.y) / 2.0f;
// Alignment of the actual carousel inside to the overall component area. // Alignment of the actual carousel inside to the overall component area.
if (mLegacyMode) { if (mLegacyMode) {
@ -649,7 +650,8 @@ template <typename T> void CarouselComponent<T>::render(const glm::mat4& parentT
} }
} }
else if (mType == CarouselType::VERTICAL) { else if (mType == CarouselType::VERTICAL) {
itemSpacing.y = ((mSize.y - (mItemSize.y * mMaxItemCount)) / mMaxItemCount) + mItemSize.y; itemSpacing.y =
std::round(((mSize.y - (mItemSize.y * mMaxItemCount)) / mMaxItemCount) + mItemSize.y);
yOff = (mSize.y - mItemSize.y) / 2.0f - (camOffset * itemSpacing.y); yOff = (mSize.y - mItemSize.y) / 2.0f - (camOffset * itemSpacing.y);
if (mItemHorizontalAlignment == ALIGN_LEFT) { if (mItemHorizontalAlignment == ALIGN_LEFT) {
if (mLegacyMode) if (mLegacyMode)
@ -668,7 +670,8 @@ template <typename T> void CarouselComponent<T>::render(const glm::mat4& parentT
} }
} }
else { // HORIZONTAL. else { // HORIZONTAL.
itemSpacing.x = ((mSize.x - (mItemSize.x * mMaxItemCount)) / mMaxItemCount) + mItemSize.x; itemSpacing.x =
std::round(((mSize.x - (mItemSize.x * mMaxItemCount)) / mMaxItemCount) + mItemSize.x);
xOff = (mSize.x - mItemSize.x) / 2.0f - (camOffset * itemSpacing.x); xOff = (mSize.x - mItemSize.x) / 2.0f - (camOffset * itemSpacing.x);
if (mItemVerticalAlignment == ALIGN_TOP) { if (mItemVerticalAlignment == ALIGN_TOP) {
if (mLegacyMode) if (mLegacyMode)
@ -695,10 +698,6 @@ template <typename T> void CarouselComponent<T>::render(const glm::mat4& parentT
yOff += mSize.y * mVerticalOffset; yOff += mSize.y * mVerticalOffset;
} }
// This is necessary to avoid single-pixel horizontal jumps at the end positions.
if (mType != CarouselType::HORIZONTAL)
xOff = std::round(xOff);
int center {0}; int center {0};
int centerOffset {0}; int centerOffset {0};
// Needed to make sure that overlapping items are renderered correctly. // Needed to make sure that overlapping items are renderered correctly.
@ -781,8 +780,9 @@ template <typename T> void CarouselComponent<T>::render(const glm::mat4& parentT
if (singleEntry) if (singleEntry)
itemTrans = glm::translate(carouselTrans, glm::vec3 {xOff, yOff, 0.0f}); itemTrans = glm::translate(carouselTrans, glm::vec3 {xOff, yOff, 0.0f});
else else
itemTrans = glm::translate( itemTrans =
itemTrans, glm::vec3 {i * itemSpacing.x + xOff, i * itemSpacing.y + yOff, 0.0f}); glm::translate(itemTrans, glm::vec3 {std::round(i * itemSpacing.x + xOff),
std::round(i * itemSpacing.y + yOff), 0.0f});
float opacity {0.0f}; float opacity {0.0f};
@ -1011,8 +1011,8 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (elem->has("itemSize")) { if (elem->has("itemSize")) {
const glm::vec2 itemSize {glm::clamp(elem->get<glm::vec2>("itemSize"), 0.05f, 1.0f)}; const glm::vec2 itemSize {glm::clamp(elem->get<glm::vec2>("itemSize"), 0.05f, 1.0f)};
mItemSize = mItemSize = glm::round(
itemSize * glm::vec2(Renderer::getScreenWidth(), Renderer::getScreenHeight()); itemSize * glm::vec2(Renderer::getScreenWidth(), Renderer::getScreenHeight()));
} }
if (elem->has("itemScale")) if (elem->has("itemScale"))
@ -1164,8 +1164,8 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
itemSize.x = glm::clamp(itemSize.x, 0.005f, 1.0f); itemSize.x = glm::clamp(itemSize.x, 0.005f, 1.0f);
itemSize.y = glm::clamp(itemSize.y, 0.005f, 1.0f); itemSize.y = glm::clamp(itemSize.y, 0.005f, 1.0f);
} }
mItemSize = mItemSize = glm::round(
itemSize * glm::vec2(Renderer::getScreenWidth(), Renderer::getScreenHeight()); itemSize * glm::vec2(Renderer::getScreenWidth(), Renderer::getScreenHeight()));
} }
if (elem->has("maxLogoCount")) { if (elem->has("maxLogoCount")) {

View file

@ -207,7 +207,7 @@ TextCache* Font::buildTextCache(const std::string& text,
size_t i {0}; size_t i {0};
for (auto it = vertMap.cbegin(); it != vertMap.cend(); ++it) { for (auto it = vertMap.cbegin(); it != vertMap.cend(); ++it) {
TextCache::VertexList& vertList = cache->vertexLists.at(i); TextCache::VertexList& vertList {cache->vertexLists.at(i)};
vertList.textureIdPtr = &it->first->textureId; vertList.textureIdPtr = &it->first->textureId;
vertList.verts = it->second; vertList.verts = it->second;
++i; ++i;