Skip to content

Commit 4a2ae06

Browse files
committed
Changed signature of ImageButton() function: Added 'const char* str_id' parameter + removed 'int frame_padding = -1' parameter. (#5533, #4471, #2464, #1390).
Also removed frame_padding parameter from ImageButtonEx(), amend e0ec69d.
1 parent 0e95cf0 commit 4a2ae06

6 files changed

+66
-20
lines changed

docs/CHANGELOG.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ Breaking changes:
5151
semantic, but the additional indirection and copy added complexity and got in the way of other
5252
incoming work. User's code (other than backends) should not be affected, unless you have custom
5353
widgets intercepting navigation events via the named enums (in which case you can upgrade your code).
54+
- Changed signature of ImageButton() function: (#5533, #4471, #2464, #1390)
55+
- Added 'const char* str_id' parameter + removed 'int frame_padding = -1' parameter.
56+
- Old signature: bool ImageButton(ImTextureID tex_id, ImVec2 size, ImVec2 uv0 = ImVec2(0,0), ImVec2 uv1 = ImVec2(1,1), int frame_padding = -1, ImVec4 bg_col = ImVec4(0,0,0,0), ImVec4 tint_col = ImVec4(1,1,1,1));
57+
- used the ImTextureID value to create an ID. This was inconsistent with other functions, led to ID conflicts, and caused problems with engines using transient ImTextureID values.
58+
- had a FramePadding override which was inconsistent with other functions and made the already-long signature even longer.
59+
- New signature: bool ImageButton(const char* str_id, ImTextureID tex_id, ImVec2 size, ImVec2 uv0 = ImVec2(0,0), ImVec2 uv1 = ImVec2(1,1), ImVec4 bg_col = ImVec4(0,0,0,0), ImVec4 tint_col = ImVec4(1,1,1,1));
60+
- requires an explicit identifier. You may still use e.g. PushID() calls and then pass an empty identifier.
61+
- always uses style.FramePadding for padding, to be consistent with other buttons. You may use PushStyleVar() to alter this.
62+
- As always we are keeping a redirection function available (will obsolete later).
5463

5564
Other Changes:
5665

@@ -460,7 +469,7 @@ If you are stuck on ancient compiler you may need to stay at this version onward
460469

461470
Breaking Changes:
462471

463-
- Removed GetWindowContentRegionWidth() function. Keep inline redirection helper.
472+
- Removed GetWindowContentRegionWidth() function. Kept inline redirection helper.
464473
Can use 'GetWindowContentRegionMax().x - GetWindowContentRegionMin().x' instead but it's not
465474
very useful in practice, and the only use of it in the demo was illfit.
466475
Using 'GetContentRegionAvail().x' is generally a better choice.

imgui.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,15 @@ CODE
384384
When you are not sure about an old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
385385
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
386386

387-
- 2022/07/08 (1.88) - inputs: removed io.NavInputs[] and ImGuiNavInput enum (following 1.87 changes).
387+
- 2022/08/03 (1.89) - changed signature of ImageButton() function. Kept redirection function (will obsolete).
388+
- added 'const char* str_id' parameter + removed 'int frame_padding = -1' parameter.
389+
- old signature: bool ImageButton(ImTextureID tex_id, ImVec2 size, ImVec2 uv0 = ImVec2(0,0), ImVec2 uv1 = ImVec2(1,1), int frame_padding = -1, ImVec4 bg_col = ImVec4(0,0,0,0), ImVec4 tint_col = ImVec4(1,1,1,1));
390+
- used the ImTextureID value to create an ID. This was inconsistent with other functions, led to ID conflicts, and caused problems with engines using transient ImTextureID values.
391+
- had a FramePadding override which was inconsistent with other functions and made the already-long signature even longer.
392+
- new signature: bool ImageButton(const char* str_id, ImTextureID tex_id, ImVec2 size, ImVec2 uv0 = ImVec2(0,0), ImVec2 uv1 = ImVec2(1,1), ImVec4 bg_col = ImVec4(0,0,0,0), ImVec4 tint_col = ImVec4(1,1,1,1));
393+
- requires an explicit identifier. You may still use e.g. PushID() calls and then pass an empty identifier.
394+
- always uses style.FramePadding for padding, to be consistent with other buttons. You may use PushStyleVar() to alter this.
395+
- 2022/07/08 (1.89) - inputs: removed io.NavInputs[] and ImGuiNavInput enum (following 1.87 changes).
388396
- Official backends from 1.87+ -> no issue.
389397
- Official backends from 1.60 to 1.86 -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need updating!
390398
- Custom backends not writing to io.NavInputs[] -> no issue.

imgui.h

+8-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Index of this file:
6565
// Version
6666
// (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)
6767
#define IMGUI_VERSION "1.89 WIP"
68-
#define IMGUI_VERSION_NUM 18806
68+
#define IMGUI_VERSION_NUM 18807
6969
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
7070
#define IMGUI_HAS_TABLE
7171

@@ -493,8 +493,6 @@ namespace ImGui
493493
IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text
494494
IMGUI_API bool InvisibleButton(const char* str_id, const ImVec2& size, ImGuiButtonFlags flags = 0); // flexible button behavior without the visuals, frequently useful to build custom behaviors using the public api (along with IsItemActive, IsItemHovered, etc.)
495495
IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir); // square button with an arrow shape
496-
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), const ImVec4& tint_col = ImVec4(1,1,1,1), const ImVec4& border_col = ImVec4(0,0,0,0));
497-
IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1,1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0,0,0,0), const ImVec4& tint_col = ImVec4(1,1,1,1)); // <0 frame_padding uses default frame padding settings. 0 for no padding
498496
IMGUI_API bool Checkbox(const char* label, bool* v);
499497
IMGUI_API bool CheckboxFlags(const char* label, int* flags, int flags_value);
500498
IMGUI_API bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
@@ -503,6 +501,11 @@ namespace ImGui
503501
IMGUI_API void ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-FLT_MIN, 0), const char* overlay = NULL);
504502
IMGUI_API void Bullet(); // draw a small circle + keep the cursor on the same line. advance cursor x position by GetTreeNodeToLabelSpacing(), same distance that TreeNode() uses
505503

