| 399 | } |
| 400 | |
| 401 | void RibbonButtonDrawer::drawButtonIcon( const MenuItemInfo& item, const DrawButtonParams& params ) const |
| 402 | { |
| 403 | ImGui::BeginGroup(); |
| 404 | |
| 405 | int colorChanged = pushRibbonButtonColors( true, false, params.forceHovered, params.rootType ); |
| 406 | |
| 407 | float fontScale = 1.f; |
| 408 | if ( params.iconSize != 0 ) |
| 409 | fontScale = params.iconSize / cBigIconSize; |
| 410 | else if ( params.sizeType != DrawButtonParams::SizeType::Big ) |
| 411 | fontScale = cSmallIconSize / cBigIconSize; |
| 412 | RibbonFontHolder iconsFont( RibbonFontManager::FontType::Icons, fontScale ); |
| 413 | if ( !iconsFont.isPushed() ) |
| 414 | fontScale = 1.f; |
| 415 | |
| 416 | auto imageRequiredSize = std::round( 32.0f * fontScale * UI::scale() ); |
| 417 | ImVec2 iconRealSize = ImVec2( imageRequiredSize, imageRequiredSize ); |
| 418 | bool needTextColor = params.rootType != DrawButtonParams::Ribbon; |
| 419 | bool needChangeColor = needTextColor || monochrome_.has_value(); |
| 420 | auto* imageIcon = RibbonIcons::findByName( item.item->name(), iconRealSize.x, needChangeColor ? |
| 421 | RibbonIcons::ColorType::White : RibbonIcons::ColorType::Colored, |
| 422 | RibbonIcons::IconType::RibbonItemIcon ); |
| 423 | |
| 424 | if ( !imageIcon ) |
| 425 | iconRealSize = ImGui::CalcTextSize( item.icon.c_str() ); |
| 426 | |
| 427 | ImVec2 cursorPos = ImGui::GetCursorPos(); |
| 428 | cursorPos.x += ( params.itemSize.x - iconRealSize.x ) / 2.f; |
| 429 | cursorPos.y += ( params.itemSize.y - iconRealSize.y ) / 2.f; |
| 430 | ImGui::SetCursorPos( cursorPos ); |
| 431 | |
| 432 | if ( !imageIcon ) |
| 433 | { |
| 434 | ( !needTextColor && monochrome_.has_value() ) ? |
| 435 | ImGui::TextColored( ImVec4( Vector4f( *monochrome_ ) ), "%s", item.icon.c_str() ) : |
| 436 | ImGui::Text( "%s", item.icon.c_str() ); |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | ImVec4 multColor = ImVec4( 1, 1, 1, 1 ); |
| 441 | if ( needChangeColor ) |
| 442 | { |
| 443 | multColor = ( !needTextColor && monochrome_.has_value() ) ? |
| 444 | ImVec4( Vector4f( *monochrome_ ) ) : |
| 445 | ImGui::GetStyleColorVec4( ImGuiCol_Text ); |
| 446 | } |
| 447 | ImGui::Image( *imageIcon, iconRealSize, multColor ); |
| 448 | } |
| 449 | |
| 450 | iconsFont.popFont(); |
| 451 | |
| 452 | if ( colorChanged > 0 ) |
| 453 | ImGui::PopStyleColor( colorChanged ); |
| 454 | |
| 455 | ImGui::EndGroup(); |
| 456 | } |
| 457 | |
| 458 | bool RibbonButtonDrawer::drawTabArrowButton( const char* icon, const ImVec2& size, float iconSize ) |