You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (!wordWrapEnabled && y + lineHeight < clipRect.y)
1215
-
while (s < textEnd && text[s] !='\n') // Fast-forward to next line
1216
-
s++
1214
+
if (y + lineHeight < clipRect.y &&!wordWrapEnabled)
1215
+
while (y + lineHeight < clipRect.y) {
1216
+
while (s < textEnd_)
1217
+
if (text[s++] =='\n')
1218
+
break
1219
+
y += lineHeight
1220
+
}
1221
+
1222
+
/* For large text, scan for the last visible line in order to avoid over-reserving in the call to PrimReserve()
1223
+
Note that very large horizontal line will still be affected by the issue (e.g. a one megabyte string buffer without a newline will likely crash atm) */
1224
+
var textEnd = textEnd_
1225
+
if (textEnd - s >10000&&!wordWrapEnabled) {
1226
+
var sEnd = s
1227
+
var yEnd = y
1228
+
while (yEnd < clipRect.w) {
1229
+
while (sEnd < textEnd)
1230
+
if (text[sEnd++] =='\n')
1231
+
break
1232
+
yEnd += lineHeight
1233
+
}
1234
+
textEnd = sEnd
1235
+
}
1236
+
1237
+
1217
1238
1218
1239
// Reserve vertices for remaining worse case (over-reserving is useful and easily amortized)
1219
1240
val vtxCountMax = (textEnd - s) *4
@@ -1274,12 +1295,8 @@ class Font {
1274
1295
if (c =='\n') {
1275
1296
x = pos.x
1276
1297
y += lineHeight
1277
-
1278
-
if (y > clipRect.w) break
1279
-
1280
-
if (!wordWrapEnabled && y + lineHeight < clipRect.y)
1281
-
while (s < textEnd && text[s] !='\n') // Fast-forward to next line
Copy file name to clipboardExpand all lines: src/main/kotlin/imgui/helpers.kt
+73-11Lines changed: 73 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,9 @@ import imgui.ImGui.inputText
14
14
importimgui.ImGui.popItemWidth
15
15
importimgui.ImGui.pushItemWidth
16
16
importimgui.ImGui.style
17
+
importimgui.internal.strlen
17
18
importjava.nio.ByteBuffer
19
+
importkotlin.math.max
18
20
19
21
/** Helper: Execute a block of code at maximum once a frame. Convenient if you want to quickly create an UI within
20
22
* deep-nested code that runs multiple times every frame.
@@ -139,14 +141,18 @@ class Storage {
139
141
funsetAllInt(value:Int) = data.replaceAll { _, _ -> value }
140
142
}
141
143
142
-
/** Shared state of InputText(), passed to callback when a ImGuiInputTextFlags_Callback* flag is used and the corresponding callback is triggered.
144
+
/** Shared state of InputText(), passed as an argument to your callback when a ImGuiInputTextFlags_Callback* flag is used.
143
145
* The callback function should return 0 by default.
144
146
* Special processing:
145
147
* - InputTextFlag.CallbackCharFilter: return 1 if the character is not allowed. You may also set 'EventChar=0'
146
148
* as any character replacement are allowed.
147
-
* - InputTextFlag.CallbackResize: BufTextLen is set to the new desired string length so you can allocate or update known size.
148
-
* No need to initialize new characters or zero-terminator as InputText will do it. */
149
-
classTextEditCallbackData {
149
+
* - InputTextFlag.CallbackResize: notified by InputText() when the string is resized.
150
+
* BufTextLen is set to the new desired string length so you can allocate or update known size.
151
+
* No need to initialize new characters or zero-terminator as InputText will do it.
152
+
*
153
+
* Helper functions for text manipulation.
154
+
* Use those function to benefit from the CallbackResize behaviors. Calling those function reset the selection. */
155
+
classInputTextCallbackData {
150
156
151
157
/** One ImGuiInputTextFlags_Callback* // Read-only */
152
158
var eventFlag:InputTextFlags=0
@@ -156,19 +162,20 @@ class TextEditCallbackData {
156
162
var userData:Any?=null
157
163
158
164
/* Arguments for the different callback events
159
-
* (If you modify the 'buf' contents make sure you update 'BufTextLen' and set 'BufDirty' to true!) */
165
+
* - To modify the text buffer in a callback, prefer using the InsertChars() / DeleteChars() function. InsertChars() will take care of calling the resize callback if necessary.
166
+
* - If you know your edits are not going to resize the underlying buffer allocation, you may modify the contents of 'Buf[]' directly. You need to update 'BufTextLen' accordingly (0 <= BufTextLen < BufSize) and set 'BufDirty'' to true so InputText can update its internal state. */
160
167
161
168
/** Character input Read-write [CharFilter] Replace character or set to zero. return 1 is equivalent to setting EventChar=0; */
/** Current text buffer Read-write [Resize] Can replace pointer / [Completion,History,Always] Only write to pointed data, don't replace the actual pointer! */
172
+
/** Text buffer Read-write [Resize] Can replace pointer / [Completion,History,Always] Only write to pointed data, don't replace the actual pointer! */
166
173
var buf =CharArray(0)
167
174
/** JVM custom, current buf pointer */
168
175
var bufPtr =0
169
-
/** Current text length in bytes Read-write [Resize,Completion,History,Always] */
176
+
/** Text length in bytes Read-write [Resize,Completion,History,Always] */
val isResizable = flags has InputTextFlag.CallbackResize
215
+
val newTextLen = newTextEnd ?: newText.strlen
216
+
if (newTextLen + bufTextLen >= bufSize) {
217
+
218
+
if (!isResizable) return
219
+
220
+
// Contrary to STB_TEXTEDIT_INSERTCHARS() this is working in the UTF8 buffer, hence the midly similar code (until we remove the U16 buffer alltogether!)
0 commit comments