From 497781b0481c3dbc5eebb5daae154ea8f7a9d2b2 Mon Sep 17 00:00:00 2001 From: Quentin Date: Wed, 19 Jul 2023 09:28:22 +0200 Subject: [PATCH] feat(lua): Add `tab:is_selected` function to check if the tab is the currently selected one in the GUI. (#1763) --- docs/lua/classes/tab.md | 12 +++++++++++- src/lua/bindings/gui.cpp | 14 ++++++++++---- src/lua/bindings/gui.hpp | 8 +++++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/docs/lua/classes/tab.md b/docs/lua/classes/tab.md index be2af18f..89b7b3ff 100644 --- a/docs/lua/classes/tab.md +++ b/docs/lua/classes/tab.md @@ -2,7 +2,17 @@ Class for representing a tab within the GUI. -## Functions (11) +## Functions (12) + +### `is_selected()` + +- **Returns:** + - `boolean`: Returns true if this tab is the currently selected one in the GUI. + +**Example Usage:** +```lua +boolean = tab:is_selected() +``` ### `clear()` diff --git a/src/lua/bindings/gui.cpp b/src/lua/bindings/gui.cpp index 5158e73b..77aba6b6 100644 --- a/src/lua/bindings/gui.cpp +++ b/src/lua/bindings/gui.cpp @@ -115,6 +115,11 @@ namespace lua::gui module->m_owned_tabs.push_back(id()); } + bool tab::is_selected(sol::this_state state) + { + return big::g_gui_service->get_selected()->hash == m_tab_hash; + } + void tab::clear(sol::this_state state) { auto module = sol::state_view(state)["!this"].get(); @@ -318,10 +323,10 @@ namespace lua::gui text_ut["set_text"] = &lua::gui::text::set_text; text_ut["set_font"] = &lua::gui::text::set_font; - auto checkbox_ut = ns.new_usertype("checkbox"); - checkbox_ut["get_text"] = &lua::gui::checkbox::get_text; - checkbox_ut["set_text"] = &lua::gui::checkbox::set_text; - checkbox_ut["is_enabled"] = &lua::gui::checkbox::is_enabled; + auto checkbox_ut = ns.new_usertype("checkbox"); + checkbox_ut["get_text"] = &lua::gui::checkbox::get_text; + checkbox_ut["set_text"] = &lua::gui::checkbox::set_text; + checkbox_ut["is_enabled"] = &lua::gui::checkbox::is_enabled; checkbox_ut["set_enabled"] = &lua::gui::checkbox::set_enabled; ns.new_usertype("sameline"); @@ -346,6 +351,7 @@ namespace lua::gui input_string_ut["set_value"] = &lua::gui::input_string::set_value; auto tab_ut = ns.new_usertype("tab"); + tab_ut["is_selected"] = &tab::is_selected; tab_ut["clear"] = &tab::clear; tab_ut["add_tab"] = &tab::add_tab; tab_ut["add_button"] = &tab::add_button; diff --git a/src/lua/bindings/gui.hpp b/src/lua/bindings/gui.hpp index d383f11e..805c14ba 100644 --- a/src/lua/bindings/gui.hpp +++ b/src/lua/bindings/gui.hpp @@ -35,6 +35,12 @@ namespace lua::gui tab(const std::string& name, const rage::joaat_t parent_tab_hash, const sol::this_state& state); + // Lua API: Function + // Class: tab + // Name: is_selected + // Returns: boolean: Returns true if this tab is the one currently selected in the GUI. + bool is_selected(sol::this_state state); + // Lua API: Function // Class: tab // Name: clear @@ -123,7 +129,7 @@ namespace lua::gui // -- call natives in there // end) // end - // + // // ImGui.End() // end // end)