From 69a29e4715d463e22a58bb0766275168efa1586a Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 16 May 2016 20:14:07 +0200 Subject: [PATCH] Added NewLine() (very shy reminder that #97 isn't done) --- imgui.cpp | 11 +++++++++++ imgui.h | 1 + imgui_demo.cpp | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 6ee82661a..822edcb94 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9122,6 +9122,17 @@ void ImGui::SameLine(float pos_x, float spacing_w) window->DC.CurrentLineTextBaseOffset = window->DC.PrevLineTextBaseOffset; } +void ImGui::NewLine() +{ + ImGuiWindow* window = GetCurrentWindow(); + if (window->SkipItems) + return; + if (window->DC.CurrentLineHeight > 0.0f) // In the event that we are on a line with items that is smaller that FontSize high, we will preserve its height. + ItemSize(ImVec2(0,0)); + else + ItemSize(ImVec2(0.0f, GImGui->FontSize)); +} + void ImGui::NextColumn() { ImGuiWindow* window = GetCurrentWindow(); diff --git a/imgui.h b/imgui.h index 376217629..7697e120f 100644 --- a/imgui.h +++ b/imgui.h @@ -191,6 +191,7 @@ namespace ImGui // Cursor / Layout IMGUI_API void Separator(); // horizontal line IMGUI_API void SameLine(float pos_x = 0.0f, float spacing_w = -1.0f); // call between widgets or groups to layout them horizontally + IMGUI_API void NewLine(); // undo a SameLine() IMGUI_API void Spacing(); // add spacing IMGUI_API void Dummy(const ImVec2& size); // add a dummy item of given size IMGUI_API void Indent(); // move content position toward the right by style.IndentSpacing pixels diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 9ff0cb169..c5f90a28f 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -384,14 +384,14 @@ void ImGui::ShowTestWindow(bool* p_open) static int pressed_count = 0; for (int i = 0; i < 8; i++) { - if (i > 0) - ImGui::SameLine(); ImGui::PushID(i); int frame_padding = -1 + i; // -1 = uses default padding if (ImGui::ImageButton(tex_id, ImVec2(32,32), ImVec2(0,0), ImVec2(32.0f/tex_w,32/tex_h), frame_padding, ImColor(0,0,0,255))) pressed_count += 1; ImGui::PopID(); + ImGui::SameLine(); } + ImGui::NewLine(); ImGui::Text("Pressed %d times.", pressed_count); ImGui::TreePop(); }