mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-03-21 18:31:10 +00:00
Remember last selected item
This commit is contained in:
parent
ab07343985
commit
8ad15de138
3 changed files with 19 additions and 6 deletions
|
@ -14,6 +14,7 @@ public:
|
|||
|
||||
void AddItem(const std::string& text);
|
||||
int GetSelectedItem() const { return selectedItem; }
|
||||
void SetSelectedItem(int index);
|
||||
void ScrollToItem(int index);
|
||||
|
||||
void Activate();
|
||||
|
|
|
@ -22,6 +22,15 @@ void ListView::Activate()
|
|||
OnActivated();
|
||||
}
|
||||
|
||||
void ListView::SetSelectedItem(int index)
|
||||
{
|
||||
if (selectedItem != index && index >= 0 && index < items.size())
|
||||
{
|
||||
selectedItem = index;
|
||||
Update();
|
||||
}
|
||||
}
|
||||
|
||||
void ListView::ScrollToItem(int index)
|
||||
{
|
||||
double itemHeight = 20.0;
|
||||
|
@ -95,8 +104,7 @@ void ListView::OnMouseDown(const Point& pos, int key)
|
|||
int index = (int)((pos.y - 5.0 + scrollbar->GetPosition()) / 20.0);
|
||||
if (index >= 0 && (size_t)index < items.size())
|
||||
{
|
||||
selectedItem = index;
|
||||
Update();
|
||||
SetSelectedItem(index);
|
||||
ScrollToItem(selectedItem);
|
||||
}
|
||||
}
|
||||
|
@ -128,8 +136,7 @@ void ListView::OnKeyDown(EInputKey key)
|
|||
{
|
||||
if (selectedItem + 1 < (int)items.size())
|
||||
{
|
||||
selectedItem++;
|
||||
Update();
|
||||
SetSelectedItem(selectedItem + 1);
|
||||
}
|
||||
ScrollToItem(selectedItem);
|
||||
}
|
||||
|
@ -137,8 +144,7 @@ void ListView::OnKeyDown(EInputKey key)
|
|||
{
|
||||
if (selectedItem > 0)
|
||||
{
|
||||
selectedItem--;
|
||||
Update();
|
||||
SetSelectedItem(selectedItem - 1);
|
||||
}
|
||||
ScrollToItem(selectedItem);
|
||||
}
|
||||
|
|
|
@ -139,6 +139,12 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int
|
|||
GamesList->AddItem(work.GetChars());
|
||||
}
|
||||
|
||||
if (defaultiwad >= 0 && defaultiwad < numwads)
|
||||
{
|
||||
GamesList->SetSelectedItem(defaultiwad);
|
||||
GamesList->ScrollToItem(defaultiwad);
|
||||
}
|
||||
|
||||
Logo->SetImage(Image::LoadResource("widgets/banner.png"));
|
||||
|
||||
GamesList->SetFocus();
|
||||
|
|
Loading…
Reference in a new issue