From 95dcf54d8da1e10dc4e288b3a5b9393f469cda89 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 15 Nov 2023 16:53:58 +0000 Subject: [PATCH] New is-canvas-item highlighting. --- common/lib_tree_model_adapter.cpp | 89 +++++++++++++++++-- .../symbol_tree_synchronizing_adapter.cpp | 17 +++- include/lib_tree_model_adapter.h | 4 +- include/widgets/wx_dataviewctrl.h | 1 + 4 files changed, 98 insertions(+), 13 deletions(-) diff --git a/common/lib_tree_model_adapter.cpp b/common/lib_tree_model_adapter.cpp index b9eb3dcdb6..40600851eb 100644 --- a/common/lib_tree_model_adapter.cpp +++ b/common/lib_tree_model_adapter.cpp @@ -29,12 +29,81 @@ #include #include #include +#include #include 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( static_cast( 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; } diff --git a/eeschema/symbol_tree_synchronizing_adapter.cpp b/eeschema/symbol_tree_synchronizing_adapter.cpp index a5257ed796..4afb0ceeab 100644 --- a/eeschema/symbol_tree_synchronizing_adapter.cpp +++ b/eeschema/symbol_tree_synchronizing_adapter.cpp @@ -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; diff --git a/include/lib_tree_model_adapter.h b/include/lib_tree_model_adapter.h index 69fbd2fa9f..bcc8a8d8cd 100644 --- a/include/lib_tree_model_adapter.h +++ b/include/lib_tree_model_adapter.h @@ -405,6 +405,8 @@ protected: std::map m_colIdxMap; std::vector 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* m_filter; std::vector m_columns; diff --git a/include/widgets/wx_dataviewctrl.h b/include/widgets/wx_dataviewctrl.h index d104ef7edf..51aff5400b 100644 --- a/include/widgets/wx_dataviewctrl.h +++ b/include/widgets/wx_dataviewctrl.h @@ -65,6 +65,7 @@ public: */ wxDataViewItem GetNextSibling( wxDataViewItem const& aItem ); + void DoSetToolTipText( const wxString &tip ) override {} }; #endif // WX_DATAVIEWCTRL_H_