From f634f8a76b5dac586d4bfd7abbcfd43bbc2aaa26 Mon Sep 17 00:00:00 2001 From: oy Date: Thu, 10 Jan 2019 22:14:29 +0100 Subject: [PATCH] automatically adjust the scrollbar based on the according text length. closes #1956 --- src/game/client/components/menus.cpp | 11 +++++++---- src/game/client/components/menus.h | 2 +- src/game/client/components/menus_callback.cpp | 2 +- src/game/client/components/menus_settings.cpp | 12 ++++++------ 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/game/client/components/menus.cpp b/src/game/client/components/menus.cpp index 9a03d9d2b..f9e0f2964 100644 --- a/src/game/client/components/menus.cpp +++ b/src/game/client/components/menus.cpp @@ -595,21 +595,24 @@ void CMenus::DoEditBoxOption(void *pID, char *pOption, int OptionLength, const C DoEditBox(pID, &EditBox, pOption, OptionLength, pRect->h*ms_FontmodHeight*0.8f, pOffset, Hidden); } -void CMenus::DoScrollbarOption(void *pID, int *pOption, const CUIRect *pRect, const char *pStr, float VSplitVal, int Min, int Max, bool infinite) +void CMenus::DoScrollbarOption(void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, bool infinite) { RenderTools()->DrawUIRect(pRect, vec4(0.0f, 0.0f, 0.0f, 0.25f), CUI::CORNER_ALL, 5.0f); CUIRect Label, ScrollBar; - pRect->VSplitLeft(VSplitVal, &Label, &ScrollBar); - char aBuf[32]; + char aBuf[128]; if(*pOption || !infinite) str_format(aBuf, sizeof(aBuf), "%s: %i", pStr, *pOption); else str_format(aBuf, sizeof(aBuf), "%s: \xe2\x88\x9e", pStr); + float FontSize = pRect->h*ms_FontmodHeight*0.8f; + float VSplitVal = TextRender()->TextWidth(0, FontSize, aBuf, -1); + + pRect->VSplitLeft(pRect->h+10.0f+VSplitVal, &Label, &ScrollBar); Label.VSplitLeft(Label.h+5.0f, 0, &Label); Label.y += 2.0f; - UI()->DoLabel(&Label, aBuf, pRect->h*ms_FontmodHeight*0.8f, CUI::ALIGN_LEFT); + UI()->DoLabel(&Label, aBuf, FontSize, CUI::ALIGN_LEFT); ScrollBar.VMargin(4.0f, &ScrollBar); *pOption = round_to_int(DoScrollbarH(pOption, &ScrollBar, (float)(*pOption-Min)/(float)(Max-Min))*(float)(Max-Min)+(float)Min+0.1f); diff --git a/src/game/client/components/menus.h b/src/game/client/components/menus.h index 4dba57eff..0ece33b33 100644 --- a/src/game/client/components/menus.h +++ b/src/game/client/components/menus.h @@ -84,7 +84,7 @@ private: */ int DoEditBox(void *pID, const CUIRect *pRect, char *pStr, unsigned StrSize, float FontSize, float *pOffset, bool Hidden=false, int Corners=CUI::CORNER_ALL); void DoEditBoxOption(void *pID, char *pOption, int OptionLength, const CUIRect *pRect, const char *pStr, float VSplitVal, float *pOffset, bool Hidden=false); - void DoScrollbarOption(void *pID, int *pOption, const CUIRect *pRect, const char *pStr, float VSplitVal, int Min, int Max, bool infinite=false); + void DoScrollbarOption(void *pID, int *pOption, const CUIRect *pRect, const char *pStr, int Min, int Max, bool infinite=false); float DoDropdownMenu(void *pID, const CUIRect *pRect, const char *pStr, float HeaderHeight, FDropdownCallback pfnCallback); float DoIndependentDropdownMenu(void *pID, const CUIRect *pRect, const char *pStr, float HeaderHeight, FDropdownCallback pfnCallback, bool* pActive); void DoInfoBox(const CUIRect *pRect, const char *pLable, const char *pValue); diff --git a/src/game/client/components/menus_callback.cpp b/src/game/client/components/menus_callback.cpp index 36cca3503..abb88f065 100644 --- a/src/game/client/components/menus_callback.cpp +++ b/src/game/client/components/menus_callback.cpp @@ -127,7 +127,7 @@ float CMenus::RenderSettingsControlsMovement(CUIRect View, void *pUser) CUIRect Button; View.HSplitTop(Spaceing, 0, &View); View.HSplitTop(ButtonHeight, &Button, &View); - pSelf->DoScrollbarOption(&g_Config.m_InpMousesens, &g_Config.m_InpMousesens, &Button, Localize("Mouse sens."), 200.0f, 5, 500); + pSelf->DoScrollbarOption(&g_Config.m_InpMousesens, &g_Config.m_InpMousesens, &Button, Localize("Mouse sens."), 5, 500); pSelf->UiDoGetButtons(0, 5, View, ButtonHeight, Spaceing); diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index df7812905..14e4457ae 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -958,7 +958,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) GameLeft.HSplitTop(Spacing, 0, &GameLeft); GameLeft.HSplitTop(ButtonHeight, &Button, &GameLeft); Button.VSplitLeft(ButtonHeight, 0, &Button); - DoScrollbarOption(&g_Config.m_ClNameplatesSize, &g_Config.m_ClNameplatesSize, &Button, Localize("Size"), 100.0f, 0, 100); + DoScrollbarOption(&g_Config.m_ClNameplatesSize, &g_Config.m_ClNameplatesSize, &Button, Localize("Size"), 0, 100); GameLeft.HSplitTop(Spacing, 0, &GameLeft); GameLeft.HSplitTop(ButtonHeight, &Button, &GameLeft); @@ -1044,7 +1044,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) Client.HSplitTop(Spacing, 0, &Client); Client.HSplitTop(ButtonHeight, &Button, &Client); Button.VSplitLeft(ButtonHeight, 0, &Button); - DoScrollbarOption(&g_Config.m_ClAutoDemoMax, &g_Config.m_ClAutoDemoMax, &Button, Localize("Max"), 100.0f, 0, 1000, true); + DoScrollbarOption(&g_Config.m_ClAutoDemoMax, &g_Config.m_ClAutoDemoMax, &Button, Localize("Max"), 0, 1000, true); } Client.HSplitTop(Spacing, 0, &Client); @@ -1058,7 +1058,7 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) Client.HSplitTop(Spacing, 0, &Client); Client.HSplitTop(ButtonHeight, &Button, &Client); Button.VSplitLeft(ButtonHeight, 0, &Button); - DoScrollbarOption(&g_Config.m_ClAutoScreenshotMax, &g_Config.m_ClAutoScreenshotMax, &Button, Localize("Max"), 100.0f, 0, 1000, true); + DoScrollbarOption(&g_Config.m_ClAutoScreenshotMax, &g_Config.m_ClAutoScreenshotMax, &Button, Localize("Max"), 0, 1000, true); } MainView.HSplitTop(10.0f, 0, &MainView); @@ -1681,7 +1681,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) ScreenRight.HSplitTop(Spacing, 0, &ScreenRight); ScreenRight.HSplitTop(ButtonHeight, &Button, &ScreenRight); DoScrollbarOption(&g_Config.m_GfxMaxFps, &g_Config.m_GfxMaxFps, - &Button, Localize("Max fps"), 144.0f, 30, 300); + &Button, Localize("Max fps"), 30, 300); } } @@ -1690,7 +1690,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) ScreenRight.HSplitTop(Spacing, 0, &ScreenRight); ScreenRight.HSplitTop(ButtonHeight, &Button, &ScreenRight); int Index = g_Config.m_GfxScreen; - DoScrollbarOption(&g_Config.m_GfxScreen, &Index, &Button, Localize("Screen"), 110.0f, 0, Graphics()->GetNumScreens()-1); + DoScrollbarOption(&g_Config.m_GfxScreen, &Index, &Button, Localize("Screen"), 0, Graphics()->GetNumScreens()-1); if(Index != g_Config.m_GfxScreen) Client()->SwitchWindowScreen(Index); } @@ -1939,7 +1939,7 @@ void CMenus::RenderSettingsSound(CUIRect MainView) } Right.HSplitTop(ButtonHeight, &Button, &Right); - DoScrollbarOption(&g_Config.m_SndVolume, &g_Config.m_SndVolume, &Button, Localize("Volume"), 130.0f, 0, 100); + DoScrollbarOption(&g_Config.m_SndVolume, &g_Config.m_SndVolume, &Button, Localize("Volume"), 0, 100); } else {