Skip to content

Commit

Permalink
Buttons: using ImGuiItemFlags_ButtonRepeat makes default button behav…
Browse files Browse the repository at this point in the history
…ior use PressedOnClick instead of PressedOnClickRelease when unspecified.
  • Loading branch information
ocornut committed Oct 29, 2024
1 parent 0bde57c commit 9a0dff1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ Other changes:

- Selectable: selected Selectables use ImGuiCol_Header instead of an arbitrary lerp
between _Header and _HeaderHovered which was introduced v1.91 (#8106, #1861)
- Buttons: using ImGuiItemFlags_ButtonRepeat makes default button behavior use
PressedOnClick instead of PressedOnClickRelease when unspecified.
- Fonts: removed const qualifiers from most font functions.
- Backends: DX12: Unmap() call specify written range. The range is informational and
may be used by debug tools.
Expand Down
2 changes: 1 addition & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// Library Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
#define IMGUI_VERSION "1.91.5 WIP"
#define IMGUI_VERSION_NUM 19141
#define IMGUI_VERSION_NUM 19142
#define IMGUI_HAS_TABLE

/*
Expand Down
14 changes: 7 additions & 7 deletions imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,19 +495,19 @@ bool ImGui::ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();

// Default behavior inherited from item flags
// Note that _both_ ButtonFlags and ItemFlags are valid sources, so copy one into the item_flags and only check that.
ImGuiItemFlags item_flags = (g.LastItemData.ID == id ? g.LastItemData.ItemFlags : g.CurrentItemFlags);
if (flags & ImGuiButtonFlags_AllowOverlap)
item_flags |= ImGuiItemFlags_AllowOverlap;

// Default only reacts to left mouse button
if ((flags & ImGuiButtonFlags_MouseButtonMask_) == 0)
flags |= ImGuiButtonFlags_MouseButtonLeft;

// Default behavior requires click + release inside bounding box
if ((flags & ImGuiButtonFlags_PressedOnMask_) == 0)
flags |= ImGuiButtonFlags_PressedOnDefault_;

// Default behavior inherited from item flags
// Note that _both_ ButtonFlags and ItemFlags are valid sources, so copy one into the item_flags and only check that.
ImGuiItemFlags item_flags = (g.LastItemData.ID == id ? g.LastItemData.ItemFlags : g.CurrentItemFlags);
if (flags & ImGuiButtonFlags_AllowOverlap)
item_flags |= ImGuiItemFlags_AllowOverlap;
flags |= (item_flags & ImGuiItemFlags_ButtonRepeat) ? ImGuiButtonFlags_PressedOnClick : ImGuiButtonFlags_PressedOnDefault_;

ImGuiWindow* backup_hovered_window = g.HoveredWindow;
const bool flatten_hovered_children = (flags & ImGuiButtonFlags_FlattenChildren) && g.HoveredWindow && g.HoveredWindow->RootWindow == window;
Expand Down

0 comments on commit 9a0dff1

Please sign in to comment.