Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Allow null to be passed as the shortcut param to MenuItem #35

Merged
merged 4 commits into from
Mar 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 42 additions & 11 deletions imgui-binding/src/main/java/imgui/ImGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -4010,23 +4010,23 @@ public static void listBox(String label, ImInt currentItem, String[] items, int
/**
* Return true when activated. shortcuts are displayed for convenience but not processed by ImGui at the moment
*/
public static native boolean menuItem(String label, String shortcut); /*
return ImGui::MenuItem(label, shortcut);
*/
public static boolean menuItem(String label, String shortcut) {
return nMenuItem(label, shortcut, false, true);
}

/**
* Return true when activated. shortcuts are displayed for convenience but not processed by ImGui at the moment
*/
public static native boolean menuItem(String label, String shortcut, boolean selected); /*
return ImGui::MenuItem(label, shortcut, selected);
*/
public static boolean menuItem(String label, String shortcut, boolean selected) {
return nMenuItem(label, shortcut, selected, true);
}

/**
* Return true when activated. shortcuts are displayed for convenience but not processed by ImGui at the moment
*/
public static native boolean menuItem(String label, String shortcut, boolean selected, boolean enabled); /*
return ImGui::MenuItem(label, shortcut, selected, enabled);
*/
public static boolean menuItem(String label, String shortcut, boolean selected, boolean enabled) {
return nMenuItem(label, shortcut, selected, enabled);
}

/**
* Return true when activated + toggle (*pSelected) if pSelected != NULL
Expand All @@ -4042,11 +4042,42 @@ public static boolean menuItem(String label, String shortcut, ImBoolean pSelecte
return nMenuItem(label, shortcut, pSelected.getData(), enabled);
}

/**
* Return true when activated
*/
private static native boolean nMenuItem(String labelObj, String shortcutObj, boolean selected, boolean enabled); /*MANUAL
char* label = (char*)env->GetStringUTFChars(labelObj, JNI_FALSE);
char* shortcut = NULL;
if (shortcutObj != NULL)
shortcut = (char*)env->GetStringUTFChars(shortcutObj, JNI_FALSE);

jboolean result = ImGui::MenuItem(label, shortcut, selected, enabled);

if (shortcutObj != NULL)
env->ReleaseStringUTFChars(shortcutObj, shortcut);
env->ReleaseStringUTFChars(labelObj, label);

return result;
*/

/**
* Return true when activated + toggle (*pSelected) if pSelected != NULL
*/
private static native boolean nMenuItem(String label, String shortcut, boolean[] pSelected, boolean enabled); /*
return ImGui::MenuItem(label, shortcut, &pSelected[0], enabled);
private static native boolean nMenuItem(String labelObj, String shortcutObj, boolean[] pSelectedObj, boolean enabled); /*MANUAL
char* label = (char*)env->GetStringUTFChars(labelObj, JNI_FALSE);
char* shortcut = NULL;
if (shortcutObj != NULL)
shortcut = (char*)env->GetStringUTFChars(shortcutObj, JNI_FALSE);
bool* pSelected = (bool*)env->GetPrimitiveArrayCritical(pSelectedObj, JNI_FALSE);

jboolean result = ImGui::MenuItem(label, shortcut, &pSelected[0], enabled);

env->ReleasePrimitiveArrayCritical(pSelectedObj, pSelected, 0);
if (shortcutObj != NULL)
env->ReleaseStringUTFChars(shortcutObj, shortcut);
env->ReleaseStringUTFChars(labelObj, label);

return result;
*/

// Tooltips
Expand Down