mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 06:58:20 +00:00
fixed auto-scrolling in server browser and listbox
This commit is contained in:
parent
68851630ca
commit
2f388139c1
|
@ -166,14 +166,22 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
|
|||
if(NewIndex > -1 && NewIndex < NumServers)
|
||||
{
|
||||
//scroll
|
||||
if(ScrollNum)
|
||||
{
|
||||
if(NewIndex - m_SelectedIndex > 0)
|
||||
s_ScrollValue += 1.0f/ScrollNum;
|
||||
else
|
||||
s_ScrollValue -= 1.0f/ScrollNum;
|
||||
}
|
||||
|
||||
float IndexY = View.y - s_ScrollValue*ScrollNum*s_aCols[0].m_Rect.h + NewIndex*s_aCols[0].m_Rect.h;
|
||||
int Scroll = View.y > IndexY ? -1 : View.y+View.h < IndexY+s_aCols[0].m_Rect.h ? 1 : 0;
|
||||
if(Scroll)
|
||||
{
|
||||
if(Scroll < 0)
|
||||
{
|
||||
int NumScrolls = (View.y-IndexY+s_aCols[0].m_Rect.h-1.0f)/s_aCols[0].m_Rect.h;
|
||||
s_ScrollValue -= (1.0f/ScrollNum)*NumScrolls;
|
||||
}
|
||||
else
|
||||
{
|
||||
int NumScrolls = (IndexY+s_aCols[0].m_Rect.h-(View.y+View.h)+s_aCols[0].m_Rect.h-1.0f)/s_aCols[0].m_Rect.h;
|
||||
s_ScrollValue += (1.0f/ScrollNum)*NumScrolls;
|
||||
}
|
||||
}
|
||||
|
||||
m_SelectedIndex = NewIndex;
|
||||
|
||||
const CServerInfo *pItem = ServerBrowser()->SortedGet(m_SelectedIndex);
|
||||
|
|
|
@ -370,15 +370,24 @@ CMenus::CListboxItem CMenus::UiDoListboxNextItem(void *pId, bool Selected)
|
|||
if(NewIndex > -1 && NewIndex < gs_ListBoxNumItems)
|
||||
{
|
||||
// scroll
|
||||
int NumViewable = (int)(gs_ListBoxOriginalView.h/gs_ListBoxRowHeight) + 1;
|
||||
int ScrollNum = (gs_ListBoxNumItems+gs_ListBoxItemsPerRow-1)/gs_ListBoxItemsPerRow-NumViewable+1;
|
||||
if(ScrollNum > 0 && NewIndex/gs_ListBoxItemsPerRow-gs_ListBoxSelectedIndex/gs_ListBoxItemsPerRow)
|
||||
float Offset = (NewIndex-gs_ListBoxNewSelected)*gs_ListBoxRowHeight;
|
||||
int Scroll = gs_ListBoxOriginalView.y > Item.m_Rect.y+Offset ? -1 :
|
||||
gs_ListBoxOriginalView.y+gs_ListBoxOriginalView.h < Item.m_Rect.y+Item.m_Rect.h+Offset ? 1 : 0;
|
||||
if(Scroll)
|
||||
{
|
||||
// TODO: make the scrolling better
|
||||
if(NewIndex - gs_ListBoxSelectedIndex > 0)
|
||||
gs_ListBoxScrollValue += 1.0f/ScrollNum;
|
||||
int NumViewable = (int)(gs_ListBoxOriginalView.h/gs_ListBoxRowHeight) + 1;
|
||||
int ScrollNum = (gs_ListBoxNumItems+gs_ListBoxItemsPerRow-1)/gs_ListBoxItemsPerRow-NumViewable+1;
|
||||
if(Scroll < 0)
|
||||
{
|
||||
int Num = (gs_ListBoxOriginalView.y-Item.m_Rect.y-Offset+gs_ListBoxRowHeight-1.0f)/(gs_ListBoxItemsPerRow*gs_ListBoxRowHeight);
|
||||
gs_ListBoxScrollValue -= (1.0f/ScrollNum)*Num;
|
||||
}
|
||||
else
|
||||
gs_ListBoxScrollValue -= 1.0f/ScrollNum;
|
||||
{
|
||||
int Num = (Item.m_Rect.y+Item.m_Rect.h+Offset-(gs_ListBoxOriginalView.y+gs_ListBoxOriginalView.h)+gs_ListBoxRowHeight-1.0f)/
|
||||
(gs_ListBoxItemsPerRow*gs_ListBoxRowHeight);
|
||||
gs_ListBoxScrollValue += (1.0f/ScrollNum)*Num;
|
||||
}
|
||||
if(gs_ListBoxScrollValue < 0.0f) gs_ListBoxScrollValue = 0.0f;
|
||||
if(gs_ListBoxScrollValue > 1.0f) gs_ListBoxScrollValue = 1.0f;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue