From 4cd0ec880859de66e1d0663a72fe1ae76abb85ce Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Tue, 7 Jul 2020 19:43:51 +0100 Subject: [PATCH] Fix library tree column widths when tree is refreshed GTK only calculates new widths once the tree is displayed, so calling Refresh after updating the tree but before display will return a column width of 0. Instead, use saved column widths if an invalid width was returned. Fixes https://gitlab.com/kicad/code/kicad/issues/4837 --- common/lib_tree_model_adapter.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/common/lib_tree_model_adapter.cpp b/common/lib_tree_model_adapter.cpp index 56677762c4..a4404a3521 100644 --- a/common/lib_tree_model_adapter.cpp +++ b/common/lib_tree_model_adapter.cpp @@ -403,8 +403,22 @@ void LIB_TREE_MODEL_ADAPTER::RefreshTree() // user's scroll position (which re-attaching or deleting/re-inserting columns does). static int walk = 1; - m_col_part->SetWidth( m_col_part->GetWidth() + walk ); - m_col_desc->SetWidth( m_col_desc->GetWidth() - walk ); + int partWidth = m_col_part->GetWidth(); + int descWidth = m_col_desc->GetWidth(); + + // Only use the widths read back if they are non-zero. + // GTK returns the displayed width of the column, which is not calculated immediately + if( descWidth > 0 ) + { + m_colWidths[PART_COL] = partWidth; + m_colWidths[DESC_COL] = descWidth; + } + + m_colWidths[PART_COL] += walk; + m_colWidths[DESC_COL] -= walk; + + m_col_part->SetWidth( m_colWidths[PART_COL] ); + m_col_desc->SetWidth( m_colWidths[DESC_COL] ); walk = -walk; }