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 e0ec69d8
.
This commit is contained in:
parent
0e95cf0dec
commit
4a2ae06ca4
@ -51,6 +51,15 @@ Breaking changes:
|
||||
semantic, but the additional indirection and copy added complexity and got in the way of other
|
||||
incoming work. User's code (other than backends) should not be affected, unless you have custom
|
||||
widgets intercepting navigation events via the named enums (in which case you can upgrade your code).
|
||||
- Changed signature of ImageButton() function: (#5533, #4471, #2464, #1390)
|
||||
- Added 'const char* str_id' parameter + removed 'int frame_padding = -1' parameter.
|
||||
- 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));
|
||||
- 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.
|
||||
- had a FramePadding override which was inconsistent with other functions and made the already-long signature even longer.
|
||||
- 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));
|
||||
- requires an explicit identifier. You may still use e.g. PushID() calls and then pass an empty identifier.
|
||||
- always uses style.FramePadding for padding, to be consistent with other buttons. You may use PushStyleVar() to alter this.
|
||||
- As always we are keeping a redirection function available (will obsolete later).
|
||||
|
||||
Other Changes:
|
||||
|
||||
@ -460,7 +469,7 @@ If you are stuck on ancient compiler you may need to stay at this version onward
|
||||
|
||||
Breaking Changes:
|
||||
|
||||
- Removed GetWindowContentRegionWidth() function. Keep inline redirection helper.
|
||||
- Removed GetWindowContentRegionWidth() function. Kept inline redirection helper.
|
||||
Can use 'GetWindowContentRegionMax().x - GetWindowContentRegionMin().x' instead but it's not
|
||||
very useful in practice, and the only use of it in the demo was illfit.
|
||||
Using 'GetContentRegionAvail().x' is generally a better choice.
|
||||
|
10
imgui.cpp
10
imgui.cpp
@ -384,7 +384,15 @@ CODE
|
||||
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.
|
||||
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
|
||||
|
||||
- 2022/07/08 (1.88) - inputs: removed io.NavInputs[] and ImGuiNavInput enum (following 1.87 changes).
|
||||
- 2022/08/03 (1.89) - changed signature of ImageButton() function. Kept redirection function (will obsolete).
|
||||
- added 'const char* str_id' parameter + removed 'int frame_padding = -1' parameter.
|
||||
- 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));
|
||||
- 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.
|
||||
- had a FramePadding override which was inconsistent with other functions and made the already-long signature even longer.
|
||||
- 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));
|
||||
- requires an explicit identifier. You may still use e.g. PushID() calls and then pass an empty identifier.
|
||||
- always uses style.FramePadding for padding, to be consistent with other buttons. You may use PushStyleVar() to alter this.
|
||||
- 2022/07/08 (1.89) - inputs: removed io.NavInputs[] and ImGuiNavInput enum (following 1.87 changes).
|
||||
- Official backends from 1.87+ -> no issue.
|
||||
- Official backends from 1.60 to 1.86 -> will build and convert gamepad inputs, unless IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Need updating!
|
||||
- Custom backends not writing to io.NavInputs[] -> no issue.
|
||||
|
11
imgui.h
11
imgui.h
@ -65,7 +65,7 @@ Index of this file:
|
||||
// Version
|
||||
// (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)
|
||||
#define IMGUI_VERSION "1.89 WIP"
|
||||
#define IMGUI_VERSION_NUM 18806
|
||||
#define IMGUI_VERSION_NUM 18807
|
||||
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
|
||||
#define IMGUI_HAS_TABLE
|
||||
|
||||
@ -493,8 +493,6 @@ namespace ImGui
|
||||
IMGUI_API bool SmallButton(const char* label); // button with FramePadding=(0,0) to easily embed within text
|
||||
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.)
|
||||
IMGUI_API bool ArrowButton(const char* str_id, ImGuiDir dir); // square button with an arrow shape
|
||||
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));
|
||||
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
|
||||
IMGUI_API bool Checkbox(const char* label, bool* v);
|
||||
IMGUI_API bool CheckboxFlags(const char* label, int* flags, int flags_value);
|
||||
IMGUI_API bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value);
|
||||
@ -503,6 +501,11 @@ namespace ImGui
|
||||
IMGUI_API void ProgressBar(float fraction, const ImVec2& size_arg = ImVec2(-FLT_MIN, 0), const char* overlay = NULL);
|
||||
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
|
||||
|
||||
// Widgets: Images
|
||||
// - Read about ImTextureID here: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples
|
||||
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));
|
||||
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));
|
||||
|
||||
// Widgets: Combo Box
|
||||
// - The BeginCombo()/EndCombo() api allows you to manage your contents and selection state however you want it, by creating e.g. Selectable() items.
|
||||
// - 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
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
namespace ImGui
|
||||
{
|
||||
// OBSOLETED in 1.89 (from August 2022)
|
||||
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)
|
||||
// OBSOLETED in 1.88 (from May 2022)
|
||||
static inline void CaptureKeyboardFromApp(bool want_capture_keyboard = true) { SetNextFrameWantCaptureKeyboard(want_capture_keyboard); } // Renamed as name was misleading + removed default value.
|
||||
static inline void CaptureMouseFromApp(bool want_capture_mouse = true) { SetNextFrameWantCaptureMouse(want_capture_mouse); } // Renamed as name was misleading + removed default value.
|
||||
|
@ -1063,15 +1063,21 @@ static void ShowDemoWindowWidgets()
|
||||
static int pressed_count = 0;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
// UV coordinates are often (0.0f, 0.0f) and (1.0f, 1.0f) to display an entire textures.
|
||||
// Here are trying to display only a 32x32 pixels area of the texture, hence the UV computation.
|
||||
// Read about UV coordinates here: https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples
|
||||
ImGui::PushID(i);
|
||||
int frame_padding = -1 + i; // -1 == uses default padding (style.FramePadding)
|
||||
ImVec2 size = ImVec2(32.0f, 32.0f); // Size of the image we want to make visible
|
||||
ImVec2 uv0 = ImVec2(0.0f, 0.0f); // UV coordinates for lower-left
|
||||
ImVec2 uv1 = ImVec2(32.0f / my_tex_w, 32.0f / my_tex_h);// UV coordinates for (32,32) in our texture
|
||||
ImVec4 bg_col = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); // Black background
|
||||
ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint
|
||||
if (ImGui::ImageButton(my_tex_id, size, uv0, uv1, frame_padding, bg_col, tint_col))
|
||||
if (i > 0)
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(i - 1.0f, i - 1.0f));
|
||||
ImVec2 size = ImVec2(32.0f, 32.0f); // Size of the image we want to make visible
|
||||
ImVec2 uv0 = ImVec2(0.0f, 0.0f); // UV coordinates for lower-left
|
||||
ImVec2 uv1 = ImVec2(32.0f / my_tex_w, 32.0f / my_tex_h); // UV coordinates for (32,32) in our texture
|
||||
ImVec4 bg_col = ImVec4(0.0f, 0.0f, 0.0f, 1.0f); // Black background
|
||||
ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); // No tint
|
||||
if (ImGui::ImageButton("", my_tex_id, size, uv0, uv1, bg_col, tint_col))
|
||||
pressed_count += 1;
|
||||
if (i > 0)
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopID();
|
||||
ImGui::SameLine();
|
||||
}
|
||||
|
@ -2833,7 +2833,7 @@ namespace ImGui
|
||||
IMGUI_API bool ArrowButtonEx(const char* str_id, ImGuiDir dir, ImVec2 size_arg, ImGuiButtonFlags flags = 0);
|
||||
IMGUI_API void Scrollbar(ImGuiAxis axis);
|
||||
IMGUI_API bool ScrollbarEx(const ImRect& bb, ImGuiID id, ImGuiAxis axis, ImS64* p_scroll_v, ImS64 avail_v, ImS64 contents_v, ImDrawFlags flags);
|
||||
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);
|
||||
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);
|
||||
IMGUI_API ImRect GetWindowScrollbarRect(ImGuiWindow* window, ImGuiAxis axis);
|
||||
IMGUI_API ImGuiID GetWindowScrollbarID(ImGuiWindow* window, ImGuiAxis axis);
|
||||
IMGUI_API ImGuiID GetWindowResizeCornerID(ImGuiWindow* window, int n); // 0..3: corners
|
||||
|
@ -1038,14 +1038,15 @@ void ImGui::Image(ImTextureID user_texture_id, const ImVec2& size, const ImVec2&
|
||||
|
||||
// ImageButton() is flawed as 'id' is always derived from 'texture_id' (see #2464 #1390)
|
||||
// We provide this internal helper to write your own variant while we figure out how to redesign the public ImageButton() API.
|
||||
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)
|
||||
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)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding * 2);
|
||||
const ImVec2 padding = g.Style.FramePadding;
|
||||
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size + padding * 2.0f);
|
||||
ItemSize(bb);
|
||||
if (!ItemAdd(bb, id))
|
||||
return false;
|
||||
@ -1064,9 +1065,21 @@ bool ImGui::ImageButtonEx(ImGuiID id, ImTextureID texture_id, const ImVec2& size
|
||||
return pressed;
|
||||
}
|
||||
|
||||
// frame_padding < 0: uses FramePadding from style (default)
|
||||
// frame_padding = 0: no framing
|
||||
// frame_padding > 0: set framing size
|
||||
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)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
return ImageButtonEx(window->GetID(str_id), user_texture_id, size, uv0, uv1, bg_col, tint_col);
|
||||
}
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
// Legacy API obsoleted in 1.89. Two differences with new ImageButton()
|
||||
// - 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)
|
||||
// - new ImageButton() always use style.FramePadding Old ImageButton() had an override argument.
|
||||
// If you need to change padding with new ImageButton() you can use PushStyleVar(ImGuiStyleVar_FramePadding, value), consistent with other Button functions.
|
||||
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)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -1079,9 +1092,14 @@ bool ImGui::ImageButton(ImTextureID user_texture_id, const ImVec2& size, const I
|
||||
const ImGuiID id = window->GetID("#image");
|
||||
PopID();
|
||||
|
||||
const ImVec2 padding = (frame_padding >= 0) ? ImVec2((float)frame_padding, (float)frame_padding) : g.Style.FramePadding;
|
||||
return ImageButtonEx(id, user_texture_id, size, uv0, uv1, padding, bg_col, tint_col);
|
||||
if (frame_padding >= 0)
|
||||
PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2((float)frame_padding, (float)frame_padding));
|
||||
bool ret = ImageButtonEx(id, user_texture_id, size, uv0, uv1, bg_col, tint_col);
|
||||
if (frame_padding >= 0)
|
||||
PopStyleVar();
|
||||
return ret;
|
||||
}
|
||||
#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
|
||||
bool ImGui::Checkbox(const char* label, bool* v)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user