2014-03-01 21:02:44 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "IList.h"
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
struct ComponentListElement
|
|
|
|
{
|
2014-03-21 19:51:25 +00:00
|
|
|
ComponentListElement(const std::shared_ptr<GuiComponent>& cmp = nullptr, bool resize_w = true, bool inv = true)
|
|
|
|
: component(cmp), resize_width(resize_w), invert_when_selected(inv) { };
|
2014-03-01 21:02:44 +00:00
|
|
|
|
|
|
|
std::shared_ptr<GuiComponent> component;
|
|
|
|
bool resize_width;
|
2014-03-21 19:51:25 +00:00
|
|
|
bool invert_when_selected;
|
2014-03-01 21:02:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ComponentListRow
|
|
|
|
{
|
|
|
|
std::vector<ComponentListElement> elements;
|
2014-03-02 18:36:23 +00:00
|
|
|
|
|
|
|
// The input handler is called when the user enters any input while this row is highlighted (including up/down).
|
|
|
|
// Return false to let the list try to use it or true if the input has been consumed.
|
|
|
|
// If no input handler is supplied (input_handler == nullptr), the default behavior is to forward the input to
|
|
|
|
// the rightmost element in the currently selected row.
|
2014-03-01 21:02:44 +00:00
|
|
|
std::function<bool(InputConfig*, Input)> input_handler;
|
|
|
|
|
2014-03-21 19:51:25 +00:00
|
|
|
inline void addElement(const std::shared_ptr<GuiComponent>& component, bool resize_width, bool invert_when_selected = true)
|
2014-03-01 21:02:44 +00:00
|
|
|
{
|
2014-03-21 19:51:25 +00:00
|
|
|
elements.push_back(ComponentListElement(component, resize_width, invert_when_selected));
|
2014-03-01 21:02:44 +00:00
|
|
|
}
|
2014-03-02 18:36:23 +00:00
|
|
|
|
|
|
|
// Utility method for making an input handler for "when the users presses A on this, do func."
|
|
|
|
inline void makeAcceptInputHandler(const std::function<void()>& func)
|
|
|
|
{
|
|
|
|
input_handler = [func](InputConfig* config, Input input) -> bool {
|
|
|
|
if(config->isMappedTo("a", input) && input.value != 0)
|
|
|
|
{
|
|
|
|
func();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
2014-03-01 21:02:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ComponentList : public IList<ComponentListRow, void*>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ComponentList(Window* window);
|
|
|
|
|
2014-03-06 19:45:03 +00:00
|
|
|
void addRow(const ComponentListRow& row, bool setCursorHere = false);
|
2014-03-01 21:02:44 +00:00
|
|
|
|
2014-03-21 02:47:45 +00:00
|
|
|
void textInput(const char* text) override;
|
2014-03-01 21:02:44 +00:00
|
|
|
bool input(InputConfig* config, Input input) override;
|
|
|
|
void update(int deltaTime) override;
|
|
|
|
void render(const Eigen::Affine3f& parentTrans) override;
|
2014-03-13 19:09:50 +00:00
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
2014-03-01 21:02:44 +00:00
|
|
|
|
|
|
|
void onSizeChanged() override;
|
2014-03-12 03:00:08 +00:00
|
|
|
void onFocusGained() override;
|
|
|
|
void onFocusLost() override;
|
|
|
|
|
2014-03-22 01:12:57 +00:00
|
|
|
bool moveCursor(int amt);
|
2014-03-12 03:00:08 +00:00
|
|
|
inline int getCursorId() const { return mCursor; }
|
2014-03-22 01:38:16 +00:00
|
|
|
|
2014-03-12 23:24:34 +00:00
|
|
|
float getTotalRowHeight() const;
|
|
|
|
|
2014-03-01 21:02:44 +00:00
|
|
|
protected:
|
|
|
|
void onCursorChanged(const CursorState& state) override;
|
|
|
|
|
|
|
|
private:
|
2014-03-12 03:00:08 +00:00
|
|
|
bool mFocused;
|
|
|
|
|
2014-03-01 21:02:44 +00:00
|
|
|
void updateElementPosition(const ComponentListRow& row);
|
|
|
|
void updateElementSize(const ComponentListRow& row);
|
|
|
|
|
2014-03-02 16:41:02 +00:00
|
|
|
float getRowHeight(const ComponentListRow& row) const;
|
2014-03-12 23:24:34 +00:00
|
|
|
|
2014-03-01 21:02:44 +00:00
|
|
|
float mSelectorBarOffset;
|
2014-03-02 16:41:02 +00:00
|
|
|
float mCameraOffset;
|
2014-03-01 21:02:44 +00:00
|
|
|
};
|