2014-03-01 21:02:44 +00:00
|
|
|
#pragma once
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_COMPONENT_LIST_H
|
|
|
|
#define ES_CORE_COMPONENTS_COMPONENT_LIST_H
|
2014-03-01 21:02:44 +00:00
|
|
|
|
|
|
|
#include "IList.h"
|
|
|
|
|
|
|
|
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.
|
2019-08-25 15:23:02 +00:00
|
|
|
// If no input handler is supplied (input_handler == nullptr), the default behavior is to forward the input to
|
2014-03-02 18:36:23 +00:00
|
|
|
// the rightmost element in the currently selected row.
|
2014-03-01 21:02:44 +00:00
|
|
|
std::function<bool(InputConfig*, Input)> input_handler;
|
2019-08-25 15:23:02 +00:00
|
|
|
|
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;
|
2017-10-28 20:24:35 +00:00
|
|
|
void render(const Transform4x4f& 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; }
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2014-03-12 23:24:34 +00:00
|
|
|
float getTotalRowHeight() const;
|
2014-03-23 00:48:48 +00:00
|
|
|
inline float getRowHeight(int row) const { return getRowHeight(mEntries.at(row).data); }
|
2014-03-12 23:24:34 +00:00
|
|
|
|
2014-03-24 22:55:36 +00:00
|
|
|
inline void setCursorChangedCallback(const std::function<void(CursorState state)>& callback) { mCursorChangedCallback = callback; };
|
|
|
|
inline const std::function<void(CursorState state)>& getCursorChangedCallback() const { return mCursorChangedCallback; };
|
|
|
|
|
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-24 22:55:36 +00:00
|
|
|
void updateCameraOffset();
|
2014-03-01 21:02:44 +00:00
|
|
|
void updateElementPosition(const ComponentListRow& row);
|
|
|
|
void updateElementSize(const ComponentListRow& row);
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2014-03-23 00:48:48 +00:00
|
|
|
float getRowHeight(const ComponentListRow& row) const;
|
|
|
|
|
2014-03-01 21:02:44 +00:00
|
|
|
float mSelectorBarOffset;
|
2014-03-02 16:41:02 +00:00
|
|
|
float mCameraOffset;
|
2014-03-24 22:55:36 +00:00
|
|
|
|
|
|
|
std::function<void(CursorState state)> mCursorChangedCallback;
|
2014-03-01 21:02:44 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_COMPONENT_LIST_H
|