New is-canvas-item highlighting.

This commit is contained in:
Jeff Young 2023-11-15 16:53:58 +00:00
parent a5c34c50d7
commit 95dcf54d8d
4 changed files with 98 additions and 13 deletions

View File

@ -29,12 +29,81 @@
#include <widgets/ui_common.h>
#include <wx/tokenzr.h>
#include <wx/wupdlock.h>
#include <wx/settings.h>
#include <string_utils.h>
static const int kDataViewIndent = 20;
class LIB_TREE_RENDERER : public wxDataViewCustomRenderer
{
public:
LIB_TREE_RENDERER() :
m_canvasItem( false )
{}
wxSize GetSize() const override
{
return wxSize( GetOwner()->GetWidth(), GetTextExtent( m_text ).y );
}
bool GetValue( wxVariant& aValue ) const override
{
aValue = m_text;
return true;
}
bool SetValue( const wxVariant& aValue ) override
{
m_text = aValue.GetString();
return true;
}
void SetAttr( const wxDataViewItemAttr& aAttr ) override
{
// Use strikethrough as a proxy for is-canvas-item
m_canvasItem = aAttr.GetStrikethrough();
wxDataViewItemAttr realAttr = aAttr;
realAttr.SetStrikethrough( false );
wxDataViewCustomRenderer::SetAttr( realAttr );
}
bool Render( wxRect aRect, wxDC *dc, int aState ) override
{
RenderBackground( dc, aRect );
if( m_canvasItem )
{
wxPoint points[6];
points[0] = aRect.GetTopLeft();
points[1] = aRect.GetTopRight() + wxPoint( -4, 0 );
points[2] = aRect.GetTopRight() + wxPoint( 0, aRect.GetHeight() / 2 );
points[3] = aRect.GetBottomRight() + wxPoint( -4, 1 );
points[4] = aRect.GetBottomLeft() + wxPoint( 0, 1 );
points[5] = aRect.GetTopLeft();
dc->DrawLines( 6, points );
}
// We should be able to pass wxDATAVIEW_CELL_SELECTED into RenderText() and have it do
// the right thing -- but it picks wxSYS_COLOUR_HIGHLIGHTTEXT on MacOS and GTK (instead
// of wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT).
if ( aState & wxDATAVIEW_CELL_SELECTED )
dc->SetTextForeground( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
aRect.Deflate( 1 );
RenderText( m_text, 0, aRect, dc, 0 );
return true;
}
private:
bool m_canvasItem;
wxString m_text;
};
wxDataViewItem LIB_TREE_MODEL_ADAPTER::ToItem( const LIB_TREE_NODE* aNode )
{
return wxDataViewItem( const_cast<void*>( static_cast<void const*>( aNode ) ) );
@ -49,12 +118,12 @@ LIB_TREE_NODE* LIB_TREE_MODEL_ADAPTER::ToNode( wxDataViewItem aItem )
LIB_TREE_MODEL_ADAPTER::LIB_TREE_MODEL_ADAPTER( EDA_BASE_FRAME* aParent,
const wxString& aPinnedKey ) :
m_widget( nullptr ),
m_parent( aParent ),
m_sort_mode( BEST_MATCH ),
m_show_units( true ),
m_preselect_unit( 0 ),
m_freeze( 0 ),
m_widget( nullptr ),
m_filter( nullptr )
{
// Default column widths. Do not translate these names.
@ -305,18 +374,20 @@ wxDataViewColumn* LIB_TREE_MODEL_ADAPTER::doAddColumn( const wxString& aHeader,
if( !m_colWidths.count( aHeader ) || m_colWidths[aHeader] < headerMinWidth.x )
m_colWidths[aHeader] = headerMinWidth.x;
int index = m_columns.size();
int index = (int) m_columns.size();
wxDataViewColumn* ret = m_widget->AppendTextColumn( translatedHeader, index,
wxDATAVIEW_CELL_INERT,
m_colWidths[aHeader] );
ret->SetMinWidth( headerMinWidth.x );
wxDataViewColumn* col = new wxDataViewColumn( translatedHeader, new LIB_TREE_RENDERER(),
index, m_colWidths[aHeader], wxALIGN_NOT,
wxDATAVIEW_CELL_INERT );
m_widget->AppendColumn( col );
m_columns.emplace_back( ret );
m_colNameMap[aHeader] = ret;
col->SetMinWidth( headerMinWidth.x );
m_columns.emplace_back( col );
m_colNameMap[aHeader] = col;
m_colIdxMap[m_columns.size() - 1] = aHeader;
return ret;
return col;
}

View File

@ -326,9 +326,16 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, un
// mark modified libs with bold font
aAttr.SetBold( m_libMgr->IsLibraryModified( node->m_Name ) );
// mark the current library with background color
// mark the current library if it's collapsed
if( curSymbol && curSymbol->GetLibId().GetLibNickname() == node->m_LibId.GetLibNickname() )
{
#if 1
if( !m_widget->IsExpanded( ToItem( node ) ) )
{
// LIB_TREE_RENDERER uses strikethrough as a proxy for is-canvas-item
aAttr.SetStrikethrough( true );
}
#else
#ifdef __WXGTK__
// The native wxGTK+ impl ignores background colour, so set the text colour instead.
// This works reasonably well in dark themes, and quite poorly in light ones....
@ -336,6 +343,7 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, un
#else
aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
#endif
#endif
}
break;
@ -347,9 +355,13 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, un
// mark aliases with italic font
aAttr.SetItalic( !node->m_IsRoot );
// mark the current part with background color
// mark the current (on-canvas) part
if( curSymbol && curSymbol->GetLibId() == node->m_LibId )
{
#if 1
// LIB_TREE_RENDERER uses strikethrough as a proxy for is-canvas-item
aAttr.SetStrikethrough( true );
#else
#ifdef __WXGTK__
// The native wxGTK+ impl ignores background colour, so set the text colour instead.
// This works reasonably well in dark themes, and quite poorly in light ones....
@ -357,6 +369,7 @@ bool SYMBOL_TREE_SYNCHRONIZING_ADAPTER::GetAttr( wxDataViewItem const& aItem, un
#else
aAttr.SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_HIGHLIGHT ) );
aAttr.SetColour( wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT ) );
#endif
#endif
}
break;

View File

@ -405,6 +405,8 @@ protected:
std::map<unsigned, wxString> m_colIdxMap;
std::vector<wxString> m_availableColumns;
wxDataViewCtrl* m_widget;
private:
EDA_BASE_FRAME* m_parent;
@ -414,8 +416,6 @@ private:
int m_preselect_unit;
int m_freeze;
wxDataViewCtrl* m_widget;
std::function<bool( LIB_TREE_NODE& aNode )>* m_filter;
std::vector<wxDataViewColumn*> m_columns;

View File

@ -65,6 +65,7 @@ public:
*/
wxDataViewItem GetNextSibling( wxDataViewItem const& aItem );
void DoSetToolTipText( const wxString &tip ) override {}
};
#endif // WX_DATAVIEWCTRL_H_