mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-02-17 01:31:47 +00:00
idListWindow: Scroll to selected item
from listName_sel_0 that way when setting that state-int and calling StateChanged(), the list is scrolled so the selected item is visible
This commit is contained in:
parent
10dea591a8
commit
8d8f345c25
1 changed files with 21 additions and 11 deletions
|
@ -600,23 +600,33 @@ void idListWindow::UpdateList() {
|
|||
}
|
||||
float vert = GetMaxCharHeight();
|
||||
int fit = textRect.h / vert;
|
||||
int selection = gui->State().GetInt( va( "%s_sel_0", listName.c_str() ) );
|
||||
if ( listItems.Num() < fit ) {
|
||||
scroller->SetRange(0.0f, 0.0f, 1.0f);
|
||||
top = 0;
|
||||
scroller->SetValue(0.0f);
|
||||
} else {
|
||||
scroller->SetRange(0.0f, (listItems.Num() - fit) + 1.0f, 1.0f);
|
||||
|
||||
// DG: scroll to selected item
|
||||
float value = scroller->GetValue();
|
||||
if ( value < 0.0f ) {
|
||||
value = 0.0f;
|
||||
top = 0;
|
||||
} else if ( value > listItems.Num() - 1 ) {
|
||||
value = listItems.Num() - 1;
|
||||
}
|
||||
float maxVisibleVal = Min(value + fit, scroller->GetHigh());
|
||||
if ( selection >= 0 && (selection < value || selection > maxVisibleVal) ) {
|
||||
// if selected entry is not currently visible, center it (if possible)
|
||||
value = Max(0.0f, selection - 0.5f * fit);
|
||||
}
|
||||
|
||||
scroller->SetValue(value);
|
||||
top = value;
|
||||
}
|
||||
|
||||
SetCurrentSel( gui->State().GetInt( va( "%s_sel_0", listName.c_str() ) ) );
|
||||
|
||||
float value = scroller->GetValue();
|
||||
if ( value > listItems.Num() - 1 ) {
|
||||
value = listItems.Num() - 1;
|
||||
}
|
||||
if ( value < 0.0f ) {
|
||||
value = 0.0f;
|
||||
}
|
||||
scroller->SetValue(value);
|
||||
top = value;
|
||||
SetCurrentSel( selection );
|
||||
|
||||
typedTime = 0;
|
||||
clickTime = 0;
|
||||
|
|
Loading…
Reference in a new issue