Skip to content

Commit

Permalink
Added set_keyboard_focus_here (#38)
Browse files Browse the repository at this point in the history
* Added SetKeyboardFocusHere function

* Update extension_imgui.cpp

* Fixed stack check value, used the function in example
  • Loading branch information
dima13230 committed Dec 2, 2023
1 parent c31fad1 commit e7585a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions example/example.script
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ local function update_tab2(self)

imgui.separator()

if imgui.button("Push me to focus on test double") then
imgui.set_keyboard_focus_here(0)
end
local testdbl = self.testdbl or 0
local changed, value = imgui.input_double("test double", testdbl, 0.0001, 0.01, 5)
if changed then
Expand Down
8 changes: 8 additions & 0 deletions imgui/api/imgui.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,14 @@
- name: y
type: number

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

- name: set_keyboard_focus_here
type: function

parameters:
- name: offset
type: number

#*****************************************************************************************************
#***** STYLE *****************************************************************************************
Expand Down
10 changes: 10 additions & 0 deletions imgui/src/extension_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1642,6 +1642,15 @@ static int imgui_GetItemRectMax(lua_State* L)
return 2;
}

static int imgui_SetKeyboardFocusHere(lua_State* L)
{
DM_LUA_STACK_CHECK(L, 0);
imgui_NewFrame();
int offset = luaL_checknumber(L, 1);
ImGui::SetKeyboardFocusHere(offset);
return 0;
}

// ----------------------------
// ----- STYLE ----------------
// ----------------------------
Expand Down Expand Up @@ -2284,6 +2293,7 @@ static const luaL_reg Module_methods[] =
{"get_item_rect_max", imgui_GetItemRectMax},
{"is_mouse_clicked", imgui_IsMouseClicked},
{"is_mouse_double_clicked", imgui_IsMouseDoubleClicked},
{"set_keyboard_focus_here", imgui_SetKeyboardFocusHere},

{"set_style_window_rounding", imgui_SetStyleWindowRounding},
{"set_style_window_bordersize", imgui_SetStyleWindowBorderSize},
Expand Down

0 comments on commit e7585a1

Please sign in to comment.