Refactor CMenus::RenderSettings

Use correct enum literal `SETTINGS_LENGTH` as array size for button containers instead of the `sizeof(apTabs)`, which does not consider the size of the array elements.

Use code for dynamic size calculation directly instead of putting it in comments.
This commit is contained in:
Robert Müller 2023-06-07 18:16:32 +02:00
parent 8d65e0ac34
commit 2fb4a39e10

View file

@ -2003,37 +2003,33 @@ bool CMenus::RenderLanguageSelection(CUIRect MainView)
void CMenus::RenderSettings(CUIRect MainView) void CMenus::RenderSettings(CUIRect MainView)
{ {
// render background // render background
CUIRect Temp, TabBar, RestartWarning; CUIRect Button, TabBar, RestartWarning;
MainView.VSplitRight(120.0f, &MainView, &TabBar); MainView.VSplitRight(120.0f, &MainView, &TabBar);
MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f); MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f);
MainView.Margin(10.0f, &MainView); MainView.Margin(10.0f, &MainView);
MainView.HSplitBottom(15.0f, &MainView, &RestartWarning); MainView.HSplitBottom(15.0f, &MainView, &RestartWarning);
TabBar.HSplitTop(50.0f, &Temp, &TabBar); TabBar.HSplitTop(50.0f, &Button, &TabBar);
Temp.Draw(ms_ColorTabbarActive, IGraphics::CORNER_BR, 10.0f); Button.Draw(ms_ColorTabbarActive, IGraphics::CORNER_BR, 10.0f);
MainView.HSplitTop(10.0f, 0, &MainView); MainView.HSplitTop(10.0f, nullptr, &MainView);
CUIRect Button; const char *apTabs[SETTINGS_LENGTH] = {
const char *apTabs[] = {
Localize("Language"), Localize("Language"),
Localize("General"), Localize("General"),
Localize("Player"), Localize("Player"),
("Tee"), "Tee",
Localize("Appearance"), Localize("Appearance"),
Localize("Controls"), Localize("Controls"),
Localize("Graphics"), Localize("Graphics"),
Localize("Sound"), Localize("Sound"),
Localize("DDNet"), Localize("DDNet"),
Localize("Assets")}; Localize("Assets")};
static CButtonContainer s_aTabButtons[sizeof(apTabs)]; static CButtonContainer s_aTabButtons[SETTINGS_LENGTH];
int NumTabs = (int)std::size(apTabs); for(int i = 0; i < SETTINGS_LENGTH; i++)
for(int i = 0; i < NumTabs; i++)
{ {
TabBar.HSplitTop(10, &Button, &TabBar); TabBar.HSplitTop(10.0f, nullptr, &TabBar);
TabBar.HSplitTop(26, &Button, &TabBar); TabBar.HSplitTop(26.0f, &Button, &TabBar);
if(DoButton_MenuTab(&s_aTabButtons[i], apTabs[i], g_Config.m_UiSettingsPage == i, &Button, IGraphics::CORNER_R, &m_aAnimatorsSettingsTab[i])) if(DoButton_MenuTab(&s_aTabButtons[i], apTabs[i], g_Config.m_UiSettingsPage == i, &Button, IGraphics::CORNER_R, &m_aAnimatorsSettingsTab[i]))
g_Config.m_UiSettingsPage = i; g_Config.m_UiSettingsPage = i;
} }
@ -2481,14 +2477,14 @@ void CMenus::RenderSettingsAppearance(CUIRect MainView)
if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_LASER], Localize("Laser"), s_CurTab == APPEARANCE_TAB_LASER, &Page6Tab, IGraphics::CORNER_R, NULL, NULL, NULL, NULL, 4)) if(DoButton_MenuTab(&s_aPageTabs[APPEARANCE_TAB_LASER], Localize("Laser"), s_CurTab == APPEARANCE_TAB_LASER, &Page6Tab, IGraphics::CORNER_R, NULL, NULL, NULL, NULL, 4))
s_CurTab = APPEARANCE_TAB_LASER; s_CurTab = APPEARANCE_TAB_LASER;
MainView.HSplitTop(10.0f, 0x0, &MainView); // Margin MainView.HSplitTop(10.0f, nullptr, &MainView);
const float LineSize = 20.0f; const float LineSize = 20.0f;
const float ColorPickerLineSize = 25.0f; const float ColorPickerLineSize = 25.0f;
const float SectionMargin = 5.0f; const float SectionMargin = 5.0f;
const float SectionTotalMargin = 10.0f; // SectionMargin * 2; const float SectionTotalMargin = SectionMargin * 2;
const float HeadlineFontSize = 20.0f; const float HeadlineFontSize = 20.0f;
const float HeadlineAndVMargin = 30.0f; // HeadlineFontSize + SectionTotalMargin; const float HeadlineAndVMargin = HeadlineFontSize + SectionTotalMargin;
const float MarginToNextSection = 5.0f; const float MarginToNextSection = 5.0f;
const float ColorPickerLabelSize = 13.0f; const float ColorPickerLabelSize = 13.0f;