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.
This commit is contained in:
Malkierian
2024-05-29 12:33:55 +01:00
committed by GitHub
parent 63def6f8df
commit e2fb954d99
+5 -7
View File
@@ -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;