MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / setupItemsGroupConfig_

Method setupItemsGroupConfig_

source/MRViewer/MRRibbonMenu.cpp:1353–1469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1351
1352
1353RibbonMenu::DrawTabConfig RibbonMenu::setupItemsGroupConfig_( const std::vector<std::string>& groupsInTab,
1354 const std::string& tabName, bool centerItems )
1355{
1356 DrawTabConfig res( groupsInTab.size() );
1357 const auto& style = ImGui::GetStyle();
1358 const float screenWidth = float( getViewerInstance().framebufferSize.x ) - ( ImGui::GetCursorScreenPos().x - ImGui::GetMainViewport()->Pos.x ) -
1359 ( float( groupsInTab.size() ) + 1.0f ) * UI::scale();
1360 std::vector<float> groupWidths( groupsInTab.size() );
1361 float sumWidth = 0.0f;
1362
1363 auto calcGroupWidth = [&] ( const MenuItemsList& items, DrawGroupConfig config )->float
1364 {
1365 assert( config.numBig + config.numSmallText + config.numSmall == items.size() );
1366 float resWidth = 0.0f;
1367 for ( int i = 0; i < items.size();)
1368 {
1369 if ( config.numBig > 0 )
1370 {
1371 auto itemIt = RibbonSchemaHolder::schema().items.find( items[i] );
1372 ++i;
1373 --config.numBig;
1374 if ( itemIt == RibbonSchemaHolder::schema().items.end() )
1375 continue; // TODO: asserts or log
1376 resWidth += buttonDrawer_.calcItemWidth( itemIt->second, DrawButtonParams::SizeType::Big ).baseWidth;
1377 resWidth += style.ItemSpacing.x;
1378 continue;
1379 }
1380 else
1381 {
1382 bool smallText = config.numSmallText > 0;
1383 assert( smallText || config.numSmall > 0 );
1384 auto& num = smallText ? config.numSmallText : config.numSmall;
1385 int n = std::min( 3, num );
1386 float maxWidth = 0.0f;
1387 for ( int j = i; j < i + n; ++j )
1388 {
1389 auto itemIt = RibbonSchemaHolder::schema().items.find( items[j] );
1390 if ( itemIt == RibbonSchemaHolder::schema().items.end() )
1391 continue; // TODO: asserts or log
1392 auto width = buttonDrawer_.calcItemWidth( itemIt->second,
1393 smallText ?
1394 DrawButtonParams::SizeType::SmallText :
1395 DrawButtonParams::SizeType::Small );
1396 maxWidth = std::max( width.baseWidth + width.additionalWidth, maxWidth );
1397 }
1398 resWidth += maxWidth;
1399 i += n;
1400 num -= n;
1401 resWidth += style.ItemSpacing.x;
1402 continue;
1403 }
1404 }
1405 resWidth += 2.0f * style.CellPadding.x;
1406 resWidth -= style.ItemSpacing.x; // remove one last spacing
1407 return resWidth;
1408 };
1409
1410 for ( int i = 0; i < groupsInTab.size(); ++i )

Callers

nothing calls this directly

Calls 11

minFunction · 0.85
maxFunction · 0.85
calcItemWidthMethod · 0.80
push_backMethod · 0.80
scaleFunction · 0.70
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
reserveMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected