mirror of
https://github.com/xemu-project/imgui.git
synced 2024-11-23 10:19:46 +00:00
Internals: RenderCollapseTriangle() -> RenderTriangle(), takes a ImGuiDir
This commit is contained in:
parent
a03093b2d4
commit
370a48c10b
48
imgui.cpp
48
imgui.cpp
@ -3058,31 +3058,39 @@ void ImGui::RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding)
|
||||
}
|
||||
|
||||
// Render a triangle to denote expanded/collapsed state
|
||||
void ImGui::RenderCollapseTriangle(ImVec2 p_min, bool is_open, float scale)
|
||||
void ImGui::RenderTriangle(ImVec2 p_min, ImGuiDir dir, float scale)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
|
||||
const float h = g.FontSize * 1.00f;
|
||||
const float r = h * 0.40f * scale;
|
||||
ImVec2 center = p_min + ImVec2(h*0.50f, h*0.50f*scale);
|
||||
float r = h * 0.40f * scale;
|
||||
ImVec2 center = p_min + ImVec2(h * 0.50f, h * 0.50f * scale);
|
||||
|
||||
ImVec2 a, b, c;
|
||||
if (is_open)
|
||||
switch (dir)
|
||||
{
|
||||
center.y -= r*0.25f;
|
||||
a = center + ImVec2(0,1)*r;
|
||||
b = center + ImVec2(-0.866f,-0.5f)*r;
|
||||
c = center + ImVec2(0.866f,-0.5f)*r;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = center + ImVec2(1,0)*r;
|
||||
b = center + ImVec2(-0.500f,0.866f)*r;
|
||||
c = center + ImVec2(-0.500f,-0.866f)*r;
|
||||
case ImGuiDir_Up:
|
||||
r = -r; // ...fall through, no break!
|
||||
case ImGuiDir_Down:
|
||||
center.y -= r * 0.25f;
|
||||
a = ImVec2(0,1) * r;
|
||||
b = ImVec2(-0.866f,-0.5f) * r;
|
||||
c = ImVec2(+0.866f,-0.5f) * r;
|
||||
break;
|
||||
case ImGuiDir_Left:
|
||||
r = -r; // ...fall through, no break!
|
||||
case ImGuiDir_Right:
|
||||
a = ImVec2(1,0) * r;
|
||||
b = ImVec2(-0.500f,+0.866f) * r;
|
||||
c = ImVec2(-0.500f,-0.866f) * r;
|
||||
break;
|
||||
default:
|
||||
IM_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
|
||||
window->DrawList->AddTriangleFilled(a, b, c, GetColorU32(ImGuiCol_Text));
|
||||
window->DrawList->AddTriangleFilled(center + a, center + b, center + c, GetColorU32(ImGuiCol_Text));
|
||||
}
|
||||
|
||||
void ImGui::RenderBullet(ImVec2 pos)
|
||||
@ -4486,7 +4494,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
||||
// Collapse button
|
||||
if (!(flags & ImGuiWindowFlags_NoCollapse))
|
||||
{
|
||||
RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f);
|
||||
RenderTriangle(window->Pos + style.FramePadding, window->Collapsed ? ImGuiDir_Right : ImGuiDir_Down, 1.0f);
|
||||
}
|
||||
|
||||
// Close button
|
||||
@ -6211,7 +6219,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
|
||||
{
|
||||
// Framed type
|
||||
RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
|
||||
RenderCollapseTriangle(bb.Min + ImVec2(padding.x, text_base_offset_y), is_open, 1.0f);
|
||||
RenderTriangle(bb.Min + ImVec2(padding.x, text_base_offset_y), is_open ? ImGuiDir_Down : ImGuiDir_Right, 1.0f);
|
||||
if (g.LogEnabled)
|
||||
{
|
||||
// NB: '##' is normally used to hide text (as a library-wide feature), so we need to specify the text range to make sure the ## aren't stripped out here.
|
||||
@ -6235,7 +6243,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l
|
||||
if (flags & ImGuiTreeNodeFlags_Bullet)
|
||||
RenderBullet(bb.Min + ImVec2(text_offset_x * 0.5f, g.FontSize*0.50f + text_base_offset_y));
|
||||
else if (!(flags & ImGuiTreeNodeFlags_Leaf))
|
||||
RenderCollapseTriangle(bb.Min + ImVec2(padding.x, g.FontSize*0.15f + text_base_offset_y), is_open, 0.70f);
|
||||
RenderTriangle(bb.Min + ImVec2(padding.x, g.FontSize*0.15f + text_base_offset_y), is_open ? ImGuiDir_Down : ImGuiDir_Right, 0.70f);
|
||||
if (g.LogEnabled)
|
||||
LogRenderedText(&text_pos, ">");
|
||||
RenderText(text_pos, label, label_end, false);
|
||||
@ -8714,7 +8722,7 @@ bool ImGui::BeginCombo(const char* label, const char* preview_value, ImVec2 popu
|
||||
const ImRect value_bb(frame_bb.Min, frame_bb.Max - ImVec2(arrow_size, 0.0f));
|
||||
RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
|
||||
RenderFrame(ImVec2(frame_bb.Max.x-arrow_size, frame_bb.Min.y), frame_bb.Max, GetColorU32(popup_open || hovered ? ImGuiCol_ButtonHovered : ImGuiCol_Button), true, style.FrameRounding); // FIXME-ROUNDING
|
||||
RenderCollapseTriangle(ImVec2(frame_bb.Max.x - arrow_size + style.FramePadding.y, frame_bb.Min.y + style.FramePadding.y), true);
|
||||
RenderTriangle(ImVec2(frame_bb.Max.x - arrow_size + style.FramePadding.y, frame_bb.Min.y + style.FramePadding.y), ImGuiDir_Down);
|
||||
|
||||
if (preview_value != NULL)
|
||||
RenderTextClipped(frame_bb.Min + style.FramePadding, value_bb.Max, preview_value, NULL, NULL, ImVec2(0.0f,0.0f));
|
||||
@ -9134,7 +9142,7 @@ bool ImGui::BeginMenu(const char* label, bool enabled)
|
||||
float extra_w = ImMax(0.0f, GetContentRegionAvail().x - w);
|
||||
pressed = Selectable(label, menu_is_open, ImGuiSelectableFlags_Menu | ImGuiSelectableFlags_DontClosePopups | ImGuiSelectableFlags_DrawFillAvailWidth | (!enabled ? ImGuiSelectableFlags_Disabled : 0), ImVec2(w, 0.0f));
|
||||
if (!enabled) PushStyleColor(ImGuiCol_Text, g.Style.Colors[ImGuiCol_TextDisabled]);
|
||||
RenderCollapseTriangle(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * 0.20f, 0.0f), false);
|
||||
RenderTriangle(pos + ImVec2(window->MenuColumns.Pos[2] + extra_w + g.FontSize * 0.20f, 0.0f), ImGuiDir_Right);
|
||||
if (!enabled) PopStyleColor();
|
||||
}
|
||||
|
||||
|
@ -823,7 +823,7 @@ namespace ImGui
|
||||
IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
|
||||
IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f);
|
||||
IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, int rounding_corners_flags = ~0);
|
||||
IMGUI_API void RenderCollapseTriangle(ImVec2 pos, bool is_open, float scale = 1.0f);
|
||||
IMGUI_API void RenderTriangle(ImVec2 pos, ImGuiDir dir, float scale = 1.0f);
|
||||
IMGUI_API void RenderBullet(ImVec2 pos);
|
||||
IMGUI_API void RenderCheckMark(ImVec2 pos, ImU32 col, float sz);
|
||||
IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding);
|
||||
|
Loading…
Reference in New Issue
Block a user