diff --git a/include/eepp/ui/css/stylesheetlength.hpp b/include/eepp/ui/css/stylesheetlength.hpp index a1495a840..29c040e8f 100644 --- a/include/eepp/ui/css/stylesheetlength.hpp +++ b/include/eepp/ui/css/stylesheetlength.hpp @@ -42,6 +42,8 @@ class EE_API StyleSheetLength { static bool isLength( const std::string& unitStr ); + static bool isPercentage( const std::string& val ); + static StyleSheetLength fromString( const std::string& str, const Float& defaultValue = 0, bool pxAsDp = false ); diff --git a/src/eepp/ui/blocklayouter.cpp b/src/eepp/ui/blocklayouter.cpp index 63068ddb3..6b7d3e381 100644 --- a/src/eepp/ui/blocklayouter.cpp +++ b/src/eepp/ui/blocklayouter.cpp @@ -68,6 +68,12 @@ void BlockLayouter::updateLayout() { { mContainer->lengthFromValue( *prop ), mContainer->getPixelsSize().getHeight() } ); } + if ( mContainer->getLayoutHeightPolicy() == SizePolicy::Fixed && mContainer->getUIStyle() && + ( prop = mContainer->getUIStyle()->getProperty( PropertyId::Height ) ) ) { + mContainer->setInternalPixelsSize( + { mContainer->getPixelsSize().getWidth(), mContainer->lengthFromValue( *prop ) } ); + } + UIRichText::rebuildRichText( widget, *rt ); rt->updateLayout(); @@ -80,6 +86,20 @@ void BlockLayouter::updateLayout() { mContainer->getPixelsContentOffset().Right; if ( !mContainer->getMaxWidthEq().empty() && totW > mContainer->getMaxSizePx().getWidth() ) mContainer->setClipType( ClipType::ContentBox ); + } else if ( mContainer->getLayoutWidthPolicy() == SizePolicy::Fixed && + mContainer->getUIStyle() ) { + const StyleSheetProperty* wprop = + mContainer->getUIStyle()->getProperty( PropertyId::Width ); + if ( wprop && StyleSheetLength::isPercentage( wprop->value() ) && mContainer->getParent() && + mContainer->getParent()->isWidget() && + mContainer->getParent()->asType()->getLayoutWidthPolicy() == + SizePolicy::WrapContent ) { + totW = rt->getSize().getWidth() + mContainer->getPixelsContentOffset().Left + + mContainer->getPixelsContentOffset().Right; + if ( !mContainer->getMaxWidthEq().empty() && + totW > mContainer->getMaxSizePx().getWidth() ) + mContainer->setClipType( ClipType::ContentBox ); + } } if ( totW != mContainer->getPixelsSize().getWidth() || @@ -93,6 +113,20 @@ void BlockLayouter::updateLayout() { if ( !mContainer->getMaxHeightEq().empty() && totH > mContainer->getMaxSizePx().getHeight() ) mContainer->setClipType( ClipType::ContentBox ); + } else if ( mContainer->getLayoutHeightPolicy() == SizePolicy::Fixed && + mContainer->getUIStyle() ) { + const StyleSheetProperty* hprop = + mContainer->getUIStyle()->getProperty( PropertyId::Height ); + if ( hprop && StyleSheetLength::isPercentage( hprop->value() ) && mContainer->getParent() && + mContainer->getParent()->isWidget() && + mContainer->getParent()->asType()->getLayoutHeightPolicy() == + SizePolicy::WrapContent ) { + totH = rt->getSize().getHeight() + mContainer->getPixelsContentOffset().Top + + mContainer->getPixelsContentOffset().Bottom; + if ( !mContainer->getMaxHeightEq().empty() && + totH > mContainer->getMaxSizePx().getHeight() ) + mContainer->setClipType( ClipType::ContentBox ); + } } if ( totH != mContainer->getPixelsSize().getHeight() || diff --git a/src/eepp/ui/css/stylesheetlength.cpp b/src/eepp/ui/css/stylesheetlength.cpp index 76e47e948..d12b5fc2d 100644 --- a/src/eepp/ui/css/stylesheetlength.cpp +++ b/src/eepp/ui/css/stylesheetlength.cpp @@ -188,6 +188,10 @@ bool StyleSheetLength::isLength( const std::string& unitStr ) { return false; } +bool StyleSheetLength::isPercentage( const std::string& val ) { + return !val.empty() && val.back() == '%'; +} + StyleSheetLength::StyleSheetLength() : mUnit( Px ), mValue( 0 ) {} StyleSheetLength::StyleSheetLength( const Float& val, const StyleSheetLength::Unit& unit ) : diff --git a/src/eepp/ui/tablelayouter.cpp b/src/eepp/ui/tablelayouter.cpp index d4bd7aafb..84b1bed8c 100644 --- a/src/eepp/ui/tablelayouter.cpp +++ b/src/eepp/ui/tablelayouter.cpp @@ -272,9 +272,11 @@ void TableLayouter::computeIntrinsicWidths() { } mMinIntrinsicWidth = totalMin + mContainer->getPixelsContentOffset().Left + - mContainer->getPixelsContentOffset().Right + ( maxCols + 1 ) * mCellspacing; + mContainer->getPixelsContentOffset().Right + + ( maxCols + 1 ) * mCellspacing; mMaxIntrinsicWidth = totalMax + mContainer->getPixelsContentOffset().Left + - mContainer->getPixelsContentOffset().Right + ( maxCols + 1 ) * mCellspacing; + mContainer->getPixelsContentOffset().Right + + ( maxCols + 1 ) * mCellspacing; mIntrinsicWidthsDirty = false; } @@ -297,8 +299,36 @@ void TableLayouter::updateLayout() { { widget->lengthFromValue( *prop ), widget->getPixelsSize().getHeight() } ); } + if ( widget->getLayoutHeightPolicy() == SizePolicy::Fixed && widget->getUIStyle() && + ( prop = widget->getUIStyle()->getProperty( PropertyId::Height ) ) ) { + widget->asType()->setInternalPixelsSize( + { widget->getPixelsSize().getWidth(), widget->lengthFromValue( *prop ) } ); + } + computeIntrinsicWidths(); + bool useContentWidth = false; + if ( widget->getLayoutWidthPolicy() == SizePolicy::Fixed && widget->getUIStyle() ) { + const StyleSheetProperty* wprop = widget->getUIStyle()->getProperty( PropertyId::Width ); + if ( wprop && StyleSheetLength::isPercentage( wprop->value() ) && widget->getParent() && + widget->getParent()->isWidget() && + widget->getParent()->asType()->getLayoutWidthPolicy() == + SizePolicy::WrapContent ) { + useContentWidth = true; + } + } + + bool useContentHeight = false; + if ( widget->getLayoutHeightPolicy() == SizePolicy::Fixed && widget->getUIStyle() ) { + const StyleSheetProperty* hprop = widget->getUIStyle()->getProperty( PropertyId::Height ); + if ( hprop && StyleSheetLength::isPercentage( hprop->value() ) && widget->getParent() && + widget->getParent()->isWidget() && + widget->getParent()->asType()->getLayoutHeightPolicy() == + SizePolicy::WrapContent ) { + useContentHeight = true; + } + } + if ( mRows.empty() ) { mPacking = false; return; @@ -306,8 +336,11 @@ void TableLayouter::updateLayout() { size_t maxCols = mColMinWidths.size(); mColWidths.assign( maxCols, 0.f ); - Float paddingH = mContainer->getPixelsContentOffset().Left + mContainer->getPixelsContentOffset().Right; + Float paddingH = + mContainer->getPixelsContentOffset().Left + mContainer->getPixelsContentOffset().Right; Float containerWidth = mContainer->getPixelsSize().getWidth(); + if ( useContentWidth ) + containerWidth = mMaxIntrinsicWidth; Float availableWidth = sanitizeFloat( std::max( 0.f, containerWidth - paddingH - ( maxCols + 1 ) * mCellspacing ) ); @@ -523,12 +556,15 @@ void TableLayouter::updateLayout() { if ( mFooter && !mRows.empty() ) mRows[rowCount - 1]->setPixelsPosition( mContainer->getPixelsContentOffset().Left, 0 ); - if ( mContainer->getLayoutHeightPolicy() == SizePolicy::WrapContent ) { + if ( mContainer->getLayoutHeightPolicy() == SizePolicy::WrapContent || useContentHeight ) { mContainer->asType()->setInternalPixelsHeight( mContainer->getPixelsContentOffset().Top + headHeight + bodyHeight + footerHeight + ( rowCount + 1 ) * mCellspacing + mContainer->getPixelsContentOffset().Bottom ); } + if ( useContentWidth ) + widget->asType()->setInternalPixelsWidth( mMaxIntrinsicWidth ); + mPacking = false; } diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index f5a56ac33..3b2fa8bf2 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -1947,22 +1947,14 @@ bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) { if ( attribute.value() == "auto" ) { setLayoutHeightPolicy( SizePolicy::WrapContent ); } else { - StyleSheetLength length( attribute.value() ); - if ( length.getUnit() == StyleSheetLength::Unit::Percentage && getParent() && - getParent()->isWidget() && - getParent()->asType()->getLayoutHeightPolicy() == - SizePolicy::WrapContent ) { - setLayoutHeightPolicy( SizePolicy::WrapContent ); - } else { - if ( mStyle ) { - mStyle->setStyleSheetProperty( - StyleSheetProperty( "layout-height", attribute.value(), true, - StyleSheetSelectorRule::SpecificityImportant ) ); - } - setLayoutHeightPolicy( SizePolicy::Fixed ); - setSize( mDpSize.getWidth(), eefloor( lengthFromValueAsDp( attribute ) ) ); - notifyLayoutAttrChange(); + if ( mStyle ) { + mStyle->setStyleSheetProperty( + StyleSheetProperty( "layout-height", attribute.value(), true, + StyleSheetSelectorRule::SpecificityImportant ) ); } + setLayoutHeightPolicy( SizePolicy::Fixed ); + setSize( mDpSize.getWidth(), eefloor( lengthFromValueAsDp( attribute ) ) ); + notifyLayoutAttrChange(); } break; case PropertyId::BackgroundColor: @@ -2210,21 +2202,13 @@ bool UIWidget::applyProperty( const StyleSheetProperty& attribute ) { setLayoutHeightPolicy( SizePolicy::Fixed ); unsetFlags( UI_AUTO_SIZE ); } else { - StyleSheetLength length( val, 0 ); - if ( length.getUnit() == StyleSheetLength::Unit::Percentage && getParent() && - getParent()->isWidget() && - getParent()->asType()->getLayoutHeightPolicy() == - SizePolicy::WrapContent ) { - setLayoutHeightPolicy( SizePolicy::WrapContent ); - } else { - unsetFlags( UI_AUTO_SIZE ); - setLayoutHeightPolicy( SizePolicy::Fixed ); - Float newVal = eefloor( lengthFromValueAsDp( attribute ) ); - if ( !( newVal == 0 && getLayoutWeight() != 0 && - getParent()->isType( UI_TYPE_LINEAR_LAYOUT ) ) ) { - setInternalHeight( newVal ); - onSizeChange(); - } + unsetFlags( UI_AUTO_SIZE ); + setLayoutHeightPolicy( SizePolicy::Fixed ); + Float newVal = eefloor( lengthFromValueAsDp( attribute ) ); + if ( !( newVal == 0 && getLayoutWeight() != 0 && + getParent()->isType( UI_TYPE_LINEAR_LAYOUT ) ) ) { + setInternalHeight( newVal ); + onSizeChange(); } } break;