Skip to content

Commit

Permalink
Port "Popups" api
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaiR committed Jul 10, 2022
1 parent 09872d4 commit a34c369
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -963,5 +963,52 @@ class ImGui : ApiMetadata() {
argString("tooltip")
argNull()
}

// Popups, Modals
method("BeginPopup", resultBoolean()) {
argString("strId")
argInt("flags", optional = true)
}
method("BeginPopupModal", resultBoolean()) {
argString("name")
argBooleanPtr("pOpen", optional = true, default = "NULL")
argInt("flags", optional = true)
}
method("EndPopup")

// Popups: open/close functions
method("OpenPopup") {
argString("strId")
argInt("popupFlags", optional = true)
}
method("OpenPopup") {
argInt("id")
argInt("popupFlags", optional = true)
}
method("OpenPopupOnItemClick") {
argString("strId", optional = true, default = "NULL")
argInt("popupFlags", optional = true)
}
method("CloseCurrentPopup")

// Popups: open+begin combined functions helpers
method("BeginPopupContextItem", resultBoolean()) {
argString("strId", optional = true, default = "NULL")
argInt("popupFlags", optional = true)
}
method("BeginPopupContextWindow", resultBoolean()) {
argString("strId", optional = true, default = "NULL")
argInt("popupFlags", optional = true)
}
method("BeginPopupContextVoid", resultBoolean()) {
argString("strId", optional = true, default = "NULL")
argInt("popupFlags", optional = true)
}