504+
// Widgets: Images
505+
// - Read about ImTextureID here: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples
506+
IMGUI_API void Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), const ImVec4& tint_col = ImVec4(1, 1, 1, 1), const ImVec4& border_col = ImVec4(0, 0, 0, 0));
507+
IMGUI_API bool ImageButton(const char* str_id, ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), const ImVec4& bg_col = ImVec4(0, 0, 0, 0), const ImVec4& tint_col = ImVec4(1, 1, 1, 1));
508+
506509
// Widgets: Combo Box
507510
// - The BeginCombo()/EndCombo() api allows you to manage your contents and selection state however you want it, by creating e.g. Selectable() items.
508511
// - The old Combo() api are helpers over BeginCombo()/EndCombo() which are kept available for convenience purpose. This is analogous to how ListBox are created.
@@ -2949,6 +2952,8 @@ namespace ImGui
29492952
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
29502953
namespace ImGui
29512954
{
2955+
// OBSOLETED in 1.89 (from August 2022)
2956+
IMGUI_API bool ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0 = ImVec2(0, 0), const ImVec2& uv1 = ImVec2(1, 1), int frame_padding = -1, const ImVec4& bg_col = ImVec4(0, 0, 0, 0), const ImVec4& tint_col = ImVec4(1, 1, 1, 1)); // Use new ImageButton() signature (explicit item id, regular FramePadding)
29522957
// OBSOLETED in 1.88 (from May 2022)
29532958
static inline void CaptureKeyboardFromApp(bool want_capture_keyboard = true) { SetNextFrameWantCaptureKeyboard(want_capture_keyboard); } // Renamed as name was misleading + removed default value.
29542959
static inline void CaptureMouseFromApp(bool want_capture_mouse = true) { SetNextFrameWantCaptureMouse(want_capture_mouse); } // Renamed as name was misleading + removed default value.

imgui_demo.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -1063,15 +1063,21 @@ static void ShowDemoWindowWidgets()
10631063
static int pressed_count = 0;
10641064
for (int i = 0; i < 8; i++)
10651065
{
1066+
// UV coordinates are often (0.0f, 0.0f) and (1.0f, 1.0f) to display an entire textures.
1067+
// Here are trying to display only a 32x32 pixels area of the texture, hence the UV computation.
1068+
// Read about UV coordinates here: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples
10661069
ImGui::PushID(i);
1067-
int frame_padding = -1 + i; // -1 == uses default padding (style.FramePadding)
1068-
ImVec2 size = ImVec2(32.0f, 32.0f); // Size of the image we want to make visible
1069-
ImVec2 uv0 = ImVec2(0.0f, 0.0f); // UV coordinates for lower-left
1070-
ImVec2 uv1 = ImVec2(32.0f / my_tex_w, 32.0f / my_tex_h);// UV coordinates for (32,32) in our texture
1071-
ImVec4 bg_col = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); // Black background
1072-
ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint
1073-
if (ImGui::ImageButton(my_tex_id, size, uv0, uv1, frame_padding, bg_col, tint_col))
1070+
if (i > 0)
1071+
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(i - 1.0f, i - 1.0f));
1072+
ImVec2 size = ImVec2(32.0f, 32.0f); // Size of the image we want to make visible
1073+
ImVec2 uv0 = ImVec2(0.0f, 0.0f); // UV coordinates for lower-left
1074+
ImVec2 uv1 = ImVec2(32.0f / my_tex_w, 32.0f / my_tex_h); // UV coordinates for (32,32) in our texture
1075+
ImVec4 bg_col = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); // Black background
1076+
ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint
1077+
if (ImGui::ImageButton("", my_tex_id, size, uv0, uv1, bg_col, tint_col))
10741078
pressed_count += 1;
1079+
if (i > 0)
1080+
ImGui::PopStyleVar();
10751081
ImGui::PopID();
10761082
ImGui::SameLine();
10771083
}

