From a985f74035a29b5511d5ef5662eac7fbe5219a2b Mon Sep 17 00:00:00 2001 From: Richard Bates Date: Mon, 18 Sep 2023 14:09:34 +0100 Subject: [PATCH] Radio button support (#31) --- example/example.script | 13 +++++++++++++ imgui/api/imgui.script_api | 17 +++++++++++++++++ imgui/src/extension_imgui.cpp | 13 +++++++++++++ 3 files changed, 43 insertions(+) diff --git a/example/example.script b/example/example.script index 91b2e65..cf2e7ab 100644 --- a/example/example.script +++ b/example/example.script @@ -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 @@ -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 diff --git a/imgui/api/imgui.script_api b/imgui/api/imgui.script_api index de987f0..7d2889d 100644 --- a/imgui/api/imgui.script_api +++ b/imgui/api/imgui.script_api @@ -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 ************************************************************************************** #***************************************************************************************************** diff --git a/imgui/src/extension_imgui.cpp b/imgui/src/extension_imgui.cpp index c39813b..24bae20 100644 --- a/imgui/src/extension_imgui.cpp +++ b/imgui/src/extension_imgui.cpp @@ -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); @@ -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},