MCPcopy Create free account
hub / github.com/SpartanJ/eepp / createListViewHelper

Method createListViewHelper

src/tools/ecode/plugins/plugin.cpp:128–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126}
127
128UIListView* 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
167void Plugin::createListView( UICodeEditor* editor, std::shared_ptr<Model> model,
168 const ModelEventCallback& onModelEventCb,

Callers

nothing calls this directly

Calls 15

findAllByClassMethod · 0.80
setParentMethod · 0.80
addClassMethod · 0.80
getDocumentRefMethod · 0.80
setPixelsPositionMethod · 0.80
setScrollModeMethod · 0.80
closeMethod · 0.65
getIdMethod · 0.65
NewFunction · 0.50
startMethod · 0.45

Tested by

no test coverage detected