diff --git a/src/CellularPanel.cpp b/src/CellularPanel.cpp index 28248a966..d6312a46b 100644 --- a/src/CellularPanel.cpp +++ b/src/CellularPanel.cpp @@ -1043,6 +1043,21 @@ wxRect CellularPanel::FindRect( const TrackPanelCell &cell ) return result; } +wxRect CellularPanel::FindRect( + const std::function< bool( TrackPanelNode& ) > &pred) +{ + wxRect result; + + struct Stop{}; + try { VisitPreorder( [&]( const wxRect &rect, TrackPanelNode &visited ) { + if ( pred( visited ) ) + result = rect, throw Stop{}; + } ); } + catch ( const Stop& ) {} + + return result; +} + UIHandlePtr CellularPanel::Target() { auto &state = *mState; diff --git a/src/CellularPanel.h b/src/CellularPanel.h index f4c57eeab..6f8f37e9a 100644 --- a/src/CellularPanel.h +++ b/src/CellularPanel.h @@ -97,6 +97,12 @@ public: // is not specified which rectangle is returned. wxRect FindRect(const TrackPanelCell &cell); + // Search the tree of subdivisions of the panel area for a node (group or + // cell) satisfying the predicate. If more than one sub-area is associated + // with some node satisfying the predicate, it is not specified which + // rectangle is returned. + wxRect FindRect(const std::function< bool( TrackPanelNode& ) > &pred); + UIHandlePtr Target(); std::shared_ptr LastCell() const;