Merge branch 'master' into navigation
diff --git a/LICENSE.txt b/LICENSE.txt
index 5a9b98b..21b6ee7 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-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
diff --git a/imgui.cpp b/imgui.cpp
index 07f62dc..ae679c0 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -1736,7 +1736,7 @@
// ImGuiSimpleColumns (internal use only)
//-----------------------------------------------------------------------------
-ImGuiSimpleColumns::ImGuiSimpleColumns()
+ImGuiMenuColumns::ImGuiMenuColumns()
{
Count = 0;
Spacing = Width = NextWidth = 0.0f;
@@ -1744,7 +1744,7 @@
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;
@@ -1761,7 +1761,7 @@
}
}
-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);
@@ -1772,7 +1772,7 @@
return ImMax(Width, NextWidth);
}
-float ImGuiSimpleColumns::CalcExtraSpace(float avail_w)
+float ImGuiMenuColumns::CalcExtraSpace(float avail_w)
{
return ImMax(0.0f, avail_w - Width);
}
@@ -12180,6 +12180,10 @@
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)
@@ -12192,7 +12196,6 @@
columns->Columns.push_back(column);
}
}
- IM_ASSERT(columns->Columns.Size == columns_count + 1);
for (int n = 0; n < columns_count + 1; n++)
{
@@ -12641,12 +12644,6 @@
IM_ASSERT(g.DragDropActive);
}
-bool ImGui::IsDragDropActive()
-{
- ImGuiContext& g = *GImGui;
- return g.DragDropActive;
-}
-
//-----------------------------------------------------------------------------
// PLATFORM DEPENDENT HELPERS
//-----------------------------------------------------------------------------
@@ -12764,7 +12761,7 @@
{
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.h b/imgui.h
index 5d9b446..a6dfcc7 100644
--- a/imgui.h
+++ b/imgui.h
@@ -379,8 +379,8 @@
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.
@@ -437,7 +437,6 @@
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);
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 9d9d779..9427516 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -160,7 +160,7 @@
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.");
@@ -416,7 +416,7 @@
{
ImGui::Text("blah blah");
ImGui::SameLine();
- if (ImGui::SmallButton("print")) printf("Child %d pressed", i);
+ if (ImGui::SmallButton("button")) { };
ImGui::TreePop();
}
ImGui::TreePop();
@@ -612,24 +612,58 @@
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"))
@@ -776,14 +810,14 @@
{
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:");
diff --git a/imgui_internal.h b/imgui_internal.h
index 655e5c2..d1dd581 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -36,7 +36,7 @@
struct ImGuiColMod;
struct ImGuiStyleMod;
struct ImGuiGroupData;
-struct ImGuiSimpleColumns;
+struct ImGuiMenuColumns;
struct ImGuiDrawContext;
struct ImGuiTextEditState;
struct ImGuiMouseCursorData;
@@ -341,14 +341,14 @@
};
// 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);
@@ -898,7 +898,7 @@
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<ImGuiColumnsSet> ColumnsStorage;
float FontWindowScale; // Scale multiplier per-window