From e2fb954d99087f80cb7c895f10286c1999ec28b2 Mon Sep 17 00:00:00 2001 From: Malkierian Date: Wed, 29 May 2024 04:33:55 -0700 Subject: [PATCH] Disabled checkbox fix (#498) * Prevent style change and toggle when disabled. * Fix performance issues for disabled elements being drawn. * Move `BeginDisabled` to after visible window check to avoid potential mismatch issues. --- mm/2s2h/BenGui/UIWidgets.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/mm/2s2h/BenGui/UIWidgets.cpp b/mm/2s2h/BenGui/UIWidgets.cpp index 8b6ef9225..c50aceae7 100644 --- a/mm/2s2h/BenGui/UIWidgets.cpp +++ b/mm/2s2h/BenGui/UIWidgets.cpp @@ -180,6 +180,8 @@ bool Checkbox(const char* _label, bool* value, const CheckboxOptions& options) { if (window->SkipItems) return false; + ImGui::BeginDisabled(options.disabled); + bool above = options.labelPosition == LabelPosition::Above; bool lpFar = options.labelPosition == LabelPosition::Far; bool right = options.alignment == ComponentAlignment::Right; @@ -210,19 +212,15 @@ bool Checkbox(const char* _label, bool* value, const CheckboxOptions& options) { ImGui::ItemSize(total_bb, style.FramePadding.y); if (!ImGui::ItemAdd(total_bb, id)) { - IMGUI_TEST_ENGINE_ITEM_INFO(id, label, - g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | - (*value ? ImGuiItemStatusFlags_Checked : 0)); + ImGui::EndDisabled(); return false; } - - bool hovered, held; - bool pressed = ImGui::ButtonBehavior(total_bb, id, &hovered, &held); + bool hovered, held, pressed; + pressed = ImGui::ButtonBehavior(total_bb, id, &hovered, &held); if (pressed) { *value = !(*value); ImGui::MarkItemEdited(id); } - ImGui::BeginDisabled(options.disabled); PushStyleCheckbox(options.color); ImVec2 checkPos = pos; ImVec2 labelPos = pos;