From 05ec0b07365b36319ed6ef301c723634c7f8777d Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 14:30:40 +0100 Subject: [PATCH 1/7] Casing tweaks + clarify license copyright (simpler/safer?) (#1346) --- LICENSE.txt | 2 +- imgui.cpp | 2 +- imgui_demo.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 5a9b98b83..24fcd01a7 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2017 Omar Cornut and ImGui contributors +Copyright (c) 2014-2017 Omar Cornut Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/imgui.cpp b/imgui.cpp index b616af838..6f57bb40e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11588,7 +11588,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) { if (ImGui::Begin("ImGui Metrics", p_open)) { - ImGui::Text("ImGui %s", ImGui::GetVersion()); + ImGui::Text("Dear ImGui %s", ImGui::GetVersion()); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::Text("%d vertices, %d indices (%d triangles)", ImGui::GetIO().MetricsRenderVertices, ImGui::GetIO().MetricsRenderIndices, ImGui::GetIO().MetricsRenderIndices / 3); ImGui::Text("%d allocations", ImGui::GetIO().MetricsAllocs); diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 4a5c32dec..4bcc516a4 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -160,7 +160,7 @@ void ImGui::ShowDemoWindow(bool* p_open) if (show_app_about) { ImGui::Begin("About Dear ImGui", &show_app_about, ImGuiWindowFlags_AlwaysAutoResize); - ImGui::Text("dear imgui, %s", ImGui::GetVersion()); + ImGui::Text("Dear ImGui, %s", ImGui::GetVersion()); ImGui::Separator(); ImGui::Text("By Omar Cornut and all dear imgui contributors."); ImGui::Text("Dear ImGui is licensed under the MIT License, see LICENSE for more information."); From 79d38e5aded9c30956cb147cf71e9935f7bb4202 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 14:31:13 +0100 Subject: [PATCH 2/7] Updated copyright date for 2018 --- LICENSE.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE.txt b/LICENSE.txt index 24fcd01a7..21b6ee7e2 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014-2017 Omar Cornut +Copyright (c) 2014-2018 Omar Cornut Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From f9b2058d5a264c184f8c935eded18926f90d9226 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 14:35:11 +0100 Subject: [PATCH 3/7] Internals: Renamed ImGuiSimpleColumns to ImGuiMenuColumns to avoid confusion. Reduced internal buffer size (we only use 3 slots). --- imgui.cpp | 8 ++++---- imgui_internal.h | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 6f57bb40e..71a40d1fe 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1693,7 +1693,7 @@ void ImGuiTextBuffer::appendf(const char* fmt, ...) // ImGuiSimpleColumns (internal use only) //----------------------------------------------------------------------------- -ImGuiSimpleColumns::ImGuiSimpleColumns() +ImGuiMenuColumns::ImGuiMenuColumns() { Count = 0; Spacing = Width = NextWidth = 0.0f; @@ -1701,7 +1701,7 @@ ImGuiSimpleColumns::ImGuiSimpleColumns() memset(NextWidths, 0, sizeof(NextWidths)); } -void ImGuiSimpleColumns::Update(int count, float spacing, bool clear) +void ImGuiMenuColumns::Update(int count, float spacing, bool clear) { IM_ASSERT(Count <= IM_ARRAYSIZE(Pos)); Count = count; @@ -1718,7 +1718,7 @@ void ImGuiSimpleColumns::Update(int count, float spacing, bool clear) } } -float ImGuiSimpleColumns::DeclColumns(float w0, float w1, float w2) // not using va_arg because they promote float to double +float ImGuiMenuColumns::DeclColumns(float w0, float w1, float w2) // not using va_arg because they promote float to double { NextWidth = 0.0f; NextWidths[0] = ImMax(NextWidths[0], w0); @@ -1729,7 +1729,7 @@ float ImGuiSimpleColumns::DeclColumns(float w0, float w1, float w2) // not using return ImMax(Width, NextWidth); } -float ImGuiSimpleColumns::CalcExtraSpace(float avail_w) +float ImGuiMenuColumns::CalcExtraSpace(float avail_w) { return ImMax(0.0f, avail_w - Width); } diff --git a/imgui_internal.h b/imgui_internal.h index 8481f3ac0..babda0b5d 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -35,7 +35,7 @@ struct ImRect; struct ImGuiColMod; struct ImGuiStyleMod; struct ImGuiGroupData; -struct ImGuiSimpleColumns; +struct ImGuiMenuColumns; struct ImGuiDrawContext; struct ImGuiTextEditState; struct ImGuiMouseCursorData; @@ -323,14 +323,14 @@ struct ImGuiGroupData }; // Simple column measurement currently used for MenuItem() only. This is very short-sighted/throw-away code and NOT a generic helper. -struct IMGUI_API ImGuiSimpleColumns +struct IMGUI_API ImGuiMenuColumns { int Count; float Spacing; float Width, NextWidth; - float Pos[8], NextWidths[8]; + float Pos[4], NextWidths[4]; - ImGuiSimpleColumns(); + ImGuiMenuColumns(); void Update(int count, float spacing, bool clear); float DeclColumns(float w0, float w1, float w2); float CalcExtraSpace(float avail_w); @@ -801,7 +801,7 @@ struct IMGUI_API ImGuiWindow ImRect InnerRect; int LastFrameActive; float ItemWidthDefault; - ImGuiSimpleColumns MenuColumns; // Simplified columns storage for menu items + ImGuiMenuColumns MenuColumns; // Simplified columns storage for menu items ImGuiStorage StateStorage; ImVector ColumnsStorage; float FontWindowScale; // Scale multiplier per-window From 33f7769d85fc12c5255919a59d88ec8d540e2589 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 14:38:01 +0100 Subject: [PATCH 4/7] Columns: Clear offsets data when columns count changed. (#1525) --- imgui.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index 71a40d1fe..c4239190c 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11004,6 +11004,10 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag window->DC.ColumnsOffsetX = 0.0f; window->DC.CursorPos.x = (float)(int)(window->Pos.x + window->DC.IndentX + window->DC.ColumnsOffsetX); + // Clear data if columns count changed + if (columns->Columns.Size != 0 && columns->Columns.Size != columns_count + 1) + columns->Columns.resize(0); + // Initialize defaults columns->IsFirstFrame = (columns->Columns.Size == 0); if (columns->Columns.Size == 0) @@ -11016,7 +11020,6 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag columns->Columns.push_back(column); } } - IM_ASSERT(columns->Columns.Size == columns_count + 1); for (int n = 0; n < columns_count + 1; n++) { From 9fbecac87eda2265a6384f9e146493f5750ef0c2 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 15:11:14 +0100 Subject: [PATCH 5/7] Demo: Improved Selectable() examples. (#1528) --- imgui.h | 4 ++-- imgui_demo.cpp | 52 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/imgui.h b/imgui.h index 4e9b2e797..87d3ae380 100644 --- a/imgui.h +++ b/imgui.h @@ -376,8 +376,8 @@ namespace ImGui IMGUI_API bool CollapsingHeader(const char* label, bool* p_open, ImGuiTreeNodeFlags flags = 0); // when 'p_open' isn't NULL, display an additional small close button on upper right of the header // Widgets: Selectable / Lists - IMGUI_API bool Selectable(const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); // size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height - IMGUI_API bool Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); + IMGUI_API bool Selectable(const char* label, bool selected = false, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); // "bool selected" carry the selection state (read-only). Selectable() is clicked is returns true so you can modify your selection state. size.x==0.0: use remaining width, size.x>0.0: specify width. size.y==0.0: use label height, size.y>0.0: specify height + IMGUI_API bool Selectable(const char* label, bool* p_selected, ImGuiSelectableFlags flags = 0, const ImVec2& size = ImVec2(0,0)); // "bool* p_selected" point to the selection state (read-write), as a convenient helper. IMGUI_API bool ListBox(const char* label, int* current_item, const char* const items[], int items_count, int height_in_items = -1); IMGUI_API bool ListBox(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int height_in_items = -1); IMGUI_API bool ListBoxHeader(const char* label, const ImVec2& size = ImVec2(0,0)); // use if you want to reimplement ListBox() will custom data or interactions. make sure to call ListBoxFooter() afterwards. diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 4bcc516a4..9f11de36c 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -609,24 +609,58 @@ void ImGui::ShowDemoWindow(bool* p_open) if (ImGui::TreeNode("Selectables")) { + // Selectable() has 2 overloads: + // - The one taking "bool selected" as a read-only selection information. When Selectable() has been clicked is returns true and you can alter selection state accordingly. + // - The one taking "bool* p_selected" as a read-write selection information (convenient in some cases) + // The earlier is more flexible, as in real application your selection may be stored in a different manner (in flags within objects, as an external list, etc). if (ImGui::TreeNode("Basic")) { - static bool selected[4] = { false, true, false, false }; - ImGui::Selectable("1. I am selectable", &selected[0]); - ImGui::Selectable("2. I am selectable", &selected[1]); + static bool selection[5] = { false, true, false, false, false }; + ImGui::Selectable("1. I am selectable", &selection[0]); + ImGui::Selectable("2. I am selectable", &selection[1]); ImGui::Text("3. I am not selectable"); - ImGui::Selectable("4. I am selectable", &selected[2]); - if (ImGui::Selectable("5. I am double clickable", selected[3], ImGuiSelectableFlags_AllowDoubleClick)) + ImGui::Selectable("4. I am selectable", &selection[3]); + if (ImGui::Selectable("5. I am double clickable", selection[4], ImGuiSelectableFlags_AllowDoubleClick)) if (ImGui::IsMouseDoubleClicked(0)) - selected[3] = !selected[3]; + selection[4] = !selection[4]; ImGui::TreePop(); } - if (ImGui::TreeNode("Rendering more text into the same block")) + if (ImGui::TreeNode("Selection State: Single Selection")) { + static int selected = -1; + for (int n = 0; n < 5; n++) + { + char buf[32]; + sprintf(buf, "Object %d", n); + if (ImGui::Selectable(buf, selected == n)) + selected = n; + } + ImGui::TreePop(); + } + if (ImGui::TreeNode("Selection State: Multiple Selection")) + { + ShowHelpMarker("Hold CTRL and click to select multiple items."); + static bool selection[5] = { false, false, false, false, false }; + for (int n = 0; n < 5; n++) + { + char buf[32]; + sprintf(buf, "Object %d", n); + if (ImGui::Selectable(buf, selection[n])) + { + if (!ImGui::GetIO().KeyCtrl) // Clear selection when CTRL is not held + memset(selection, 0, sizeof(selection)); + selection[n] ^= 1; + } + } + ImGui::TreePop(); + } + if (ImGui::TreeNode("Rendering more text into the same line")) + { + // Using the Selectable() override that takes "bool* p_selected" parameter and toggle your booleans automatically. static bool selected[3] = { false, false, false }; - ImGui::Selectable("main.c", &selected[0]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes"); + ImGui::Selectable("main.c", &selected[0]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes"); ImGui::Selectable("Hello.cpp", &selected[1]); ImGui::SameLine(300); ImGui::Text("12,345 bytes"); - ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes"); + ImGui::Selectable("Hello.h", &selected[2]); ImGui::SameLine(300); ImGui::Text(" 2,345 bytes"); ImGui::TreePop(); } if (ImGui::TreeNode("In columns")) From a7deb3a3943c9fe8b0acb34bc65bc1ec5343d524 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 15:36:51 +0100 Subject: [PATCH 6/7] Demo: Minor tweaks. --- imgui_demo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 9f11de36c..76a8fa551 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -413,7 +413,7 @@ void ImGui::ShowDemoWindow(bool* p_open) { ImGui::Text("blah blah"); ImGui::SameLine(); - if (ImGui::SmallButton("print")) printf("Child %d pressed", i); + if (ImGui::SmallButton("button")) { }; ImGui::TreePop(); } ImGui::TreePop(); @@ -807,14 +807,14 @@ void ImGui::ShowDemoWindow(bool* p_open) { static ImVec4 color = ImColor(114, 144, 154, 200); - static bool hdr = false; static bool alpha_preview = true; static bool alpha_half_preview = false; static bool options_menu = true; - ImGui::Checkbox("With HDR", &hdr); ImGui::SameLine(); ShowHelpMarker("Currently all this does is to lift the 0..1 limits on dragging widgets."); + static bool hdr = false; ImGui::Checkbox("With Alpha Preview", &alpha_preview); ImGui::Checkbox("With Half Alpha Preview", &alpha_half_preview); ImGui::Checkbox("With Options Menu", &options_menu); ImGui::SameLine(); ShowHelpMarker("Right-click on the individual color widget to show options."); + ImGui::Checkbox("With HDR", &hdr); ImGui::SameLine(); ShowHelpMarker("Currently all this does is to lift the 0..1 limits on dragging widgets."); int misc_flags = (hdr ? ImGuiColorEditFlags_HDR : 0) | (alpha_half_preview ? ImGuiColorEditFlags_AlphaPreviewHalf : (alpha_preview ? ImGuiColorEditFlags_AlphaPreview : 0)) | (options_menu ? 0 : ImGuiColorEditFlags_NoOptions); ImGui::Text("Color widget:"); From 0a0b252bb6982e8033d9e321dfc75a1ff572bf60 Mon Sep 17 00:00:00 2001 From: omar Date: Wed, 3 Jan 2018 16:56:41 +0100 Subject: [PATCH 7/7] DragDrop: Removed IsDragDropActive() (introduced a few days ago, revert 06bea369c0ce977c1cb71e085d860a6644330297) as our use case doesn't need it anymore. Will add it if there is a real need. --- imgui.cpp | 6 ------ imgui.h | 1 - 2 files changed, 7 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index c4239190c..d764d60c9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11468,12 +11468,6 @@ void ImGui::EndDragDropTarget() IM_ASSERT(g.DragDropActive); } -bool ImGui::IsDragDropActive() -{ - ImGuiContext& g = *GImGui; - return g.DragDropActive; -} - //----------------------------------------------------------------------------- // PLATFORM DEPENDENT HELPERS //----------------------------------------------------------------------------- diff --git a/imgui.h b/imgui.h index 87d3ae380..fc9791a74 100644 --- a/imgui.h +++ b/imgui.h @@ -434,7 +434,6 @@ namespace ImGui IMGUI_API bool BeginDragDropTarget(); // call after submitting an item that may receive an item. If this returns true, you can call AcceptDragDropPayload() + EndDragDropTarget() IMGUI_API const ImGuiPayload* AcceptDragDropPayload(const char* type, ImGuiDragDropFlags flags = 0); // accept contents of a given type. If ImGuiDragDropFlags_AcceptBeforeDelivery is set you can peek into the payload before the mouse button is released. IMGUI_API void EndDragDropTarget(); - IMGUI_API bool IsDragDropActive(); // Clipping IMGUI_API void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect);