Polyphase Game Engine
Loading...
Searching...
No Matches
InputField.h
Go to the documentation of this file.
1#pragma once
2
4
5class Texture;
6class Quad;
7class Text;
8
10{
11public:
12
14
15 virtual void Create() override;
16 virtual void GatherProperties(std::vector<Property>& props) override;
17 void GatherInputFieldProperties(std::vector<Property>& props);
18 virtual void Tick(float deltaTime) override;
19 virtual void EditorTick(float deltaTime) override;
20 virtual void PreRender() override;
21
22 // Text manipulation
23 void SetText(const std::string& text);
24 const std::string& GetText() const;
25 void SetPlaceholder(const std::string& placeholder);
26 const std::string& GetPlaceholder() const;
27
28 // Caret/selection
29 void SetCaretPosition(int32_t pos);
30 int32_t GetCaretPosition() const;
31 void SelectAll();
32 void ClearSelection();
33 bool HasSelection() const;
34 std::string GetSelectedText() const;
35 void DeleteSelection();
36 void Select(int32_t start, int32_t end);
37 int32_t GetSelectionStart() const;
38 int32_t GetSelectionEnd() const;
39
40 // Focus
41 void SetFocused(bool focused);
42 bool IsFocused() const;
43
44 // Options
45 void SetPasswordMode(bool enabled);
46 bool IsPasswordMode() const;
47 void SetMaxLength(int32_t maxLen);
48 int32_t GetMaxLength() const;
49 void SetEditable(bool editable);
50 bool IsEditable() const;
51
52 // Visual
53 void SetBackgroundTexture(Texture* texture);
54 Texture* GetBackgroundTexture();
55 void SetBackgroundColor(glm::vec4 color);
56 glm::vec4 GetBackgroundColor();
57 void SetFocusedBackgroundColor(glm::vec4 color);
58 glm::vec4 GetFocusedBackgroundColor();
59 void SetTextColor(glm::vec4 color);
60 glm::vec4 GetTextColor();
61 void SetPlaceholderColor(glm::vec4 color);
62 glm::vec4 GetPlaceholderColor();
63 void SetCaretColor(glm::vec4 color);
64 glm::vec4 GetCaretColor();
65 void SetSelectionColor(glm::vec4 color);
66 glm::vec4 GetSelectionColor();
67 void SetTextPadding(float padding);
68 float GetTextPadding() const;
69
70 // Children
71 Quad* GetBackground();
72 Text* GetTextWidget();
73 Quad* GetCaret();
74
75protected:
76
77 static bool HandlePropChange(Datum* datum, uint32_t index, const void* newValue);
78
79 void InsertCharacter(char c);
80 void InsertText(const std::string& text);
81 void DeleteCharacter(bool forward);
82 void MoveCaret(int32_t delta, bool select);
83 void MoveCaretToWordBoundary(int32_t direction, bool select);
84
85 float GetCaretXPosition();
86 int32_t GetCharacterAtPosition(float x);
87 void UpdateDisplayText();
88 void UpdateCaretVisual();
89 void UpdateSelectionVisual();
90 void EnsureCaretVisible();
91 void ExtendSelection();
92 void EmitTextChanged();
93
94 // Content
95 std::string mTextContent;
96 std::string mPlaceholderText = "Enter text...";
97
98 // Editing state
99 int32_t mCaretPosition = 0;
100 int32_t mSelectionStart = -1;
101 int32_t mSelectionEnd = -1;
102 int32_t mSelectionAnchor = -1; // For shift+click selection
103 bool mFocused = false;
104 bool mEditable = true;
105
106 // Caret blink
107 float mCaretBlinkTime = 0.0f;
108 float mCaretBlinkRate = 0.5f;
109 bool mCaretVisible = true;
110
111 // Options
112 bool mPasswordMode = false;
113 int32_t mMaxLength = 0;
114 char mPasswordChar = '*';
115
116 // Visual
118 glm::vec4 mBackgroundColor = { 0.2f, 0.2f, 0.2f, 1.0f };
119 glm::vec4 mFocusedBackgroundColor = { 0.25f, 0.25f, 0.25f, 1.0f };
120 glm::vec4 mTextColor = { 1.0f, 1.0f, 1.0f, 1.0f };
121 glm::vec4 mPlaceholderColor = { 0.5f, 0.5f, 0.5f, 1.0f };
122 glm::vec4 mCaretColor = { 1.0f, 1.0f, 1.0f, 1.0f };
123 glm::vec4 mSelectionColor = { 0.3f, 0.5f, 0.8f, 0.5f };
124 float mTextPadding = 4.0f;
125 float mScrollOffset = 0.0f;
126
127 // Children
128 Quad* mBackground = nullptr;
129 Quad* mSelection = nullptr;
130 Text* mText = nullptr;
131 Quad* mCaret = nullptr;
132};
#define POLYPHASE_API
Definition PolyphaseAPI.h:31
Definition AssetRef.h:18
Definition Datum.h:164
Definition InputField.h:10
DECLARE_NODE(InputField, Widget)
std::string mTextContent
Definition InputField.h:95
TextureRef mBackgroundTexture
Definition InputField.h:117
virtual void EditorTick(float deltaTime)
Definition Node.cpp:563
virtual void Create()
Definition Node.cpp:220
virtual void Tick(float deltaTime)
Definition Node.cpp:558
Definition Quad.h:20
Definition Text.h:24
Definition Texture.h:10
Definition Widget.h:53
static bool HandlePropChange(Datum *datum, uint32_t index, const void *newValue)
Definition Widget.cpp:45
virtual void GatherProperties(std::vector< Property > &outProps) override
Definition Widget.cpp:115
virtual void PreRender()
Definition Widget.cpp:226