Skip to content

Commit

Permalink
ImDrawFlags: rework/revert c2d6d26 + 39432bf in a way that is closer …
Browse files Browse the repository at this point in the history
…to old version and back to opt-in but with default 0 = all corners.
  • Loading branch information
ocornut committed Mar 12, 2021
1 parent fdc2324 commit 033dfd9
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 113 deletions.
39 changes: 20 additions & 19 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,29 @@ HOW TO UPDATE?
Breaking Changes:

- Removed redirecting functions/enums names that were marked obsolete in 1.66 (September 2018):
- ImGui::SetScrollHere() --> use ImGui::SetScrollHereY()
- ImGui::SetScrollHere() --> use ImGui::SetScrollHereY()
- ImDrawList: upgraded AddPolyline()/PathStroke()'s "bool closed" parameter to use "ImDrawFlags flags".
- bool closed = false --> use ImDrawFlags_None, or 0
- bool closed = true --> use ImDrawFlags_Closed
The matching ImDrawFlags_Closed value is guaranteed to always stay == 1 in the future.
- bool closed = false --> use ImDrawFlags_None, or 0
- bool closed = true --> use ImDrawFlags_Closed
Difference may not be noticeable for most but zealous type-checking tools may report a need to change.
- ImDrawList: upgraded AddRect(), AddRectFilled(), PathRect() to use general ImDrawFlags instead of ImDrawCornersFlags.
The old ImDrawCornersFlags used an awkward default value of ~0 or 0xF (4 lower bits set) to signify "round all
corners". We still support old flags, but note that the new named flags are opt-out instead of opt-in. [@rokups]
- AddRect(..., rounding, ImDrawCornerFlags_TopLeft) --> AddRect(..., ImDrawFlags_NoRoundCorners ^ ImDrawFlags_NoRoundCornerTL)
- Flags now sanely default to 0 instead of defaulting to ~0 or ImDrawCornerFlags_All, consistent with everywhere else.
- In practice, this shouldn't have an effect as those flags were rarely used.
- All meaningful old uses are supported:
- Default flags will behave the same.
- Use of old named flags will behave the same (but will be obsoleted later)
- Use of hardcoded ~0 or 0xF, previously suggested as a convenience, will behave the same (but will be obsoleted later).
- Not supported:
- Use of hardcoded values between 0x01 and 0x0E not using named flags are NOT supported (will assert).
- Use of new ImDrawFlags together with ImDrawCornerFlags in the same call (will assert).
- Use of rounding > 0.0f along old flags explicitely set as hardcoded 0 would have previously overidden the
rounding value back into "no rounding", whereas it will now behave as "round all corners".
This is technically the only real breaking change which we can't solve automatically.
- ImDrawList: upgraded AddRect(), AddRectFilled(), PathRect() to use ImDrawFlags instead of ImDrawCornersFlags.
- ImDrawCornerFlags_TopLeft --> use ImDrawFlags_RoundCornersTopLeft
- ImDrawCornerFlags_BotRight --> use ImDrawFlags_RoundCornersBottomRight
- ImDrawCornerFlags_None --> use ImDrawFlags_RoundCornersNone etc.
Flags now sanely defaults to 0 instead of 0x0F, consistent with all other flags in the API.
IMPORTANT: The default with rounding > 0.0f is now "round all corners" vs old implicit "round no corners":
- rounding == 0.0f + flags == 0 --> meant no rounding --> unchanged (common use)
- rounding > 0.0f + flags != 0 --> meant rounding --> unchanged (common use)
- rounding == 0.0f + flags != 0 --> meant no rounding --> unchanged (unlikely use)
- rounding > 0.0f + flags == 0 --> meant no rounding --> BREAKING (unlikely use)!
- this ONLY matters for hardcoded use of 0 with rounding > 0.0f.
- fix by using named ImDrawFlags_RoundCornersNone or rounding == 0.0f!
- this is technically the only real breaking change which we can't solve automatically (it's also uncommon).
The old ImDrawCornersFlags used awkward default values of ~0 or 0xF (4 lower bits set) to signify "round all corners"
and we sometimes encouraged using them as shortcuts. As a result the legacy path still support use of hardcoded ~0
or any value from 0x1 or 0xF. They will behave the same with legacy paths enabled (will assert otherwise).
Courtesy of legacy untangling commity: [@rokups, @ocornut, @thedmd]
- ImDrawList: clarified that PathArcTo()/PathArcToFast() won't render with radius < 0.0f. Previously it sorts
of accidentally worked but would lead to counter-clockwise paths which and have an effect on anti-aliasing.
- Moved 'misc/natvis/imgui.natvis' to 'misc/debuggers/imgui.natvis' as we will provide scripts for other debuggers.
Expand Down
31 changes: 16 additions & 15 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,19 @@ CODE
When you are not sure about a 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.

- 2021/03/11 (1.82) - upgraded ImDrawList::AddRect(), AddRectFilled(), PathRect() to use general ImDrawFlags instead of ImDrawCornersFlags.
the old ImDrawCornersFlags used an awkward default value of ~0 or 0xF (4 lower bits set) to signify "round all corners". We still support old flags, but note that the new named flags are opt-out instead of opt-in!
- AddRect(..., rounding, ImDrawCornerFlags_TopLeft) --> AddRect(..., ImDrawFlags_NoRoundCorners ^ ImDrawFlags_NoRoundCornerTL)
flags now sanely defaults to 0 instead of defaulting to ~0 or ImDrawCornerFlags_All, consistent with everywhere else in the codebase.
in practice, this shouldn't have an effect as those flags were rarely used. all meaningful old uses are supported:
- default flags will behave the same.
- use of old named flags will behave the same (but will be obsoleted later).
- use of hardcoded ~0 or 0xF, previously suggested as a convenience, will behave the same (but will be obsoleted later).
not supported:
- use of hardcoded values between 0x01 and 0x0E not using named flags are NOT supported (will assert).
- use of new ImDrawFlags together with ImDrawCornerFlags in the same call (will assert).
- use of rounding > 0.0f along old flags explicitely set as hard coded 0 would have previously overidden the rounding value back into "no rounding", whereas it will now behave as "round all corners". This is technically the only real breaking change which we can't solve automatically.
- 2021/03/12 (1.82) - upgraded ImDrawList::AddRect(), AddRectFilled(), PathRect() to use ImDrawFlags instead of ImDrawCornersFlags.
- ImDrawCornerFlags_TopLeft -> use ImDrawFlags_RoundCornersTopLeft
- ImDrawCornerFlags_BotRight -> use ImDrawFlags_RoundCornersBottomRight
- ImDrawCornerFlags_None -> use ImDrawFlags_RoundCornersNone etc.
flags now sanely defaults to 0 instead of 0x0F, consistent with all other flags in the API.
breaking: the default with rounding > 0.0f is now "round all corners" vs old implicit "round no corners":
- rounding == 0.0f + flags == 0 --> meant no rounding --> unchanged (common use)
- rounding > 0.0f + flags != 0 --> meant rounding --> unchanged (common use)
- rounding == 0.0f + flags != 0 --> meant no rounding --> unchanged (unlikely use)
- rounding > 0.0f + flags == 0 --> meant no rounding --> BREAKING (unlikely use): will now round all corners --> use ImDrawFlags_RoundCornersNone or rounding == 0.0f.
this ONLY matters for hard coded use of 0 + rounding > 0.0f. Use of named ImDrawFlags_RoundCornersNone (new) or ImDrawCornerFlags_None (old) are ok.
the old ImDrawCornersFlags used awkward default values of ~0 or 0xF (4 lower bits set) to signify "round all corners" and we sometimes encouraged using them as shortcuts.
legacy path still support use of hard coded ~0 or any value from 0x1 or 0xF. They will behave the same with legacy paths enabled (will assert otherwise).
- 2021/03/11 (1.82) - removed redirecting functions/enums names that were marked obsolete in 1.66 (September 2018):
- ImGui::SetScrollHere() -> use ImGui::SetScrollHereY()
- 2021/03/11 (1.82) - clarified that ImDrawList::PathArcTo(), ImDrawList::PathArcToFast() won't render with radius < 0.0f. Previously it sorts of accidentally worked but would generally lead to counter-clockwise paths and have an effect on anti-aliasing.
Expand Down Expand Up @@ -5516,22 +5517,22 @@ void ImGui::RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar
}
if (override_alpha)
bg_col = (bg_col & ~IM_COL32_A_MASK) | (IM_F32_TO_INT8_SAT(alpha) << IM_COL32_A_SHIFT);
window->DrawList->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? 0 : ImDrawFlags_NoRoundCornerT);
window->DrawList->AddRectFilled(window->Pos + ImVec2(0, window->TitleBarHeight()), window->Pos + window->Size, bg_col, window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? 0 : ImDrawFlags_RoundCornersBottom);
}

// Title bar
if (!(flags & ImGuiWindowFlags_NoTitleBar))
{
ImU32 title_bar_col = GetColorU32(title_bar_is_highlight ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg);
window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, window_rounding, ImDrawFlags_NoRoundCornerB);
window->DrawList->AddRectFilled(title_bar_rect.Min, title_bar_rect.Max, title_bar_col, window_rounding, ImDrawFlags_RoundCornersTop);
}

// Menu bar
if (flags & ImGuiWindowFlags_MenuBar)
{
ImRect menu_bar_rect = window->MenuBarRect();
menu_bar_rect.ClipWith(window->Rect()); // Soft clipping, in particular child window don't have minimum size covering the menu bar so this is useful for them.
window->DrawList->AddRectFilled(menu_bar_rect.Min + ImVec2(window_border_size, 0), menu_bar_rect.Max - ImVec2(window_border_size, 0), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawFlags_NoRoundCornerB);
window->DrawList->AddRectFilled(menu_bar_rect.Min + ImVec2(window_border_size, 0), menu_bar_rect.Max - ImVec2(window_border_size, 0), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImDrawFlags_RoundCornersTop);
if (style.FrameBorderSize > 0.0f && menu_bar_rect.Max.y < window->Pos.y + window->Size.y)
window->DrawList->AddLine(menu_bar_rect.GetBL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_Border), style.FrameBorderSize);
}
Expand Down
39 changes: 19 additions & 20 deletions imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -2278,24 +2278,23 @@ struct ImDrawListSplitter
};

// Flags for ImDrawList functions
// (Before version 1.82: functions like AddRect(), AddRectFilled(), AddImageRounded(), PathRect() used ImDrawCornerFlags,
// we have moved those in 1.82 to ImDrawList but using opposite "opt-out" logic instead of "opt-in" logic:
// Old: ImDrawCornerFlags_BotLeft New: ImDrawFlags_NoRoundCornerBL
// The old enums are defined under ImDrawCornerFlags_ in the "Obsolete functions and types" section of this header)
// (Legacy: bit 0 must always correspond to ImDrawFlags_Closed to be backward compatible with old API using a bool. Bits 1..3 must b unused)
// (Legacy: bit 0 must always correspond to ImDrawFlags_Closed to be backward compatible with old API using a bool. Bits 1..3 must be unused)
enum ImDrawFlags_
{
ImDrawFlags_None = 0,
ImDrawFlags_Closed = 1 << 0, // PathStroke(), AddPolyline(): specify that shape should be closed (Important: this is always == 1 for legacy reason)
ImDrawFlags_NoRoundCornerTL = 1 << 4, // AddRect(), AddRectFilled(), PathRect(): disable rounding top-left corner when rounding > 0.0f
ImDrawFlags_NoRoundCornerTR = 1 << 5, // AddRect(), AddRectFilled(), PathRect(): disable rounding top-right corner when rounding > 0.0f
ImDrawFlags_NoRoundCornerBL = 1 << 6, // AddRect(), AddRectFilled(), PathRect(): disable rounding bottom-left corner when rounding > 0.0f
ImDrawFlags_NoRoundCornerBR = 1 << 7, // AddRect(), AddRectFilled(), PathRect(): disable rounding bottom-right corner when rounding > 0.0f
ImDrawFlags_NoRoundCornerT = ImDrawFlags_NoRoundCornerTL | ImDrawFlags_NoRoundCornerTR,
ImDrawFlags_NoRoundCornerR = ImDrawFlags_NoRoundCornerTR | ImDrawFlags_NoRoundCornerBR,
ImDrawFlags_NoRoundCornerL = ImDrawFlags_NoRoundCornerTL | ImDrawFlags_NoRoundCornerBL,
ImDrawFlags_NoRoundCornerB = ImDrawFlags_NoRoundCornerBL | ImDrawFlags_NoRoundCornerBR,
ImDrawFlags_NoRoundCorners = ImDrawFlags_NoRoundCornerTL | ImDrawFlags_NoRoundCornerTR | ImDrawFlags_NoRoundCornerBL | ImDrawFlags_NoRoundCornerBR
ImDrawFlags_RoundCornersTopLeft = 1 << 4, // AddRect(), AddRectFilled(), PathRect(): enable rounding top-left corner only (when rounding > 0.0f, we default to all corners). Was 0x01.
ImDrawFlags_RoundCornersTopRight = 1 << 5, // AddRect(), AddRectFilled(), PathRect(): enable rounding top-right corner only (when rounding > 0.0f, we default to all corners). Was 0x02.
ImDrawFlags_RoundCornersBottomLeft = 1 << 6, // AddRect(), AddRectFilled(), PathRect(): enable rounding bottom-left corner only (when rounding > 0.0f, we default to all corners). Was 0x04.
ImDrawFlags_RoundCornersBottomRight = 1 << 7, // AddRect(), AddRectFilled(), PathRect(): enable rounding bottom-right corner only (when rounding > 0.0f, we default to all corners). Wax 0x08.
ImDrawFlags_RoundCornersNone = 1 << 8, // AddRect(), AddRectFilled(), PathRect(): disable rounding on all corners (when rounding > 0.0f). This is NOT zero, NOT an implicit flag!
ImDrawFlags_RoundCornersTop = ImDrawFlags_RoundCornersTopLeft | ImDrawFlags_RoundCornersTopRight,
ImDrawFlags_RoundCornersBottom = ImDrawFlags_RoundCornersBottomLeft | ImDrawFlags_RoundCornersBottomRight,
ImDrawFlags_RoundCornersLeft = ImDrawFlags_RoundCornersBottomLeft | ImDrawFlags_RoundCornersTopLeft,
ImDrawFlags_RoundCornersRight = ImDrawFlags_RoundCornersBottomRight | ImDrawFlags_RoundCornersTopRight,
ImDrawFlags_RoundCornersAll = ImDrawFlags_RoundCornersTopLeft | ImDrawFlags_RoundCornersTopRight | ImDrawFlags_RoundCornersBottomLeft | ImDrawFlags_RoundCornersBottomRight,
ImDrawFlags_RoundCornersDefault_ = ImDrawFlags_RoundCornersAll, // Default to ALL corners if none of the _RoundCornersXX flags are specified.
ImDrawFlags_RoundCornersMask_ = ImDrawFlags_RoundCornersAll | ImDrawFlags_RoundCornersNone
};

