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

Method propagateInheritedProperty

src/eepp/ui/uiwidget.cpp:1758–1813  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1756}
1757
1758void UIWidget::propagateInheritedProperty( const CSS::StyleSheetProperty& property ) {
1759 CSS::StyleSheetProperty propToPropagate = property;
1760
1761 if ( property.getPropertyDefinition() &&
1762 property.getPropertyDefinition()->getPropertyId() == PropertyId::FontSize ) {
1763 StyleSheetLength length( property.value() );
1764 Float pxSize = 0;
1765
1766 if ( length.getUnit() == StyleSheetLength::Unit::Rem ) {
1767 Float rootFontSize = 12.f;
1768 if ( getUISceneNode() != NULL ) {
1769 UIWidget* docRoot = this;
1770 while ( docRoot->getParent() && docRoot->getParent()->isWidget() )
1771 docRoot = docRoot->getParent()->asType<UIWidget>();
1772 rootFontSize = getAbsoluteFontSize( docRoot );
1773 }
1774 pxSize = length.getValue() * rootFontSize;
1775 } else if ( length.getUnit() == StyleSheetLength::Unit::Em ||
1776 length.getUnit() == StyleSheetLength::Unit::Percentage ) {
1777 Float parentFontSize = 12.f;
1778 Node* parentNode = getParent();
1779 while ( parentNode ) {
1780 if ( parentNode->isWidget() ) {
1781 parentFontSize = getAbsoluteFontSize( parentNode->asType<UIWidget>() );
1782 break;
1783 }
1784 parentNode = parentNode->getParent();
1785 }
1786 if ( length.getUnit() == StyleSheetLength::Unit::Em )
1787 pxSize = length.getValue() * parentFontSize;
1788 else
1789 pxSize = ( length.getValue() / 100.f ) * parentFontSize;
1790 } else {
1791 pxSize = lengthFromValue( property );
1792 }
1793
1794 propToPropagate = CSS::StyleSheetProperty(
1795 property.getName(), String::fromFloat( PixelDensity::pxToDp( pxSize ), "dp" ),
1796 property.getSpecificity() );
1797 }
1798
1799 Node* child = getFirstChild();
1800 while ( child ) {
1801 if ( child->isWidget() ) {
1802 UIWidget* childWidget = child->asType<UIWidget>();
1803 UIStyle* childStyle = childWidget->getUIStyle();
1804 // Only propagate if the child doesn't explicitly override it
1805 if ( childStyle && !childStyle->hasLocalProperty(
1806 property.getPropertyDefinition()->getPropertyId() ) ) {
1807 childWidget->applyProperty( propToPropagate );
1808 childWidget->propagateInheritedProperty( propToPropagate );
1809 }
1810 }
1811 child = child->getNextNode();
1812 }
1813}
1814
1815bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) {

Callers 1

onStateChangeMethod · 0.80

Calls 13

getParentFunction · 0.85
getPropertyIdMethod · 0.80
isWidgetMethod · 0.80
getUIStyleMethod · 0.80
hasLocalPropertyMethod · 0.80
getNextNodeMethod · 0.80
getPropertyDefinitionMethod · 0.45
valueMethod · 0.45
getUnitMethod · 0.45
getParentMethod · 0.45
getValueMethod · 0.45
getNameMethod · 0.45

Tested by

no test coverage detected