// Popups: query functions
method("IsPopupOpen", resultBoolean()) {
argString("strId")
argInt("flags", optional = true)
}
}
}
238 changes: 0 additions & 238 deletions imgui-binding/src/main/java/imgui/ImGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,244 +362,6 @@ public static void listBox(String label, ImInt currentItem, String[] items, int
return flag;
*/

// Popups, Modals
// - They block normal mouse hovering detection (and therefore most mouse interactions) behind them.
// - If not modal: they can be closed by clicking anywhere outside them, or by pressing ESCAPE.
// - Their visibility state (~bool) is held internally instead of being held by the programmer as we are used to with regular Begin*() calls.
// - The 3 properties above are related: we need to retain popup visibility state in the library because popups may be closed as any time.
// - You can bypass the hovering restriction by using ImGuiHoveredFlags_AllowWhenBlockedByPopup when calling IsItemHovered() or IsWindowHovered().
// - IMPORTANT: Popup identifiers are relative to the current ID stack, so OpenPopup and BeginPopup generally needs to be at the same level of the stack.
// This is sometimes leading to confusing mistakes. May rework this in the future.
// Popups: begin/end functions
// - BeginPopup(): query popup state, if open start appending into the window. Call EndPopup() afterwards. ImGuiWindowFlags are forwarded to the window.
// - BeginPopupModal(): block every interactions behind the window, cannot be closed by user, add a dimming background, has a title bar.

/**
* Return true if the popup is open, and you can start outputting to it.
*/
public static native boolean beginPopup(String strId); /*
return ImGui::BeginPopup(strId);
*/

/**
* Return true if the popup is open, and you can start outputting to it.
*/
public static native boolean beginPopup(String strId, int imGuiWindowFlags); /*
return ImGui::BeginPopup(strId, imGuiWindowFlags);
*/

/**
* Return true if the popup is open, and you can start outputting to it.
*/
public static native boolean beginPopupModal(String name); /*
return ImGui::BeginPopupModal(name);
*/

/**
* Return true if the popup is open, and you can start outputting to it.
*/
public static boolean beginPopupModal(String name, ImBoolean pOpen) {
return nBeginPopupModal(name, pOpen.getData(), 0);
}

/**
* Return true if the popup is open, and you can start outputting to it.
*/
public static boolean beginPopupModal(String name, int imGuiWindowFlags) {
return nBeginPopupModal(name, imGuiWindowFlags);
}

/**
* Return true if the popup is open, and you can start outputting to it.
*/
public static boolean beginPopupModal(String name, ImBoolean pOpen, int imGuiWindowFlags) {
return nBeginPopupModal(name, pOpen.getData(), imGuiWindowFlags);
}

private static native boolean nBeginPopupModal(String name, int imGuiWindowFlags); /*
return ImGui::BeginPopupModal(name, NULL, imGuiWindowFlags);
*/

private static native boolean nBeginPopupModal(String name, boolean[] pOpen, int imGuiWindowFlags); /*
return ImGui::BeginPopupModal(name, &pOpen[0], imGuiWindowFlags);
*/

/**
* Only call EndPopup() if BeginPopupXXX() returns true!
*/
public static native void endPopup(); /*
ImGui::EndPopup();
*/

// Popups: open/close functions
// - OpenPopup(): set popup state to open. ImGuiPopupFlags are available for opening options.
// - If not modal: they can be closed by clicking anywhere outside them, or by pressing ESCAPE.
// - CloseCurrentPopup(): use inside the BeginPopup()/EndPopup() scope to close manually.
// - CloseCurrentPopup() is called by default by Selectable()/MenuItem() when activated (FIXME: need some options).
// - Use ImGuiPopupFlags_NoOpenOverExistingPopup to avoid opening a popup if there's already one at the same level. This is equivalent to e.g. testing for !IsAnyPopupOpen() prior to OpenPopup().

/**
* Call to mark popup as open (don't call every frame!).
*/
public static native void openPopup(String strId); /*
ImGui::OpenPopup(strId);
*/

/**
* Call to mark popup as open (don't call every frame!).
*/
public static native void openPopup(String strId, int imGuiPopupFlags); /*
ImGui::OpenPopup(strId, imGuiPopupFlags);
*/

/**
* Helper to open popup when clicked on last item. return true when just opened. (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors)
*/
public static native void openPopupOnItemClick(); /*
ImGui::OpenPopupOnItemClick();
*/

/**
* Helper to open popup when clicked on last item. return true when just opened. (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors)
*/
public static native void openPopupOnItemClick(String strId); /*
ImGui::OpenPopupOnItemClick(strId);
*/

/**
* Helper to open popup when clicked on last item. return true when just opened. (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors)
*/
public static native void openPopupOnItemClick(int imGuiPopupFlags); /*
ImGui::OpenPopupOnItemClick(NULL, imGuiPopupFlags);
*/

/**
* Helper to open popup when clicked on last item. return true when just opened. (note: actually triggers on the mouse _released_ event to be consistent with popup behaviors)
*/
public static native void openPopupOnItemClick(String strId, int imGuiPopupFlags); /*
ImGui::OpenPopupOnItemClick(strId, imGuiPopupFlags);
*/

/**
* Manually close the popup we have begin-ed into.
*/
public static native void closeCurrentPopup(); /*
ImGui::CloseCurrentPopup();
*/

// Popups: open+begin combined functions helpers
// - Helpers to do OpenPopup+BeginPopup where the Open action is triggered by e.g. hovering an item and right-clicking.
// - They are convenient to easily create context menus, hence the name.
// - IMPORTANT: Notice that BeginPopupContextXXX takes ImGuiPopupFlags just like OpenPopup() and unlike BeginPopup(). For full consistency, we may add ImGuiWindowFlags to the BeginPopupContextXXX functions in the future.
// - IMPORTANT: we exceptionally default their flags to 1 (== ImGuiPopupFlags_MouseButtonRight) for backward compatibility with older API taking 'int mouse_button = 1' parameter, so if you add other flags remember to re-add the ImGuiPopupFlags_MouseButtonRight.

/**
* Open+begin popup when clicked on last item. if you can pass a NULL str_id only if the previous item had an id.
* If you want to use that on a non-interactive item such as Text() you need to pass in an explicit ID here. read comments in .cpp!
*/
public static native boolean beginPopupContextItem(); /*
return ImGui::BeginPopupContextItem();
*/

/**
* Open+begin popup when clicked on last item. if you can pass a NULL str_id only if the previous item had an id.
* If you want to use that on a non-interactive item such as Text() you need to pass in an explicit ID here. read comments in .cpp!
*/
public static native boolean beginPopupContextItem(String strId); /*
return ImGui::BeginPopupContextItem(strId);
*/

/**
* Open+begin popup when clicked on last item. if you can pass a NULL str_id only if the previous item had an id.
* If you want to use that on a non-interactive item such as Text() you need to pass in an explicit ID here. read comments in .cpp!
*/
public static native boolean beginPopupContextItem(int imGuiPopupFlags); /*
return ImGui::BeginPopupContextItem(NULL, imGuiPopupFlags);
*/

/**
* Open+begin popup when clicked on last item. if you can pass a NULL str_id only if the previous item had an id.
* If you want to use that on a non-interactive item such as Text() you need to pass in an explicit ID here. read comments in .cpp!
*/
public static native boolean beginPopupContextItem(String strId, int imGuiPopupFlags); /*
return ImGui::BeginPopupContextItem(strId, imGuiPopupFlags);
*/

/**
* Open+begin popup when clicked on current window.
*/
public static native boolean beginPopupContextWindow(); /*
return ImGui::BeginPopupContextWindow();
*/

/**
* Open+begin popup when clicked on current window.
*/
public static native boolean beginPopupContextWindow(String strId); /*
return ImGui::BeginPopupContextWindow(strId);
*/

/**
* Open+begin popup when clicked on current window.
*/
public static native boolean beginPopupContextWindow(int imGuiPopupFlags); /*
return ImGui::BeginPopupContextWindow(NULL, imGuiPopupFlags);
*/

/**
* Open+begin popup when clicked on current window.
*/
public static native boolean beginPopupContextWindow(String strId, int imGuiPopupFlags); /*
return ImGui::BeginPopupContextWindow(strId, imGuiPopupFlags);
*/

/**
* Open+begin popup when clicked in void (where there are no windows).
*/
public static native boolean beginPopupContextVoid(); /*
return ImGui::BeginPopupContextVoid();
*/

/**
* Open+begin popup when clicked in void (where there are no windows).
*/
public static native boolean beginPopupContextVoid(String strId); /*
return ImGui::BeginPopupContextVoid(strId);
*/

/**
* Open+begin popup when clicked in void (where there are no windows).
*/
public static native boolean beginPopupContextVoid(int imGuiPopupFlags); /*
return ImGui::BeginPopupContextVoid(NULL, imGuiPopupFlags);
*/

/**
* Open+begin popup when clicked in void (where there are no windows).
*/
public static native boolean beginPopupContextVoid(String strId, int imGuiPopupFlags); /*
return ImGui::BeginPopupContextVoid(strId, imGuiPopupFlags);
*/

// Popups: test function
// - IsPopupOpen(): return true if the popup is open at the current BeginPopup() level of the popup stack.
// - IsPopupOpen() with ImGuiPopupFlags_AnyPopupId: return true if any popup is open at the current BeginPopup() level of the popup stack.
// - IsPopupOpen() with ImGuiPopupFlags_AnyPopupId + ImGuiPopupFlags_AnyPopupLevel: return true if any popup is open.

/**
* Return true if the popup is open.
*/
public static native boolean isPopupOpen(String strId); /*
return ImGui::IsPopupOpen(strId);
*/

/**
* Return true if the popup is open.
*/
public static native boolean isPopupOpen(String strId, int imGuiPopupFlags); /*
return ImGui::IsPopupOpen(strId, imGuiPopupFlags);
*/

// Tables
// [BETA API] API may evolve slightly! If you use this, please update to the next version when it comes out!
// - Full-featured replacement for old Columns API.
Expand Down

0 comments on commit a34c369

Please sign in to comment.