Avoid collapsing component chooser column widths to zero
Fixes: lp:1670762 * https://bugs.launchpad.net/kicad/+bug/1670762
This commit is contained in:
parent
11f4622ea5
commit
36e400ec5b
|
@ -198,10 +198,14 @@ void CMP_TREE_MODEL_ADAPTER::AttachTo( wxDataViewCtrl* aDataViewCtrl )
|
||||||
aDataViewCtrl->SetIndent( kDataViewIndent );
|
aDataViewCtrl->SetIndent( kDataViewIndent );
|
||||||
aDataViewCtrl->AssociateModel( this );
|
aDataViewCtrl->AssociateModel( this );
|
||||||
aDataViewCtrl->ClearColumns();
|
aDataViewCtrl->ClearColumns();
|
||||||
m_col_part = aDataViewCtrl->AppendTextColumn( _( "Part" ), 0, wxDATAVIEW_CELL_INERT,
|
|
||||||
ColWidth( m_tree, 0 ) );
|
wxString part_head = _( "Part" );
|
||||||
m_col_desc = aDataViewCtrl->AppendTextColumn( _( "Description" ), 1, wxDATAVIEW_CELL_INERT,
|
wxString desc_head = _( "Desc" );
|
||||||
ColWidth( m_tree, 1 ) );
|
|
||||||
|
m_col_part = aDataViewCtrl->AppendTextColumn( part_head, 0, wxDATAVIEW_CELL_INERT,
|
||||||
|
ColWidth( m_tree, 0, part_head ) );
|
||||||
|
m_col_desc = aDataViewCtrl->AppendTextColumn( desc_head, 1, wxDATAVIEW_CELL_INERT,
|
||||||
|
ColWidth( m_tree, 1, desc_head ) );
|
||||||
aDataViewCtrl->Thaw();
|
aDataViewCtrl->Thaw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,18 +321,22 @@ int CMP_TREE_MODEL_ADAPTER::Compare(
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int CMP_TREE_MODEL_ADAPTER::ColWidth( CMP_TREE_NODE& aNode, int aCol )
|
int CMP_TREE_MODEL_ADAPTER::ColWidth( CMP_TREE_NODE& aTree, int aCol, wxString const& aHeading )
|
||||||
{
|
{
|
||||||
const int indent = aCol ? 0 : kDataViewIndent;
|
const int indent = aCol ? 0 : kDataViewIndent;
|
||||||
int max_width = aNode.Score > 0 ? WidthFor( aNode, aCol ) : 0;
|
|
||||||
|
|
||||||
for( auto& node: aNode.Children )
|
int min_width = WidthFor( aHeading, aCol );
|
||||||
|
int width = std::max( aTree.Score > 0 ? WidthFor( aTree, aCol ) : 0, min_width );
|
||||||
|
|
||||||
|
if( aTree.Score > 0 )
|
||||||
{
|
{
|
||||||
if( aNode.Score > 0 )
|
for( auto& node: aTree.Children )
|
||||||
max_width = std::max( max_width, ColWidth( *node, aCol ) + indent );
|
{
|
||||||
|
width = std::max( width, ColWidth( *node, aCol, aHeading ) + indent );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return max_width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -352,6 +360,24 @@ int CMP_TREE_MODEL_ADAPTER::WidthFor( CMP_TREE_NODE& aNode, int aCol )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int CMP_TREE_MODEL_ADAPTER::WidthFor( wxString const& aHeading, int aCol )
|
||||||
|
{
|
||||||
|
static std::vector<int> widths;
|
||||||
|
|
||||||
|
for( int i = (int) widths.size(); i <= aCol; ++i )
|
||||||
|
{
|
||||||
|
widths.push_back( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if( widths[aCol] == 0 )
|
||||||
|
{
|
||||||
|
widths[aCol] = m_widget->GetTextExtent( aHeading ).x;
|
||||||
|
}
|
||||||
|
|
||||||
|
return widths[aCol];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool CMP_TREE_MODEL_ADAPTER::ShowResults()
|
bool CMP_TREE_MODEL_ADAPTER::ShowResults()
|
||||||
{
|
{
|
||||||
return FindAndExpand( m_tree,
|
return FindAndExpand( m_tree,
|
||||||
|
|
|
@ -322,8 +322,12 @@ private:
|
||||||
/**
|
/**
|
||||||
* Compute the width required for the given column of a node and its
|
* Compute the width required for the given column of a node and its
|
||||||
* children.
|
* children.
|
||||||
|
*
|
||||||
|
* @param aNode - root node of the tree
|
||||||
|
* @param aCol - column number
|
||||||
|
* @param aHeading - heading text, to set the minimum width
|
||||||
*/
|
*/
|
||||||
int ColWidth( CMP_TREE_NODE& aNode, int aCol );
|
int ColWidth( CMP_TREE_NODE& aTree, int aCol, wxString const& aHeading );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the width required to display a single row's aCol text.
|
* Return the width required to display a single row's aCol text.
|
||||||
|
@ -332,6 +336,12 @@ private:
|
||||||
*/
|
*/
|
||||||
int WidthFor( CMP_TREE_NODE& aNode, int aCol );
|
int WidthFor( CMP_TREE_NODE& aNode, int aCol );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the width required to display a column's heading. This is
|
||||||
|
* cached by column number for the same reason as the width per cell.
|
||||||
|
*/
|
||||||
|
int WidthFor( wxString const& aHeading, int aCol );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find any results worth highlighting and expand them, according to given
|
* Find any results worth highlighting and expand them, according to given
|
||||||
* criteria (f(CMP_TREE_NODE const*) -> bool)
|
* criteria (f(CMP_TREE_NODE const*) -> bool)
|
||||||
|
|
Loading…
Reference in New Issue