Internal RenderTextClipped() merged optional/rate clip_min* clip_max* into clip_rect*
This commit is contained in:
parent
02cea0c3c3
commit
de9f8944ea
20
imgui.cpp
20
imgui.cpp
@ -2866,8 +2866,9 @@ void ImGui::RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end
|
||||
}
|
||||
}
|
||||
|
||||
// Default clip_rect uses (pos_min,pos_max)
|
||||
// Handle clipping on CPU immediately (vs typically let the GPU clip the triangles that are overlapping the clipping rectangle edges)
|
||||
void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align, const ImVec2* clip_min, const ImVec2* clip_max)
|
||||
void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align, const ImRect* clip_rect)
|
||||
{
|
||||
// Hide anything after a '##' string
|
||||
const char* text_display_end = FindRenderedTextEnd(text, text_end);
|
||||
@ -2882,11 +2883,13 @@ void ImGui::RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, cons
|
||||
ImVec2 pos = pos_min;
|
||||
const ImVec2 text_size = text_size_if_known ? *text_size_if_known : CalcTextSize(text, text_display_end, false, 0.0f);
|
||||
|
||||
if (!clip_max) clip_max = &pos_max;
|
||||
const ImVec2* clip_min = clip_rect ? &clip_rect->Min : &pos_min;
|
||||
const ImVec2* clip_max = clip_rect ? &clip_rect->Max : &pos_max;
|
||||
bool need_clipping = (pos.x + text_size.x >= clip_max->x) || (pos.y + text_size.y >= clip_max->y);
|
||||
if (!clip_min) clip_min = &pos_min; else need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y);
|
||||
if (clip_rect) // If we had no explicit clipping rectangle then pos==clip_min
|
||||
need_clipping |= (pos.x < clip_min->x) || (pos.y < clip_min->y);
|
||||
|
||||
// Align
|
||||
// Align whole block (we should defer that to the better rendering function)
|
||||
if (align & ImGuiAlign_Center) pos.x = ImMax(pos.x, (pos.x + pos_max.x - text_size.x) * 0.5f);
|
||||
else if (align & ImGuiAlign_Right) pos.x = ImMax(pos.x, pos_max.x - text_size.x);
|
||||
if (align & ImGuiAlign_VCenter) pos.y = ImMax(pos.y, (pos.y + pos_max.y - text_size.y) * 0.5f);
|
||||
@ -4306,14 +4309,15 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
||||
|
||||
ImVec2 text_min = window->Pos + style.FramePadding;
|
||||
ImVec2 text_max = window->Pos + ImVec2(window->Size.x - style.FramePadding.x, style.FramePadding.y*2 + text_size.y);
|
||||
ImVec2 clip_max = ImVec2(window->Pos.x + window->Size.x - (p_open ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x), text_max.y); // Match the size of CloseWindowButton()
|
||||
ImRect clip_rect;
|
||||
clip_rect.Max = ImVec2(window->Pos.x + window->Size.x - (p_open ? title_bar_rect.GetHeight() - 3 : style.FramePadding.x), text_max.y); // Match the size of CloseWindowButton()
|
||||
bool pad_left = (flags & ImGuiWindowFlags_NoCollapse) == 0;
|
||||
bool pad_right = (p_open != NULL);
|
||||
if (style.WindowTitleAlign & ImGuiAlign_Center) pad_right = pad_left;
|
||||
if (pad_left) text_min.x += g.FontSize + style.ItemInnerSpacing.x;
|
||||
if (pad_right) text_max.x -= g.FontSize + style.ItemInnerSpacing.x;
|
||||
ImVec2 clip_min = ImVec2(text_min.x, window->Pos.y);
|
||||
RenderTextClipped(text_min, text_max, name, NULL, &text_size, style.WindowTitleAlign, &clip_min, &clip_max);
|
||||
clip_rect.Min = ImVec2(text_min.x, window->Pos.y);
|
||||
RenderTextClipped(text_min, text_max, name, NULL, &text_size, style.WindowTitleAlign, &clip_rect);
|
||||
}
|
||||
|
||||
// Save clipped aabb so we can access it in constant-time in FindHoveredWindow()
|
||||
@ -7222,7 +7226,7 @@ void ImGui::ProgressBar(float fraction, const ImVec2& size_arg, const char* over
|
||||
|
||||
ImVec2 overlay_size = CalcTextSize(overlay, NULL);
|
||||
if (overlay_size.x > 0.0f)
|
||||
RenderTextClipped(ImVec2(ImClamp(fill_br.x + style.ItemSpacing.x, bb.Min.x, bb.Max.x - overlay_size.x - style.ItemInnerSpacing.x), bb.Min.y), bb.Max, overlay, NULL, &overlay_size, ImGuiAlign_Left|ImGuiAlign_VCenter, &bb.Min, &bb.Max);
|
||||
RenderTextClipped(ImVec2(ImClamp(fill_br.x + style.ItemSpacing.x, bb.Min.x, bb.Max.x - overlay_size.x - style.ItemInnerSpacing.x), bb.Min.y), bb.Max, overlay, NULL, &overlay_size, ImGuiAlign_Left|ImGuiAlign_VCenter, &bb);
|
||||
}
|
||||
|
||||
bool ImGui::Checkbox(const char* label, bool* v)
|
||||
|
@ -714,7 +714,7 @@ namespace ImGui
|
||||
// We need: a sort of symbol library, preferably baked into font atlas when possible + decent text rendering helpers.
|
||||
IMGUI_API void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true);
|
||||
IMGUI_API void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width);
|
||||
IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align = ImGuiAlign_Default, const ImVec2* clip_min = NULL, const ImVec2* clip_max = NULL);
|
||||
IMGUI_API void RenderTextClipped(const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, ImGuiAlign align = ImGuiAlign_Default, const ImRect* clip_rect = NULL);
|
||||
IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
|
||||
IMGUI_API void RenderCollapseTriangle(ImVec2 pos, bool is_open, float scale = 1.0f, bool shadow = false);
|
||||
IMGUI_API void RenderBullet(ImVec2 pos);
|
||||
|
Loading…
Reference in New Issue
Block a user