Skip to content

Commit

Permalink
Added window pivot to set_next_window_pos (#60)
Browse files Browse the repository at this point in the history
* Update extension_imgui.cpp

Exposed to Defold the pivot parameter of SetNextWindowPos so we can center the windows with parameters 0.5, 0.5 and so

* Added to the documentation

Added the two new numeric parameters corresponding to the window pivot to the documentation
  • Loading branch information
MrSanShiro authored Jan 26, 2025
1 parent a82aaaa commit 80e94d7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
12 changes: 11 additions & 1 deletion api.json
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,19 @@
"description": "",
"name": "cond",
"type": "number"
},
{
"description": "",
"name": "pivot_x",
"type": "number"
},
{
"description": "",
"name": "pivot_y",
"type": "number"
}
],
"params_string": "x,y,cond",
"params_string": "x,y,cond,pivot_x,pivot_y",
"returns": [],
"summary": "SetNextWindowPos",
"usage": null
Expand Down
4 changes: 3 additions & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,16 @@ PARAMS
* `cond` [`number`] -


### set_next_window_pos(x,y,cond)
### set_next_window_pos(x,y,cond,pivot_x,pivot_y)
SetNextWindowPos


PARAMS
* `x` [`number`] -
* `y` [`number`] -
* `cond` [`number`] -
* `pivot_x` [`number`] -
* `pivot_y` [`number`] -


### get_window_size()
Expand Down
6 changes: 6 additions & 0 deletions imgui/api/imgui.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@
- name: cond
type: number

- name: pivot_x
type: number

- name: pivot_y
type: number


- name: get_window_size
type: function
Expand Down
10 changes: 9 additions & 1 deletion imgui/src/extension_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ static int imgui_SetNextWindowSize(lua_State* L)
* @number x
* @number y
* @number cond
* @number pivot_x
* @number pivot_y
*/
static int imgui_SetNextWindowPos(lua_State* L)
{
Expand All @@ -730,7 +732,13 @@ static int imgui_SetNextWindowPos(lua_State* L)
{
cond = luaL_checkint(L, 3);
}
ImGui::SetNextWindowPos(ImVec2(x, y), cond);
ImVec2 pivot = ImVec2(0, 0);
if (lua_isnumber(L, 4) && lua_isnumber(L, 5))
{
pivot.x = luaL_checknumber(L, 4);
pivot.y = luaL_checknumber(L, 5);
}
ImGui::SetNextWindowPos(ImVec2(x, y), cond, pivot);
return 0;
}
/** GetWindowSize
Expand Down

0 comments on commit 80e94d7

Please sign in to comment.