Expose BeginDisabled()/EndDisabled() in public API. Add to demo. (#211)

This commit is contained in:
ocornut
2021-07-19 19:21:18 +02:00
parent cb00972b87
commit c543d93af1
6 changed files with 68 additions and 33 deletions

View File

@ -3439,7 +3439,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data
style.FramePadding.x = style.FramePadding.y;
ImGuiButtonFlags button_flags = ImGuiButtonFlags_Repeat | ImGuiButtonFlags_DontClosePopups;
if (flags & ImGuiInputTextFlags_ReadOnly)
PushDisabled(true);
BeginDisabled(true);
SameLine(0, style.ItemInnerSpacing.x);
if (ButtonEx("-", ImVec2(button_size, button_size), button_flags))
{
@ -3453,7 +3453,7 @@ bool ImGui::InputScalar(const char* label, ImGuiDataType data_type, void* p_data
value_changed = true;
}
if (flags & ImGuiInputTextFlags_ReadOnly)
PopDisabled();
EndDisabled();
const char* label_end = FindRenderedTextEnd(label);
if (label != label_end)
@ -6163,7 +6163,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
const bool disabled_global = (g.CurrentItemFlags & ImGuiItemFlags_Disabled) != 0;
if (disabled_item && !disabled_global) // Only testing this as an optimization
PushDisabled(true);
BeginDisabled(true);
// FIXME: We can standardize the behavior of those two, we could also keep the fast path of override ClipRect + full push on render only,
// which would be advantageous since most selectable are not selected.
@ -6236,7 +6236,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
CloseCurrentPopup();
if (disabled_item && !disabled_global)
PopDisabled();
EndDisabled();
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags);
return pressed;
@ -6828,7 +6828,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
ImVec2 popup_pos, pos = window->DC.CursorPos;
PushID(label);
if (!enabled)
PushDisabled();
BeginDisabled();
const ImGuiMenuColumns* offsets = &window->DC.MenuColumns;
if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
{
@ -6861,7 +6861,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
RenderArrow(window->DrawList, pos + ImVec2(offsets->OffsetMark + extra_w + g.FontSize * 0.30f, 0.0f), GetColorU32(ImGuiCol_Text), ImGuiDir_Right);
}
if (!enabled)
PopDisabled();
EndDisabled();
const bool hovered = (g.HoveredId == id) && enabled;
if (menuset_is_open)
@ -6994,7 +6994,7 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut
bool pressed;
PushID(label);
if (!enabled)
PushDisabled(true);
BeginDisabled(true);
const ImGuiSelectableFlags flags = ImGuiSelectableFlags_SelectOnRelease | ImGuiSelectableFlags_SetNavIdOnHover;
const ImGuiMenuColumns* offsets = &window->DC.MenuColumns;
if (window->DC.LayoutType == ImGuiLayoutType_Horizontal)
@ -7034,7 +7034,7 @@ bool ImGui::MenuItemEx(const char* label, const char* icon, const char* shortcut
}
IMGUI_TEST_ENGINE_ITEM_INFO(g.LastItemData.ID, label, g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Checkable | (selected ? ImGuiItemStatusFlags_Checked : 0));
if (!enabled)
PopDisabled();
EndDisabled();
PopID();
return pressed;