6734: Use `DoLabel` instead of `Text`/`TextEx` in menus, other minor refactoring of menus r=def- a=Robyt3


## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
bors[bot] 2023-06-11 20:36:46 +00:00 committed by GitHub
commit 4d0247a24c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 88 deletions

View file

@ -617,7 +617,6 @@ void CMenus::RenderServerbrowserFilters(CUIRect View)
{
CUIRect ServerFilter = View, FilterHeader;
const float FontSize = 12.0f;
ServerFilter.HSplitBottom(0.0f, &ServerFilter, 0);
// server filter
ServerFilter.HSplitTop(ms_ListheaderHeight, &FilterHeader, &ServerFilter);
@ -1037,7 +1036,6 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
ServerDetails.HSplitTop(110.0f, &ServerDetails, &ServerScoreBoard);
// server details
CTextCursor Cursor;
const float FontSize = 12.0f;
ServerDetails.HSplitTop(ms_ListheaderHeight, &ServerHeader, &ServerDetails);
ServerHeader.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_T, 4.0f);
@ -1110,25 +1108,19 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
for(auto &Label : s_aLabels)
{
LeftColumn.HSplitTop(15.0f, &Row, &LeftColumn);
UI()->DoLabel(&Row, Localize(Label), FontSize, TEXTALIGN_ML);
UI()->DoLabel(&Row, Label, FontSize, TEXTALIGN_ML);
}
RightColumn.HSplitTop(15.0f, &Row, &RightColumn);
TextRender()->SetCursor(&Cursor, Row.x, Row.y + (15.f - FontSize) / 2.f, FontSize, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = Row.w;
TextRender()->TextEx(&Cursor, pSelectedServer->m_aVersion, -1);
UI()->DoLabel(&Row, pSelectedServer->m_aVersion, FontSize, TEXTALIGN_ML);
RightColumn.HSplitTop(15.0f, &Row, &RightColumn);
TextRender()->SetCursor(&Cursor, Row.x, Row.y + (15.f - FontSize) / 2.f, FontSize, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = Row.w;
TextRender()->TextEx(&Cursor, pSelectedServer->m_aGameType, -1);
UI()->DoLabel(&Row, pSelectedServer->m_aGameType, FontSize, TEXTALIGN_ML);
char aTemp[16];
FormatServerbrowserPing(aTemp, sizeof(aTemp), pSelectedServer);
RightColumn.HSplitTop(15.0f, &Row, &RightColumn);
TextRender()->SetCursor(&Cursor, Row.x, Row.y + (15.f - FontSize) / 2.f, FontSize, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = Row.w;
TextRender()->TextEx(&Cursor, aTemp, -1);
UI()->DoLabel(&Row, aTemp, FontSize, TEXTALIGN_ML);
}
else
{
@ -1138,6 +1130,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
// server scoreboard
ServerScoreBoard.HSplitBottom(23.0f, &ServerScoreBoard, 0x0);
CTextCursor Cursor;
if(pSelectedServer)
{
static CListBox s_ListBox;
@ -1208,13 +1201,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View)
}
}
float ScoreFontSize = 12.0f;
while(ScoreFontSize >= 4.0f && TextRender()->TextWidth(ScoreFontSize, aTemp, -1, -1.0f) > Score.w)
ScoreFontSize--;
TextRender()->SetCursor(&Cursor, Score.x, Score.y + (Score.h - ScoreFontSize) / 2.0f, ScoreFontSize, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = Score.w;
TextRender()->TextEx(&Cursor, aTemp, -1);
UI()->DoLabel(&Score, aTemp, FontSize, TEXTALIGN_ML);
// render tee if available
if(HasTeeToRender)
@ -1704,7 +1691,7 @@ void CMenus::RenderServerbrowser(CUIRect MainView)
ToolboxPage = 0;
static CButtonContainer s_InfoTab;
if(DoButton_MenuTab(&s_InfoTab, Localize("Info"), ToolboxPage == 1, &TabButton1, 0, NULL, NULL, NULL, NULL, 4.0f))
if(DoButton_MenuTab(&s_InfoTab, Localize("Info"), ToolboxPage == 1, &TabButton1, IGraphics::CORNER_NONE, NULL, NULL, NULL, NULL, 4.0f))
ToolboxPage = 1;
static CButtonContainer s_FriendsTab;

View file

@ -577,10 +577,7 @@ void CMenus::RenderDemoPlayer(CUIRect MainView)
DemoPlayer()->GetDemoName(aDemoName, sizeof(aDemoName));
char aBuf[IO_MAX_PATH_LENGTH + 128];
str_format(aBuf, sizeof(aBuf), Localize("Demofile: %s"), aDemoName);
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, NameBar.x, NameBar.y + (NameBar.h - (Button.h * 0.5f)) / 2.f, Button.h * 0.5f, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = DemoControls.w;
TextRender()->TextEx(&Cursor, aBuf, -1);
UI()->DoLabel(&NameBar, aBuf, Button.h * 0.5f, TEXTALIGN_ML);
if(IncreaseDemoSpeed)
{

View file

@ -311,14 +311,9 @@ void CMenus::RenderPlayers(CUIRect MainView)
Player.HSplitTop(1.5f, nullptr, &Player);
Player.VSplitMid(&Player, &Button);
Row.VSplitRight(210.0f, &Button2, &Row);
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, Player.x, Player.y + (Player.h - 14.f) / 2.f, 14.0f, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = Player.w;
TextRender()->TextEx(&Cursor, CurrentClient.m_aName, -1);
TextRender()->SetCursor(&Cursor, Button.x, Button.y + (Button.h - 14.f) / 2.f, 14.0f, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = Button.w;
TextRender()->TextEx(&Cursor, CurrentClient.m_aClan, -1);
UI()->DoLabel(&Player, CurrentClient.m_aName, 14.0f, TEXTALIGN_ML);
UI()->DoLabel(&Button, CurrentClient.m_aClan, 14.0f, TEXTALIGN_ML);
m_pClient->m_CountryFlags.Render(CurrentClient.m_Country, ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f),
Button2.x, Button2.y + Button2.h / 2.0f - 0.75f * Button2.h / 2.0f, 1.5f * Button2.h, 0.75f * Button2.h);
@ -1075,21 +1070,13 @@ void CMenus::RenderGhost(CUIRect MainView)
}
else if(Id == COL_NAME)
{
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, Button.x, Button.y + (Button.h - 12.0f) / 2.f, 12.0f, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = Button.w;
TextRender()->TextEx(&Cursor, pGhost->m_aPlayer, -1);
UI()->DoLabel(&Button, pGhost->m_aPlayer, 12.0f, TEXTALIGN_ML);
}
else if(Id == COL_TIME)
{
CTextCursor Cursor;
TextRender()->SetCursor(&Cursor, Button.x, Button.y + (Button.h - 12.0f) / 2.f, 12.0f, TEXTFLAG_RENDER | TEXTFLAG_STOP_AT_END);
Cursor.m_LineWidth = Button.w;
char aBuf[64];
str_time(pGhost->m_Time / 10, TIME_HOURS_CENTISECS, aBuf, sizeof(aBuf));
TextRender()->TextEx(&Cursor, aBuf, -1);
UI()->DoLabel(&Button, aBuf, 12.0f, TEXTALIGN_ML);
}
}

View file

@ -1289,7 +1289,7 @@ void CMenus::RenderSettingsControls(CUIRect MainView)
const float Margin = 10.0f;
const float HeaderHeight = FontSize + 5.0f + Margin;
CUIRect MouseSettings, MovementSettings, WeaponSettings, VotingSettings, ChatSettings, DummySettings, MiscSettings, JoystickSettings, ResetButton;
CUIRect MouseSettings, MovementSettings, WeaponSettings, VotingSettings, ChatSettings, DummySettings, MiscSettings, JoystickSettings, ResetButton, Button;
MainView.VSplitMid(&MouseSettings, &VotingSettings);
// mouse settings
@ -1301,15 +1301,13 @@ void CMenus::RenderSettingsControls(CUIRect MainView)
MouseSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f);
MouseSettings.VMargin(10.0f, &MouseSettings);
TextRender()->Text(MouseSettings.x, MouseSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Mouse"), -1.0f);
MouseSettings.HSplitTop(HeaderHeight, &Button, &MouseSettings);
UI()->DoLabel(&Button, Localize("Mouse"), FontSize, TEXTALIGN_ML);
MouseSettings.HSplitTop(HeaderHeight, 0, &MouseSettings);
CUIRect Button;
MouseSettings.HSplitTop(20.0f, &Button, &MouseSettings);
UI()->DoScrollbarOption(&g_Config.m_InpMousesens, &g_Config.m_InpMousesens, &Button, Localize("Ingame mouse sens."), 1, 500, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_OPTION_NOCLAMPVALUE);
MouseSettings.HSplitTop(2.0f, 0, &MouseSettings);
MouseSettings.HSplitTop(2.0f, nullptr, &MouseSettings);
MouseSettings.HSplitTop(20.0f, &Button, &MouseSettings);
UI()->DoScrollbarOption(&g_Config.m_UiMousesens, &g_Config.m_UiMousesens, &Button, Localize("UI mouse sens."), 1, 500, &CUI::ms_LogarithmicScrollbarScale, CUI::SCROLLBAR_OPTION_NOCLAMPVALUE);
@ -1318,61 +1316,60 @@ void CMenus::RenderSettingsControls(CUIRect MainView)
// joystick settings
{
JoystickSettings.HSplitTop(Margin, 0, &JoystickSettings);
JoystickSettings.HSplitTop(Margin, nullptr, &JoystickSettings);
JoystickSettings.HSplitTop(s_JoystickSettingsHeight + HeaderHeight + Margin, &JoystickSettings, &MovementSettings);
if(s_ScrollRegion.AddRect(JoystickSettings))
{
JoystickSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f);
JoystickSettings.VMargin(Margin, &JoystickSettings);
TextRender()->Text(JoystickSettings.x, JoystickSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Controller"), -1.0f);
JoystickSettings.HSplitTop(HeaderHeight, &Button, &JoystickSettings);
UI()->DoLabel(&Button, Localize("Controller"), FontSize, TEXTALIGN_ML);
JoystickSettings.HSplitTop(HeaderHeight, 0, &JoystickSettings);
s_JoystickSettingsHeight = RenderSettingsControlsJoystick(JoystickSettings);
}
}
// movement settings
{
MovementSettings.HSplitTop(Margin, 0, &MovementSettings);
MovementSettings.HSplitTop(Margin, nullptr, &MovementSettings);
MovementSettings.HSplitTop(365.0f, &MovementSettings, &WeaponSettings);
if(s_ScrollRegion.AddRect(MovementSettings))
{
MovementSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f);
MovementSettings.VMargin(Margin, &MovementSettings);
TextRender()->Text(MovementSettings.x, MovementSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Movement"), -1.0f);
MovementSettings.HSplitTop(HeaderHeight, &Button, &MovementSettings);
UI()->DoLabel(&Button, Localize("Movement"), FontSize, TEXTALIGN_ML);
MovementSettings.HSplitTop(HeaderHeight, 0, &MovementSettings);
DoSettingsControlsButtons(0, 15, MovementSettings);
}
}
// weapon settings
{
WeaponSettings.HSplitTop(Margin, 0, &WeaponSettings);
WeaponSettings.HSplitTop(Margin, nullptr, &WeaponSettings);
WeaponSettings.HSplitTop(190.0f, &WeaponSettings, &ResetButton);
if(s_ScrollRegion.AddRect(WeaponSettings))
{
WeaponSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f);
WeaponSettings.VMargin(Margin, &WeaponSettings);
TextRender()->Text(WeaponSettings.x, WeaponSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Weapon"), -1.0f);
WeaponSettings.HSplitTop(HeaderHeight, &Button, &WeaponSettings);
UI()->DoLabel(&Button, Localize("Weapon"), FontSize, TEXTALIGN_ML);
WeaponSettings.HSplitTop(HeaderHeight, 0, &WeaponSettings);
DoSettingsControlsButtons(15, 22, WeaponSettings);
}
}
// defaults
{
ResetButton.HSplitTop(Margin, 0, &ResetButton);
ResetButton.HSplitTop(40.0f, &ResetButton, 0);
ResetButton.HSplitTop(Margin, nullptr, &ResetButton);
ResetButton.HSplitTop(40.0f, &ResetButton, nullptr);
if(s_ScrollRegion.AddRect(ResetButton))
{
ResetButton.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f);
ResetButton.HMargin(10.0f, &ResetButton);
ResetButton.VMargin(30.0f, &ResetButton);
ResetButton.Margin(10.0f, &ResetButton);
static CButtonContainer s_DefaultButton;
if(DoButton_Menu(&s_DefaultButton, Localize("Reset to defaults"), 0, &ResetButton))
{
@ -1391,57 +1388,57 @@ void CMenus::RenderSettingsControls(CUIRect MainView)
VotingSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f);
VotingSettings.VMargin(Margin, &VotingSettings);
TextRender()->Text(VotingSettings.x, VotingSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Voting"), -1.0f);
VotingSettings.HSplitTop(HeaderHeight, &Button, &VotingSettings);
UI()->DoLabel(&Button, Localize("Voting"), FontSize, TEXTALIGN_ML);
VotingSettings.HSplitTop(HeaderHeight, 0, &VotingSettings);
DoSettingsControlsButtons(22, 24, VotingSettings);
}
}
// chat settings
{
ChatSettings.HSplitTop(Margin, 0, &ChatSettings);
ChatSettings.HSplitTop(Margin, nullptr, &ChatSettings);
ChatSettings.HSplitTop(145.0f, &ChatSettings, &DummySettings);
if(s_ScrollRegion.AddRect(ChatSettings))
{
ChatSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f);
ChatSettings.VMargin(Margin, &ChatSettings);
TextRender()->Text(ChatSettings.x, ChatSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Chat"), -1.0f);
ChatSettings.HSplitTop(HeaderHeight, &Button, &ChatSettings);
UI()->DoLabel(&Button, Localize("Chat"), FontSize, TEXTALIGN_ML);
ChatSettings.HSplitTop(HeaderHeight, 0, &ChatSettings);
DoSettingsControlsButtons(24, 29, ChatSettings);
}
}
// dummy settings
{
DummySettings.HSplitTop(Margin, 0, &DummySettings);
DummySettings.HSplitTop(Margin, nullptr, &DummySettings);
DummySettings.HSplitTop(100.0f, &DummySettings, &MiscSettings);
if(s_ScrollRegion.AddRect(DummySettings))
{
DummySettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f);
DummySettings.VMargin(Margin, &DummySettings);
TextRender()->Text(DummySettings.x, DummySettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Dummy"), -1.0f);
DummySettings.HSplitTop(HeaderHeight, &Button, &DummySettings);
UI()->DoLabel(&Button, Localize("Dummy"), FontSize, TEXTALIGN_ML);
DummySettings.HSplitTop(HeaderHeight, 0, &DummySettings);
DoSettingsControlsButtons(29, 32, DummySettings);
}
}
// misc settings
{
MiscSettings.HSplitTop(Margin, 0, &MiscSettings);
MiscSettings.HSplitTop(Margin, nullptr, &MiscSettings);
MiscSettings.HSplitTop(300.0f, &MiscSettings, 0);
if(s_ScrollRegion.AddRect(MiscSettings))
{
MiscSettings.Draw(ColorRGBA(1, 1, 1, 0.25f), IGraphics::CORNER_ALL, 10.0f);
MiscSettings.VMargin(Margin, &MiscSettings);
TextRender()->Text(MiscSettings.x, MiscSettings.y + (HeaderHeight - FontSize) / 2.f, FontSize, Localize("Miscellaneous"), -1.0f);
MiscSettings.HSplitTop(HeaderHeight, &Button, &MiscSettings);
UI()->DoLabel(&Button, Localize("Miscellaneous"), FontSize, TEXTALIGN_ML);
MiscSettings.HSplitTop(HeaderHeight, 0, &MiscSettings);
DoSettingsControlsButtons(32, 44, MiscSettings);
}
}
@ -2006,37 +2003,33 @@ bool CMenus::RenderLanguageSelection(CUIRect MainView)
void CMenus::RenderSettings(CUIRect MainView)
{
// render background
CUIRect Temp, TabBar, RestartWarning;
CUIRect Button, TabBar, RestartWarning;
MainView.VSplitRight(120.0f, &MainView, &TabBar);
MainView.Draw(ms_ColorTabbarActive, IGraphics::CORNER_B, 10.0f);
MainView.Margin(10.0f, &MainView);
MainView.HSplitBottom(15.0f, &MainView, &RestartWarning);
TabBar.HSplitTop(50.0f, &Temp, &TabBar);
Temp.Draw(ms_ColorTabbarActive, IGraphics::CORNER_BR, 10.0f);
TabBar.HSplitTop(50.0f, &Button, &TabBar);
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[] = {
const char *apTabs[SETTINGS_LENGTH] = {
Localize("Language"),
Localize("General"),
Localize("Player"),
("Tee"),
"Tee",
Localize("Appearance"),
Localize("Controls"),
Localize("Graphics"),
Localize("Sound"),
Localize("DDNet"),
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 < NumTabs; i++)
for(int i = 0; i < SETTINGS_LENGTH; i++)
{
TabBar.HSplitTop(10, &Button, &TabBar);
TabBar.HSplitTop(26, &Button, &TabBar);
TabBar.HSplitTop(10.0f, nullptr, &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]))
g_Config.m_UiSettingsPage = i;
}
@ -2484,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))
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 ColorPickerLineSize = 25.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 HeadlineAndVMargin = 30.0f; // HeadlineFontSize + SectionTotalMargin;
const float HeadlineAndVMargin = HeadlineFontSize + SectionTotalMargin;
const float MarginToNextSection = 5.0f;
const float ColorPickerLabelSize = 13.0f;