diff --git a/imgui.cpp b/imgui.cpp index b30ff4d..c3f9c0e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -495,8 +495,9 @@ struct ImGuiIniData; struct ImGuiState; struct ImGuiWindow; +typedef int ImGuiButtonFlags; // enum ImGuiButtonFlags_ -static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat = false, bool pressed_on_click = false); +static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, ImGuiButtonFlags flags = 0); static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); @@ -932,6 +933,12 @@ //----------------------------------------------------------------------------- +enum ImGuiButtonFlags_ +{ + ImGuiButtonFlags_Repeat = (1 << 0), + ImGuiButtonFlags_PressedOnClick = (1 << 1) +}; + struct ImGuiColMod // Color modifier, backup of modified data so we can restore it { ImGuiCol Col; @@ -4546,13 +4553,13 @@ return false; } -static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, bool repeat, bool pressed_on_click) +static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, ImGuiButtonFlags flags) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); - const bool hovered = IsHovered(bb, id); bool pressed = false; + const bool hovered = IsHovered(bb, id); if (hovered) { g.HoveredId = id; @@ -4560,7 +4567,7 @@ { if (g.IO.MouseClicked[0]) { - if (pressed_on_click) + if (flags & ImGuiButtonFlags_PressedOnClick) { pressed = true; SetActiveId(0); @@ -4571,7 +4578,7 @@ } FocusWindow(window); } - else if (repeat && g.ActiveId && ImGui::IsMouseClicked(0, true)) + else if ((flags & ImGuiButtonFlags_Repeat) && g.ActiveId == id && ImGui::IsMouseClicked(0, true)) { pressed = true; } @@ -4617,7 +4624,7 @@ return false; bool hovered, held; - bool pressed = ButtonBehavior(bb, id, &hovered, &held, true, repeat_when_held); + bool pressed = ButtonBehavior(bb, id, &hovered, &held, true, repeat_when_held ? ImGuiButtonFlags_Repeat : 0); // Render const ImU32 col = window->Color((hovered && held) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button); @@ -7093,7 +7100,7 @@ return false; bool hovered, held; - bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, true, false, false); + bool pressed = ButtonBehavior(bb_with_spacing, id, &hovered, &held, true); // Render if (hovered || selected)