WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit d1e262a

Browse files
committed
Internals: refactor RenderRectFilledRangeH() into RenderRectFilledInRangeH() to take absolute coordinates instead of normalized ones.
Amend 01d4bf2 (#1296)
1 parent 6e0ee6f commit d1e262a

File tree

5 files changed

+21
-17
lines changed

5 files changed

+21
-17
lines changed

imgui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,7 @@ enum ImGuiSliderFlags_
19271927
ImGuiSliderFlags_ClampZeroRange = 1 << 10, // Clamp even if min==max==0.0f. Otherwise due to legacy reason DragXXX functions don't clamp with those values. When your clamping limits are dynamic you almost always want to use it.
19281928
ImGuiSliderFlags_NoSpeedTweaks = 1 << 11, // Disable keyboard modifiers altering tweak speed. Useful if you want to alter tweak speed yourself based on your own logic.
19291929
ImGuiSliderFlags_AlwaysClamp = ImGuiSliderFlags_ClampOnInput | ImGuiSliderFlags_ClampZeroRange,
1930-
ImGuiSliderFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed.
1930+
ImGuiSliderFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from legacy API (obsoleted 2020-08) that has got miscast to this enum, and will trigger an assert if needed.
19311931
};
19321932

19331933
// Identify a mouse button.

imgui_demo.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2045,20 +2045,21 @@ static void DemoWindowWidgetsProgressBars()
20452045
if (ImGui::TreeNode("Progress Bars"))
20462046
{
20472047
// Animate a simple progress bar
2048-
static float progress = 0.0f, progress_dir = 1.0f;
2049-
progress += progress_dir * 0.4f * ImGui::GetIO().DeltaTime;
2050-
if (progress >= +1.1f) { progress = +1.1f; progress_dir *= -1.0f; }
2051-
if (progress <= -0.1f) { progress = -0.1f; progress_dir *= -1.0f; }
2048+
static float progress_accum = 0.0f, progress_dir = 1.0f;
2049+
progress_accum += progress_dir * 0.4f * ImGui::GetIO().DeltaTime;
2050+
if (progress_accum >= +1.1f) { progress_accum = +1.1f; progress_dir *= -1.0f; }
2051+
if (progress_accum <= -0.1f) { progress_accum = -0.1f; progress_dir *= -1.0f; }
2052+
2053+
const float progress = IM_CLAMP(progress_accum, 0.0f, 1.0f);
20522054

20532055
// Typically we would use ImVec2(-1.0f,0.0f) or ImVec2(-FLT_MIN,0.0f) to use all available width,
20542056
// or ImVec2(width,0.0f) for a specified width. ImVec2(0.0f,0.0f) uses ItemWidth.
20552057
ImGui::ProgressBar(progress, ImVec2(0.0f, 0.0f));
20562058
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
20572059
ImGui::Text("Progress Bar");
20582060

2059-
float progress_saturated = IM_CLAMP(progress, 0.0f, 1.0f);
20602061
char buf[32];
2061-
sprintf(buf, "%d/%d", (int)(progress_saturated * 1753), 1753);
2062+
sprintf(buf, "%d/%d", (int)(progress * 1753), 1753);
20622063
ImGui::ProgressBar(progress, ImVec2(0.f, 0.f), buf);
20632064

20642065
// Pass an animated negative value, e.g. -1.0f * (float)ImGui::GetTime() is the recommended value.

imgui_draw.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5830,7 +5830,7 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, const ImVec2& pos, Im
58305830
// - RenderBullet()
58315831
// - RenderCheckMark()
58325832
// - RenderArrowPointingAt()
5833-
// - RenderRectFilledRangeH()
5833+
// - RenderRectFilledInRangeH()
58345834
// - RenderRectFilledWithHole()
58355835
//-----------------------------------------------------------------------------
58365836
// Function in need of a redesign (legacy mess)
@@ -5913,15 +5913,15 @@ static inline float ImAcos01(float x)
59135913
}
59145914

