Skip to content

Commit

Permalink
Added PushDisabled(), PopDisabled() currently only exposed in imgui_i…
Browse files Browse the repository at this point in the history
…nternal.h (#211)
  • Loading branch information
ocornut committed Jun 9, 2021
1 parent a44d4da commit 865b2ca
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
22 changes: 22 additions & 0 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7178,6 +7178,28 @@ void ImGui::PopItemFlag()
g.CurrentItemFlags = g.ItemFlagsStack.back();
}

// PushDisabled()/PopDisabled()
// - Those are not yet exposed in imgui.h because we are unsure of how to alter the style in a way that works for everyone.
// We may rework this. Hypothetically, a future styling system may set a flag which make widgets use different colors.
// - Feedback welcome at https://github.com/ocornut/imgui/issues/211
// - You may trivially implement your own variation of this if needed.
// Here we test (CurrentItemFlags & ImGuiItemFlags_Disabled) to allow nested PushDisabled() calls.
void ImGui::PushDisabled()
{
ImGuiContext& g = *GImGui;
if ((g.CurrentItemFlags & ImGuiItemFlags_Disabled) == 0)
PushStyleVar(ImGuiStyleVar_Alpha, g.Style.Alpha * 0.6f);
PushItemFlag(ImGuiItemFlags_Disabled, true);
}

void ImGui::PopDisabled()
{
ImGuiContext& g = *GImGui;
PopItemFlag();
if ((g.CurrentItemFlags & ImGuiItemFlags_Disabled) == 0)
PopStyleVar();
}

// FIXME: Look into renaming this once we have settled the new Focus/Activation/TabStop system.
void ImGui::PushAllowKeyboardFocus(bool allow_keyboard_focus)
{
Expand Down
2 changes: 1 addition & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Index of this file:
// Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
#define IMGUI_VERSION "1.84 WIP"
#define IMGUI_VERSION_NUM 18305
#define IMGUI_VERSION_NUM 18306
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
#define IMGUI_HAS_TABLE
#define IMGUI_HAS_VIEWPORT // Viewport WIP branch
Expand Down
2 changes: 2 additions & 0 deletions imgui_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2604,6 +2604,8 @@ namespace ImGui
IMGUI_API void PushMultiItemsWidths(int components, float width_full);
IMGUI_API void PushItemFlag(ImGuiItemFlags option, bool enabled);
IMGUI_API void PopItemFlag();
IMGUI_API void PushDisabled();
IMGUI_API void PopDisabled();
IMGUI_API bool IsItemToggledSelection(); // Was the last item selection toggled? (after Selectable(), TreeNode() etc. We only returns toggle _event_ in order to handle clipping correctly)
IMGUI_API ImVec2 GetContentRegionMaxAbs();
IMGUI_API void ShrinkWidths(ImGuiShrinkWidthItem* items, int count, float width_excess);
Expand Down

0 comments on commit 865b2ca

Please sign in to comment.