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

Method drawSmallButtonsSet_

source/MRViewer/MRRibbonMenu.cpp:1295–1350  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1293}
1294
1295void RibbonMenu::drawSmallButtonsSet_( const std::vector<std::string>& group, int setFrontIndex, int setLength, bool withText )
1296{
1297 assert( setFrontIndex >= 0 );
1298 assert( setLength <= 3 );
1299 assert( setLength > 0 );
1300 assert( setFrontIndex + setLength <= group.size() );
1301
1302 const auto& style = ImGui::GetStyle();
1303
1304 const float cIconSize = cSmallIconSize * UI::scale();
1305
1306 float maxSetWidth = 0.0f;
1307 std::array<RibbonButtonDrawer::ButtonItemWidth, 3> widths;
1308 std::array<const MenuItemInfo*, 3> items{ nullptr,nullptr ,nullptr };
1309 auto type = withText ? DrawButtonParams::SizeType::SmallText : DrawButtonParams::SizeType::Small;
1310 for ( int i = setFrontIndex; i < setFrontIndex + setLength; ++i )
1311 {
1312 auto it = RibbonSchemaHolder::schema().items.find( group[i] );
1313 if ( it == RibbonSchemaHolder::schema().items.end() )
1314 continue; // TODO: assert or log
1315
1316 widths[i - setFrontIndex] = buttonDrawer_.calcItemWidth( it->second, type );
1317 auto sumWidth = widths[i - setFrontIndex].baseWidth + widths[i - setFrontIndex].additionalWidth;
1318 items[i - setFrontIndex] = &it->second;
1319 if ( sumWidth > maxSetWidth )
1320 maxSetWidth = sumWidth;
1321 }
1322 ImVec2 setSize;
1323
1324 auto availReg = ImGui::GetContentRegionAvail();
1325
1326 setSize.x = maxSetWidth;
1327
1328 setSize.y = availReg.y - 2 * style.WindowPadding.y;
1329
1330 ImVec2 smallItemSize;
1331 smallItemSize.x = setSize.x;
1332 smallItemSize.y = std::min( cIconSize + 2 * style.WindowPadding.y, setSize.y / 3.0f );
1333 ImGui::SetCursorPosY( ImGui::GetCursorPosY() + availReg.y * 0.5f - setSize.y * 0.5f - ImGui::GetStyle().CellPadding.y * 0.5f );
1334
1335 float spaceY = ( setSize.y - 3.0f * smallItemSize.y ) * 0.5f;
1336
1337 ImGui::BeginChild( ( "##SmallSet" + group[setFrontIndex] ).c_str(), setSize );
1338 auto basePosY = ImGui::GetCursorPosY();
1339 for ( int i = setFrontIndex; i < setFrontIndex + setLength; ++i )
1340 {
1341 smallItemSize.x = widths[i - setFrontIndex].baseWidth;
1342 if ( withText )
1343 smallItemSize.x += widths[i - setFrontIndex].additionalWidth;
1344
1345 ImGui::SetCursorPosY( basePosY + float( i - setFrontIndex ) * ( spaceY + smallItemSize.y ) );
1346 buttonDrawer_.drawButtonItem( *items[i - setFrontIndex], { type,smallItemSize,cSmallIconSize } );
1347 }
1348
1349 ImGui::EndChild();
1350}
1351
1352

Callers

nothing calls this directly

Calls 7

minFunction · 0.85
calcItemWidthMethod · 0.80
drawButtonItemMethod · 0.80
scaleFunction · 0.70
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected