| 1765 | } |
| 1766 | |
| 1767 | Float UINode::getAbsoluteFontSize( const UIWidget* widget ) const { |
| 1768 | std::string pxStr = widget->getPropertyString( |
| 1769 | StyleSheetSpecification::instance()->getProperty( PropertyId::FontSize ) ); |
| 1770 | if ( pxStr.empty() ) |
| 1771 | return 12.f * PixelDensity::getPixelDensity(); |
| 1772 | StyleSheetLength len( pxStr ); |
| 1773 | if ( len.getUnit() == StyleSheetLength::Unit::Rem ) { |
| 1774 | Float rootFontSize = 12.f * PixelDensity::getPixelDensity(); |
| 1775 | if ( widget->getUISceneNode() ) { |
| 1776 | UIWidget* docRoot = const_cast<UIWidget*>( widget ); |
| 1777 | while ( docRoot->getParent() && docRoot->getParent()->isWidget() ) { |
| 1778 | if ( docRoot->getElementTag() == "html" ) |
| 1779 | break; |
| 1780 | docRoot = docRoot->getParent()->asType<UIWidget>(); |
| 1781 | } |
| 1782 | rootFontSize = getAbsoluteFontSize( docRoot ); |
| 1783 | } |
| 1784 | return len.getValue() * rootFontSize; |
| 1785 | } else if ( len.getUnit() == StyleSheetLength::Unit::Em || |
| 1786 | len.getUnit() == StyleSheetLength::Unit::Percentage ) { |
| 1787 | Float parentFontSize = 12.f; |
| 1788 | Node* pNode = widget->getParent(); |
| 1789 | while ( pNode ) { |
| 1790 | if ( pNode->isWidget() ) { |
| 1791 | parentFontSize = getAbsoluteFontSize( pNode->asType<UIWidget>() ); |
| 1792 | break; |
| 1793 | } |
| 1794 | pNode = pNode->getParent(); |
| 1795 | } |
| 1796 | if ( len.getUnit() == StyleSheetLength::Unit::Em ) |
| 1797 | return len.getValue() * parentFontSize; |
| 1798 | return ( len.getValue() / 100.f ) * parentFontSize; |
| 1799 | } |
| 1800 | return widget->convertLength( len, 0 ); |
| 1801 | } |
| 1802 | |
| 1803 | }} // namespace EE::UI |
nothing calls this directly
no test coverage detected