Skip to content

Commit

Permalink
Columns: Fixed offset rounding leading to SetColumnOffset() being des…
Browse files Browse the repository at this point in the history
…tructive when ImGuiColumnsFlags_NoPreserveWidths flag is not set. (#913, #125)
  • Loading branch information
ocornut committed Aug 20, 2017
1 parent 3bf2af2 commit a511b00
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9952,7 +9952,7 @@ static float GetDraggedColumnOffset(int column_index)
if ((window->DC.ColumnsFlags & ImGuiColumnsFlags_NoPreserveWidths))
x = ImMin(x, ImGui::GetColumnOffset(column_index+1) - g.Style.ColumnsMinSpacing);

return (float)(int)x;
return x;
}

float ImGui::GetColumnOffset(int column_index)
Expand All @@ -9972,7 +9972,7 @@ float ImGui::GetColumnOffset(int column_index)
IM_ASSERT(column_index < window->DC.ColumnsData.Size);
const float t = window->DC.ColumnsData[column_index].OffsetNorm;
const float x_offset = ImLerp(window->DC.ColumnsMinX, window->DC.ColumnsMaxX, t);
return (float)(int)x_offset;
return x_offset;
}

void ImGui::SetColumnOffset(int column_index, float offset)
Expand All @@ -9988,7 +9988,7 @@ void ImGui::SetColumnOffset(int column_index, float offset)
const float width = preserve_width ? GetColumnWidth(column_index) : 0.0f;

if (!(window->DC.ColumnsFlags & ImGuiColumnsFlags_NoForceWithinWindow))
offset = ImMin((float)(int)offset, window->DC.ColumnsMaxX - g.Style.ColumnsMinSpacing * (window->DC.ColumnsCount - column_index));
offset = ImMin(offset, window->DC.ColumnsMaxX - g.Style.ColumnsMinSpacing * (window->DC.ColumnsCount - column_index));
const float offset_norm = PixelsToOffsetNorm(window, offset);

const ImGuiID column_id = window->DC.ColumnsSetId + ImGuiID(column_index);
Expand Down
2 changes: 1 addition & 1 deletion imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ namespace ImGui
IMGUI_API int GetColumnIndex(); // get current column index
IMGUI_API float GetColumnWidth(int column_index = -1); // get column width (in pixels). pass -1 to use current column
IMGUI_API void SetColumnWidth(int column_index, float width); // set column width (in pixels). pass -1 to use current column
IMGUI_API float GetColumnOffset(int column_index = -1); // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetColumnsCount() inclusive. column 0 is usually 0.0f and not resizable unless you call this
IMGUI_API float GetColumnOffset(int column_index = -1); // get position of column line (in pixels, from the left side of the contents region). pass -1 to use current column, otherwise 0..GetColumnsCount() inclusive. column 0 is typically 0.0f
IMGUI_API void SetColumnOffset(int column_index, float offset_x); // set position of column line (in pixels, from the left side of the contents region). pass -1 to use current column
IMGUI_API int GetColumnsCount();

Expand Down

0 comments on commit a511b00

Please sign in to comment.