|
|
@@ -294,7 +294,7 @@
|
|
|
Also make sure your orthographic projection matrix and io.DisplaySize matches your actual framebuffer dimension.
|
|
|
|
|
|
Q: I integrated ImGui in my engine and some elements are clipping or disappearing when I move windows around..
|
|
|
- A: Most likely you are mishandling the clipping rectangles in your render function. Rectangles provided by ImGui are defined as (x1,y1,x2,y2) and NOT as (x1,y1,width,height).
|
|
|
+ A: Most likely you are mishandling the clipping rectangles in your render function. Rectangles provided by ImGui are defined as (x1=left,y1=top,x2=right,y2=bottom) and NOT as (x1,y1,width,height).
|
|
|
|
|
|
Q: Can I have multiple widgets with the same label? Can I have widget without a label? (Yes)
|
|
|
A: Yes. A primer on the use of labels/IDs in ImGui..
|
|
|
@@ -2934,7 +2934,7 @@ void ImGui::RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border,
|
|
|
}
|
|
|
|
|
|
// Render a triangle to denote expanded/collapsed state
|
|
|
-void ImGui::RenderCollapseTriangle(ImVec2 p_min, bool is_open, float scale, bool shadow)
|
|
|
+void ImGui::RenderCollapseTriangle(ImVec2 p_min, bool is_open, float scale)
|
|
|
{
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
@@ -2958,8 +2958,6 @@ void ImGui::RenderCollapseTriangle(ImVec2 p_min, bool is_open, float scale, bool
|
|
|
c = center + ImVec2(-0.500f,-0.866f)*r;
|
|
|
}
|
|
|
|
|
|
- if (shadow && (window->Flags & ImGuiWindowFlags_ShowBorders) != 0)
|
|
|
- window->DrawList->AddTriangleFilled(a+ImVec2(2,2), b+ImVec2(2,2), c+ImVec2(2,2), GetColorU32(ImGuiCol_BorderShadow));
|
|
|
window->DrawList->AddTriangleFilled(a, b, c, GetColorU32(ImGuiCol_Text));
|
|
|
}
|
|
|
|
|
|
@@ -3495,11 +3493,11 @@ static bool BeginPopupEx(const char* str_id, ImGuiWindowFlags extra_flags)
|
|
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
|
|
|
ImGuiWindowFlags flags = extra_flags|ImGuiWindowFlags_Popup|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoMove|ImGuiWindowFlags_NoResize|ImGuiWindowFlags_NoSavedSettings|ImGuiWindowFlags_AlwaysAutoResize;
|
|
|
|
|
|
- char name[32];
|
|
|
+ char name[20];
|
|
|
if (flags & ImGuiWindowFlags_ChildMenu)
|
|
|
- ImFormatString(name, 20, "##menu_%d", g.CurrentPopupStack.Size); // Recycle windows based on depth
|
|
|
+ ImFormatString(name, IM_ARRAYSIZE(name), "##menu_%d", g.CurrentPopupStack.Size); // Recycle windows based on depth
|
|
|
else
|
|
|
- ImFormatString(name, 20, "##popup_%08x", id); // Not recycling, so we can close/open during the same frame
|
|
|
+ ImFormatString(name, IM_ARRAYSIZE(name), "##popup_%08x", id); // Not recycling, so we can close/open during the same frame
|
|
|
|
|
|
bool is_open = ImGui::Begin(name, NULL, flags);
|
|
|
if (!(window->Flags & ImGuiWindowFlags_ShowBorders))
|
|
|
@@ -4199,8 +4197,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
|
|
window->ScrollbarSizes = ImVec2(window->ScrollbarY ? style.ScrollbarSize : 0.0f, window->ScrollbarX ? style.ScrollbarSize : 0.0f);
|
|
|
window->BorderSize = (flags & ImGuiWindowFlags_ShowBorders) ? 1.0f : 0.0f;
|
|
|
|
|
|
- // Window background
|
|
|
- // Default alpha
|
|
|
+ // Window background, Default Alpha
|
|
|
ImGuiCol bg_color_idx = ImGuiCol_WindowBg;
|
|
|
if ((flags & ImGuiWindowFlags_ComboBox) != 0)
|
|
|
bg_color_idx = ImGuiCol_ComboBg;
|
|
|
@@ -4213,19 +4210,19 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
|
|
bg_color.w = bg_alpha;
|
|
|
bg_color.w *= style.Alpha;
|
|
|
if (bg_color.w > 0.0f)
|
|
|
- window->DrawList->AddRectFilled(window->Pos+ImVec2(0,window->TitleBarHeight()), window->Pos+window->Size, ColorConvertFloat4ToU32(bg_color), window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? 15 : 4|8);
|
|
|
+ window->DrawList->AddRectFilled(window->Pos+ImVec2(0,window->TitleBarHeight()), window->Pos+window->Size, ColorConvertFloat4ToU32(bg_color), window_rounding, (flags & ImGuiWindowFlags_NoTitleBar) ? ImGuiCorner_All : ImGuiCorner_BottomLeft|ImGuiCorner_BottomRight);
|
|
|
|
|
|
// Title bar
|
|
|
if (!(flags & ImGuiWindowFlags_NoTitleBar))
|
|
|
- window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), GetColorU32((g.FocusedWindow && window->RootNonPopupWindow == g.FocusedWindow->RootNonPopupWindow) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg), window_rounding, 1|2);
|
|
|
+ window->DrawList->AddRectFilled(title_bar_rect.GetTL(), title_bar_rect.GetBR(), GetColorU32((g.FocusedWindow && window->RootNonPopupWindow == g.FocusedWindow->RootNonPopupWindow) ? ImGuiCol_TitleBgActive : ImGuiCol_TitleBg), window_rounding, ImGuiCorner_TopLeft|ImGuiCorner_TopRight);
|
|
|
|
|
|
// Menu bar
|
|
|
if (flags & ImGuiWindowFlags_MenuBar)
|
|
|
{
|
|
|
ImRect menu_bar_rect = window->MenuBarRect();
|
|
|
- window->DrawList->AddRectFilled(menu_bar_rect.GetTL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, 1|2);
|
|
|
if (flags & ImGuiWindowFlags_ShowBorders)
|
|
|
- window->DrawList->AddLine(menu_bar_rect.GetBL()-ImVec2(0,0), menu_bar_rect.GetBR()-ImVec2(0,0), GetColorU32(ImGuiCol_Border));
|
|
|
+ window->DrawList->AddLine(menu_bar_rect.GetBL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_Border));
|
|
|
+ window->DrawList->AddRectFilled(menu_bar_rect.GetTL(), menu_bar_rect.GetBR(), GetColorU32(ImGuiCol_MenuBarBg), (flags & ImGuiWindowFlags_NoTitleBar) ? window_rounding : 0.0f, ImGuiCorner_TopLeft|ImGuiCorner_TopRight);
|
|
|
}
|
|
|
|
|
|
// Scrollbars
|
|
|
@@ -4317,7 +4314,7 @@ bool ImGui::Begin(const char* name, bool* p_open, const ImVec2& size_on_first_us
|
|
|
|
|
|
const ImVec2 text_size = CalcTextSize(name, NULL, true);
|
|
|
if (!(flags & ImGuiWindowFlags_NoCollapse))
|
|
|
- RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f, true);
|
|
|
+ RenderCollapseTriangle(window->Pos + style.FramePadding, !window->Collapsed, 1.0f);
|
|
|
|
|
|
ImVec2 text_min = window->Pos;
|
|
|
ImVec2 text_max = window->Pos + ImVec2(window->Size.x, style.FramePadding.y*2 + text_size.y);
|
|
|
@@ -4433,9 +4430,9 @@ static void Scrollbar(ImGuiWindow* window, bool horizontal)
|
|
|
float window_rounding = (window->Flags & ImGuiWindowFlags_ChildWindow) ? style.ChildWindowRounding : style.WindowRounding;
|
|
|
int window_rounding_corners;
|
|
|
if (horizontal)
|
|
|
- window_rounding_corners = 8 | (other_scrollbar ? 0 : 4);
|
|
|
+ window_rounding_corners = ImGuiCorner_BottomLeft | (other_scrollbar ? 0 : ImGuiCorner_BottomRight);
|
|
|
else
|
|
|
- window_rounding_corners = (((window->Flags & ImGuiWindowFlags_NoTitleBar) && !(window->Flags & ImGuiWindowFlags_MenuBar)) ? 2 : 0) | (other_scrollbar ? 0 : 4);
|
|
|
+ window_rounding_corners = (((window->Flags & ImGuiWindowFlags_NoTitleBar) && !(window->Flags & ImGuiWindowFlags_MenuBar)) ? ImGuiCorner_TopRight : 0) | (other_scrollbar ? 0 : ImGuiCorner_BottomRight);
|
|
|
window->DrawList->AddRectFilled(bb.Min, bb.Max, ImGui::GetColorU32(ImGuiCol_ScrollbarBg), window_rounding, window_rounding_corners);
|
|
|
bb.Reduce(ImVec2(ImClamp((float)(int)((bb.Max.x - bb.Min.x - 2.0f) * 0.5f), 0.0f, 3.0f), ImClamp((float)(int)((bb.Max.y - bb.Min.y - 2.0f) * 0.5f), 0.0f, 3.0f)));
|
|
|
|
|
|
@@ -5956,7 +5953,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 + padding + ImVec2(0.0f, text_base_offset_y), is_open, 1.0f, true);
|
|
|
+ RenderCollapseTriangle(bb.Min + padding + ImVec2(0.0f, text_base_offset_y), is_open, 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.
|
|
|
@@ -5980,7 +5977,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, false);
|
|
|
+ RenderCollapseTriangle(bb.Min + ImVec2(padding.x, g.FontSize*0.15f + text_base_offset_y), is_open, 0.70f);
|
|
|
if (g.LogEnabled)
|
|
|
LogRenderedText(text_pos, ">");
|
|
|
RenderText(text_pos, label, label_end, false);
|
|
|
@@ -7086,59 +7083,62 @@ void ImGui::PlotEx(ImGuiPlotType plot_type, const char* label, float (*values_ge
|
|
|
|
|
|
RenderFrame(frame_bb.Min, frame_bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding);
|
|
|
|
|
|
- int res_w = ImMin((int)graph_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
|
|
|
- int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
|
|
|
-
|
|
|
- // Tooltip on hover
|
|
|
- int v_hovered = -1;
|
|
|
- if (IsHovered(inner_bb, 0))
|
|
|
+ if (values_count > 0)
|
|
|
{
|
|
|
- const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f);
|
|
|
- const int v_idx = (int)(t * item_count);
|
|
|
- IM_ASSERT(v_idx >= 0 && v_idx < values_count);
|
|
|
-
|
|
|
- const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
|
|
|
- const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count);
|
|
|
- if (plot_type == ImGuiPlotType_Lines)
|
|
|
- SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1);
|
|
|
- else if (plot_type == ImGuiPlotType_Histogram)
|
|
|
- SetTooltip("%d: %8.4g", v_idx, v0);
|
|
|
- v_hovered = v_idx;
|
|
|
- }
|
|
|
+ int res_w = ImMin((int)graph_size.x, values_count) + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
|
|
|
+ int item_count = values_count + ((plot_type == ImGuiPlotType_Lines) ? -1 : 0);
|
|
|
|
|
|
- const float t_step = 1.0f / (float)res_w;
|
|
|
+ // Tooltip on hover
|
|
|
+ int v_hovered = -1;
|
|
|
+ if (IsHovered(inner_bb, 0))
|
|
|
+ {
|
|
|
+ const float t = ImClamp((g.IO.MousePos.x - inner_bb.Min.x) / (inner_bb.Max.x - inner_bb.Min.x), 0.0f, 0.9999f);
|
|
|
+ const int v_idx = (int)(t * item_count);
|
|
|
+ IM_ASSERT(v_idx >= 0 && v_idx < values_count);
|
|
|
+
|
|
|
+ const float v0 = values_getter(data, (v_idx + values_offset) % values_count);
|
|
|
+ const float v1 = values_getter(data, (v_idx + 1 + values_offset) % values_count);
|
|
|
+ if (plot_type == ImGuiPlotType_Lines)
|
|
|
+ SetTooltip("%d: %8.4g\n%d: %8.4g", v_idx, v0, v_idx+1, v1);
|
|
|
+ else if (plot_type == ImGuiPlotType_Histogram)
|
|
|
+ SetTooltip("%d: %8.4g", v_idx, v0);
|
|
|
+ v_hovered = v_idx;
|
|
|
+ }
|
|
|
|
|
|
- float v0 = values_getter(data, (0 + values_offset) % values_count);
|
|
|
- float t0 = 0.0f;
|
|
|
- ImVec2 tp0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) ); // Point in the normalized space of our target rectangle
|
|
|
+ const float t_step = 1.0f / (float)res_w;
|
|
|
|
|
|
- const ImU32 col_base = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram);
|
|
|
- const ImU32 col_hovered = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered);
|
|
|
+ float v0 = values_getter(data, (0 + values_offset) % values_count);
|
|
|
+ float t0 = 0.0f;
|
|
|
+ ImVec2 tp0 = ImVec2( t0, 1.0f - ImSaturate((v0 - scale_min) / (scale_max - scale_min)) ); // Point in the normalized space of our target rectangle
|
|
|
|
|
|
- for (int n = 0; n < res_w; n++)
|
|
|
- {
|
|
|
- const float t1 = t0 + t_step;
|
|
|
- const int v1_idx = (int)(t0 * item_count + 0.5f);
|
|
|
- IM_ASSERT(v1_idx >= 0 && v1_idx < values_count);
|
|
|
- const float v1 = values_getter(data, (v1_idx + values_offset + 1) % values_count);
|
|
|
- const ImVec2 tp1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );
|
|
|
+ const ImU32 col_base = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLines : ImGuiCol_PlotHistogram);
|
|
|
+ const ImU32 col_hovered = GetColorU32((plot_type == ImGuiPlotType_Lines) ? ImGuiCol_PlotLinesHovered : ImGuiCol_PlotHistogramHovered);
|
|
|
|
|
|
- // NB: Draw calls are merged together by the DrawList system. Still, we should render our batch are lower level to save a bit of CPU.
|
|
|
- ImVec2 pos0 = ImLerp(inner_bb.Min, inner_bb.Max, tp0);
|
|
|
- ImVec2 pos1 = ImLerp(inner_bb.Min, inner_bb.Max, (plot_type == ImGuiPlotType_Lines) ? tp1 : ImVec2(tp1.x, 1.0f));
|
|
|
- if (plot_type == ImGuiPlotType_Lines)
|
|
|
- {
|
|
|
- window->DrawList->AddLine(pos0, pos1, v_hovered == v1_idx ? col_hovered : col_base);
|
|
|
- }
|
|
|
- else if (plot_type == ImGuiPlotType_Histogram)
|
|
|
+ for (int n = 0; n < res_w; n++)
|
|
|
{
|
|
|
- if (pos1.x >= pos0.x + 2.0f)
|
|
|
- pos1.x -= 1.0f;
|
|
|
- window->DrawList->AddRectFilled(pos0, pos1, v_hovered == v1_idx ? col_hovered : col_base);
|
|
|
- }
|
|
|
+ const float t1 = t0 + t_step;
|
|
|
+ const int v1_idx = (int)(t0 * item_count + 0.5f);
|
|
|
+ IM_ASSERT(v1_idx >= 0 && v1_idx < values_count);
|
|
|
+ const float v1 = values_getter(data, (v1_idx + values_offset + 1) % values_count);
|
|
|
+ const ImVec2 tp1 = ImVec2( t1, 1.0f - ImSaturate((v1 - scale_min) / (scale_max - scale_min)) );
|
|
|
+
|
|
|
+ // NB: Draw calls are merged together by the DrawList system. Still, we should render our batch are lower level to save a bit of CPU.
|
|
|
+ ImVec2 pos0 = ImLerp(inner_bb.Min, inner_bb.Max, tp0);
|
|
|
+ ImVec2 pos1 = ImLerp(inner_bb.Min, inner_bb.Max, (plot_type == ImGuiPlotType_Lines) ? tp1 : ImVec2(tp1.x, 1.0f));
|
|
|
+ if (plot_type == ImGuiPlotType_Lines)
|
|
|
+ {
|
|
|
+ window->DrawList->AddLine(pos0, pos1, v_hovered == v1_idx ? col_hovered : col_base);
|
|
|
+ }
|
|
|
+ else if (plot_type == ImGuiPlotType_Histogram)
|
|
|
+ {
|
|
|
+ if (pos1.x >= pos0.x + 2.0f)
|
|
|
+ pos1.x -= 1.0f;
|
|
|
+ window->DrawList->AddRectFilled(pos0, pos1, v_hovered == v1_idx ? col_hovered : col_base);
|
|
|
+ }
|
|
|
|
|
|
- t0 = t1;
|
|
|
- tp0 = tp1;
|
|
|
+ t0 = t1;
|
|
|
+ tp0 = tp1;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Text overlay
|
|
|
@@ -8253,7 +8253,7 @@ bool ImGui::InputFloat(const char* label, float* v, float step, float step_fast,
|
|
|
if (decimal_precision < 0)
|
|
|
strcpy(display_format, "%f"); // Ideally we'd have a minimum decimal precision of 1 to visually denote that this is a float, while hiding non-significant digits? %f doesn't have a minimum of 1
|
|
|
else
|
|
|
- ImFormatString(display_format, 16, "%%.%df", decimal_precision);
|
|
|
+ ImFormatString(display_format, IM_ARRAYSIZE(display_format), "%%.%df", decimal_precision);
|
|
|
return InputScalarEx(label, ImGuiDataType_Float, (void*)v, (void*)(step>0.0f ? &step : NULL), (void*)(step_fast>0.0f ? &step_fast : NULL), display_format, extra_flags);
|
|
|
}
|
|
|
|
|
|
@@ -9098,8 +9098,8 @@ void ImGui::Separator()
|
|
|
if (!window->DC.GroupStack.empty())
|
|
|
x1 += window->DC.IndentX;
|
|
|
|
|
|
- const ImRect bb(ImVec2(x1, window->DC.CursorPos.y), ImVec2(x2, window->DC.CursorPos.y));
|
|
|
- ItemSize(ImVec2(0.0f, 0.0f)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit // FIXME: Height should be 1.0f not 0.0f ?
|
|
|
+ const ImRect bb(ImVec2(x1, window->DC.CursorPos.y), ImVec2(x2, window->DC.CursorPos.y+1.0f));
|
|
|
+ ItemSize(ImVec2(0.0f, 0.0f)); // NB: we don't provide our width so that it doesn't get feed back into AutoFit, we don't provide height to not alter layout.
|
|
|
if (!ItemAdd(bb, NULL))
|
|
|
{
|
|
|
if (window->DC.ColumnsCount > 1)
|
|
|
@@ -9107,7 +9107,7 @@ void ImGui::Separator()
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- window->DrawList->AddLine(bb.Min, bb.Max, GetColorU32(ImGuiCol_Border));
|
|
|
+ window->DrawList->AddLine(bb.Min, ImVec2(bb.Max.x,bb.Min.y), GetColorU32(ImGuiCol_Border));
|
|
|
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
if (g.LogEnabled)
|