From 8d21ee56d2a4ae50a5ca4c84442280251d945e84 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 22 Dec 2017 20:19:48 +0100 Subject: [PATCH 1/4] ImDrawList, Font: Fixed bug introduced in 531c11d5c72890f324c9734ef5c860408b8a7f3d (#1519) --- imgui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 272859c3..943b63ec 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1922,7 +1922,7 @@ static void SetCurrentWindow(ImGuiWindow* window) ImGuiContext& g = *GImGui; g.CurrentWindow = window; if (window) - g.FontSize = window->CalcFontSize(); + g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize(); } void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window) @@ -5843,7 +5843,7 @@ void ImGui::SetWindowFontScale(float scale) ImGuiContext& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); window->FontWindowScale = scale; - g.FontSize = window->CalcFontSize(); + g.FontSize = g.DrawListSharedData.FontSize = window->CalcFontSize(); } // User generally sees positions in window coordinates. Internally we store CursorPos in absolute screen coordinates because it is more convenient. From e1a103b251f219d567c60f8cffda100a057523c1 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 22 Dec 2017 13:41:41 +0100 Subject: [PATCH 2/4] Drag and Drop: Disable tracking mouse button ownership when an external drag source is active, to make it easier to achieve drag and drop over multiple OS windows. (#143) --- imgui.cpp | 5 +++-- imgui_demo.cpp | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 943b63ec..81a37d7a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2456,8 +2456,9 @@ void ImGui::NewFrame() g.OsImePosRequest = ImVec2(1.0f, 1.0f); // OS Input Method Editor showing on top-left of our window by default // If mouse was first clicked outside of ImGui bounds we also cancel out hovering. - // FIXME: For patterns of drag and drop between "application" and "imgui" we may need to rework/remove this test (first committed 311c0ca9 on 2015/02) - if (!mouse_avail_to_imgui) + // FIXME: For patterns of drag and drop across OS windows, we may need to rework/remove this test (first committed 311c0ca9 on 2015/02) + bool mouse_dragging_extern_payload = g.DragDropActive && (g.DragDropSourceFlags & ImGuiDragDropFlags_SourceExtern) != 0; + if (!mouse_avail_to_imgui && !mouse_dragging_extern_payload) g.HoveredWindow = g.HoveredRootWindow = NULL; // Scale & Scrolling diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 4f2705db..fb0cff59 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1734,7 +1734,10 @@ void ImGui::ShowTestWindow(bool* p_open) if (ImGui::TreeNode("Keyboard & Mouse State")) { - ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); + if (ImGui::IsMousePosValid()) + ImGui::Text("Mouse pos: (%g, %g)", io.MousePos.x, io.MousePos.y); + else + ImGui::Text("Mouse pos: "); 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); } From 471bcf8b5e5caa341293fb0b0e79daf19357189b Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 22 Dec 2017 19:35:58 +0100 Subject: [PATCH 3/4] Columns: Fixed dragging when using a same of columns multiple times in the frame. (#125) --- imgui.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 81a37d7a..2a1f5e8f 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10867,6 +10867,8 @@ static float PixelsToOffsetNorm(const ImGuiColumnsSet* columns, float offset) return (offset - columns->MinX) / (columns->MaxX - columns->MinX); } +static inline float GetColumnsRectHalfWidth() { return 4.0f; } + static float GetDraggedColumnOffset(ImGuiColumnsSet* columns, int column_index) { // Active (dragged) column always follow mouse. The reason we need this is that dragging a column to the right edge of an auto-resizing @@ -10876,7 +10878,7 @@ static float GetDraggedColumnOffset(ImGuiColumnsSet* columns, int column_index) IM_ASSERT(column_index > 0); // We cannot drag column 0. If you get this assert you may have a conflict between the ID of your columns and another widgets. IM_ASSERT(g.ActiveId == columns->ID + ImGuiID(column_index)); - float x = g.IO.MousePos.x - g.ActiveIdClickOffset.x - window->Pos.x; + float x = g.IO.MousePos.x - g.ActiveIdClickOffset.x + GetColumnsRectHalfWidth() - window->Pos.x; x = ImMax(x, ImGui::GetColumnOffset(column_index - 1) + g.Style.ColumnsMinSpacing); if ((columns->Flags & ImGuiColumnsFlags_NoPreserveWidths)) x = ImMin(x, ImGui::GetColumnOffset(column_index + 1) - g.Style.ColumnsMinSpacing); @@ -11086,7 +11088,7 @@ void ImGui::EndColumns() { float x = window->Pos.x + GetColumnOffset(n); const ImGuiID column_id = columns->ID + ImGuiID(n); - const float column_hw = 4.0f; // Half-width for interaction + const float column_hw = GetColumnsRectHalfWidth(); // Half-width for interaction const ImRect column_rect(ImVec2(x - column_hw, y1), ImVec2(x + column_hw, y2)); KeepAliveID(column_id); if (IsClippedEx(column_rect, column_id, false)) @@ -11098,8 +11100,6 @@ void ImGui::EndColumns() ButtonBehavior(column_rect, column_id, &hovered, &held); if (hovered || held) g.MouseCursor = ImGuiMouseCursor_ResizeEW; - if (held && g.ActiveIdIsJustActivated) - g.ActiveIdClickOffset.x -= column_hw; // Store from center of column line (we used a 8 wide rect for columns clicking). This is used by GetDraggedColumnOffset(). if (held && !(columns->Columns[n].Flags & ImGuiColumnsFlags_NoResize)) dragging_column = n; } From 46dcd9aa50148a0904f084713f38a0c53b1980d0 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 22 Dec 2017 19:45:15 +0100 Subject: [PATCH 4/4] Columns: Made PixelsToOffsetNorm() properly symetrical to OffsetNormToPixels() (#125) --- imgui.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 2a1f5e8f..dd580538 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -10864,7 +10864,7 @@ static float OffsetNormToPixels(const ImGuiColumnsSet* columns, float offset_nor static float PixelsToOffsetNorm(const ImGuiColumnsSet* columns, float offset) { - return (offset - columns->MinX) / (columns->MaxX - columns->MinX); + return offset / (columns->MaxX - columns->MinX); } static inline float GetColumnsRectHalfWidth() { return 4.0f; } @@ -10951,7 +10951,7 @@ void ImGui::SetColumnOffset(int column_index, float offset) if (!(columns->Flags & ImGuiColumnsFlags_NoForceWithinWindow)) offset = ImMin(offset, columns->MaxX - g.Style.ColumnsMinSpacing * (columns->Count - column_index)); - columns->Columns[column_index].OffsetNorm = PixelsToOffsetNorm(columns, offset); + columns->Columns[column_index].OffsetNorm = PixelsToOffsetNorm(columns, offset - columns->MinX); if (preserve_width) SetColumnOffset(column_index + 1, offset + ImMax(g.Style.ColumnsMinSpacing, width)); @@ -11015,7 +11015,7 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag // Set state for first column const float content_region_width = (window->SizeContentsExplicit.x != 0.0f) ? (window->SizeContentsExplicit.x) : (window->Size.x -window->ScrollbarSizes.x); columns->MinX = window->DC.IndentX - g.Style.ItemSpacing.x; // Lock our horizontal range - //column->ColumnsMaxX = content_region_width - window->Scroll.x -((window->Flags & ImGuiWindowFlags_NoScrollbar) ? 0 : g.Style.ScrollbarSize);// - window->WindowPadding().x; + //column->MaxX = content_region_width - window->Scroll.x - ((window->Flags & ImGuiWindowFlags_NoScrollbar) ? 0 : g.Style.ScrollbarSize);// - window->WindowPadding().x; columns->MaxX = content_region_width - window->Scroll.x; columns->StartPosY = window->DC.CursorPos.y; columns->StartMaxPosX = window->DC.CursorMaxPos.x; @@ -11043,7 +11043,7 @@ void ImGui::BeginColumns(const char* str_id, int columns_count, ImGuiColumnsFlag ImGuiColumnData* column = &columns->Columns[n]; float t = column->OffsetNorm; if (!(columns->Flags & ImGuiColumnsFlags_NoForceWithinWindow)) - t = ImMin(t, PixelsToOffsetNorm(columns, columns->MaxX - g.Style.ColumnsMinSpacing * (columns->Count - n))); + t = ImMin(t, PixelsToOffsetNorm(columns, (columns->MaxX - columns->MinX) - g.Style.ColumnsMinSpacing * (columns->Count - n))); column->OffsetNorm = t; if (n == columns_count)