Skip to content

Commit

Permalink
ButtonBehavior: pull ImGuiButtonFlags_Repeat from ImGuiItemFlags_Butt…
Browse files Browse the repository at this point in the history
…onRepeat, matching ItemHoverable() logic. So more widgets can take advantage of Repeat logic.
  • Loading branch information
ocornut committed Jun 28, 2023
1 parent 51f564e commit 07e24b4
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
if ((flags & ImGuiButtonFlags_PressedOnMask_) == 0)
flags |= ImGuiButtonFlags_PressedOnDefault_;

// Default behavior inherited from item flags
const ImGuiItemFlags item_flags = (g.LastItemData.ID == id ? g.LastItemData.InFlags : g.CurrentItemFlags);
if (item_flags & ImGuiItemFlags_ButtonRepeat)
flags |= ImGuiButtonFlags_Repeat;

ImGuiWindow* backup_hovered_window = g.HoveredWindow;
const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredWindow && g.HoveredWindow->RootWindow == window;
if (flatten_hovered_children)
Expand Down Expand Up @@ -698,9 +703,6 @@ bool ImGui::ButtonEx(const char* label, const ImVec2& size_arg, ImGuiButtonFlags
if (!ItemAdd(bb, id))
return false;

if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat)
flags |= ImGuiButtonFlags_Repeat;

bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);

Expand Down Expand Up @@ -777,9 +779,6 @@ bool ImGui::ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size, ImGuiBu
if (!ItemAdd(bb, id))
return false;

if (g.LastItemData.InFlags & ImGuiItemFlags_ButtonRepeat)
flags |= ImGuiButtonFlags_Repeat;

bool hovered, held;
bool pressed = ButtonBehavior(bb, id, &hovered, &held, flags);

Expand Down

0 comments on commit 07e24b4

Please sign in to comment.