2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// MenuComponent.h
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
2020-06-21 12:25:28 +00:00
|
|
|
// Basic component for building a menu.
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_MENU_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_MENU_COMPONENT_H
|
2014-03-01 21:02:44 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "components/ComponentGrid.h"
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "components/ComponentList.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "components/NinePatchComponent.h"
|
2021-10-10 16:15:37 +00:00
|
|
|
#include "components/ScrollIndicatorComponent.h"
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "components/TextComponent.h"
|
2018-01-27 17:04:28 +00:00
|
|
|
#include "utils/StringUtil.h"
|
2014-03-12 03:00:08 +00:00
|
|
|
|
2020-12-28 22:23:01 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2014-03-12 03:00:08 +00:00
|
|
|
class ButtonComponent;
|
2014-03-22 21:02:25 +00:00
|
|
|
class ImageComponent;
|
2014-03-01 21:02:44 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
std::shared_ptr<ComponentGrid> makeButtonGrid(
|
2022-01-19 17:01:54 +00:00
|
|
|
const std::vector<std::shared_ptr<ButtonComponent>>& buttons);
|
|
|
|
std::shared_ptr<ImageComponent> makeArrow();
|
2014-03-15 17:18:50 +00:00
|
|
|
|
2014-03-01 21:02:44 +00:00
|
|
|
class MenuComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2022-01-19 17:01:54 +00:00
|
|
|
MenuComponent(std::string title,
|
2021-07-07 18:31:46 +00:00
|
|
|
const std::shared_ptr<Font>& titleFont = Font::get(FONT_SIZE_LARGE));
|
2021-05-23 08:40:11 +00:00
|
|
|
virtual ~MenuComponent();
|
2014-03-01 21:02:44 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
void save();
|
|
|
|
void onSizeChanged() override;
|
2014-03-01 21:02:44 +00:00
|
|
|
|
2021-01-17 11:21:33 +00:00
|
|
|
void setNeedsSaving() { mNeedsSaving = true; }
|
2020-11-05 17:18:11 +00:00
|
|
|
|
2021-09-25 17:22:59 +00:00
|
|
|
void addRow(const ComponentListRow& row, bool setCursorHere = false, bool updateRowSize = true)
|
2021-07-07 18:31:46 +00:00
|
|
|
{
|
|
|
|
mList->addRow(row, setCursorHere);
|
2021-09-25 17:22:59 +00:00
|
|
|
if (updateRowSize)
|
|
|
|
updateSize();
|
2021-07-07 18:31:46 +00:00
|
|
|
}
|
2014-03-01 21:02:44 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void addWithLabel(const std::string& label,
|
|
|
|
const std::shared_ptr<GuiComponent>& comp,
|
|
|
|
bool setCursorHere = false,
|
|
|
|
bool invert_when_selected = true)
|
2020-06-21 12:25:28 +00:00
|
|
|
{
|
|
|
|
ComponentListRow row;
|
2022-01-19 17:01:54 +00:00
|
|
|
row.addElement(std::make_shared<TextComponent>(Utils::String::toUpper(label),
|
2021-07-07 18:31:46 +00:00
|
|
|
Font::get(FONT_SIZE_MEDIUM), 0x777777FF),
|
|
|
|
true);
|
2020-06-21 12:25:28 +00:00
|
|
|
row.addElement(comp, false, invert_when_selected);
|
|
|
|
addRow(row, setCursorHere);
|
|
|
|
}
|
2014-03-08 18:19:21 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void addSaveFunc(const std::function<void()>& func) { mSaveFuncs.push_back(func); }
|
2020-06-06 11:10:33 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void addButton(const std::string& label,
|
|
|
|
const std::string& helpText,
|
|
|
|
const std::function<void()>& callback);
|
2014-03-12 03:00:08 +00:00
|
|
|
|
2020-11-06 19:27:41 +00:00
|
|
|
void setTitle(std::string title, const std::shared_ptr<Font>& font);
|
2021-09-25 08:47:59 +00:00
|
|
|
std::shared_ptr<ComponentList> getList() { return mList; }
|
2014-04-19 19:15:44 +00:00
|
|
|
|
2021-01-17 11:21:33 +00:00
|
|
|
void setCursorToFirstListEntry() { mList->moveCursor(-mList->getCursorId()); }
|
2021-07-07 18:31:46 +00:00
|
|
|
void setCursorToList() { mGrid.setCursorTo(mList); }
|
|
|
|
void setCursorToButtons()
|
|
|
|
{
|
|
|
|
assert(mButtonGrid);
|
|
|
|
mGrid.setCursorTo(mButtonGrid);
|
|
|
|
}
|
2014-03-12 03:00:08 +00:00
|
|
|
|
2022-01-18 16:40:47 +00:00
|
|
|
std::vector<HelpPrompt> getHelpPrompts() override { return mGrid.getHelpPrompts(); }
|
2014-03-13 19:09:50 +00:00
|
|
|
|
2014-03-01 21:02:44 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
void updateSize();
|
|
|
|
void updateGrid();
|
|
|
|
float getButtonGridHeight() const;
|
|
|
|
|
|
|
|
NinePatchComponent mBackground;
|
|
|
|
ComponentGrid mGrid;
|
|
|
|
|
|
|
|
std::shared_ptr<TextComponent> mTitle;
|
2021-10-10 16:15:37 +00:00
|
|
|
std::shared_ptr<ImageComponent> mScrollUp;
|
|
|
|
std::shared_ptr<ImageComponent> mScrollDown;
|
|
|
|
std::shared_ptr<ScrollIndicatorComponent> mScrollIndicator;
|
2020-06-21 12:25:28 +00:00
|
|
|
std::shared_ptr<ComponentList> mList;
|
|
|
|
std::shared_ptr<ComponentGrid> mButtonGrid;
|
2020-11-05 17:18:11 +00:00
|
|
|
std::vector<std::shared_ptr<ButtonComponent>> mButtons;
|
|
|
|
std::vector<std::function<void()>> mSaveFuncs;
|
|
|
|
|
|
|
|
bool mNeedsSaving;
|
2014-03-01 21:02:44 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_MENU_COMPONENT_H
|