Demo: Merged a few demo tweaks from navigation branch to minimize drift.

This commit is contained in:
omar 2017-08-08 17:49:12 +08:00
parent a78ef7a369
commit d888de4483

View File

@ -542,13 +542,10 @@ void ImGui::ShowTestWindow(bool* p_open)
ImGui::TreePop(); ImGui::TreePop();
} }
static bool my_toggle = false; static int clicked = 0;
if (ImGui::Button("Button")) if (ImGui::Button("Button"))
{ clicked++;
printf("Clicked\n"); if (clicked & 1)
my_toggle = !my_toggle;
}
if (my_toggle)
{ {
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text("Thanks for clicking me!"); ImGui::Text("Thanks for clicking me!");
@ -902,7 +899,7 @@ void ImGui::ShowTestWindow(bool* p_open)
} }
} }
if (ImGui::CollapsingHeader("Graphs widgets")) if (ImGui::CollapsingHeader("Plots widgets"))
{ {
static bool animate = true; static bool animate = true;
ImGui::Checkbox("Animate", &animate); ImGui::Checkbox("Animate", &animate);
@ -914,16 +911,16 @@ void ImGui::ShowTestWindow(bool* p_open)
// 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. // 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] = { 0 }; static float values[90] = { 0 };
static int values_offset = 0; static int values_offset = 0;
if (animate) static float refresh_time = 0.0f;
if (!animate || refresh_time == 0.0f)
refresh_time = ImGui::GetTime();
while (refresh_time < ImGui::GetTime()) // Create dummy data at fixed 60 hz rate for the demo
{ {
static float refresh_time = ImGui::GetTime(); // Create dummy data at fixed 60 hz rate for the demo static float phase = 0.0f;
for (; ImGui::GetTime() > refresh_time + 1.0f/60.0f; refresh_time += 1.0f/60.0f) values[values_offset] = cosf(phase);
{ values_offset = (values_offset+1) % IM_ARRAYSIZE(values);
static float phase = 0.0f; phase += 0.10f*values_offset;
values[values_offset] = cosf(phase); refresh_time += 1.0f/60.0f;
values_offset = (values_offset+1) % IM_ARRAYSIZE(values);
phase += 0.10f*values_offset;
}
} }
ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80)); ImGui::PlotLines("Lines", values, IM_ARRAYSIZE(values), values_offset, "avg 0.0", -1.0f, 1.0f, ImVec2(0,80));
ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80)); ImGui::PlotHistogram("Histogram", arr, IM_ARRAYSIZE(arr), 0, NULL, 0.0f, 1.0f, ImVec2(0,80));
@ -933,7 +930,7 @@ void ImGui::ShowTestWindow(bool* p_open)
struct Funcs struct Funcs
{ {
static float Sin(void*, int i) { return sinf(i * 0.1f); } static float Sin(void*, int i) { return sinf(i * 0.1f); }
static float Saw(void*, int i) { return (i & 1) ? 1.0f : 0.0f; } static float Saw(void*, int i) { return (i & 1) ? 1.0f : -1.0f; }
}; };
static int func_type = 0, display_count = 70; static int func_type = 0, display_count = 70;
ImGui::Separator(); ImGui::Separator();
@ -1458,9 +1455,11 @@ void ImGui::ShowTestWindow(bool* p_open)
ImGui::OpenPopup("Stacked 1"); ImGui::OpenPopup("Stacked 1");
if (ImGui::BeginPopupModal("Stacked 1")) if (ImGui::BeginPopupModal("Stacked 1"))
{ {
ImGui::Text("Hello from Stacked The First"); ImGui::Text("Hello from Stacked The First\nUsing style.Colors[ImGuiCol_ModalWindowDarkening] for darkening.");
static int item = 1;
ImGui::Combo("Combo", &item, "aaaa\0bbbb\0cccc\0dddd\0eeee\0\0");
if (ImGui::Button("Another one..")) if (ImGui::Button("Add another modal.."))
ImGui::OpenPopup("Stacked 2"); ImGui::OpenPopup("Stacked 2");
if (ImGui::BeginPopupModal("Stacked 2")) if (ImGui::BeginPopupModal("Stacked 2"))
{ {
@ -1617,7 +1616,7 @@ void ImGui::ShowTestWindow(bool* p_open)
} }
bool node_open = ImGui::TreeNode("Tree within single cell"); bool node_open = ImGui::TreeNode("Tree within single cell");
ImGui::SameLine(); ShowHelpMarker("NB: Tree node must be poped before ending the cell.\nThere's no storage of state per-cell."); ImGui::SameLine(); ShowHelpMarker("NB: Tree node must be poped before ending the cell. There's no storage of state per-cell.");
if (node_open) if (node_open)
{ {
ImGui::Columns(2, "tree items"); ImGui::Columns(2, "tree items");
@ -1645,8 +1644,42 @@ void ImGui::ShowTestWindow(bool* p_open)
ImGui::BulletText("%s", lines[i]); ImGui::BulletText("%s", lines[i]);
} }
if (ImGui::CollapsingHeader("Keyboard, Mouse & Focus")) if (ImGui::CollapsingHeader("Inputs & Focus"))
{ {
ImGuiIO& io = ImGui::GetIO();
ImGui::Checkbox("io.MouseDrawCursor", &io.MouseDrawCursor);
ImGui::SameLine(); ShowHelpMarker("Request ImGui to render a mouse cursor for you in software. Note that a mouse cursor rendered via regular GPU rendering will feel more laggy than hardware cursor, but will be more in sync with your other visuals.");
ImGui::Text("WantCaptureMouse: %d", io.WantCaptureMouse);
ImGui::Text("WantCaptureKeyboard: %d", io.WantCaptureKeyboard);
ImGui::Text("WantTextInput: %d", io.WantTextInput);
if (ImGui::TreeNode("Keyboard & Mouse State"))
{
ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.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 dbl-clicked:"); 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);
ImGui::Text("Keys down:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (io.KeysDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("%d (%.02f secs)", i, io.KeysDownDuration[i]); }
ImGui::Text("Keys pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyPressed(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
ImGui::Text("Keys release:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyReleased(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
ImGui::Text("Keys mods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : "");
ImGui::Button("Hovering me sets the\nkeyboard capture flag");
if (ImGui::IsItemHovered())
ImGui::CaptureKeyboardFromApp(true);
ImGui::SameLine();
ImGui::Button("Holding me clears the\nthe keyboard capture flag");
if (ImGui::IsItemActive())
ImGui::CaptureKeyboardFromApp(false);
ImGui::TreePop();
}
if (ImGui::TreeNode("Tabbing")) if (ImGui::TreeNode("Tabbing"))
{ {
ImGui::Text("Use TAB/SHIFT+TAB to cycle through keyboard editable fields."); ImGui::Text("Use TAB/SHIFT+TAB to cycle through keyboard editable fields.");
@ -1700,52 +1733,20 @@ void ImGui::ShowTestWindow(bool* p_open)
// Draw a line between the button and the mouse cursor // Draw a line between the button and the mouse cursor
ImDrawList* draw_list = ImGui::GetWindowDrawList(); ImDrawList* draw_list = ImGui::GetWindowDrawList();
draw_list->PushClipRectFullScreen(); draw_list->PushClipRectFullScreen();
draw_list->AddLine(ImGui::CalcItemRectClosestPoint(ImGui::GetIO().MousePos, true, -2.0f), ImGui::GetIO().MousePos, ImColor(ImGui::GetStyle().Colors[ImGuiCol_Button]), 4.0f); draw_list->AddLine(ImGui::CalcItemRectClosestPoint(io.MousePos, true, -2.0f), io.MousePos, ImColor(ImGui::GetStyle().Colors[ImGuiCol_Button]), 4.0f);
draw_list->PopClipRect(); draw_list->PopClipRect();
ImVec2 value_raw = ImGui::GetMouseDragDelta(0, 0.0f); ImVec2 value_raw = ImGui::GetMouseDragDelta(0, 0.0f);
ImVec2 value_with_lock_threshold = ImGui::GetMouseDragDelta(0); ImVec2 value_with_lock_threshold = ImGui::GetMouseDragDelta(0);
ImVec2 mouse_delta = ImGui::GetIO().MouseDelta; ImVec2 mouse_delta = io.MouseDelta;
ImGui::SameLine(); ImGui::Text("Raw (%.1f, %.1f), WithLockThresold (%.1f, %.1f), MouseDelta (%.1f, %.1f)", value_raw.x, value_raw.y, value_with_lock_threshold.x, value_with_lock_threshold.y, mouse_delta.x, mouse_delta.y); ImGui::SameLine(); ImGui::Text("Raw (%.1f, %.1f), WithLockThresold (%.1f, %.1f), MouseDelta (%.1f, %.1f)", value_raw.x, value_raw.y, value_with_lock_threshold.x, value_with_lock_threshold.y, mouse_delta.x, mouse_delta.y);
} }
ImGui::TreePop(); ImGui::TreePop();
} }
if (ImGui::TreeNode("Keyboard & Mouse State"))
{
ImGuiIO& io = ImGui::GetIO();
ImGui::Text("MousePos: (%g, %g)", io.MousePos.x, io.MousePos.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 dbl-clicked:"); 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("MouseWheel: %.1f", io.MouseWheel);
ImGui::Text("Keys down:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (io.KeysDownDuration[i] >= 0.0f) { ImGui::SameLine(); ImGui::Text("%d (%.02f secs)", i, io.KeysDownDuration[i]); }
ImGui::Text("Keys pressed:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyPressed(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
ImGui::Text("Keys release:"); for (int i = 0; i < IM_ARRAYSIZE(io.KeysDown); i++) if (ImGui::IsKeyReleased(i)) { ImGui::SameLine(); ImGui::Text("%d", i); }
ImGui::Text("KeyMods: %s%s%s%s", io.KeyCtrl ? "CTRL " : "", io.KeyShift ? "SHIFT " : "", io.KeyAlt ? "ALT " : "", io.KeySuper ? "SUPER " : "");
ImGui::Text("WantCaptureMouse: %s", io.WantCaptureMouse ? "true" : "false");
ImGui::Text("WantCaptureKeyboard: %s", io.WantCaptureKeyboard ? "true" : "false");
ImGui::Text("WantTextInput: %s", io.WantTextInput ? "true" : "false");
ImGui::Button("Hovering me sets the\nkeyboard capture flag");
if (ImGui::IsItemHovered())
ImGui::CaptureKeyboardFromApp(true);
ImGui::SameLine();
ImGui::Button("Holding me clears the\nthe keyboard capture flag");
if (ImGui::IsItemActive())
ImGui::CaptureKeyboardFromApp(false);
ImGui::TreePop();
}
if (ImGui::TreeNode("Mouse cursors")) if (ImGui::TreeNode("Mouse cursors"))
{ {
ImGui::TextWrapped("Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. You can also set io.MouseDrawCursor to ask ImGui to render the cursor for you in software.");
ImGui::Checkbox("io.MouseDrawCursor", &ImGui::GetIO().MouseDrawCursor);
ImGui::Text("Hover to see mouse cursors:"); ImGui::Text("Hover to see mouse cursors:");
ImGui::SameLine(); ShowHelpMarker("Your application can render a different mouse cursor based on what ImGui::GetMouseCursor() returns. If software cursor rendering (io.MouseDrawCursor) is set ImGui will draw the right cursor for you, otherwise your backend needs to handle it.");
for (int i = 0; i < ImGuiMouseCursor_Count_; i++) for (int i = 0; i < ImGuiMouseCursor_Count_; i++)
{ {
char label[32]; char label[32];
@ -2014,9 +2015,11 @@ static void ShowExampleMenuFile()
ImGui::EndChild(); ImGui::EndChild();
static float f = 0.5f; static float f = 0.5f;
static int n = 0; static int n = 0;
static bool b = true;
ImGui::SliderFloat("Value", &f, 0.0f, 1.0f); ImGui::SliderFloat("Value", &f, 0.0f, 1.0f);
ImGui::InputFloat("Input", &f, 0.1f); ImGui::InputFloat("Input", &f, 0.1f);
ImGui::Combo("Combo", &n, "Yes\0No\0Maybe\0\0"); ImGui::Combo("Combo", &n, "Yes\0No\0Maybe\0\0");
ImGui::Checkbox("Check", &b);
ImGui::EndMenu(); ImGui::EndMenu();
} }
if (ImGui::BeginMenu("Colors")) if (ImGui::BeginMenu("Colors"))