ES-DE/es-core/src/components/MenuComponent.h

100 lines
3.1 KiB
C
Raw Normal View History

// SPDX-License-Identifier: MIT
//
// EmulationStation Desktop Edition
// MenuComponent.h
//
// Basic component for building a menu.
//
#ifndef ES_CORE_COMPONENTS_MENU_COMPONENT_H
#define ES_CORE_COMPONENTS_MENU_COMPONENT_H
2017-11-01 22:21:10 +00:00
#include "components/ComponentGrid.h"
#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"
#include "components/TextComponent.h"
#include "utils/StringUtil.h"
#include <cmath>
class ButtonComponent;
2014-03-22 21:02:25 +00:00
class ImageComponent;
std::shared_ptr<ComponentGrid> makeButtonGrid(
const std::vector<std::shared_ptr<ButtonComponent>>& buttons);
std::shared_ptr<ImageComponent> makeArrow();
2014-03-15 17:18:50 +00:00
class MenuComponent : public GuiComponent
{
public:
MenuComponent(std::string title,
const std::shared_ptr<Font>& titleFont = Font::get(FONT_SIZE_LARGE));
virtual ~MenuComponent();
void save();
void onSizeChanged() override;
void setNeedsSaving() { mNeedsSaving = true; }
2020-11-05 17:18:11 +00:00
void addRow(const ComponentListRow& row, bool setCursorHere = false, bool updateRowSize = true)
{
mList->addRow(row, setCursorHere);
if (updateRowSize)
updateSize();
}
void addWithLabel(const std::string& label,
const std::shared_ptr<GuiComponent>& comp,
bool setCursorHere = false,
bool invert_when_selected = true)
{
ComponentListRow row;
row.addElement(std::make_shared<TextComponent>(Utils::String::toUpper(label),
Font::get(FONT_SIZE_MEDIUM), 0x777777FF),
true);
row.addElement(comp, false, invert_when_selected);
addRow(row, setCursorHere);
}
2014-03-08 18:19:21 +00:00
void addSaveFunc(const std::function<void()>& func) { mSaveFuncs.push_back(func); }
void addButton(const std::string& label,
const std::string& helpText,
const std::function<void()>& callback);
void setTitle(std::string title, const std::shared_ptr<Font>& font);
std::shared_ptr<ComponentList> getList() { return mList; }
void setCursorToFirstListEntry() { mList->moveCursor(-mList->getCursorId()); }
void setCursorToList() { mGrid.setCursorTo(mList); }
void setCursorToButtons()
{
assert(mButtonGrid);
mGrid.setCursorTo(mButtonGrid);
}
std::vector<HelpPrompt> getHelpPrompts() override { return mGrid.getHelpPrompts(); }
private:
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;
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;
};
#endif // ES_CORE_COMPONENTS_MENU_COMPONENT_H