From bc0ce03cd716084220a1ebde9739c107bbfdc7ed Mon Sep 17 00:00:00 2001 From: Dmitry Senyushkin Date: Wed, 24 Jul 2024 11:08:32 +0300 Subject: [PATCH 1/3] Window focus and collapse functions --- imgui/api/imgui.script_api | 53 +++++++++++++++++++++++ imgui/src/extension_imgui.cpp | 79 +++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+) diff --git a/imgui/api/imgui.script_api b/imgui/api/imgui.script_api index 61167e4..f3a0c5d 100644 --- a/imgui/api/imgui.script_api +++ b/imgui/api/imgui.script_api @@ -288,6 +288,59 @@ type: number optional: true +#***************************************************************************************************** + + - name: set_next_window_focus + type: function + +#***************************************************************************************************** + + - name: set_window_focus + type: function + + parameters: + - name: name + type: string + optional: true + +#***************************************************************************************************** + + - name: set_next_window_collapsed + type: function + + parameters: + - name: collapsed + type: boolean + - name: cond + type: number + optional: true + +#***************************************************************************************************** + + - name: set_window_collapsed + type: function + + parameters: + - name: collapsed + type: boolean + - name: cond + type: number + optional: true + +#***************************************************************************************************** + + - name: set_window_collapsed + type: function + + parameters: + - name: name + type: string + - name: collapsed + type: boolean + - name: cond + type: number + optional: true + #***************************************************************************************************** - name: get_window_size diff --git a/imgui/src/extension_imgui.cpp b/imgui/src/extension_imgui.cpp index 7afae19..1142edb 100644 --- a/imgui/src/extension_imgui.cpp +++ b/imgui/src/extension_imgui.cpp @@ -591,6 +591,81 @@ static int imgui_SetNextWindowPos(lua_State* L) ImGui::SetNextWindowPos(ImVec2(x, y), cond); return 0; } +static int imgui_SetNextWindowFocus(lua_State* L) +{ + DM_LUA_STACK_CHECK(L, 0); + imgui_NewFrame(); + ImGui::SetNextWindowFocus(); + return 0; +} +static int imgui_SetWindowFocus(lua_State* L) +{ + DM_LUA_STACK_CHECK(L, 0); + imgui_NewFrame(); + if (lua_isstring(L, 1)) + { + const char* name = luaL_checkstring(L, 1); + ImGUI::SetWindowFocus(name); + } + else + { + ImGUI::SetWindowFocus(); + } + ImGui::SetNextWindowPos(ImVec2(x, y), cond); + return 0; +} +static int imgui_SetNextWindowCollapsed(lua_State* L) +{ + DM_LUA_STACK_CHECK(L, 0); + imgui_NewFrame(); + bool collapsed = false; + if (lua_isboolean(L, 1)) + { + collapsed = lua_toboolean(L, 1); + } + uint32_t cond = ImGuiCond_None; + if (lua_isnumber(L, 2)) + { + cond = luaL_checkint(L, 2); + } + ImGui::SetNextWindowCollapsed(collapsed, cond); + return 0; +} +static int imgui_SetWindowCollapsed(lua_State* L) +{ + DM_LUA_STACK_CHECK(L, 0); + imgui_NewFrame(); + if (lua_isstring(L, 1)) + { + const char* name = luaL_checkstring(L, 1); + bool collapsed = false; + if (lua_isboolean(L, 2)) + { + collapsed = lua_toboolean(L, 2); + } + uint32_t cond = ImGuiCond_None; + if (lua_isnumber(L, 3)) + { + cond = luaL_checkint(L, 3); + } + ImGui::SetWindowCollapsed(name, collapsed, cond); + } + else + { + bool collapsed = false; + if (lua_isboolean(L, 1)) + { + collapsed = lua_toboolean(L, 1); + } + uint32_t cond = ImGuiCond_None; + if (lua_isnumber(L, 2)) + { + cond = luaL_checkint(L, 2); + } + ImGui::SetWindowCollapsed(collapsed, cond); + } + return 0; +} static int imgui_GetWindowSize(lua_State* L) { DM_LUA_STACK_CHECK(L, 2); @@ -2633,6 +2708,10 @@ static const luaL_reg Module_methods[] = {"set_next_window_size", imgui_SetNextWindowSize}, {"set_next_window_pos", imgui_SetNextWindowPos}, + {"set_next_window_focus", imgui_SetNextWindowFocus}, + {"set_window_focus", imgui_SetWindowFocus}, + {"set_next_window_collapsed", imgui_SetNextWindowCollapsed} + {"set_window_collapsed", imgui_SetWindowCollapsed} {"get_window_size", imgui_GetWindowSize}, {"get_window_pos", imgui_GetWindowPos}, {"begin_window", imgui_Begin}, From cbe50dd210ce946b8a0ef92f20bf759bb57aa88c Mon Sep 17 00:00:00 2001 From: Dmitry Senyushkin Date: Wed, 24 Jul 2024 11:12:36 +0300 Subject: [PATCH 2/3] Fixed imgui name typos in imgui_SetWindowFocus --- imgui/src/extension_imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui/src/extension_imgui.cpp b/imgui/src/extension_imgui.cpp index 1142edb..74c2bb8 100644 --- a/imgui/src/extension_imgui.cpp +++ b/imgui/src/extension_imgui.cpp @@ -605,11 +605,11 @@ static int imgui_SetWindowFocus(lua_State* L) if (lua_isstring(L, 1)) { const char* name = luaL_checkstring(L, 1); - ImGUI::SetWindowFocus(name); + ImGui::SetWindowFocus(name); } else { - ImGUI::SetWindowFocus(); + ImGui::SetWindowFocus(); } ImGui::SetNextWindowPos(ImVec2(x, y), cond); return 0; From 2e7b38fc5dfa7701916d022cb49dd8e314d71904 Mon Sep 17 00:00:00 2001 From: Dmitry Senyushkin Date: Wed, 24 Jul 2024 12:08:07 +0300 Subject: [PATCH 3/3] Fixed other typos --- imgui/src/extension_imgui.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/imgui/src/extension_imgui.cpp b/imgui/src/extension_imgui.cpp index 74c2bb8..1b868c7 100644 --- a/imgui/src/extension_imgui.cpp +++ b/imgui/src/extension_imgui.cpp @@ -611,7 +611,6 @@ static int imgui_SetWindowFocus(lua_State* L) { ImGui::SetWindowFocus(); } - ImGui::SetNextWindowPos(ImVec2(x, y), cond); return 0; } static int imgui_SetNextWindowCollapsed(lua_State* L) @@ -2710,8 +2709,8 @@ static const luaL_reg Module_methods[] = {"set_next_window_pos", imgui_SetNextWindowPos}, {"set_next_window_focus", imgui_SetNextWindowFocus}, {"set_window_focus", imgui_SetWindowFocus}, - {"set_next_window_collapsed", imgui_SetNextWindowCollapsed} - {"set_window_collapsed", imgui_SetWindowCollapsed} + {"set_next_window_collapsed", imgui_SetNextWindowCollapsed}, + {"set_window_collapsed", imgui_SetWindowCollapsed}, {"get_window_size", imgui_GetWindowSize}, {"get_window_pos", imgui_GetWindowPos}, {"begin_window", imgui_Begin},