Columns: Made GetColumnOffset() and GetColumnWidth() behave when there's no column set, consistently with other column functions + fixed Columns demo (#2683)

This commit is contained in:
omar 2019-07-21 11:23:15 -07:00
parent b443bc0a64
commit c37f21788f
3 changed files with 11 additions and 4 deletions

View File

@ -64,6 +64,8 @@ Other Changes:
- Columns: Improved honoring alignment with various values of ItemSpacing.x and WindowPadding.x. (#125, #2666) - Columns: Improved honoring alignment with various values of ItemSpacing.x and WindowPadding.x. (#125, #2666)
- Word-wrapping: Fixed overzealous word-wrapping when glyph edge lands exactly on the limit. Because - Word-wrapping: Fixed overzealous word-wrapping when glyph edge lands exactly on the limit. Because
of this, auto-fitting exactly unwrapped text would make it wrap. (fixes initial 1.15 commit, 78645a7d). of this, auto-fitting exactly unwrapped text would make it wrap. (fixes initial 1.15 commit, 78645a7d).
- Columns: Made GetColumnOffset() and GetColumnWidth() behave when there's no column set, consistently with
other column functions. (#2683)
- Scrolling: Added SetScrollHereX(), SetScrollFromPosX() for completeness. (#1580) [@kevreco] - Scrolling: Added SetScrollHereX(), SetScrollFromPosX() for completeness. (#1580) [@kevreco]
- Style: Attenuated default opacity of ImGuiCol_Separator in Classic and Light styles. - Style: Attenuated default opacity of ImGuiCol_Separator in Classic and Light styles.
- Style: Added style.ColorButtonPosition (left/right, defaults to ImGuiDir_Right) to move the color button - Style: Added style.ColorButtonPosition (left/right, defaults to ImGuiDir_Right) to move the color button

View File

@ -2593,7 +2593,9 @@ static void ShowDemoWindowColumns()
static int columns_count = 4; static int columns_count = 4;
const int lines_count = 3; const int lines_count = 3;
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8); ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8);
ImGui::DragInt("##columns_count", &columns_count, 0.1f, 1, 10, "%d columns"); ImGui::DragInt("##columns_count", &columns_count, 0.1f, 2, 10, "%d columns");
if (columns_count < 2)
columns_count = 2;
ImGui::SameLine(); ImGui::SameLine();
ImGui::Checkbox("horizontal", &h_borders); ImGui::Checkbox("horizontal", &h_borders);
ImGui::SameLine(); ImGui::SameLine();

View File

@ -7152,7 +7152,8 @@ float ImGui::GetColumnOffset(int column_index)
{ {
ImGuiWindow* window = GetCurrentWindowRead(); ImGuiWindow* window = GetCurrentWindowRead();
ImGuiColumns* columns = window->DC.CurrentColumns; ImGuiColumns* columns = window->DC.CurrentColumns;
IM_ASSERT(columns != NULL); if (columns == NULL)
return 0.0f;
if (column_index < 0) if (column_index < 0)
column_index = columns->Current; column_index = columns->Current;
@ -7178,9 +7179,11 @@ static float GetColumnWidthEx(ImGuiColumns* columns, int column_index, bool befo
float ImGui::GetColumnWidth(int column_index) float ImGui::GetColumnWidth(int column_index)
{ {
ImGuiWindow* window = GetCurrentWindowRead(); ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
ImGuiColumns* columns = window->DC.CurrentColumns; ImGuiColumns* columns = window->DC.CurrentColumns;
IM_ASSERT(columns != NULL); if (columns == NULL)
return GetContentRegionAvail().x;
if (column_index < 0) if (column_index < 0)
column_index = columns->Current; column_index = columns->Current;