Skip to content

Commit

Permalink
Lua: Add imgui.begin/end_disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Apr 3, 2024
1 parent 7a7c912 commit e38c236
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mods/ScriptRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ void ScriptState::on_frame() {
ScriptRunner::get()->spew_error("Unknown error in on_frame");
}

api::imgui::cleanup();
api::imnodes::cleanup();
}

Expand Down
30 changes: 30 additions & 0 deletions src/mods/bindings/ImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
#include "ImGui.hpp"

namespace api::imgui {
int32_t g_disabled_counts{0};

void cleanup() {
for (auto i = 0; i < g_disabled_counts; ++i) {
ImGui::EndDisabled();
}

g_disabled_counts = 0;
}

ImVec2 create_imvec2(sol::object obj) {
ImVec2 out{ 0.0f, 0.0f };

Expand Down Expand Up @@ -495,6 +505,24 @@ void end_rect(sol::object additional_size_obj, sol::object rounding_obj) {
ImGui::GetWindowDrawList()->AddRect(mins, maxs, ImGui::GetColorU32(ImGuiCol_Border), ImGui::GetStyle().FrameRounding, ImDrawCornerFlags_All, 1.0f);
}

void begin_disabled(sol::object disabled_obj) {
bool disabled{true};

if (disabled_obj.is<bool>()) {
disabled = disabled_obj.as<bool>();
}

++g_disabled_counts;
ImGui::BeginDisabled(disabled);
}

void end_disabled() {
if (g_disabled_counts > 0) {
--g_disabled_counts;
ImGui::EndDisabled();
}
}

void separator() {
ImGui::Separator();
}
Expand Down Expand Up @@ -1962,6 +1990,8 @@ void bindings::open_imgui(ScriptState* s) {
imgui["end_group"] = api::imgui::end_group;
imgui["begin_rect"] = api::imgui::begin_rect;
imgui["end_rect"] = api::imgui::end_rect;
imgui["begin_disabled"] = api::imgui::begin_disabled;
imgui["end_disabled"] = api::imgui::end_disabled;
imgui["separator"] = api::imgui::separator;
imgui["spacing"] = api::imgui::spacing;
imgui["new_line"] = api::imgui::new_line;
Expand Down
4 changes: 4 additions & 0 deletions src/mods/bindings/ImGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace bindings {
void open_imgui(ScriptState* s);
}

namespace api::imgui {
void cleanup();
}

namespace api::imnodes {
// pop the active nodes/editors/attributes etc so we dont crash.
void cleanup();
Expand Down

0 comments on commit e38c236

Please sign in to comment.