Skip to content

Commit

Permalink
Added support for conditions in SetNextWindow* methods (#30)
Browse files Browse the repository at this point in the history
* Added support for conditions in SetNextWindow* methods

* Marked `cond` parameters optional
  • Loading branch information
u546342 authored Sep 6, 2023
1 parent 20df44a commit 1a3d4b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions imgui/api/imgui.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@
type: number
- name: height
type: number
- name: cond
type: number
optional: true

#*****************************************************************************************************

Expand All @@ -277,6 +280,9 @@
type: number
- name: y
type: number
- name: cond
type: number
optional: true

#*****************************************************************************************************

Expand Down
19 changes: 17 additions & 2 deletions imgui/src/extension_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,12 @@ static int imgui_SetNextWindowSize(lua_State* L)
imgui_NewFrame();
float width = luaL_checknumber(L, 1);
float height = luaL_checknumber(L, 2);
ImGui::SetNextWindowSize(ImVec2(width, height));
uint32_t cond = ImGuiCond_None;
if (lua_isnumber(L, 3))
{
cond = luaL_checkint(L, 3);
}
ImGui::SetNextWindowSize(ImVec2(width, height), cond);
return 0;
}
static int imgui_SetNextWindowPos(lua_State* L)
Expand All @@ -524,7 +529,12 @@ static int imgui_SetNextWindowPos(lua_State* L)
imgui_NewFrame();
float x = luaL_checknumber(L, 1);
float y = luaL_checknumber(L, 2);
ImGui::SetNextWindowPos(ImVec2(x, y));
uint32_t cond = ImGuiCond_None;
if (lua_isnumber(L, 3))
{
cond = luaL_checkint(L, 3);
}
ImGui::SetNextWindowPos(ImVec2(x, y), cond);
return 0;
}
static int imgui_GetWindowSize(lua_State* L)
Expand Down Expand Up @@ -2447,6 +2457,11 @@ static void LuaInit(lua_State* L)
lua_setfieldstringint(L, "INPUTFLAGS_CALLBACKRESIZE", ImGuiInputTextFlags_CallbackResize); // Callback on buffer capacity changes request (beyond 'buf_size' parameter value), allowing the string to grow. Notify when the string wants to be resized (for string types which hold a cache of their Size). You will be provided a new BufSize in the callback and NEED to honor it. (see misc/cpp/imgui_stdlib.h for an example of using this)
lua_setfieldstringint(L, "INPUTFLAGS_CALLBACKEDIT", ImGuiInputTextFlags_CallbackEdit); // Callback on any edit (note that InputText() already returns true on edit, the callback is useful mainly to manipulate the underlying buffer while focus is active)

lua_setfieldstringint(L, "COND_NONE", ImGuiCond_None); // No condition (always set the variable), same as _Always
lua_setfieldstringint(L, "COND_ALWAYS", ImGuiCond_Always); // No condition (always set the variable)
lua_setfieldstringint(L, "COND_ONCE", ImGuiCond_Once); // Set the variable once per runtime session (only the first call will succeed)
lua_setfieldstringint(L, "COND_FIRSTUSEEVER", ImGuiCond_FirstUseEver); // Set the variable if the object/window has no persistently saved data (no entry in .ini file)
lua_setfieldstringint(L, "COND_APPEARING", ImGuiCond_Appearing); // Set the variable if the object/window is appearing after being hidden/inactive (or the first time)

lua_pop(L, 1);
assert(top == lua_gettop(L));
Expand Down

0 comments on commit 1a3d4b0

Please sign in to comment.