Add maximum size to tabs in options menu. (#376)

* Add maximum size to tabs in options menu.

* Simplify squash ratio computation.

* Allow room for less padding if the text can't fit to the fixed width.

* Stretch every tab instead of individual ones.

---------

Co-authored-by: Skyth <19259897+blueskythlikesclouds@users.noreply.github.com>
This commit is contained in:
Darío 2025-02-12 09:19:06 -03:00 committed by GitHub
parent 3081aec7c1
commit 86b346e037
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -477,36 +477,43 @@ static bool DrawCategories()
auto clipRectMin = drawList->GetClipRectMin(); auto clipRectMin = drawList->GetClipRectMin();
auto clipRectMax = drawList->GetClipRectMax(); auto clipRectMax = drawList->GetClipRectMax();
constexpr float NARROW_PADDING_GRID_COUNT = 1.5f;
constexpr float WIDE_PADDING_GRID_COUNT = 3.0f;
float gridSize = Scale(GRID_SIZE); float gridSize = Scale(GRID_SIZE);
float textPadding = gridSize * Lerp(NARROW_PADDING_GRID_COUNT, WIDE_PADDING_GRID_COUNT, g_aspectRatioNarrowScale);
float tabPadding = gridSize;
float size = Scale(32.0f); float size = Scale(32.0f);
ImVec2 textSizes[g_categoryCount]; ImVec2 textSizes[g_categoryCount];
float tabWidthSum = 0.0f; float clipRectWidth = clipRectMax.x - clipRectMin.x;
float textWidthSum = 0.0f;
for (size_t i = 0; i < g_categoryCount; i++) for (size_t i = 0; i < g_categoryCount; i++)
{ {
textSizes[i] = g_dfsogeistdFont->CalcTextSizeA(size, FLT_MAX, 0.0f, GetCategory(i).c_str()); textSizes[i] = g_dfsogeistdFont->CalcTextSizeA(size, FLT_MAX, 0.0f, GetCategory(i).c_str());
tabWidthSum += textSizes[i].x + textPadding * 2.0f; textWidthSum += textSizes[i].x;
}
float textSquashRatio = 1.0f;
float maxTextWidthSum = clipRectWidth - (gridSize * 4.0f * (g_categoryCount - 1));
if (textWidthSum > maxTextWidthSum)
{
textSquashRatio = maxTextWidthSum / textWidthSum;
for (auto& textSize : textSizes)
textSize.x *= textSquashRatio;
textWidthSum = maxTextWidthSum;
} }
tabWidthSum += (g_categoryCount - 1) * tabPadding;
float tabHeight = gridSize * 4.0f; float tabHeight = gridSize * 4.0f;
float xOffset = ((clipRectMax.x - clipRectMin.x) - tabWidthSum) / 2.0f; float textPadding = (clipRectWidth - textWidthSum) / (g_categoryCount + 1.0f);
float xOffset = textPadding;
xOffset -= (1.0 - motion) * gridSize * 4.0; xOffset -= (1.0 - motion) * gridSize * 4.0;
ImVec2 minVec[g_categoryCount]; ImVec2 textPositions[g_categoryCount];
for (size_t i = 0; i < g_categoryCount; i++) for (size_t i = 0; i < g_categoryCount; i++)
{ {
ImVec2 min = { clipRectMin.x + xOffset, clipRectMin.y }; float tabPadding = std::min(textPadding / 2.0f, gridSize * 3.0f);
xOffset += textSizes[i].x + textPadding * 2.0f; ImVec2 min = { clipRectMin.x + xOffset - tabPadding, clipRectMin.y };
ImVec2 max = { clipRectMin.x + xOffset, clipRectMin.y + tabHeight }; ImVec2 max = { min.x + textSizes[i].x + tabPadding * 2.0f, min.y + tabHeight};
xOffset += tabPadding;
if (g_categoryIndex == i) if (g_categoryIndex == i)
{ {
@ -570,21 +577,23 @@ static bool DrawCategories()
SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE); SetShaderModifier(IMGUI_SHADER_MODIFIER_NONE);
} }
min.x += textPadding;
// Store to draw again later, otherwise the tab background gets drawn on top of text during the animation. // Store to draw again later, otherwise the tab background gets drawn on top of text during the animation.
minVec[i] = min; textPositions[i] = { clipRectMin.x + xOffset, clipRectMin.y };
xOffset += textSizes[i].x + textPadding;
} }
SetScale({ textSquashRatio, 1.0f });
for (size_t i = 0; i < g_categoryCount; i++) for (size_t i = 0; i < g_categoryCount; i++)
{ {
auto& min = minVec[i]; auto& pos = textPositions[i];
uint8_t alpha = (i == g_categoryIndex ? 235 : 128) * motion; uint8_t alpha = (i == g_categoryIndex ? 235 : 128) * motion;
SetOrigin({ pos.x, pos.y });
SetGradient SetGradient
( (
min, pos,
{ min.x + textSizes[i].x, min.y + textSizes[i].y }, { pos.x + textSizes[i].x, pos.y + textSizes[i].y },
IM_COL32(128, 255, 0, alpha), IM_COL32(128, 255, 0, alpha),
IM_COL32(255, 192, 0, alpha) IM_COL32(255, 192, 0, alpha)
); );
@ -593,17 +602,19 @@ static bool DrawCategories()
( (
g_dfsogeistdFont, g_dfsogeistdFont,
size, size,
min, pos,
IM_COL32_WHITE, IM_COL32_WHITE,
GetCategory(i).c_str(), GetCategory(i).c_str(),
4, 4,
IM_COL32_BLACK, IM_COL32_BLACK,
IMGUI_SHADER_MODIFIER_CATEGORY_BEVEL IMGUI_SHADER_MODIFIER_CATEGORY_BEVEL
); );
ResetGradient();
} }
SetScale({ 1.0f, 1.0f });
SetOrigin({ 0.0f, 0.0f });
ResetGradient();
if (g_isStage || (ImGui::GetTime() - g_appearTime) >= (CONTAINER_FULL_DURATION / 60.0)) if (g_isStage || (ImGui::GetTime() - g_appearTime) >= (CONTAINER_FULL_DURATION / 60.0))
{ {
drawList->PushClipRect({ clipRectMin.x, clipRectMin.y + gridSize * 6.0f }, { clipRectMax.x - gridSize, clipRectMax.y - gridSize }); drawList->PushClipRect({ clipRectMin.x, clipRectMin.y + gridSize * 6.0f }, { clipRectMax.x - gridSize, clipRectMax.y - gridSize });