59155915
// FIXME: Cleanup and move code to ImDrawList.
5916-
void ImGui::RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding)
5916+
// - Before 2025-12-04: RenderRectFilledRangeH() with 'float x_start_norm, float x_end_norm` <- normalized
5917+
// - After 2025-12-04: RenderRectFilledInRangeH() with 'float x1, float x2' <- absolute coords!!
5918+
void ImGui::RenderRectFilledInRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x1, float x2, float rounding)
59175919
{
5918-
if (x_end_norm == x_start_norm)
5920+
if (x1 == x2)
59195921
return;
5920-
if (x_start_norm > x_end_norm)
5921-
ImSwap(x_start_norm, x_end_norm);
59225922

5923-
ImVec2 p0 = ImVec2(ImLerp(rect.Min.x, rect.Max.x, x_start_norm), rect.Min.y);
5924-
ImVec2 p1 = ImVec2(ImLerp(rect.Min.x, rect.Max.x, x_end_norm), rect.Max.y);
5923+
ImVec2 p0 = ImVec2(x1, rect.Min.y);
5924+
ImVec2 p1 = ImVec2(x2, rect.Max.y);
59255925
if (rounding == 0.0f)
59265926
{
59275927
draw_list->AddRectFilled(p0, p1, col, 0.0f);

imgui_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3587,7 +3587,7 @@ namespace ImGui
35873587
IMGUI_API void RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col);
35883588
IMGUI_API void RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz);
35893589
IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col);
3590-
IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding);
3590+
IMGUI_API void RenderRectFilledInRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x1, float x2, float rounding);
35913591
IMGUI_API void RenderRectFilledWithHole(ImDrawList* draw_list, const ImRect& outer, const ImRect& inner, ImU32 col, float rounding);
35923592

35933593
// Widgets: Text

imgui_widgets.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,10 @@ void ImGui::ProgressBar(float fraction, const ImVec2& size_arg, const char* over
14401440
// Render
14411441
RenderFrame(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
14421442
bb.Expand(ImVec2(-style.FrameBorderSize, -style.FrameBorderSize));
1443-
RenderRectFilledRangeH(window->DrawList, bb, GetColorU32(ImGuiCol_PlotHistogram), fill_n0, fill_n1, style.FrameRounding);
1443+
float fill_x0 = ImLerp(bb.Min.x, bb.Max.x, fill_n0);
1444+
float fill_x1 = ImLerp(bb.Min.x, bb.Max.x, fill_n1);
1445+
if (fill_x0 < fill_x1)
1446+
RenderRectFilledInRangeH(window->DrawList, bb, GetColorU32(ImGuiCol_PlotHistogram), fill_x0, fill_x1, style.FrameRounding);
14441447

14451448
// Default displaying the fraction as percentage string, but user can override it
14461449
// Don't display text for indeterminate bars by default
@@ -1456,7 +1459,7 @@ void ImGui::ProgressBar(float fraction, const ImVec2& size_arg, const char* over
14561459
ImVec2 overlay_size = CalcTextSize(overlay, NULL);
14571460
if (overlay_size.x > 0.0f)
14581461
{
1459-
float text_x = is_indeterminate ? (bb.Min.x + bb.Max.x - overlay_size.x) * 0.5f : ImLerp(bb.Min.x, bb.Max.x, fill_n1) + style.ItemSpacing.x;
1462+
float text_x = is_indeterminate ? (bb.Min.x + bb.Max.x - overlay_size.x) * 0.5f : fill_x1 + style.ItemSpacing.x;
14601463
RenderTextClipped(ImVec2(ImClamp(text_x, bb.Min.x, bb.Max.x - overlay_size.x - style.ItemInnerSpacing.x), bb.Min.y), bb.Max, overlay, NULL, &overlay_size, ImVec2(0.0f, 0.5f), &bb);
14611464
}
14621465
}

0 commit comments

Comments
 (0)