Make element search scrollable
But this is very buggy, ToolButtons don't lose their hover state when they get scrolled out from under the cursor and the scroll bar ignores clicks if they land on a component under it.
This commit is contained in:
parent
e6e36a6b7c
commit
c3cd4f1691
@ -6,6 +6,7 @@
|
||||
#include <SDL.h>
|
||||
|
||||
#include "gui/interface/Textbox.h"
|
||||
#include "gui/interface/ScrollPanel.h"
|
||||
#include "gui/interface/Label.h"
|
||||
#include "gui/game/Tool.h"
|
||||
#include "gui/game/Menu.h"
|
||||
@ -52,6 +53,9 @@ ElementSearchActivity::ElementSearchActivity(GameController * gameController, st
|
||||
AddComponent(okButton);
|
||||
AddComponent(closeButton);
|
||||
|
||||
scrollPanel = new ui::ScrollPanel(searchField->Position + Vec2{ 1, searchField->Size.Y+9 }, { searchField->Size.X - 2, Size.Y-(searchField->Position.Y+searchField->Size.Y+6)-23 });
|
||||
AddComponent(scrollPanel);
|
||||
|
||||
searchTools("");
|
||||
}
|
||||
|
||||
@ -59,12 +63,12 @@ void ElementSearchActivity::searchTools(String query)
|
||||
{
|
||||
firstResult = NULL;
|
||||
for (auto &toolButton : toolButtons) {
|
||||
RemoveComponent(toolButton);
|
||||
scrollPanel->RemoveChild(toolButton);
|
||||
delete toolButton;
|
||||
}
|
||||
toolButtons.clear();
|
||||
|
||||
ui::Point viewPosition = searchField->Position + ui::Point(2+0, searchField->Size.Y+2+8);
|
||||
ui::Point viewPosition = { 1, 1 };
|
||||
ui::Point current = ui::Point(0, 0);
|
||||
|
||||
String queryLower = query.ToLower();
|
||||
@ -178,7 +182,7 @@ void ElementSearchActivity::searchTools(String query)
|
||||
}
|
||||
|
||||
toolButtons.push_back(tempButton);
|
||||
AddComponent(tempButton);
|
||||
scrollPanel->AddChild(tempButton);
|
||||
|
||||
current.X += 31;
|
||||
|
||||
@ -186,10 +190,9 @@ void ElementSearchActivity::searchTools(String query)
|
||||
current.X = 0;
|
||||
current.Y += 19;
|
||||
}
|
||||
|
||||
if(current.Y + viewPosition.Y + 18 > Size.Y-23)
|
||||
break;
|
||||
}
|
||||
|
||||
scrollPanel->InnerSize = ui::Point(scrollPanel->Size.X, current.Y + 1);
|
||||
}
|
||||
|
||||
void ElementSearchActivity::SetActiveTool(int selectionState, Tool * tool)
|
||||
@ -216,8 +219,7 @@ void ElementSearchActivity::OnDraw()
|
||||
g->DrawRect(RectSized(Position, Size), 0xFFFFFF_rgb);
|
||||
|
||||
g->BlendRect(
|
||||
RectSized(Position + searchField->Position + Vec2{ 0, searchField->Size.Y+8 },
|
||||
{ searchField->Size.X, Size.Y-(searchField->Position.Y+searchField->Size.Y+8)-23 }),
|
||||
RectSized(Position + scrollPanel->Position - Vec2{ 1, 1 }, scrollPanel->Size + Vec2{ 2, 2 }),
|
||||
0xFFFFFF_rgb .WithAlpha(180));
|
||||
if (toolTipPresence && toolTip.length())
|
||||
{
|
||||
|
@ -10,6 +10,7 @@ class GameController;
|
||||
|
||||
namespace ui
|
||||
{
|
||||
class ScrollPanel;
|
||||
class Textbox;
|
||||
}
|
||||
|
||||
@ -20,6 +21,7 @@ class ElementSearchActivity: public WindowActivity
|
||||
std::vector<Tool*> tools;
|
||||
ui::Textbox * searchField;
|
||||
std::vector<ToolButton*> toolButtons;
|
||||
ui::ScrollPanel *scrollPanel = nullptr;
|
||||
String toolTip;
|
||||
int toolTipPresence;
|
||||
bool shiftPressed;
|
||||
|
Loading…
Reference in New Issue
Block a user