ImGuiToolkit to render a Disabled Button

This commit is contained in:
Bruno Herbelin
2023-01-29 10:54:57 +01:00
parent 3e6ddf560a
commit 48f1df2fd6
2 changed files with 28 additions and 0 deletions

View File

@@ -72,6 +72,33 @@ bool ImGuiToolkit::ButtonToggle( const char* label, bool* toggle, const char *to
return action;
}
void ImGuiToolkit::ButtonDisabled(const char* label, const ImVec2 &size_arg)
{
ImGuiWindow* window = ImGui::GetCurrentWindow();
if (window->SkipItems)
return;
ImGuiContext& g = *GImGui;
const ImGuiStyle& style = g.Style;
const ImGuiID id = window->GetID(label);
const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
ImVec2 pos = window->DC.CursorPos;
ImVec2 size = ImGui::CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
const ImRect bb(pos, pos + size);
ImGui::ItemSize(size, style.FramePadding.y);
if (!ImGui::ItemAdd(bb, id))
return;
// Render
const ImU32 col = ImGui::GetColorU32(ImGuiCol_FrameBg);
ImGui::RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetColorU32(ImGuiCol_TextDisabled));
ImGui::RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, style.ButtonTextAlign, &bb);
ImGui::PopStyleColor(1);
}
bool ImGuiToolkit::ButtonSwitch(const char* label, bool* toggle, const char* shortcut)
{

View File

@@ -35,6 +35,7 @@ namespace ImGuiToolkit
bool ButtonToggle (const char* label, bool* toggle, const char *tooltip = nullptr);
bool ButtonSwitch (const char* label, bool* toggle, const char *shortcut = nullptr);
void ButtonOpenUrl (const char* label, const char* url, const ImVec2& size_arg = ImVec2(0,0));
void ButtonDisabled(const char* label, const ImVec2& size_arg = ImVec2(0,0));
// tooltip and mouse over help
void setToolTipsEnabled (bool on);