Refactor ImGuiInputTextData into an inner ImString class and rename to InputData
This commit is contained in:
1 parent
e60f56beb7
commit
ebd1e69f89
3 files changed
+46
-48
No files matched your search
@@ -4,7 +4,6 @@ import imgui.flag.ImGuiInputTextFlags;
|
|||||||
import imgui.type.ImBool;
|
import imgui.type.ImBool;
|
||||||
import imgui.type.ImDouble;
|
import imgui.type.ImDouble;
|
||||||
import imgui.type.ImFloat;
|
import imgui.type.ImFloat;
|
||||||
import imgui.type.ImGuiInputTextData;
|
|
||||||
import imgui.type.ImInt;
|
import imgui.type.ImInt;
|
||||||
import imgui.type.ImLong;
|
import imgui.type.ImLong;
|
||||||
import imgui.type.ImShort;
|
import imgui.type.ImShort;
|
||||||
@@ -2639,9 +2638,9 @@ public final class ImGui {
|
|||||||
/*JNI
|
/*JNI
|
||||||
jmethodID jImStringResizeInternalMID;
|
jmethodID jImStringResizeInternalMID;
|
||||||
|
|
||||||
jfieldID imTextInputDataSizeID;
|
jfieldID inputDataSizeID;
|
||||||
jfieldID imTextInputDataIsDirtyID;
|
jfieldID inputDataIsDirtyID;
|
||||||
jfieldID imTextInputDataIsResizedID;
|
jfieldID inputDataIsResizedID;
|
||||||
|
|
||||||
struct InputTextCallbackUserData {
|
struct InputTextCallbackUserData {
|
||||||
JNIEnv* env;
|
JNIEnv* env;
|
||||||
@@ -2688,12 +2687,12 @@ public final class ImGui {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
private static native void nInitInputTextData(); /*
|
private static native void nInitInputTextData(); /*
|
||||||
jclass jImInputTextDataClass = env->FindClass("imgui/ImGuiInputTextData");
|
jclass jInputDataClass = env->FindClass("imgui/type/ImString$InputData");
|
||||||
imTextInputDataSizeID = env->GetFieldID(jImInputTextDataClass, "size", "I");
|
inputDataSizeID = env->GetFieldID(jInputDataClass, "size", "I");
|
||||||
imTextInputDataIsDirtyID = env->GetFieldID(jImInputTextDataClass, "isDirty", "Z");
|
inputDataIsDirtyID = env->GetFieldID(jInputDataClass, "isDirty", "Z");
|
||||||
imTextInputDataIsResizedID = env->GetFieldID(jImInputTextDataClass, "isResized", "Z");
|
inputDataIsResizedID = env->GetFieldID(jInputDataClass, "isResized", "Z");
|
||||||
|
|
||||||
jclass jImString = env->FindClass("imgui/ImString");
|
jclass jImString = env->FindClass("imgui/type/ImString");
|
||||||
jImStringResizeInternalMID = env->GetMethodID(jImString, "resizeInternal", "(I)[B");
|
jImStringResizeInternalMID = env->GetMethodID(jImString, "resizeInternal", "(I)[B");
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -2722,7 +2721,7 @@ public final class ImGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean preInputText(boolean multiline, String label, ImString text, float width, float height, int flags) {
|
private static boolean preInputText(boolean multiline, String label, ImString text, float width, float height, int flags) {
|
||||||
final ImGuiInputTextData inputData = text.inputData;
|
final ImString.InputData inputData = text.inputData;
|
||||||
|
|
||||||
if (inputData.isResizable) {
|
if (inputData.isResizable) {
|
||||||
flags |= ImGuiInputTextFlags.CallbackResize;
|
flags |= ImGuiInputTextFlags.CallbackResize;
|
||||||
@@ -2735,7 +2734,7 @@ public final class ImGui {
|
|||||||
return nInputText(multiline, label, text, text.getData(), text.getData().length, width, height, flags, inputData, inputData.allowedChars);
|
return nInputText(multiline, label, text, text.getData(), text.getData().length, width, height, flags, inputData, inputData.allowedChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native boolean nInputText(boolean multiline, String label, ImString imString, byte[] buf, int maxSize, float width, float height, int flags, ImGuiInputTextData textInputData, String allowedChars); /*
|
private static native boolean nInputText(boolean multiline, String label, ImString imString, byte[] buf, int maxSize, float width, float height, int flags, ImString.InputData textInputData, String allowedChars); /*
|
||||||
InputTextCallbackUserData userData;
|
InputTextCallbackUserData userData;
|
||||||
userData.imString = &imString;
|
userData.imString = &imString;
|
||||||
userData.maxSize = maxSize;
|
userData.maxSize = maxSize;
|
||||||
@@ -2763,8 +2762,8 @@ public final class ImGui {
|
|||||||
size = strlen(buf);
|
size = strlen(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
env->SetIntField(textInputData, imTextInputDataSizeID, size);
|
env->SetIntField(textInputData, inputDataSizeID, size);
|
||||||
env->SetBooleanField(textInputData, imTextInputDataIsDirtyID, true);
|
env->SetBooleanField(textInputData, inputDataIsDirtyID, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return valueChanged;
|
return valueChanged;
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
package imgui.type;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this class to customize your ImGui input.
|
|
||||||
*/
|
|
||||||
public final class ImGuiInputTextData {
|
|
||||||
private static final short DEFAULT_RESIZE_FACTOR = 10;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If not empty, then other chars which are different from provided will be filtered during the {@link imgui.ImGui#inputText}
|
|
||||||
* and {@link imgui.ImGui#inputTextMultiline} methods.
|
|
||||||
*/
|
|
||||||
public String allowedChars = "";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* If true, then string will be resized during the the {@link imgui.ImGui#inputText} and {@link imgui.ImGui#inputTextMultiline} methods.
|
|
||||||
* Alternatively you can provide {@link imgui.flag.ImGuiInputTextFlags#CallbackResize} flag to the input text widgets to enable string resizing.
|
|
||||||
* Resize factor of the string could be modified by changing {@link #resizeFactor} field.
|
|
||||||
*/
|
|
||||||
public boolean isResizable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* String will be resized to the value equal to a new size plus this resize factor.
|
|
||||||
* Default value is 10.
|
|
||||||
*/
|
|
||||||
public int resizeFactor = DEFAULT_RESIZE_FACTOR;
|
|
||||||
|
|
||||||
int size;
|
|
||||||
boolean isDirty;
|
|
||||||
boolean isResized = false;
|
|
||||||
|
|
||||||
ImGuiInputTextData() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -20,7 +20,7 @@ public final class ImString implements Cloneable {
|
|||||||
* Configuration class to setup some specific behaviour for current string.
|
* Configuration class to setup some specific behaviour for current string.
|
||||||
* This is useful when string used inside of ImGui#InputText*() methods.
|
* This is useful when string used inside of ImGui#InputText*() methods.
|
||||||
*/
|
*/
|
||||||
public final ImGuiInputTextData inputData = new ImGuiInputTextData();
|
public final InputData inputData = new InputData();
|
||||||
|
|
||||||
private byte[] data;
|
private byte[] data;
|
||||||
private String text = "";
|
private String text = "";
|
||||||
@@ -169,4 +169,37 @@ public final class ImString implements Cloneable {
|
|||||||
public ImString clone() {
|
public ImString clone() {
|
||||||
return new ImString(this);
|
return new ImString(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this class to customize your ImGui input.
|
||||||
|
*/
|
||||||
|
public static final class InputData {
|
||||||
|
private static final short DEFAULT_RESIZE_FACTOR = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If not empty, then other chars which are different from provided will be filtered during the {@link imgui.ImGui#inputText}
|
||||||
|
* and {@link imgui.ImGui#inputTextMultiline} methods.
|
||||||
|
*/
|
||||||
|
public String allowedChars = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, then string will be resized during the the {@link imgui.ImGui#inputText} and {@link imgui.ImGui#inputTextMultiline} methods.
|
||||||
|
* Alternatively you can provide {@link imgui.flag.ImGuiInputTextFlags#CallbackResize} flag to the input text widgets to enable string resizing.
|
||||||
|
* Resize factor of the string could be modified by changing {@link #resizeFactor} field.
|
||||||
|
*/
|
||||||
|
public boolean isResizable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* String will be resized to the value equal to a new size plus this resize factor.
|
||||||
|
* Default value is 10.
|
||||||
|
*/
|
||||||
|
public int resizeFactor = DEFAULT_RESIZE_FACTOR;
|
||||||
|
|
||||||
|
int size;
|
||||||
|
boolean isDirty;
|
||||||
|
boolean isResized = false;
|
||||||
|
|
||||||
|
private InputData() {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user