Fixed TextListComponent scrolling so text always clips within margins.

Made all gamelists get recreated when GuiScraperMulti closes since there isn't a way to catch FileData changes efficiently yet.
This commit is contained in:
Aloshi 2014-05-03 16:19:28 -05:00
parent e2458f5d92
commit b2193c3bf5
4 changed files with 24 additions and 14 deletions

View file

@ -130,12 +130,9 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
std::shared_ptr<Font>& font = mFont;
if(size() == 0)
{
return;
}
const int cutoff = 0;
const int entrySize = (int)font->getHeight() + 5;
const float entrySize = font->getHeight() + 5;
int startEntry = 0;
@ -144,32 +141,34 @@ void TextListComponent<T>::render(const Eigen::Affine3f& parentTrans)
if(size() >= screenCount)
{
startEntry = mCursor - (int)(screenCount * 0.5);
startEntry = mCursor - screenCount/2;
if(startEntry < 0)
startEntry = 0;
if(startEntry >= size() - screenCount)
startEntry = size() - screenCount;
}
float y = (float)cutoff;
float y = 0;
int listCutoff = startEntry + screenCount;
if(listCutoff > size())
listCutoff = size();
// draw selector bar
if(startEntry < listCutoff)
{
Renderer::setMatrix(trans);
Renderer::drawRect(0.f, (mCursor - startEntry)*entrySize, mSize.x(), font->getHeight(), mSelectorColor);
}
// clip to inside margins
Eigen::Vector3f dim(mSize.x(), mSize.y(), 0);
dim = trans * dim - trans.translation();
Renderer::pushClipRect(Eigen::Vector2i((int)trans.translation().x(), (int)trans.translation().y()), Eigen::Vector2i((int)dim.x(), (int)dim.y()));
Renderer::pushClipRect(Eigen::Vector2i((int)(trans.translation().x() + mHorizontalMargin), (int)trans.translation().y()),
Eigen::Vector2i((int)(dim.x() - mHorizontalMargin*2), (int)dim.y()));
for(int i = startEntry; i < listCutoff; i++)
{
//draw selector bar
if(mCursor == i)
{
Renderer::setMatrix(trans);
Renderer::drawRect(0, (int)y, (int)mSize.x(), (int)font->getHeight(), mSelectorColor);
}
typename IList<TextListData, T>::Entry& entry = mEntries.at((unsigned int)i);
unsigned int color;
@ -276,6 +275,7 @@ void TextListComponent<T>::update(int deltaTime)
Eigen::Vector2f textSize = mFont->sizeText(text);
//it's long enough to marquee
mMarqueeTime += deltaTime;
if(textSize.x() - mMarqueeOffset > mSize.x() - 12 - (mAlignment != ALIGN_CENTER ? mHorizontalMargin : 0))
{
mMarqueeTime += deltaTime;

View file

@ -1,6 +1,7 @@
#include "GuiScraperMulti.h"
#include "../Renderer.h"
#include "../Log.h"
#include "../views/ViewController.h"
#include "../components/TextComponent.h"
#include "../components/ButtonComponent.h"
@ -67,6 +68,13 @@ GuiScraperMulti::GuiScraperMulti(Window* window, const std::queue<ScraperSearchP
doNextSearch();
}
GuiScraperMulti::~GuiScraperMulti()
{
// view type probably changed (basic -> detailed)
for(auto it = SystemData::sSystemVector.begin(); it != SystemData::sSystemVector.end(); it++)
mWindow->getViewController()->reloadGameListView(*it, false);
}
void GuiScraperMulti::onSizeChanged()
{
mBackground.fitTo(mSize, Vector3f::Zero(), Vector2f(-32, -32));

View file

@ -14,6 +14,7 @@ class GuiScraperMulti : public GuiComponent
{
public:
GuiScraperMulti(Window* window, const std::queue<ScraperSearchParams>& searches, bool approveResults);
virtual ~GuiScraperMulti();
void onSizeChanged() override;
std::vector<HelpPrompt> getHelpPrompts() override;

View file

@ -18,6 +18,7 @@ public:
// If a basic view detected a metadata change, it can request to recreate
// the current gamelist view (as it may change to be detailed).
void reloadGameListView(IGameListView* gamelist, bool reloadTheme = false);
inline void reloadGameListView(SystemData* system, bool reloadTheme = false) { reloadGameListView(getGameListView(system).get(), reloadTheme); }
void reloadAll(); // Reload everything with a theme. Used when the "ThemeSet" setting changes.
// Navigation.