mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Update ImGui to 1.78 + docking.
This commit is contained in:
+297
-159
@@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.77
|
||||
// dear imgui, v1.78
|
||||
// (demo code)
|
||||
|
||||
// Help:
|
||||
@@ -243,6 +243,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
static bool show_app_main_menu_bar = false;
|
||||
static bool show_app_dockspace = false;
|
||||
static bool show_app_documents = false;
|
||||
|
||||
static bool show_app_console = false;
|
||||
static bool show_app_log = false;
|
||||
static bool show_app_layout = false;
|
||||
@@ -257,6 +258,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
if (show_app_main_menu_bar) ShowExampleAppMainMenuBar();
|
||||
if (show_app_dockspace) ShowExampleAppDockSpace(&show_app_dockspace); // Process the Docking app first, as explicit DockSpace() nodes needs to be submitted early (read comments near the DockSpace function)
|
||||
if (show_app_documents) ShowExampleAppDocuments(&show_app_documents); // Process the Document app next, as it may also use a DockSpace()
|
||||
|
||||
if (show_app_console) ShowExampleAppConsole(&show_app_console);
|
||||
if (show_app_log) ShowExampleAppLog(&show_app_log);
|
||||
if (show_app_layout) ShowExampleAppLayout(&show_app_layout);
|
||||
@@ -456,6 +458,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
||||
ImGui::Checkbox("io.ConfigWindowsMoveFromTitleBarOnly", &io.ConfigWindowsMoveFromTitleBarOnly);
|
||||
ImGui::Checkbox("io.MouseDrawCursor", &io.MouseDrawCursor);
|
||||
ImGui::SameLine(); HelpMarker("Instruct Dear ImGui to render a mouse cursor itself. Note that a mouse cursor rendered via your application GPU rendering path will feel more laggy than hardware cursor, but will be more in sync with your other visuals.\n\nSome desktop applications may use both kinds of cursors (e.g. enable software cursor only when resizing/dragging something).");
|
||||
ImGui::Text("Also see Style->Rendering for rendering options.");
|
||||
ImGui::TreePop();
|
||||
ImGui::Separator();
|
||||
}
|
||||
@@ -681,7 +684,7 @@ static void ShowDemoWindowWidgets()
|
||||
|
||||
static float f1 = 0.123f, f2 = 0.0f;
|
||||
ImGui::SliderFloat("slider float", &f1, 0.0f, 1.0f, "ratio = %.3f");
|
||||
ImGui::SliderFloat("slider float (curve)", &f2, -10.0f, 10.0f, "%.4f", 2.0f);
|
||||
ImGui::SliderFloat("slider float (log)", &f2, -10.0f, 10.0f, "%.4f", ImGuiSliderFlags_Logarithmic);
|
||||
|
||||
static float angle = 0.0f;
|
||||
ImGui::SliderAngle("slider angle", &angle);
|
||||
@@ -1295,7 +1298,7 @@ static void ShowDemoWindowWidgets()
|
||||
static float arr[] = { 0.6f, 0.1f, 1.0f, 0.5f, 0.92f, 0.1f, 0.2f };
|
||||
ImGui::PlotLines("Frame Times", arr, IM_ARRAYSIZE(arr));
|
||||
|
||||
// Create a dummy array of contiguous float values to plot
|
||||
// Fill an array of contiguous float values to plot
|
||||
// Tip: If your float aren't contiguous but part of a structure, you can pass a pointer to your first float
|
||||
// and the sizeof() of your structure in the "stride" parameter.
|
||||
static float values[90] = {};
|
||||
@@ -1303,7 +1306,7 @@ static void ShowDemoWindowWidgets()
|
||||
static double refresh_time = 0.0;
|
||||
if (!animate || refresh_time == 0.0)
|
||||
refresh_time = ImGui::GetTime();
|
||||
while (refresh_time < ImGui::GetTime()) // Create dummy data at fixed 60 Hz rate for the demo
|
||||
while (refresh_time < ImGui::GetTime()) // Create data at fixed 60 Hz rate for the demo
|
||||
{
|
||||
static float phase = 0.0f;
|
||||
values[values_offset] = cosf(phase);
|
||||
@@ -1403,7 +1406,7 @@ static void ShowDemoWindowWidgets()
|
||||
|
||||
ImGui::Text("Color button with Custom Picker Popup:");
|
||||
|
||||
// Generate a dummy default palette. The palette will persist and can be edited.
|
||||
// Generate a default palette. The palette will persist and can be edited.
|
||||
static bool saved_palette_init = true;
|
||||
static ImVec4 saved_palette[32] = {};
|
||||
if (saved_palette_init)
|
||||
@@ -1540,11 +1543,45 @@ static void ShowDemoWindowWidgets()
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
if (ImGui::TreeNode("Drag/Slider Flags"))
|
||||
{
|
||||
// Demonstrate using advanced flags for DragXXX and SliderXXX functions. Note that the flags are the same!
|
||||
static ImGuiSliderFlags flags = ImGuiSliderFlags_None;
|
||||
ImGui::CheckboxFlags("ImGuiSliderFlags_ClampOnInput", (unsigned int*)&flags, ImGuiSliderFlags_ClampOnInput);
|
||||
ImGui::SameLine(); HelpMarker("Always clamp value to min/max bounds (if any) when input manually with CTRL+Click.");
|
||||
ImGui::CheckboxFlags("ImGuiSliderFlags_Logarithmic", (unsigned int*)&flags, ImGuiSliderFlags_Logarithmic);
|
||||
ImGui::SameLine(); HelpMarker("Enable logarithmic editing (more precision for small values).");
|
||||
ImGui::CheckboxFlags("ImGuiSliderFlags_NoRoundToFormat", (unsigned int*)&flags, ImGuiSliderFlags_NoRoundToFormat);
|
||||
ImGui::SameLine(); HelpMarker("Disable rounding underlying value to match precision of the format string (e.g. %.3f values are rounded to those 3 digits).");
|
||||
ImGui::CheckboxFlags("ImGuiSliderFlags_NoInput", (unsigned int*)&flags, ImGuiSliderFlags_NoInput);
|
||||
ImGui::SameLine(); HelpMarker("Disable CTRL+Click or Enter key allowing to input text directly into the widget.");
|
||||
|
||||
// Drags
|
||||
static float drag_f = 0.5f;
|
||||
static int drag_i = 50;
|
||||
ImGui::Text("Underlying float value: %f", drag_f);
|
||||
ImGui::DragFloat("DragFloat (0 -> 1)", &drag_f, 0.005f, 0.0f, 1.0f, "%.3f", flags);
|
||||
ImGui::DragFloat("DragFloat (0 -> +inf)", &drag_f, 0.005f, 0.0f, FLT_MAX, "%.3f", flags);
|
||||
ImGui::DragFloat("DragFloat (-inf -> 1)", &drag_f, 0.005f, -FLT_MAX, 1.0f, "%.3f", flags);
|
||||
ImGui::DragFloat("DragFloat (-inf -> +inf)", &drag_f, 0.005f, -FLT_MAX, +FLT_MAX, "%.3f", flags);
|
||||
ImGui::DragInt("DragInt (0 -> 100)", &drag_i, 0.5f, 0, 100, "%d", flags);
|
||||
|
||||
// Sliders
|
||||
static float slider_f = 0.5f;
|
||||
static int slider_i = 50;
|
||||
ImGui::Text("Underlying float value: %f", slider_f);
|
||||
ImGui::SliderFloat("SliderFloat (0 -> 1)", &slider_f, 0.0f, 1.0f, "%.3f", flags);
|
||||
ImGui::SliderInt("SliderInt (0 -> 100)", &slider_i, 0, 100, "%.3f", flags);
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
if (ImGui::TreeNode("Range Widgets"))
|
||||
{
|
||||
static float begin = 10, end = 90;
|
||||
static int begin_i = 100, end_i = 1000;
|
||||
ImGui::DragFloatRange2("range", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%");
|
||||
ImGui::DragFloatRange2("range float", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%", ImGuiSliderFlags_ClampOnInput);
|
||||
ImGui::DragIntRange2("range int", &begin_i, &end_i, 5, 0, 1000, "Min: %d units", "Max: %d units");
|
||||
ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %d units", "Max: %d units");
|
||||
ImGui::TreePop();
|
||||
}
|
||||
@@ -1608,34 +1645,34 @@ static void ShowDemoWindowWidgets()
|
||||
ImGui::DragScalar("drag u32", ImGuiDataType_U32, &u32_v, drag_speed, drag_clamp ? &u32_zero : NULL, drag_clamp ? &u32_fifty : NULL, "%u ms");
|
||||
ImGui::DragScalar("drag s64", ImGuiDataType_S64, &s64_v, drag_speed, drag_clamp ? &s64_zero : NULL, drag_clamp ? &s64_fifty : NULL);
|
||||
ImGui::DragScalar("drag u64", ImGuiDataType_U64, &u64_v, drag_speed, drag_clamp ? &u64_zero : NULL, drag_clamp ? &u64_fifty : NULL);
|
||||
ImGui::DragScalar("drag float", ImGuiDataType_Float, &f32_v, 0.005f, &f32_zero, &f32_one, "%f", 1.0f);
|
||||
ImGui::DragScalar("drag float ^2", ImGuiDataType_Float, &f32_v, 0.005f, &f32_zero, &f32_one, "%f", 2.0f); ImGui::SameLine(); HelpMarker("You can use the 'power' parameter to increase tweaking precision on one side of the range.");
|
||||
ImGui::DragScalar("drag double", ImGuiDataType_Double, &f64_v, 0.0005f, &f64_zero, NULL, "%.10f grams", 1.0f);
|
||||
ImGui::DragScalar("drag double ^2", ImGuiDataType_Double, &f64_v, 0.0005f, &f64_zero, &f64_one, "0 < %.10f < 1", 2.0f);
|
||||
ImGui::DragScalar("drag float", ImGuiDataType_Float, &f32_v, 0.005f, &f32_zero, &f32_one, "%f");
|
||||
ImGui::DragScalar("drag float log", ImGuiDataType_Float, &f32_v, 0.005f, &f32_zero, &f32_one, "%f", ImGuiSliderFlags_Logarithmic);
|
||||
ImGui::DragScalar("drag double", ImGuiDataType_Double, &f64_v, 0.0005f, &f64_zero, NULL, "%.10f grams");
|
||||
ImGui::DragScalar("drag double log",ImGuiDataType_Double, &f64_v, 0.0005f, &f64_zero, &f64_one, "0 < %.10f < 1", ImGuiSliderFlags_Logarithmic);
|
||||
|
||||
ImGui::Text("Sliders");
|
||||
ImGui::SliderScalar("slider s8 full", ImGuiDataType_S8, &s8_v, &s8_min, &s8_max, "%d");
|
||||
ImGui::SliderScalar("slider u8 full", ImGuiDataType_U8, &u8_v, &u8_min, &u8_max, "%u");
|
||||
ImGui::SliderScalar("slider s16 full", ImGuiDataType_S16, &s16_v, &s16_min, &s16_max, "%d");
|
||||
ImGui::SliderScalar("slider u16 full", ImGuiDataType_U16, &u16_v, &u16_min, &u16_max, "%u");
|
||||
ImGui::SliderScalar("slider s32 low", ImGuiDataType_S32, &s32_v, &s32_zero, &s32_fifty,"%d");
|
||||
ImGui::SliderScalar("slider s32 high", ImGuiDataType_S32, &s32_v, &s32_hi_a, &s32_hi_b, "%d");
|
||||
ImGui::SliderScalar("slider s32 full", ImGuiDataType_S32, &s32_v, &s32_min, &s32_max, "%d");
|
||||
ImGui::SliderScalar("slider u32 low", ImGuiDataType_U32, &u32_v, &u32_zero, &u32_fifty,"%u");
|
||||
ImGui::SliderScalar("slider u32 high", ImGuiDataType_U32, &u32_v, &u32_hi_a, &u32_hi_b, "%u");
|
||||
ImGui::SliderScalar("slider u32 full", ImGuiDataType_U32, &u32_v, &u32_min, &u32_max, "%u");
|
||||
ImGui::SliderScalar("slider s64 low", ImGuiDataType_S64, &s64_v, &s64_zero, &s64_fifty,"%I64d");
|
||||
ImGui::SliderScalar("slider s64 high", ImGuiDataType_S64, &s64_v, &s64_hi_a, &s64_hi_b, "%I64d");
|
||||
ImGui::SliderScalar("slider s64 full", ImGuiDataType_S64, &s64_v, &s64_min, &s64_max, "%I64d");
|
||||
ImGui::SliderScalar("slider u64 low", ImGuiDataType_U64, &u64_v, &u64_zero, &u64_fifty,"%I64u ms");
|
||||
ImGui::SliderScalar("slider u64 high", ImGuiDataType_U64, &u64_v, &u64_hi_a, &u64_hi_b, "%I64u ms");
|
||||
ImGui::SliderScalar("slider u64 full", ImGuiDataType_U64, &u64_v, &u64_min, &u64_max, "%I64u ms");
|
||||
ImGui::SliderScalar("slider float low", ImGuiDataType_Float, &f32_v, &f32_zero, &f32_one);
|
||||
ImGui::SliderScalar("slider float low^2", ImGuiDataType_Float, &f32_v, &f32_zero, &f32_one, "%.10f", 2.0f);
|
||||
ImGui::SliderScalar("slider float high", ImGuiDataType_Float, &f32_v, &f32_lo_a, &f32_hi_a, "%e");
|
||||
ImGui::SliderScalar("slider double low", ImGuiDataType_Double, &f64_v, &f64_zero, &f64_one, "%.10f grams", 1.0f);
|
||||
ImGui::SliderScalar("slider double low^2",ImGuiDataType_Double, &f64_v, &f64_zero, &f64_one, "%.10f", 2.0f);
|
||||
ImGui::SliderScalar("slider double high", ImGuiDataType_Double, &f64_v, &f64_lo_a, &f64_hi_a, "%e grams", 1.0f);
|
||||
ImGui::SliderScalar("slider s8 full", ImGuiDataType_S8, &s8_v, &s8_min, &s8_max, "%d");
|
||||
ImGui::SliderScalar("slider u8 full", ImGuiDataType_U8, &u8_v, &u8_min, &u8_max, "%u");
|
||||
ImGui::SliderScalar("slider s16 full", ImGuiDataType_S16, &s16_v, &s16_min, &s16_max, "%d");
|
||||
ImGui::SliderScalar("slider u16 full", ImGuiDataType_U16, &u16_v, &u16_min, &u16_max, "%u");
|
||||
ImGui::SliderScalar("slider s32 low", ImGuiDataType_S32, &s32_v, &s32_zero, &s32_fifty,"%d");
|
||||
ImGui::SliderScalar("slider s32 high", ImGuiDataType_S32, &s32_v, &s32_hi_a, &s32_hi_b, "%d");
|
||||
ImGui::SliderScalar("slider s32 full", ImGuiDataType_S32, &s32_v, &s32_min, &s32_max, "%d");
|
||||
ImGui::SliderScalar("slider u32 low", ImGuiDataType_U32, &u32_v, &u32_zero, &u32_fifty,"%u");
|
||||
ImGui::SliderScalar("slider u32 high", ImGuiDataType_U32, &u32_v, &u32_hi_a, &u32_hi_b, "%u");
|
||||
ImGui::SliderScalar("slider u32 full", ImGuiDataType_U32, &u32_v, &u32_min, &u32_max, "%u");
|
||||
ImGui::SliderScalar("slider s64 low", ImGuiDataType_S64, &s64_v, &s64_zero, &s64_fifty,"%I64d");
|
||||
ImGui::SliderScalar("slider s64 high", ImGuiDataType_S64, &s64_v, &s64_hi_a, &s64_hi_b, "%I64d");
|
||||
ImGui::SliderScalar("slider s64 full", ImGuiDataType_S64, &s64_v, &s64_min, &s64_max, "%I64d");
|
||||
ImGui::SliderScalar("slider u64 low", ImGuiDataType_U64, &u64_v, &u64_zero, &u64_fifty,"%I64u ms");
|
||||
ImGui::SliderScalar("slider u64 high", ImGuiDataType_U64, &u64_v, &u64_hi_a, &u64_hi_b, "%I64u ms");
|
||||
ImGui::SliderScalar("slider u64 full", ImGuiDataType_U64, &u64_v, &u64_min, &u64_max, "%I64u ms");
|
||||
ImGui::SliderScalar("slider float low", ImGuiDataType_Float, &f32_v, &f32_zero, &f32_one);
|
||||
ImGui::SliderScalar("slider float low log", ImGuiDataType_Float, &f32_v, &f32_zero, &f32_one, "%.10f", ImGuiSliderFlags_Logarithmic);
|
||||
ImGui::SliderScalar("slider float high", ImGuiDataType_Float, &f32_v, &f32_lo_a, &f32_hi_a, "%e");
|
||||
ImGui::SliderScalar("slider double low", ImGuiDataType_Double, &f64_v, &f64_zero, &f64_one, "%.10f grams");
|
||||
ImGui::SliderScalar("slider double low log",ImGuiDataType_Double, &f64_v, &f64_zero, &f64_one, "%.10f", ImGuiSliderFlags_Logarithmic);
|
||||
ImGui::SliderScalar("slider double high", ImGuiDataType_Double, &f64_v, &f64_lo_a, &f64_hi_a, "%e grams");
|
||||
|
||||
static bool inputs_step = true;
|
||||
ImGui::Text("Inputs");
|
||||
@@ -1983,8 +2020,8 @@ static void ShowDemoWindowWidgets()
|
||||
if (embed_all_inside_a_child_window)
|
||||
ImGui::EndChild();
|
||||
|
||||
static char dummy_str[] = "This is a dummy field to be able to tab-out of the widgets above.";
|
||||
ImGui::InputText("dummy", dummy_str, IM_ARRAYSIZE(dummy_str), ImGuiInputTextFlags_ReadOnly);
|
||||
static char unused_str[] = "This widget is only here to be able to tab-out of the widgets above.";
|
||||
ImGui::InputText("unused", unused_str, IM_ARRAYSIZE(unused_str), ImGuiInputTextFlags_ReadOnly);
|
||||
|
||||
// Calling IsItemHovered() after begin returns the hovered status of the title bar.
|
||||
// This is useful in particular if you want to create a context menu associated to the title bar of a window.
|
||||
@@ -2014,7 +2051,7 @@ static void ShowDemoWindowWidgets()
|
||||
|
||||
static void ShowDemoWindowLayout()
|
||||
{
|
||||
if (!ImGui::CollapsingHeader("Layout"))
|
||||
if (!ImGui::CollapsingHeader("Layout & Scrolling"))
|
||||
return;
|
||||
|
||||
if (ImGui::TreeNode("Child windows"))
|
||||
@@ -2025,12 +2062,6 @@ static void ShowDemoWindowLayout()
|
||||
ImGui::Checkbox("Disable Mouse Wheel", &disable_mouse_wheel);
|
||||
ImGui::Checkbox("Disable Menu", &disable_menu);
|
||||
|
||||
static int line = 50;
|
||||
bool goto_line = ImGui::Button("Goto");
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(100);
|
||||
goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue);
|
||||
|
||||
// Child 1: no border, enable horizontal scrollbar
|
||||
{
|
||||
ImGuiWindowFlags window_flags = ImGuiWindowFlags_HorizontalScrollbar;
|
||||
@@ -2038,13 +2069,7 @@ static void ShowDemoWindowLayout()
|
||||
window_flags |= ImGuiWindowFlags_NoScrollWithMouse;
|
||||
ImGui::BeginChild("ChildL", ImVec2(ImGui::GetWindowContentRegionWidth() * 0.5f, 260), false, window_flags);
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
ImGui::Text("%04d: scrollable region", i);
|
||||
if (goto_line && line == i)
|
||||
ImGui::SetScrollHereY();
|
||||
}
|
||||
if (goto_line && line >= 100)
|
||||
ImGui::SetScrollHereY();
|
||||
ImGui::EndChild();
|
||||
}
|
||||
|
||||
@@ -2090,15 +2115,21 @@ static void ShowDemoWindowLayout()
|
||||
// - Using ImGui::GetItemRectMin/Max() to query the "item" state (because the child window is an item from
|
||||
// the POV of the parent window). See 'Demo->Querying Status (Active/Focused/Hovered etc.)' for details.
|
||||
{
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 10);
|
||||
static int offset_x = 0;
|
||||
ImGui::SetNextItemWidth(100);
|
||||
ImGui::DragInt("Offset X", &offset_x, 1.0f, -1000, 1000);
|
||||
|
||||
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (float)offset_x);
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(255, 0, 0, 100));
|
||||
ImGui::BeginChild("Red", ImVec2(200, 100), true, ImGuiWindowFlags_None);
|
||||
for (int n = 0; n < 50; n++)
|
||||
ImGui::Text("Some test %d", n);
|
||||
ImGui::EndChild();
|
||||
bool child_is_hovered = ImGui::IsItemHovered();
|
||||
ImVec2 child_rect_min = ImGui::GetItemRectMin();
|
||||
ImVec2 child_rect_max = ImGui::GetItemRectMax();
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::Text("Hovered: %d", child_is_hovered);
|
||||
ImGui::Text("Rect of child window is: (%.0f,%.0f) (%.0f,%.0f)", child_rect_min.x, child_rect_min.y, child_rect_max.x, child_rect_max.y);
|
||||
}
|
||||
|
||||
@@ -2436,7 +2467,7 @@ static void ShowDemoWindowLayout()
|
||||
ImGui::SameLine(0.0f, spacing);
|
||||
if (ImGui::TreeNode("Node##1"))
|
||||
{
|
||||
// Dummy tree data
|
||||
// Placeholder tree data
|
||||
for (int i = 0; i < 6; i++)
|
||||
ImGui::BulletText("Item %d..", i);
|
||||
ImGui::TreePop();
|
||||
@@ -2452,7 +2483,7 @@ static void ShowDemoWindowLayout()
|
||||
ImGui::SameLine(0.0f, spacing); ImGui::Button("Button##2");
|
||||
if (node_open)
|
||||
{
|
||||
// Dummy tree data
|
||||
// Placeholder tree data
|
||||
for (int i = 0; i < 6; i++)
|
||||
ImGui::BulletText("Item %d..", i);
|
||||
ImGui::TreePop();
|
||||
@@ -2484,8 +2515,6 @@ static void ShowDemoWindowLayout()
|
||||
static float scroll_to_pos_px = 200.0f;
|
||||
|
||||
ImGui::Checkbox("Decoration", &enable_extra_decorations);
|
||||
ImGui::SameLine();
|
||||
HelpMarker("We expose this for testing because scrolling sometimes had issues with window decoration such as menu-bars.");
|
||||
|
||||
ImGui::Checkbox("Track", &enable_track);
|
||||
ImGui::PushItemWidth(100);
|
||||
@@ -2552,11 +2581,9 @@ static void ShowDemoWindowLayout()
|
||||
ImGui::Spacing();
|
||||
HelpMarker(
|
||||
"Use SetScrollHereX() or SetScrollFromPosX() to scroll to a given horizontal position.\n\n"
|
||||
"Using the \"Scroll To Pos\" button above will make the discontinuity at edges visible: "
|
||||
"scrolling to the top/bottom/left/right-most item will add an additional WindowPadding to reflect "
|
||||
"on reaching the edge of the list.\n\nBecause the clipping rectangle of most window hides half "
|
||||
"worth of WindowPadding on the left/right, using SetScrollFromPosX(+1) will usually result in "
|
||||
"clipped text whereas the equivalent SetScrollFromPosY(+1) wouldn't.");
|
||||
"Because the clipping rectangle of most window hides half worth of WindowPadding on the "
|
||||
"left/right, using SetScrollFromPosX(+1) will usually result in clipped text whereas the "
|
||||
"equivalent SetScrollFromPosY(+1) wouldn't.");
|
||||
ImGui::PushID("##HorizontalScrolling");
|
||||
for (int i = 0; i < 5; i++)
|
||||
{
|
||||
@@ -2746,23 +2773,66 @@ static void ShowDemoWindowLayout()
|
||||
|
||||
if (ImGui::TreeNode("Clipping"))
|
||||
{
|
||||
static ImVec2 size(100, 100), offset(50, 20);
|
||||
ImGui::TextWrapped(
|
||||
"On a per-widget basis we are occasionally clipping text CPU-side if it won't fit in its frame. "
|
||||
"Otherwise we are doing coarser clipping + passing a scissor rectangle to the renderer. "
|
||||
"The system is designed to try minimizing both execution and CPU/GPU rendering cost.");
|
||||
static ImVec2 size(100.0f, 100.0f);
|
||||
static ImVec2 offset(30.0f, 30.0f);
|
||||
ImGui::DragFloat2("size", (float*)&size, 0.5f, 1.0f, 200.0f, "%.0f");
|
||||
ImGui::TextWrapped("(Click and drag)");
|
||||
ImVec2 pos = ImGui::GetCursorScreenPos();
|
||||
ImVec4 clip_rect(pos.x, pos.y, pos.x + size.x, pos.y + size.y);
|
||||
ImGui::InvisibleButton("##dummy", size);
|
||||
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0))
|
||||
ImGui::TextWrapped("(Click and drag to scroll)");
|
||||
|
||||
for (int n = 0; n < 3; n++)
|
||||
{
|
||||
offset.x += ImGui::GetIO().MouseDelta.x;
|
||||
offset.y += ImGui::GetIO().MouseDelta.y;
|
||||
if (n > 0)
|
||||
ImGui::SameLine();
|
||||
ImGui::PushID(n);
|
||||
ImGui::BeginGroup(); // Lock X position
|
||||
|
||||
ImGui::InvisibleButton("##empty", size);
|
||||
if (ImGui::IsItemActive() && ImGui::IsMouseDragging(ImGuiMouseButton_Left))
|
||||
{
|
||||
offset.x += ImGui::GetIO().MouseDelta.x;
|
||||
offset.y += ImGui::GetIO().MouseDelta.y;
|
||||
}
|
||||
const ImVec2 p0 = ImGui::GetItemRectMin();
|
||||
const ImVec2 p1 = ImGui::GetItemRectMax();
|
||||
const char* text_str = "Line 1 hello\nLine 2 clip me!";
|
||||
const ImVec2 text_pos = ImVec2(p0.x + offset.x, p0.y + offset.y);
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
|
||||
switch (n)
|
||||
{
|
||||
case 0:
|
||||
HelpMarker(
|
||||
"Using ImGui::PushClipRect():\n"
|
||||
"Will alter ImGui hit-testing logic + ImDrawList rendering.\n"
|
||||
"(use this if you want your clipping rectangle to affect interactions)");
|
||||
ImGui::PushClipRect(p0, p1, true);
|
||||
draw_list->AddRectFilled(p0, p1, IM_COL32(90, 90, 120, 255));
|
||||
draw_list->AddText(text_pos, IM_COL32_WHITE, text_str);
|
||||
ImGui::PopClipRect();
|
||||
break;
|
||||
case 1:
|
||||
HelpMarker(
|
||||
"Using ImDrawList::PushClipRect():\n"
|
||||
"Will alter ImDrawList rendering only.\n"
|
||||
"(use this as a shortcut if you are only using ImDrawList calls)");
|
||||
draw_list->PushClipRect(p0, p1, true);
|
||||
draw_list->AddRectFilled(p0, p1, IM_COL32(90, 90, 120, 255));
|
||||
draw_list->AddText(text_pos, IM_COL32_WHITE, text_str);
|
||||
draw_list->PopClipRect();
|
||||
break;
|
||||
case 2:
|
||||
HelpMarker(
|
||||
"Using ImDrawList::AddText() with a fine ClipRect:\n"
|
||||
"Will alter only this specific ImDrawList::AddText() rendering.\n"
|
||||
"(this is often used internally to avoid altering the clipping rectangle and minimize draw calls)");
|
||||
ImVec4 clip_rect(p0.x, p0.y, p1.x, p1.y); // AddText() takes a ImVec4* here so let's convert.
|
||||
draw_list->AddRectFilled(p0, p1, IM_COL32(90, 90, 120, 255));
|
||||
draw_list->AddText(ImGui::GetFont(), ImGui::GetFontSize(), text_pos, IM_COL32_WHITE, text_str, NULL, 0.0f, &clip_rect);
|
||||
break;
|
||||
}
|
||||
ImGui::EndGroup();
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::GetWindowDrawList()->AddRectFilled(pos, ImVec2(pos.x + size.x, pos.y + size.y), IM_COL32(90, 90, 120, 255));
|
||||
ImGui::GetWindowDrawList()->AddText(ImGui::GetFont(), ImGui::GetFontSize()*2.0f, ImVec2(pos.x + offset.x, pos.y + offset.y), IM_COL32_WHITE, "Line 1 hello\nLine 2 clip me!", NULL, 0.0f, &clip_rect);
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
@@ -2934,8 +3004,8 @@ static void ShowDemoWindowPopups()
|
||||
ImGui::Text("All those beautiful files will be deleted.\nThis operation cannot be undone!\n\n");
|
||||
ImGui::Separator();
|
||||
|
||||
//static int dummy_i = 0;
|
||||
//ImGui::Combo("Combo", &dummy_i, "Delete\0Delete harder\0");
|
||||
//static int unused_i = 0;
|
||||
//ImGui::Combo("Combo", &unused_i, "Delete\0Delete harder\0");
|
||||
|
||||
static bool dont_ask_me_next_time = false;
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
|
||||
@@ -2957,7 +3027,7 @@ static void ShowDemoWindowPopups()
|
||||
{
|
||||
if (ImGui::BeginMenu("File"))
|
||||
{
|
||||
if (ImGui::MenuItem("Dummy menu item")) {}
|
||||
if (ImGui::MenuItem("Some menu item")) {}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
@@ -2976,8 +3046,8 @@ static void ShowDemoWindowPopups()
|
||||
// Also demonstrate passing a bool* to BeginPopupModal(), this will create a regular close button which
|
||||
// will close the popup. Note that the visibility state of popups is owned by imgui, so the input value
|
||||
// of the bool actually doesn't matter here.
|
||||
bool dummy_open = true;
|
||||
if (ImGui::BeginPopupModal("Stacked 2", &dummy_open))
|
||||
bool unused_open = true;
|
||||
if (ImGui::BeginPopupModal("Stacked 2", &unused_open))
|
||||
{
|
||||
ImGui::Text("Hello from Stacked The Second!");
|
||||
if (ImGui::Button("Close"))
|
||||
@@ -3284,7 +3354,7 @@ static void ShowDemoWindowMisc()
|
||||
ImGui::Text("Mouse delta: (%g, %g)", io.MouseDelta.x, io.MouseDelta.y);
|
||||
ImGui::Text("Mouse down:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (io.MouseDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("b%d (%.02f secs)", i, io.MouseDownDuration[i]); }
|
||||
ImGui::Text("Mouse clicked:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseClicked(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); }
|
||||
ImGui::Text("Mouse dblclick:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseDoubleClicked(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); }
|
||||
ImGui::Text("Mouse dblclick:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseDoubleClicked(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); }
|
||||
ImGui::Text("Mouse released:"); for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++) if (ImGui::IsMouseReleased(i)) { ImGui::SameLine(); ImGui::Text("b%d", i); }
|
||||
ImGui::Text("Mouse wheel: %.1f", io.MouseWheel);
|
||||
|
||||
@@ -3312,7 +3382,7 @@ static void ShowDemoWindowMisc()
|
||||
if (ImGui::TreeNode("Tabbing"))
|
||||
{
|
||||
ImGui::Text("Use TAB/SHIFT+TAB to cycle through keyboard editable fields.");
|
||||
static char buf[32] = "dummy";
|
||||
static char buf[32] = "hello";
|
||||
ImGui::InputText("1", buf, IM_ARRAYSIZE(buf));
|
||||
ImGui::InputText("2", buf, IM_ARRAYSIZE(buf));
|
||||
ImGui::InputText("3", buf, IM_ARRAYSIZE(buf));
|
||||
@@ -3787,6 +3857,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||
ImGui::SliderFloat("PopupRounding", &style.PopupRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("ScrollbarRounding", &style.ScrollbarRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("GrabRounding", &style.GrabRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("LogSliderDeadzone", &style.LogSliderDeadzone, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::SliderFloat("TabRounding", &style.TabRounding, 0.0f, 12.0f, "%.0f");
|
||||
ImGui::Text("Alignment");
|
||||
ImGui::SliderFloat2("WindowTitleAlign", (float*)&style.WindowTitleAlign, 0.0f, 1.0f, "%.2f");
|
||||
@@ -3898,10 +3969,9 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||
"rebuild the font atlas, and call style.ScaleAllSizes() on a reference ImGuiStyle structure.\n"
|
||||
"Using those settings here will give you poor quality results.");
|
||||
static float window_scale = 1.0f;
|
||||
if (ImGui::DragFloat("window scale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE, "%.2f")) // Scale only this window
|
||||
ImGui::SetWindowFontScale(IM_MAX(window_scale, MIN_SCALE));
|
||||
if (ImGui::DragFloat("global scale", &io.FontGlobalScale, 0.005f, MIN_SCALE, MAX_SCALE, "%.2f")) // Scale everything
|
||||
io.FontGlobalScale = IM_MAX(io.FontGlobalScale, MIN_SCALE);
|
||||
if (ImGui::DragFloat("window scale", &window_scale, 0.005f, MIN_SCALE, MAX_SCALE, "%.2f", ImGuiSliderFlags_ClampOnInput)) // Scale only this window
|
||||
ImGui::SetWindowFontScale(window_scale);
|
||||
ImGui::DragFloat("global scale", &io.FontGlobalScale, 0.005f, MIN_SCALE, MAX_SCALE, "%.2f", ImGuiSliderFlags_ClampOnInput); // Scale everything
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
ImGui::EndTabItem();
|
||||
@@ -3911,11 +3981,34 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
|
||||
{
|
||||
ImGui::Checkbox("Anti-aliased lines", &style.AntiAliasedLines);
|
||||
ImGui::SameLine(); HelpMarker("When disabling anti-aliasing lines, you'll probably want to disable borders in your style as well.");
|
||||
ImGui::Checkbox("Anti-aliased lines use texture", &style.AntiAliasedLinesUseTex);
|
||||
ImGui::SameLine(); HelpMarker("Faster lines using texture data. Require back-end to render with bilinear filtering (not point/nearest filtering).");
|
||||
ImGui::Checkbox("Anti-aliased fill", &style.AntiAliasedFill);
|
||||
ImGui::PushItemWidth(100);
|
||||
ImGui::DragFloat("Curve Tessellation Tolerance", &style.CurveTessellationTol, 0.02f, 0.10f, 10.0f, "%.2f");
|
||||
if (style.CurveTessellationTol < 0.10f) style.CurveTessellationTol = 0.10f;
|
||||
ImGui::DragFloat("Circle segment Max Error", &style.CircleSegmentMaxError, 0.01f, 0.10f, 10.0f, "%.2f");
|
||||
|
||||
// When editing the "Circle Segment Max Error" value, draw a preview of its effect on auto-tessellated circles.
|
||||
ImGui::DragFloat("Circle Segment Max Error", &style.CircleSegmentMaxError, 0.01f, 0.10f, 10.0f, "%.2f");
|
||||
if (ImGui::IsItemActive())
|
||||
{
|
||||
ImGui::SetNextWindowPos(ImGui::GetCursorScreenPos());
|
||||
ImGui::BeginTooltip();
|
||||
ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
float RAD_MIN = 10.0f, RAD_MAX = 80.0f;
|
||||
float off_x = 10.0f;
|
||||
for (int n = 0; n < 7; n++)
|
||||
{
|
||||
const float rad = RAD_MIN + (RAD_MAX - RAD_MIN) * (float)n / (7.0f - 1.0f);
|
||||
ImGui::GetWindowDrawList()->AddCircle(ImVec2(p.x + off_x + rad, p.y + RAD_MAX), rad, ImGui::GetColorU32(ImGuiCol_Text), 0);
|
||||
off_x += 10.0f + rad * 2.0f;
|
||||
}
|
||||
ImGui::Dummy(ImVec2(off_x, RAD_MAX * 2.0f));
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
HelpMarker("When drawing circle primitives with \"num_segments == 0\" tesselation will be calculated automatically.");
|
||||
|
||||
ImGui::DragFloat("Global Alpha", &style.Alpha, 0.005f, 0.20f, 1.0f, "%.2f"); // Not exposing zero here so user doesn't "lose" the UI (zero alpha clips all widgets). But application code could have a toggle to switch between zero and non-zero.
|
||||
ImGui::PopItemWidth();
|
||||
|
||||
@@ -3966,7 +4059,7 @@ static void ShowExampleAppMainMenuBar()
|
||||
// (future version will add explicit flags to BeginMenu() to request processing shortcuts)
|
||||
static void ShowExampleMenuFile()
|
||||
{
|
||||
ImGui::MenuItem("(dummy menu)", NULL, false, false);
|
||||
ImGui::MenuItem("(demo menu)", NULL, false, false);
|
||||
if (ImGui::MenuItem("New")) {}
|
||||
if (ImGui::MenuItem("Open", "Ctrl+O")) {}
|
||||
if (ImGui::BeginMenu("Open Recent"))
|
||||
@@ -4130,8 +4223,8 @@ struct ExampleAppConsole
|
||||
|
||||
// TODO: display items starting from the bottom
|
||||
|
||||
if (ImGui::SmallButton("Add Dummy Text")) { AddLog("%d some text", Items.Size); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
|
||||
if (ImGui::SmallButton("Add Dummy Error")) { AddLog("[error] something went wrong"); } ImGui::SameLine();
|
||||
if (ImGui::SmallButton("Add Debug Text")) { AddLog("%d some text", Items.Size); AddLog("some more text"); AddLog("display very important message here!"); } ImGui::SameLine();
|
||||
if (ImGui::SmallButton("Add Debug Error")) { AddLog("[error] something went wrong"); } ImGui::SameLine();
|
||||
if (ImGui::SmallButton("Clear")) { ClearLog(); } ImGui::SameLine();
|
||||
bool copy_to_clipboard = ImGui::SmallButton("Copy");
|
||||
//static float t = 0.0f; if (ImGui::GetTime() - t > 0.02f) { t = ImGui::GetTime(); AddLog("Spam %f", t); }
|
||||
@@ -4621,7 +4714,7 @@ static void ShowExampleAppLayout(bool* p_open)
|
||||
// [SECTION] Example App: Property Editor / ShowExampleAppPropertyEditor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static void ShowDummyObject(const char* prefix, int uid)
|
||||
static void ShowPlaceholderObject(const char* prefix, int uid)
|
||||
{
|
||||
// Use object uid as identifier. Most commonly you could also use the object pointer as a base ID.
|
||||
ImGui::PushID(uid);
|
||||
@@ -4633,13 +4726,13 @@ static void ShowDummyObject(const char* prefix, int uid)
|
||||
ImGui::NextColumn();
|
||||
if (node_open)
|
||||
{
|
||||
static float dummy_members[8] = { 0.0f, 0.0f, 1.0f, 3.1416f, 100.0f, 999.0f };
|
||||
static float placeholder_members[8] = { 0.0f, 0.0f, 1.0f, 3.1416f, 100.0f, 999.0f };
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
ImGui::PushID(i); // Use field index as identifier.
|
||||
if (i < 2)
|
||||
{
|
||||
ShowDummyObject("Child", 424242);
|
||||
ShowPlaceholderObject("Child", 424242);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -4650,9 +4743,9 @@ static void ShowDummyObject(const char* prefix, int uid)
|
||||
ImGui::NextColumn();
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
if (i >= 5)
|
||||
ImGui::InputFloat("##value", &dummy_members[i], 1.0f);
|
||||
ImGui::InputFloat("##value", &placeholder_members[i], 1.0f);
|
||||
else
|
||||
ImGui::DragFloat("##value", &dummy_members[i], 0.01f);
|
||||
ImGui::DragFloat("##value", &placeholder_members[i], 0.01f);
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
ImGui::PopID();
|
||||
@@ -4682,9 +4775,9 @@ static void ShowExampleAppPropertyEditor(bool* p_open)
|
||||
ImGui::Columns(2);
|
||||
ImGui::Separator();
|
||||
|
||||
// Iterate dummy objects with dummy members (all the same data)
|
||||
// Iterate placeholder objects (all the same data)
|
||||
for (int obj_i = 0; obj_i < 3; obj_i++)
|
||||
ShowDummyObject("Object", obj_i);
|
||||
ShowPlaceholderObject("Object", obj_i);
|
||||
|
||||
ImGui::Columns(1);
|
||||
ImGui::Separator();
|
||||
@@ -4929,31 +5022,32 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
// overloaded operators, etc. Define IM_VEC2_CLASS_EXTRA in imconfig.h to create implicit conversions between your
|
||||
// types and ImVec2/ImVec4. Dear ImGui defines overloaded operators but they are internal to imgui.cpp and not
|
||||
// exposed outside (to avoid messing with your types) In this example we are not using the maths operators!
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
|
||||
if (ImGui::BeginTabBar("##TabBar"))
|
||||
{
|
||||
if (ImGui::BeginTabItem("Primitives"))
|
||||
{
|
||||
ImGui::PushItemWidth(-ImGui::GetFontSize() * 10);
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
|
||||
// Draw gradients
|
||||
// (note that those are currently exacerbating our sRGB/Linear issues)
|
||||
// Calling ImGui::GetColorU32() multiplies the given colors by the current Style Alpha, but you may pass the IM_COL32() directly as well..
|
||||
ImGui::Text("Gradients");
|
||||
ImVec2 gradient_size = ImVec2(ImGui::CalcItemWidth(), ImGui::GetFrameHeight());
|
||||
{
|
||||
ImVec2 p0 = ImGui::GetCursorScreenPos();
|
||||
ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y);
|
||||
ImU32 col_a = ImGui::GetColorU32(ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
ImU32 col_b = ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 0, 0, 255));
|
||||
ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 255, 255, 255));
|
||||
draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a);
|
||||
ImGui::InvisibleButton("##gradient1", gradient_size);
|
||||
}
|
||||
{
|
||||
ImVec2 p0 = ImGui::GetCursorScreenPos();
|
||||
ImVec2 p1 = ImVec2(p0.x + gradient_size.x, p0.y + gradient_size.y);
|
||||
ImU32 col_a = ImGui::GetColorU32(ImVec4(0.0f, 1.0f, 0.0f, 1.0f));
|
||||
ImU32 col_b = ImGui::GetColorU32(ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
|
||||
ImU32 col_a = ImGui::GetColorU32(IM_COL32(0, 255, 0, 255));
|
||||
ImU32 col_b = ImGui::GetColorU32(IM_COL32(255, 0, 0, 255));
|
||||
draw_list->AddRectFilledMultiColor(p0, p1, col_a, col_b, col_b, col_a);
|
||||
ImGui::InvisibleButton("##gradient2", gradient_size);
|
||||
}
|
||||
@@ -4974,6 +5068,7 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
if (ImGui::SliderInt("Circle segments", &circle_segments_override_v, 3, 40))
|
||||
circle_segments_override = true;
|
||||
ImGui::ColorEdit4("Color", &colf.x);
|
||||
|
||||
const ImVec2 p = ImGui::GetCursorScreenPos();
|
||||
const ImU32 col = ImColor(colf);
|
||||
const float spacing = 10.0f;
|
||||
@@ -4981,38 +5076,39 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
const ImDrawCornerFlags corners_all = ImDrawCornerFlags_All;
|
||||
const ImDrawCornerFlags corners_tl_br = ImDrawCornerFlags_TopLeft | ImDrawCornerFlags_BotRight;
|
||||
const int circle_segments = circle_segments_override ? circle_segments_override_v : 0;
|
||||
float x = p.x + 4.0f, y = p.y + 4.0f;
|
||||
float x = p.x + 4.0f;
|
||||
float y = p.y + 4.0f;
|
||||
for (int n = 0; n < 2; n++)
|
||||
{
|
||||
// First line uses a thickness of 1.0f, second line uses the configurable thickness
|
||||
float th = (n == 0) ? 1.0f : thickness;
|
||||
draw_list->AddNgon(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, ngon_sides, th); x += sz + spacing; // N-gon
|
||||
draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments, th); x += sz + spacing; // Circle
|
||||
draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 0.0f, corners_none, th); x += sz + spacing; // Square
|
||||
draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_all, th); x += sz + spacing; // Square with all rounded corners
|
||||
draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br, th); x += sz + spacing; // Square with two rounded corners
|
||||
draw_list->AddTriangle(ImVec2(x+sz*0.5f,y), ImVec2(x+sz, y+sz-0.5f), ImVec2(x, y+sz-0.5f), col, th); x += sz + spacing; // Triangle
|
||||
draw_list->AddTriangle(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col, th); x += sz*0.4f + spacing; // Thin triangle
|
||||
draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y), col, th); x += sz + spacing; // Horizontal line (note: drawing a filled rectangle will be faster!)
|
||||
draw_list->AddLine(ImVec2(x, y), ImVec2(x, y + sz), col, th); x += spacing; // Vertical line (note: drawing a filled rectangle will be faster!)
|
||||
draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y + sz), col, th); x += sz + spacing; // Diagonal line
|
||||
draw_list->AddNgon(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, ngon_sides, th); x += sz + spacing; // N-gon
|
||||
draw_list->AddCircle(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments, th); x += sz + spacing; // Circle
|
||||
draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 0.0f, corners_none, th); x += sz + spacing; // Square
|
||||
draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_all, th); x += sz + spacing; // Square with all rounded corners
|
||||
draw_list->AddRect(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br, th); x += sz + spacing; // Square with two rounded corners
|
||||
draw_list->AddTriangle(ImVec2(x+sz*0.5f,y), ImVec2(x+sz, y+sz-0.5f), ImVec2(x, y+sz-0.5f), col, th);x += sz + spacing; // Triangle
|
||||
//draw_list->AddTriangle(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col, th);x+= sz*0.4f + spacing; // Thin triangle
|
||||
draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y), col, th); x += sz + spacing; // Horizontal line (note: drawing a filled rectangle will be faster!)
|
||||
draw_list->AddLine(ImVec2(x, y), ImVec2(x, y + sz), col, th); x += spacing; // Vertical line (note: drawing a filled rectangle will be faster!)
|
||||
draw_list->AddLine(ImVec2(x, y), ImVec2(x + sz, y + sz), col, th); x += sz + spacing; // Diagonal line
|
||||
draw_list->AddBezierCurve(ImVec2(x, y), ImVec2(x + sz*1.3f, y + sz*0.3f), ImVec2(x + sz - sz*1.3f, y + sz - sz*0.3f), ImVec2(x + sz, y + sz), col, th);
|
||||
x = p.x + 4;
|
||||
y += sz + spacing;
|
||||
}
|
||||
draw_list->AddNgonFilled(ImVec2(x + sz * 0.5f, y + sz * 0.5f), sz*0.5f, col, ngon_sides); x += sz + spacing; // N-gon
|
||||
draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments);x += sz + spacing; // Circle
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col); x += sz + spacing; // Square
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f); x += sz + spacing; // Square with all rounded corners
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br); x += sz + spacing; // Square with two rounded corners
|
||||
draw_list->AddTriangleFilled(ImVec2(x+sz*0.5f,y), ImVec2(x+sz, y+sz-0.5f), ImVec2(x, y+sz-0.5f), col); x += sz + spacing; // Triangle
|
||||
draw_list->AddTriangleFilled(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col); x += sz*0.4f + spacing; // Thin triangle
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + thickness), col); x += sz + spacing; // Horizontal line (faster than AddLine, but only handle integer thickness)
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + thickness, y + sz), col); x += spacing*2.0f; // Vertical line (faster than AddLine, but only handle integer thickness)
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + 1, y + 1), col); x += sz; // Pixel (faster than AddLine)
|
||||
draw_list->AddNgonFilled(ImVec2(x + sz * 0.5f, y + sz * 0.5f), sz*0.5f, col, ngon_sides); x += sz + spacing; // N-gon
|
||||
draw_list->AddCircleFilled(ImVec2(x + sz*0.5f, y + sz*0.5f), sz*0.5f, col, circle_segments); x += sz + spacing; // Circle
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col); x += sz + spacing; // Square
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f); x += sz + spacing; // Square with all rounded corners
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + sz), col, 10.0f, corners_tl_br); x += sz + spacing; // Square with two rounded corners
|
||||
draw_list->AddTriangleFilled(ImVec2(x+sz*0.5f,y), ImVec2(x+sz, y+sz-0.5f), ImVec2(x, y+sz-0.5f), col); x += sz + spacing; // Triangle
|
||||
//draw_list->AddTriangleFilled(ImVec2(x+sz*0.2f,y), ImVec2(x, y+sz-0.5f), ImVec2(x+sz*0.4f, y+sz-0.5f), col); x += sz*0.4f + spacing; // Thin triangle
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + sz, y + thickness), col); x += sz + spacing; // Horizontal line (faster than AddLine, but only handle integer thickness)
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + thickness, y + sz), col); x += spacing * 2.0f;// Vertical line (faster than AddLine, but only handle integer thickness)
|
||||
draw_list->AddRectFilled(ImVec2(x, y), ImVec2(x + 1, y + 1), col); x += sz; // Pixel (faster than AddLine)
|
||||
draw_list->AddRectFilledMultiColor(ImVec2(x, y), ImVec2(x + sz, y + sz), IM_COL32(0, 0, 0, 255), IM_COL32(255, 0, 0, 255), IM_COL32(255, 255, 0, 255), IM_COL32(0, 255, 0, 255));
|
||||
ImGui::Dummy(ImVec2((sz + spacing) * 9.8f, (sz + spacing) * 3));
|
||||
|
||||
ImGui::Dummy(ImVec2((sz + spacing) * 8.8f, (sz + spacing) * 3.0f));
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
@@ -5020,55 +5116,97 @@ static void ShowExampleAppCustomRendering(bool* p_open)
|
||||
if (ImGui::BeginTabItem("Canvas"))
|
||||
{
|
||||
static ImVector<ImVec2> points;
|
||||
static ImVec2 scrolling(0.0f, 0.0f);
|
||||
static bool opt_enable_grid = true;
|
||||
static bool opt_enable_context_menu = true;
|
||||
static bool adding_line = false;
|
||||
if (ImGui::Button("Clear")) points.clear();
|
||||
if (points.Size >= 2) { ImGui::SameLine(); if (ImGui::Button("Undo")) { points.pop_back(); points.pop_back(); } }
|
||||
ImGui::Text("Left-click and drag to add lines,\nRight-click to undo");
|
||||
|
||||
// Here we are using InvisibleButton() as a convenience to 1) advance the cursor and 2) allows us to use
|
||||
// IsItemHovered(). But you can also draw directly and poll mouse/keyboard by yourself.
|
||||
// You can manipulate the cursor using GetCursorPos() and SetCursorPos().
|
||||
// If you only use the ImDrawList API, you can notify the owner window of its extends with SetCursorPos(max).
|
||||
ImVec2 canvas_p = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
|
||||
ImGui::Checkbox("Enable grid", &opt_enable_grid);
|
||||
ImGui::Checkbox("Enable context menu", &opt_enable_context_menu);
|
||||
ImGui::Text("Mouse Left: drag to add lines,\nMouse Right: drag to scroll, click for context menu.");
|
||||
|
||||
// Typically you would use a BeginChild()/EndChild() pair to benefit from a clipping region + own scrolling.
|
||||
// Here we demonstrate that this can be replaced by simple offsetting + custom drawing + PushClipRect/PopClipRect() calls.
|
||||
// To use a child window instead we could use, e.g:
|
||||
// ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); // Disable padding
|
||||
// ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(50, 50, 50, 255)); // Set a background color
|
||||
// ImGui::BeginChild("canvas", ImVec2(0.0f, 0.0f), true, ImGuiWindowFlags_NoMove);
|
||||
// ImGui::PopStyleColor();
|
||||
// ImGui::PopStyleVar();
|
||||
// [...]
|
||||
// ImGui::EndChild();
|
||||
|
||||
// Using InvisibleButton() as a convenience 1) it will advance the layout cursor and 2) allows us to use IsItemHovered()/IsItemActive()
|
||||
ImVec2 canvas_p0 = ImGui::GetCursorScreenPos(); // ImDrawList API uses screen coordinates!
|
||||
ImVec2 canvas_sz = ImGui::GetContentRegionAvail(); // Resize canvas to what's available
|
||||
if (canvas_sz.x < 50.0f) canvas_sz.x = 50.0f;
|
||||
if (canvas_sz.y < 50.0f) canvas_sz.y = 50.0f;
|
||||
draw_list->AddRectFilledMultiColor(canvas_p, ImVec2(canvas_p.x + canvas_sz.x, canvas_p.y + canvas_sz.y), IM_COL32(50, 50, 50, 255), IM_COL32(50, 50, 60, 255), IM_COL32(60, 60, 70, 255), IM_COL32(50, 50, 60, 255));
|
||||
draw_list->AddRect(canvas_p, ImVec2(canvas_p.x + canvas_sz.x, canvas_p.y + canvas_sz.y), IM_COL32(255, 255, 255, 255));
|
||||
ImVec2 canvas_p1 = ImVec2(canvas_p0.x + canvas_sz.x, canvas_p0.y + canvas_sz.y);
|
||||
|
||||
bool adding_preview = false;
|
||||
ImGui::InvisibleButton("canvas", canvas_sz);
|
||||
ImVec2 mouse_pos_global = ImGui::GetIO().MousePos;
|
||||
ImVec2 mouse_pos_canvas = ImVec2(mouse_pos_global.x - canvas_p.x, mouse_pos_global.y - canvas_p.y);
|
||||
// Draw border and background color
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImDrawList* draw_list = ImGui::GetWindowDrawList();
|
||||
draw_list->AddRectFilled(canvas_p0, canvas_p1, IM_COL32(50, 50, 50, 255));
|
||||
draw_list->AddRect(canvas_p0, canvas_p1, IM_COL32(255, 255, 255, 255));
|
||||
|
||||
// This will catch our interactions
|
||||
ImGui::InvisibleButton("canvas", canvas_sz, ImGuiButtonFlags_MouseButtonLeft | ImGuiButtonFlags_MouseButtonRight);
|
||||
const bool is_hovered = ImGui::IsItemHovered(); // Hovered
|
||||
const bool is_active = ImGui::IsItemActive(); // Held
|
||||
const ImVec2 origin(canvas_p0.x + scrolling.x, canvas_p0.y + scrolling.y); // Lock scrolled origin
|
||||
const ImVec2 mouse_pos_in_canvas(io.MousePos.x - origin.x, io.MousePos.y - origin.y);
|
||||
|
||||
// Add first and second point
|
||||
if (is_hovered && !adding_line && ImGui::IsMouseClicked(ImGuiMouseButton_Left))
|
||||
{
|
||||
points.push_back(mouse_pos_in_canvas);
|
||||
points.push_back(mouse_pos_in_canvas);
|
||||
adding_line = true;
|
||||
}
|
||||
if (adding_line)
|
||||
{
|
||||
adding_preview = true;
|
||||
points.push_back(mouse_pos_canvas);
|
||||
if (!ImGui::IsMouseDown(0))
|
||||
adding_line = adding_preview = false;
|
||||
}
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
if (!adding_line && ImGui::IsMouseClicked(0))
|
||||
{
|
||||
points.push_back(mouse_pos_canvas);
|
||||
adding_line = true;
|
||||
}
|
||||
if (ImGui::IsMouseClicked(1) && !points.empty())
|
||||
{
|
||||
adding_line = adding_preview = false;
|
||||
points.pop_back();
|
||||
points.pop_back();
|
||||
}
|
||||
points.back() = mouse_pos_in_canvas;
|
||||
if (!ImGui::IsMouseDown(ImGuiMouseButton_Left))
|
||||
adding_line = false;
|
||||
}
|
||||
|
||||
// Draw all lines in the canvas (with a clipping rectangle so they don't stray out of it).
|
||||
draw_list->PushClipRect(canvas_p, ImVec2(canvas_p.x + canvas_sz.x, canvas_p.y + canvas_sz.y), true);
|
||||
for (int i = 0; i < points.Size - 1; i += 2)
|
||||
draw_list->AddLine(ImVec2(canvas_p.x + points[i].x, canvas_p.y + points[i].y), ImVec2(canvas_p.x + points[i + 1].x, canvas_p.y + points[i + 1].y), IM_COL32(255, 255, 0, 255), 2.0f);
|
||||
// Pan (we use a zero mouse threshold when there's no context menu)
|
||||
// You may decide to make that threshold dynamic based on whether the mouse is hovering something etc.
|
||||
const float mouse_threshold_for_pan = opt_enable_context_menu ? -1.0f : 0.0f;
|
||||
if (is_active && ImGui::IsMouseDragging(ImGuiMouseButton_Right, mouse_threshold_for_pan))
|
||||
{
|
||||
scrolling.x += io.MouseDelta.x;
|
||||
scrolling.y += io.MouseDelta.y;
|
||||
}
|
||||
|
||||
// Context menu (under default mouse threshold)
|
||||
ImVec2 drag_delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Right);
|
||||
if (opt_enable_context_menu && ImGui::IsMouseReleased(ImGuiMouseButton_Right) && drag_delta.x == 0.0f && drag_delta.y == 0.0f)
|
||||
ImGui::OpenPopupContextItem("context");
|
||||
if (ImGui::BeginPopup("context"))
|
||||
{
|
||||
if (adding_line)
|
||||
points.resize(points.size() - 2);
|
||||
adding_line = false;
|
||||
if (ImGui::MenuItem("Remove one", NULL, false, points.Size > 0)) { points.resize(points.size() - 2); }
|
||||
if (ImGui::MenuItem("Remove all", NULL, false, points.Size > 0)) { points.clear(); }
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
// Draw grid + all lines in the canvas
|
||||
draw_list->PushClipRect(canvas_p0, canvas_p1, true);
|
||||
if (opt_enable_grid)
|
||||
{
|
||||
const float GRID_STEP = 64.0f;
|
||||
for (float x = fmodf(scrolling.x, GRID_STEP); x < canvas_sz.x; x += GRID_STEP)
|
||||
draw_list->AddLine(ImVec2(canvas_p0.x + x, canvas_p0.y), ImVec2(canvas_p0.x + x, canvas_p1.y), IM_COL32(200, 200, 200, 40));
|
||||
for (float y = fmodf(scrolling.y, GRID_STEP); y < canvas_sz.y; y += GRID_STEP)
|
||||
draw_list->AddLine(ImVec2(canvas_p0.x, canvas_p0.y + y), ImVec2(canvas_p1.x, canvas_p0.y + y), IM_COL32(200, 200, 200, 40));
|
||||
}
|
||||
for (int n = 0; n < points.Size; n += 2)
|
||||
draw_list->AddLine(ImVec2(origin.x + points[n].x, origin.y + points[n].y), ImVec2(origin.x + points[n + 1].x, origin.y + points[n + 1].y), IM_COL32(255, 255, 0, 255), 2.0f);
|
||||
draw_list->PopClipRect();
|
||||
if (adding_preview)
|
||||
points.pop_back();
|
||||
|
||||
ImGui::EndTabItem();
|
||||
}
|
||||
|
||||
@@ -5217,7 +5355,7 @@ struct MyDocument
|
||||
void DoForceClose() { Open = false; Dirty = false; }
|
||||
void DoSave() { Dirty = false; }
|
||||
|
||||
// Display dummy contents for the Document
|
||||
// Display placeholder contents for the Document
|
||||
static void DisplayContents(MyDocument* doc)
|
||||
{
|
||||
ImGui::PushID(doc);
|
||||
|
||||
Reference in New Issue
Block a user