imgui_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2833,7 +2833,7 @@ namespace ImGui
28332833
IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags = 0);
28342834
IMGUI_API void Scrollbar(ImGuiAxis axis);
28352835
IMGUI_API bool ScrollbarEx(const ImRect& bb, ImGuiID id, ImGuiAxis axis, ImS64* p_scroll_v, ImS64 avail_v, ImS64 contents_v, ImDrawFlags flags);
2836-
IMGUI_API bool ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec2& padding, const ImVec4& bg_col, const ImVec4& tint_col);
2836+
IMGUI_API bool ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col);
28372837
IMGUI_API ImRect GetWindowScrollbarRect(ImGuiWindow* window, ImGuiAxis axis);
28382838
IMGUI_API ImGuiID GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis);
28392839
IMGUI_API ImGuiID GetWindowResizeCornerID(ImGuiWindow* window, int n); // 0..3: corners

imgui_widgets.cpp

+25-7
Original file line numberDiff line numberDiff line change
@@ -1038,14 +1038,15 @@ void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2&
10381038

10391039
// ImageButton() is flawed as 'id' is always derived from 'texture_id' (see #2464 #1390)
10401040
// We provide this internal helper to write your own variant while we figure out how to redesign the public ImageButton() API.
1041-
bool ImGui::ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec2& padding, const ImVec4& bg_col, const ImVec4& tint_col)
1041+
bool ImGui::ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col)
10421042
{
10431043
ImGuiContext& g = *GImGui;
10441044
ImGuiWindow* window = GetCurrentWindow();
10451045
if (window->SkipItems)
10461046
return false;
10471047

1048-
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding * 2);
1048+
const ImVec2 padding = g.Style.FramePadding;
1049+
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding * 2.0f);
10491050
ItemSize(bb);
10501051
if (!ItemAdd(bb, id))
10511052
return false;
@@ -1064,9 +1065,21 @@ bool ImGui::ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size
10641065
return pressed;
10651066
}
10661067

1067-
// frame_padding < 0: uses FramePadding from style (default)
1068-
// frame_padding = 0: no framing
1069-
// frame_padding > 0: set framing size
1068+
bool ImGui::ImageButton(const char* str_id, ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, const ImVec4& bg_col, const ImVec4& tint_col)
1069+
{
1070+
ImGuiContext& g = *GImGui;
1071+
ImGuiWindow* window = g.CurrentWindow;
1072+
if (window->SkipItems)
1073+
return false;
1074+
1075+
return ImageButtonEx(window->GetID(str_id), user_texture_id, size, uv0, uv1, bg_col, tint_col);
1076+
}
1077+
1078+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
1079+
// Legacy API obsoleted in 1.89. Two differences with new ImageButton()
1080+
// - new ImageButton() requires an explicit 'const char* str_id' Old ImageButton() used opaque imTextureId (created issue with: multiple buttons with same image, transient texture id values, opaque computation of ID)
1081+
// - new ImageButton() always use style.FramePadding Old ImageButton() had an override argument.
1082+
// If you need to change padding with new ImageButton() you can use PushStyleVar(ImGuiStyleVar_FramePadding, value), consistent with other Button functions.
10701083
bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const ImVec2& uv0, const ImVec2& uv1, int frame_padding, const ImVec4& bg_col, const ImVec4& tint_col)
10711084
{
10721085
ImGuiContext& g = *GImGui;
@@ -1079,9 +1092,14 @@ bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const I
10791092
const ImGuiID id = window->GetID("#image");
10801093
PopID();
10811094

1082-
const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : g.Style.FramePadding;
1083-
return ImageButtonEx(id, user_texture_id, size, uv0, uv1, padding, bg_col, tint_col);
1095+
if (frame_padding >= 0)
1096+
PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2((float)frame_padding, (float)frame_padding));
1097+
bool ret = ImageButtonEx(id, user_texture_id, size, uv0, uv1, bg_col, tint_col);
1098+
if (frame_padding >= 0)
1099+
PopStyleVar();
1100+
return ret;
10841101
}
1102+
#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
10851103

10861104
bool ImGui::Checkbox(const char* label, bool* v)
10871105
{

0 commit comments

Comments
 (0)