| 126 | } |
| 127 | |
| 128 | UIListView* Plugin::createListViewHelper( UICodeEditor* editor, std::shared_ptr<Model> model, |
| 129 | const ModelEventCallback& onModelEventCb ) { |
| 130 | auto lvs = editor->findAllByClass( "editor_listview" ); |
| 131 | for ( auto* ilv : lvs ) |
| 132 | ilv->close(); |
| 133 | std::string id = editor->getId(); // ID must be stable and unique |
| 134 | UIListView* lv = UIListView::New(); |
| 135 | lv->setParent( editor ); |
| 136 | lv->addClass( "editor_listview" ); |
| 137 | auto pos = |
| 138 | editor->getRelativeScreenPosition( editor->getDocumentRef()->getSelection().start() ); |
| 139 | lv->setPixelsPosition( { pos.x, pos.y + editor->getLineHeight() } ); |
| 140 | if ( !lv->getParent()->getLocalBounds().contains( |
| 141 | lv->getLocalBounds().setPosition( lv->getPixelsPosition() ) ) ) { |
| 142 | lv->setPixelsPosition( { pos.x, pos.y - lv->getPixelsSize().getHeight() } ); |
| 143 | } |
| 144 | lv->setVisible( true ); |
| 145 | lv->getVerticalScrollBar()->reloadStyle( true, true, true ); |
| 146 | lv->setAutoExpandOnSingleColumn( false ); |
| 147 | lv->setModel( model ); |
| 148 | Float height = std::min( lv->getContentSize().y, lv->getRowHeight() * 8 ); |
| 149 | Float colWidth = lv->getMaxColumnContentWidth( 0 ) + PixelDensity::dpToPx( 4 ); |
| 150 | bool needsVScroll = lv->getContentSize().y > lv->getRowHeight() * 8; |
| 151 | Float width = colWidth + lv->getPixelsPadding().getWidth() + |
| 152 | ( needsVScroll ? lv->getVerticalScrollBar()->getPixelsSize().getWidth() : 0 ); |
| 153 | lv->setPixelsSize( { width, height } ); |
| 154 | lv->setColumnWidth( 0, colWidth ); |
| 155 | lv->setScrollMode( needsVScroll ? ScrollBarMode::Auto : ScrollBarMode::AlwaysOff, |
| 156 | ScrollBarMode::AlwaysOff ); |
| 157 | lv->on( Event::OnModelEvent, [onModelEventCb]( const Event* event ) { |
| 158 | const ModelEvent* modelEvent = static_cast<const ModelEvent*>( event ); |
| 159 | if ( onModelEventCb ) |
| 160 | onModelEventCb( modelEvent ); |
| 161 | } ); |
| 162 | lv->setSelection( model->index( 0 ) ); |
| 163 | lv->setFocus(); |
| 164 | return lv; |
| 165 | } |
| 166 | |
| 167 | void Plugin::createListView( UICodeEditor* editor, std::shared_ptr<Model> model, |
| 168 | const ModelEventCallback& onModelEventCb, |
nothing calls this directly
no test coverage detected