2013-08-18 14:16:11 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../GuiComponent.h"
|
2013-09-14 15:58:34 +00:00
|
|
|
#include "NinePatchComponent.h"
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2013-08-19 15:36:48 +00:00
|
|
|
class Font;
|
2013-08-22 01:08:36 +00:00
|
|
|
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);
|
2013-08-22 01:08:36 +00:00
|
|
|
|
2013-08-19 15:36:48 +00:00
|
|
|
void textInput(const char* text) override;
|
2013-09-07 22:43:36 +00:00
|
|
|
bool input(InputConfig* config, Input input) override;
|
2014-03-21 02:47:45 +00:00
|
|
|
void update(int deltaTime) override;
|
2013-08-19 15:36:48 +00:00
|
|
|
void render(const Eigen::Affine3f& parentTrans) override;
|
2013-08-18 14:16:11 +00:00
|
|
|
|
|
|
|
void onFocusGained() override;
|
|
|
|
void onFocusLost() override;
|
|
|
|
|
|
|
|
void onSizeChanged() override;
|
|
|
|
|
|
|
|
void setValue(const std::string& val) override;
|
|
|
|
std::string getValue() const override;
|
2013-08-19 15:36:48 +00:00
|
|
|
|
2014-03-21 02:47:45 +00:00
|
|
|
inline bool isEditing() const { return mEditing; };
|
2014-03-21 16:10:19 +00:00
|
|
|
inline const std::shared_ptr<Font>& getFont() const { return mFont; }
|
2013-09-20 23:55:05 +00:00
|
|
|
|
2014-06-15 17:55:30 +00:00
|
|
|
void setCursor(size_t pos);
|
|
|
|
|
2014-01-25 23:34:29 +00:00
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
|
|
|
|
2013-08-18 14:16:11 +00:00
|
|
|
private:
|
2014-03-21 02:47:45 +00:00
|
|
|
void startEditing();
|
|
|
|
void stopEditing();
|
|
|
|
|
2013-08-21 19:49:33 +00:00
|
|
|
void onTextChanged();
|
2013-09-07 22:43:36 +00:00
|
|
|
void onCursorChanged();
|
2013-08-21 19:49:33 +00:00
|
|
|
|
2014-03-21 02:47:45 +00:00
|
|
|
void updateCursorRepeat(int deltaTime);
|
|
|
|
void moveCursor(int amt);
|
|
|
|
|
2013-09-12 21:35:44 +00:00
|
|
|
bool isMultiline();
|
2014-03-21 02:47:45 +00:00
|
|
|
Eigen::Vector2f getTextAreaPos() const;
|
|
|
|
Eigen::Vector2f getTextAreaSize() const;
|
2013-09-12 21:35:44 +00:00
|
|
|
|
2013-08-18 14:16:11 +00:00
|
|
|
std::string mText;
|
2013-08-19 15:36:48 +00:00
|
|
|
bool mFocused;
|
2013-09-07 22:43:36 +00:00
|
|
|
bool mEditing;
|
2014-03-21 02:47:45 +00:00
|
|
|
int mCursor; // cursor position in characters
|
|
|
|
|
|
|
|
int mCursorRepeatTimer;
|
|
|
|
int mCursorRepeatDir;
|
2013-08-19 15:36:48 +00:00
|
|
|
|
2014-03-21 02:47:45 +00:00
|
|
|
Eigen::Vector2f mScrollOffset;
|
2013-08-18 14:16:11 +00:00
|
|
|
|
2013-09-14 15:58:34 +00:00
|
|
|
NinePatchComponent mBox;
|
2013-08-22 01:08:36 +00:00
|
|
|
|
2014-03-21 02:47:45 +00:00
|
|
|
std::shared_ptr<Font> mFont;
|
2013-08-22 01:08:36 +00:00
|
|
|
std::unique_ptr<TextCache> mTextCache;
|
2013-08-18 14:16:11 +00:00
|
|
|
};
|