Improve string resize flow

This commit is contained in:
SpaiR committed 2020-01-04 18:48:00 +03:00
1 parent b5a6ee1d2a
commit 937b37b75a
5 files changed
+154 -37

No files matched your search

+16 -16
View File
@@ -2397,7 +2397,7 @@ public final class ImGui {
jfieldID imTextInputDataIsDirtyID;
jfieldID imTextInputDataIsResizedID;
char* resizedBuf;
int resizeValue;
struct InputTextCallbackUserData {
JNIEnv* env;
@@ -2434,6 +2434,10 @@ public final class ImGui {
imTextInputDataIsResizedID = env->GetFieldID(jImInputTextDataClass, "isResized", "Z");
*/
private static native int nGetResizeValue(); /*
return resizeValue;
*/
public static boolean inputText(String label, ImString text) {
return preInputText(false, label, text, 0, 0, 0);
}
@@ -2469,7 +2473,7 @@ public final class ImGui {
if (inputData.isResized) {
inputData.isResized = false;
text.set(nGetResizedStr(), true);
text.resize(nGetResizeValue(), true);
}
return hasInput;
@@ -2485,31 +2489,27 @@ public final class ImGui {
if (strlen(allowedChars) > 0)
flags |= ImGuiInputTextFlags_CallbackCharFilter;
bool hasInput;
bool valueChanged;
if (multiline) {
hasInput = ImGui::InputTextMultiline(label, buf, maxSize, ImVec2(width, height), flags, &TextEditCallbackStub, &userData);
valueChanged = ImGui::InputTextMultiline(label, buf, maxSize, ImVec2(width, height), flags, &TextEditCallbackStub, &userData);
} else {
hasInput = ImGui::InputText(label, buf, maxSize, flags, &TextEditCallbackStub, &userData);
valueChanged = ImGui::InputText(label, buf, maxSize, flags, &TextEditCallbackStub, &userData);
}
if (hasInput) {
int size = strlen(buf);
int size = strlen(buf);
if (((size + 1) > maxSize) && (flags & ImGuiInputTextFlags_CallbackResize)) {
env->SetBooleanField(textInputData, imTextInputDataIsResizedID, true);
resizedBuf = buf;
}
if ((flags & ImGuiInputTextFlags_CallbackResize) && ((size + 1) > maxSize)) {
env->SetBooleanField(textInputData, imTextInputDataIsResizedID, true);
resizeValue = size;
}
if (valueChanged) {
env->SetIntField(textInputData, imTextInputDataSizeID, size);
env->SetBooleanField(textInputData, imTextInputDataIsDirtyID, true);
}
return hasInput;
*/
private static native String nGetResizedStr(); /*
return env->NewStringUTF(resizedBuf);
return valueChanged;
*/
public static boolean inputFloat(String label, ImFloat v) {