@@ -216,6 +216,8 @@ namespace ImStb
216
216
217
217
} // namespace ImStb
218
218
219
+ typedef ImStb::STB_TexteditState ImStbTexteditState;
220
+
219
221
// -----------------------------------------------------------------------------
220
222
// [SECTION] Macros
221
223
// -----------------------------------------------------------------------------
@@ -1110,11 +1112,13 @@ struct IMGUI_API ImGuiInputTextDeactivatedState
1110
1112
ImGuiInputTextDeactivatedState () { memset (this , 0 , sizeof (*this )); }
1111
1113
void ClearFreeMemory () { ID = 0 ; TextA.clear (); }
1112
1114
};
1115
+
1113
1116
// Internal state of the currently focused/edited text input box
1114
1117
// For a given item ID, access with ImGui::GetInputTextState()
1115
1118
struct IMGUI_API ImGuiInputTextState
1116
1119
{
1117
1120
ImGuiContext* Ctx; // parent UI context (needs to be set explicitly by parent).
1121
+ ImStbTexteditState* Stb; // State for stb_textedit.h
1118
1122
ImGuiID ID; // widget id owning the text state
1119
1123
int CurLenW, CurLenA; // we need to maintain our buffer length in both UTF-8 and wchar format. UTF-8 length is valid even if TextA is not.
1120
1124
ImVector<ImWchar> TextW; // edit buffer, we need to persist but can't guarantee the persistence of the user-provided buffer. so we copy into own buffer.
@@ -1123,7 +1127,7 @@ struct IMGUI_API ImGuiInputTextState
1123
1127
bool TextAIsValid; // temporary UTF8 buffer is not initially valid before we make the widget active (until then we pull the data from user argument)
1124
1128
int BufCapacityA; // end-user buffer capacity
1125
1129
ImVec2 Scroll; // horizontal offset (managed manually) + vertical scrolling (pulled from child window's own Scroll.y)
1126
- ImStb::STB_TexteditState Stb; // state for stb_textedit.h
1130
+
1127
1131
float CursorAnim; // timer for cursor blink, reset on every user action so the cursor reappears immediately
1128
1132
bool CursorFollow; // set when we want scrolling to follow the current cursor position (not always!)
1129
1133
bool SelectedAllMouseLock; // after a double-click to select all, we ignore further mouse drags to update selection
@@ -1133,30 +1137,29 @@ struct IMGUI_API ImGuiInputTextState
1133
1137
int ReloadSelectionStart; // POSITIONS ARE IN IMWCHAR units *NOT* UTF-8 this is why this is not exposed yet.
1134
1138
int ReloadSelectionEnd;
1135
1139
1136
- ImGuiInputTextState () { memset (this , 0 , sizeof (*this )); }
1140
+ ImGuiInputTextState ();
1141
+ ~ImGuiInputTextState ();
1137
1142
void ClearText () { CurLenW = CurLenA = 0 ; TextW[0 ] = 0 ; TextA[0 ] = 0 ; CursorClamp (); }
1138
1143
void ClearFreeMemory () { TextW.clear (); TextA.clear (); InitialTextA.clear (); }
1139
- int GetUndoAvailCount () const { return Stb.undostate .undo_point ; }
1140
- int GetRedoAvailCount () const { return IMSTB_TEXTEDIT_UNDOSTATECOUNT - Stb.undostate .redo_point ; }
1141
1144
void OnKeyPressed (int key); // Cannot be inline because we call in code in stb_textedit.h implementation
1142
1145
1143
1146
// Cursor & Selection
1144
1147
void CursorAnimReset () { CursorAnim = -0 .30f ; } // After a user-input the cursor stays on for a while without blinking
1145
- void CursorClamp () { Stb. cursor = ImMin (Stb. cursor , CurLenW); Stb. select_start = ImMin (Stb. select_start , CurLenW); Stb. select_end = ImMin (Stb. select_end , CurLenW); }
1146
- bool HasSelection () const { return Stb. select_start != Stb. select_end ; }
1147
- void ClearSelection () { Stb. select_start = Stb. select_end = Stb. cursor ; }
1148
- int GetCursorPos () const { return Stb. cursor ; }
1149
- int GetSelectionStart () const { return Stb. select_start ; }
1150
- int GetSelectionEnd () const { return Stb. select_end ; }
1151
- void SelectAll () { Stb. select_start = 0 ; Stb. cursor = Stb. select_end = CurLenW; Stb. has_preferred_x = 0 ; }
1148
+ void CursorClamp () { Stb-> cursor = ImMin (Stb-> cursor , CurLenW); Stb-> select_start = ImMin (Stb-> select_start , CurLenW); Stb-> select_end = ImMin (Stb-> select_end , CurLenW); }
1149
+ bool HasSelection () const { return Stb-> select_start != Stb-> select_end ; }
1150
+ void ClearSelection () { Stb-> select_start = Stb-> select_end = Stb-> cursor ; }
1151
+ int GetCursorPos () const { return Stb-> cursor ; }
1152
+ int GetSelectionStart () const { return Stb-> select_start ; }
1153
+ int GetSelectionEnd () const { return Stb-> select_end ; }
1154
+ void SelectAll () { Stb-> select_start = 0 ; Stb-> cursor = Stb-> select_end = CurLenW; Stb-> has_preferred_x = 0 ; }
1152
1155
1153
1156
// Reload user buf (WIP #2890)
1154
1157
// If you modify underlying user-passed const char* while active you need to call this (InputText V2 may lift this)
1155
1158
// strcpy(my_buf, "hello");
1156
1159
// if (ImGuiInputTextState* state = ImGui::GetInputTextState(id)) // id may be ImGui::GetItemID() is last item
1157
1160
// state->ReloadUserBufAndSelectAll();
1158
1161
void ReloadUserBufAndSelectAll () { ReloadUserBuf = true ; ReloadSelectionStart = 0 ; ReloadSelectionEnd = INT_MAX; }
1159
- void ReloadUserBufAndKeepSelection () { ReloadUserBuf = true ; ReloadSelectionStart = Stb. select_start ; ReloadSelectionEnd = Stb. select_end ; }
1162
+ void ReloadUserBufAndKeepSelection () { ReloadUserBuf = true ; ReloadSelectionStart = Stb-> select_start ; ReloadSelectionEnd = Stb-> select_end ; }
1160
1163
void ReloadUserBufAndMoveToEnd () { ReloadUserBuf = true ; ReloadSelectionStart = ReloadSelectionEnd = INT_MAX; }
1161
1164
1162
1165
};
0 commit comments