fixed menu

This commit is contained in:
2025-12-17 18:55:55 +01:00
parent cecf5cf68e
commit a671825502
5 changed files with 124 additions and 88 deletions

View File

@ -16,6 +16,30 @@ std::array<SDL_FRect, 5> computeMenuButtonRects(const MenuLayoutParams& p) {
float btnCX = LOGICAL_W * 0.5f + contentOffsetX;
float btnCY = LOGICAL_H * 0.86f + contentOffsetY + MENU_BTN_Y_OFFSET;
float spacing = isSmall ? btnW * MENU_BTN_SPACING_FACTOR_SMALL : btnW * MENU_BTN_SPACING_FACTOR_LARGE;
// Guarantee the full 5-button group fits within the logical width so no options
// disappear in windowed mode. We shrink width + spacing proportionally when needed.
const float margin = std::max(18.0f, LOGICAL_W * 0.02f);
const float availableW = std::max(100.0f, LOGICAL_W - margin * 2.0f);
float totalW = btnW + (MENU_BTN_COUNT - 1) * spacing;
if (totalW > availableW) {
float scale = availableW / totalW;
btnW *= scale;
btnH *= scale;
spacing *= scale;
totalW = btnW + (MENU_BTN_COUNT - 1) * spacing;
}
// Keep the group centered but ensure left/right edges respect margins.
float groupLeft = btnCX - totalW * 0.5f;
float minLeft = contentOffsetX + margin;
float maxRight = contentOffsetX + LOGICAL_W - margin;
float groupRight = groupLeft + totalW;
if (groupLeft < minLeft) {
btnCX += (minLeft - groupLeft);
} else if (groupRight > maxRight) {
btnCX -= (groupRight - maxRight);
}
std::array<SDL_FRect, MENU_BTN_COUNT> rects{};
for (int i = 0; i < MENU_BTN_COUNT; ++i) {
float center = btnCX + (static_cast<float>(i) - MENU_BTN_CENTER) * spacing;

View File

@ -6,7 +6,7 @@ static constexpr float MENU_BTN_WIDTH_LARGE = 300.0f;
static constexpr float MENU_BTN_WIDTH_SMALL_FACTOR = 0.4f; // multiplied by LOGICAL_W
static constexpr float MENU_BTN_HEIGHT_LARGE = 70.0f;
static constexpr float MENU_BTN_HEIGHT_SMALL = 60.0f;
static constexpr float MENU_BTN_Y_OFFSET = 40.0f; // matches MenuState offset
static constexpr float MENU_BTN_Y_OFFSET = 58.0f; // matches MenuState offset; slightly lower for windowed visibility
static constexpr float MENU_BTN_SPACING_FACTOR_SMALL = 1.15f;
static constexpr float MENU_BTN_SPACING_FACTOR_LARGE = 1.05f;
static constexpr float MENU_BTN_CENTER = (MENU_BTN_COUNT - 1) / 2.0f;