Skip to content

Commit

Permalink
Radio button support (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
dri-richard authored Sep 18, 2023
1 parent 1a3d4b0 commit a985f74
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
13 changes: 13 additions & 0 deletions example/example.script
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ end

function init(self)
self.counter = 0
self.radio = 1
self.show_demo_window = false
self.show_close_window = false
self.show_live_data = false
Expand Down Expand Up @@ -112,6 +113,18 @@ local function update_tab1(self)

imgui.separator()

if imgui.radio_button("Option 1", self.radio == 1) then
self.radio = 1
end
if imgui.radio_button("Option 2", self.radio == 2) then
self.radio = 2
end
if imgui.radio_button("Option 3", self.radio == 3) then
self.radio = 3
end

imgui.separator()

if imgui.button("Button") then
self.counter = self.counter + 1
end
Expand Down
17 changes: 17 additions & 0 deletions imgui/api/imgui.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,23 @@
- name: pushed
type: boolean

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

- name: radio_button
type: function

parameters:
- name: text
type: string
- name: checked
type: boolean

return:
- name: changed
type: boolean
- name: pushed
type: boolean

#*****************************************************************************************************
#***** MENU BAR **************************************************************************************
#*****************************************************************************************************
Expand Down
13 changes: 13 additions & 0 deletions imgui/src/extension_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,18 @@ static int imgui_Checkbox(lua_State* L)
return 2;
}

static int imgui_RadioButton(lua_State* L)
{
DM_LUA_STACK_CHECK(L, 2);
imgui_NewFrame();
const char* text = luaL_checkstring(L, 1);
bool checked = lua_toboolean(L, 2);
bool changed = ImGui::RadioButton(text, checked);
lua_pushboolean(L, changed);
lua_pushboolean(L, checked);
return 2;
}

static int imgui_BeginMenuBar(lua_State* L)
{
DM_LUA_STACK_CHECK(L, 1);
Expand Down Expand Up @@ -2117,6 +2129,7 @@ static const luaL_reg Module_methods[] =
{"button", imgui_Button},
{"button_image", imgui_ButtonImage},
{"checkbox", imgui_Checkbox},
{"radio_button", imgui_RadioButton},
{"begin_menu_bar", imgui_BeginMenuBar},
{"end_menu_bar", imgui_EndMenuBar},
{"begin_main_menu_bar", imgui_BeginMainMenuBar},
Expand Down

0 comments on commit a985f74

Please sign in to comment.