// SPDX-License-Identifier: MIT // // ES-DE // MenuComponent.h // // Basic component for building a menu. // #ifndef ES_CORE_COMPONENTS_MENU_COMPONENT_H #define ES_CORE_COMPONENTS_MENU_COMPONENT_H #include "components/ButtonComponent.h" #include "components/ComponentGrid.h" #include "components/ComponentList.h" #include "components/ImageComponent.h" #include "components/NinePatchComponent.h" #include "components/ScrollIndicatorComponent.h" #include "components/TextComponent.h" #include "utils/StringUtil.h" #include class MenuComponent : public GuiComponent { public: MenuComponent(std::string title, const std::shared_ptr& titleFont = Font::get(FONT_SIZE_LARGE)); virtual ~MenuComponent(); void save(); void onSizeChanged() override; void setNeedsSaving() { mNeedsSaving = true; } 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& comp, bool setCursorHere = false, bool invert_when_selected = true) { ComponentListRow row; row.addElement(std::make_shared(Utils::String::toUpper(label), Font::get(FONT_SIZE_MEDIUM), mMenuColorPrimary), true); row.addElement(comp, false, invert_when_selected); addRow(row, setCursorHere); } void addSaveFunc(const std::function& func) { mSaveFuncs.push_back(func); } void addButton(const std::string& label, const std::string& helpText, const std::function& callback); static std::shared_ptr makeButtonGrid( const std::vector>& buttons); std::shared_ptr makeArrow(); void setTitle(std::string title, const std::shared_ptr& font); std::shared_ptr getList() { return mList; } void setCursorToFirstListEntry() { mList->moveCursor(-mList->getCursorId()); } void setCursorToList() { mGrid.setCursorTo(mList); } void setCursorToButtons() { assert(mButtonGrid); mGrid.setCursorTo(mButtonGrid); } std::vector getHelpPrompts() override { return mGrid.getHelpPrompts(); } private: void updateSize(); void updateGrid(); float getButtonGridHeight() const; Renderer* mRenderer; NinePatchComponent mBackground; ComponentGrid mGrid; std::shared_ptr mTitle; std::shared_ptr mScrollUp; std::shared_ptr mScrollDown; std::shared_ptr mScrollIndicator; std::shared_ptr mList; std::shared_ptr mButtonGrid; std::vector> mButtons; std::vector> mSaveFuncs; bool mNeedsSaving; }; #endif // ES_CORE_COMPONENTS_MENU_COMPONENT_H