Skip to content

Commit

Permalink
Make element search scrollable
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LBPHacker committed Feb 6, 2024
1 parent e6e36a6 commit c3cd4f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/gui/elementsearch/ElementSearchActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -52,19 +53,22 @@ 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("");
}

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();
Expand Down Expand Up @@ -178,18 +182,17 @@ void ElementSearchActivity::searchTools(String query)
}

toolButtons.push_back(tempButton);
AddComponent(tempButton);
scrollPanel->AddChild(tempButton);

current.X += 31;

if(current.X + 30 > searchField->Size.X) {
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)
Expand All @@ -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())
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/elementsearch/ElementSearchActivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class GameController;

namespace ui
{
class ScrollPanel;
class Textbox;
}

Expand All @@ -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;
Expand Down

0 comments on commit c3cd4f1

Please sign in to comment.