// Flags for ImDrawList instance. Those are set automatically by ImGui:: functions from ImGuiIO settings, and generally not manipulated directly.
Expand Down Expand Up @@ -2792,12 +2791,12 @@ namespace ImGui
typedef ImDrawFlags ImDrawCornerFlags;
enum ImDrawCornerFlags_
{
ImDrawCornerFlags_None = ImDrawFlags_NoRoundCorners,
ImDrawCornerFlags_TopLeft = 1 << 24, // Was (1 << 0) prior to 1.82. Order matches ImDrawFlags_NoRoundCorner* flag (we exploit this internally).
ImDrawCornerFlags_TopRight = 1 << 25, // Was (1 << 1) prior to 1.82.
ImDrawCornerFlags_BotLeft = 1 << 26, // Was (1 << 2) prior to 1.82.
ImDrawCornerFlags_BotRight = 1 << 27, // Was (1 << 3) prior to 1.82.
ImDrawCornerFlags_All = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight | ImDrawCornerFlags_BotLeft | ImDrawCornerFlags_BotRight, // Was (0x0F) prior to 1.82
ImDrawCornerFlags_None = ImDrawFlags_RoundCornersNone, // Was == 0 prior to 1.82, this is now == ImDrawFlags_RoundCornersNone which is != 0 and not implicit
ImDrawCornerFlags_TopLeft = ImDrawFlags_RoundCornersTopLeft, // Was == 0x01 (1 << 0) prior to 1.82. Order matches ImDrawFlags_NoRoundCorner* flag (we exploit this internally).
ImDrawCornerFlags_TopRight = ImDrawFlags_RoundCornersTopRight, // Was == 0x02 (1 << 1) prior to 1.82.
ImDrawCornerFlags_BotLeft = ImDrawFlags_RoundCornersBottomLeft, // Was == 0x04 (1 << 2) prior to 1.82.
ImDrawCornerFlags_BotRight = ImDrawFlags_RoundCornersBottomRight, // Was == 0x08 (1 << 3) prior to 1.82.
ImDrawCornerFlags_All = ImDrawFlags_RoundCornersAll, // Was == 0x0F prior to 1.82
ImDrawCornerFlags_Top = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_TopRight,
ImDrawCornerFlags_Bot = ImDrawCornerFlags_BotLeft | ImDrawCornerFlags_BotRight,
ImDrawCornerFlags_Left = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotLeft,
Expand Down
2 changes: 1 addition & 1 deletion imgui_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7205,7 +7205,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
const ImVec2 p = ImGui::GetCursorScreenPos();
const ImU32 col = ImColor(colf);
const float spacing = 10.0f;
const ImDrawFlags corners_tl_br = ImDrawFlags_NoRoundCornerTR | ImDrawFlags_NoRoundCornerBL;
const ImDrawFlags corners_tl_br = ImDrawFlags_RoundCornersTopLeft | ImDrawFlags_RoundCornersBottomRight;
const float rounding = sz / 5.0f;
const int circle_segments = circle_segments_override ? circle_segments_override_v : 0;
const int curve_segments = curve_segments_override ? curve_segments_override_v : 0;
Expand Down
Loading

0 comments on commit 033dfd9

Please sign in to comment.