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

77 lines
1.8 KiB
C
Raw Normal View History

// SPDX-License-Identifier: MIT
//
// EmulationStation Desktop Edition
// TextEditComponent.h
//
// Component for editing text fields in menus.
//
#ifndef ES_CORE_COMPONENTS_TEXT_EDIT_COMPONENT_H
#define ES_CORE_COMPONENTS_TEXT_EDIT_COMPONENT_H
2013-08-18 14:16:11 +00:00
#include "components/NinePatchComponent.h"
2017-11-01 22:21:10 +00:00
#include "GuiComponent.h"
2013-08-18 14:16:11 +00:00
2013-08-19 15:36:48 +00:00
class Font;
class TextCache;
2013-08-19 15:36:48 +00:00
2014-01-24 22:21:10 +00:00
// Used to enter text.
2013-08-18 14:16:11 +00:00
class TextEditComponent : public GuiComponent
{
public:
TextEditComponent(Window* window);
2020-12-16 22:59:00 +00:00
void textInput(const std::string& text) override;
bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override;
void render(const Transform4x4f& parentTrans) override;
2013-08-18 14:16:11 +00:00
void onFocusGained() override;
void onFocusLost() override;
2013-08-18 14:16:11 +00:00
void onSizeChanged() override;
2013-08-18 14:16:11 +00:00
void setValue(const std::string& val) override;
std::string getValue() const override;
2013-08-19 15:36:48 +00:00
void startEditing();
void stopEditing();
inline bool isEditing() const { return mEditing; };
inline std::shared_ptr<Font> getFont() const override{ return mFont; }
void setCursor(size_t pos);
virtual std::vector<HelpPrompt> getHelpPrompts() override;
2013-08-18 14:16:11 +00:00
private:
void onTextChanged();
void onCursorChanged();
void updateCursorRepeat(int deltaTime);
void moveCursor(int amt);
bool isMultiline();
Vector2f getTextAreaPos() const;
Vector2f getTextAreaSize() const;
std::string mText;
std::string mTextOrig;
bool mFocused;
bool mEditing;
unsigned int mCursor; // Cursor position in characters.
int mCursorRepeatTimer;
int mCursorRepeatDir;
2013-08-19 15:36:48 +00:00
Vector2f mScrollOffset;
2013-08-18 14:16:11 +00:00
NinePatchComponent mBox;
float mResolutionAdjustment;
std::shared_ptr<Font> mFont;
std::unique_ptr<TextCache> mTextCache;
2013-08-18 14:16:11 +00:00
};
#endif // ES_CORE_COMPONENTS_TEXT_EDIT_COMPONENT_H