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

61 lines
1.6 KiB
C
Raw Normal View History

// SPDX-License-Identifier: MIT
//
// EmulationStation Desktop Edition
// ButtonComponent.h
//
// Basic on/off button.
//
#ifndef ES_CORE_COMPONENTS_BUTTON_COMPONENT_H
#define ES_CORE_COMPONENTS_BUTTON_COMPONENT_H
2013-08-22 20:29:50 +00:00
2017-11-01 22:21:10 +00:00
#include "GuiComponent.h"
#include "components/NinePatchComponent.h"
2017-11-01 22:21:10 +00:00
class TextCache;
2013-08-22 20:29:50 +00:00
class ButtonComponent : public GuiComponent
{
public:
ButtonComponent(Window* window,
const std::string& text = "",
const std::string& helpText = "",
const std::function<void()>& func = nullptr);
2013-08-22 20:29:50 +00:00
void setPressedFunc(std::function<void()> f) { mPressedFunc = f; }
void setEnabled(bool state) override;
bool input(InputConfig* config, Input input) override;
void render(const Transform4x4f& parentTrans) override;
2013-08-22 20:29:50 +00:00
void setText(const std::string& text, const std::string& helpText);
const std::string& getText() const { return mText; }
const std::function<void()>& getPressedFunc() const { return mPressedFunc; }
void onSizeChanged() override;
void onFocusGained() override;
void onFocusLost() override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;
2013-08-22 20:29:50 +00:00
private:
std::shared_ptr<Font> mFont;
std::function<void()> mPressedFunc;
2013-08-22 20:29:50 +00:00
bool mFocused;
bool mEnabled;
unsigned int mTextColorFocused;
unsigned int mTextColorUnfocused;
unsigned int getCurTextColor() const;
void updateImage();
std::string mText;
std::string mHelpText;
std::unique_ptr<TextCache> mTextCache;
NinePatchComponent mBox;
2013-08-22 20:29:50 +00:00
};
#endif // ES_CORE_COMPONENTS_BUTTON_COMPONENT_H