Body height miscalculation fix.

This commit is contained in:
Martín Lucas Golini
2026-05-23 00:25:27 -03:00
parent 428cd55c48
commit 15db9e90eb
7 changed files with 3714 additions and 3 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -46,6 +46,8 @@ class EE_API UIHTMLWidget : public UILayout {
void setCSSClear( CSSClear cssClear );
Rectf getNormalFlowLayoutPixelsMargin() const;
const CSSBaselineAlignValue& getBaselineAlign() const { return mBaselineAlign; }
void setBaselineAlign( const CSSBaselineAlignValue& baselineAlign );

View File

@@ -435,7 +435,10 @@ void BlockLayouter::positionRichTextChildren( Graphics::RichText* rt ) {
curCharIdx += 1;
Rectf atomicBounds( maxF, maxF, lowF, lowF );
if ( getAtomicWidgetFragmentBounds( widget, atomicBounds ) ) {
Rectf margin = widget->getLayoutPixelsMargin();
Rectf margin =
widget->isType( UI_TYPE_HTML_WIDGET )
? widget->asType<UIHTMLWidget>()->getNormalFlowLayoutPixelsMargin()
: widget->getLayoutPixelsMargin();
Vector2f targetPos( atomicBounds.Left + margin.Left,
atomicBounds.Top + margin.Top );
@@ -459,7 +462,10 @@ void BlockLayouter::positionRichTextChildren( Graphics::RichText* rt ) {
size_t lineIdx = currentSpan > 0 ? currentLine : currentLine - 1;
Float lineY = lines[lineIdx].y;
Rectf margin = widget->getLayoutPixelsMargin();
Rectf margin =
widget->isType( UI_TYPE_HTML_WIDGET )
? widget->asType<UIHTMLWidget>()->getNormalFlowLayoutPixelsMargin()
: widget->getLayoutPixelsMargin();
Vector2f targetPos( contentOffset.Left + span->position.x + margin.Left,
contentOffset.Top + lineY + span->position.y + margin.Top );

View File

@@ -154,6 +154,15 @@ void UIHTMLWidget::setCSSClear( CSSClear cssClear ) {
}
}
Rectf UIHTMLWidget::getNormalFlowLayoutPixelsMargin() const {
Rectf margin = getLayoutPixelsMargin();
if ( hasLayoutMarginTopAuto() )
margin.Top = 0.f;
if ( hasLayoutMarginBottomAuto() )
margin.Bottom = 0.f;
return margin;
}
void UIHTMLWidget::setBaselineAlign( const CSSBaselineAlignValue& baselineAlign ) {
if ( mBaselineAlign != baselineAlign ) {
mBaselineAlign = baselineAlign;

View File

@@ -1331,7 +1331,10 @@ void UIRichText::rebuildRichText( UILayout* container, RichText& richText, Intri
"\n", widget->asType<UILineBreak>()->getRichText().getFontStyleConfig() );
lastSpanEndsWithSpace = false;
} else {
Rectf margin = widget->getLayoutPixelsMargin();
Rectf margin =
widget->isType( UI_TYPE_HTML_WIDGET )
? widget->asType<UIHTMLWidget>()->getNormalFlowLayoutPixelsMargin()
: widget->getLayoutPixelsMargin();
bool isBlock = widget->getLayoutWidthPolicy() == SizePolicy::MatchParent;
if ( widget->isType( UI_TYPE_HTML_WIDGET ) ) {
CSSDisplay display = widget->asType<UIHTMLWidget>()->getDisplay();

View File

@@ -1650,6 +1650,8 @@ static UISceneNode* init_test_inline_block() {
font = FontTrueType::New( "NotoSans-Regular" );
font->loadFromFile( "../assets/fonts/NotoSans-Regular.ttf" );
FontFamily::loadFromRegular( font );
FontTrueType* monoFont = FontTrueType::New( "monospace" );
monoFont->loadFromFile( "../assets/fonts/NotoSans-Regular.ttf" );
UISceneNode* sceneNode = UISceneNode::New();
SceneManager::instance()->add( sceneNode );
SceneManager::instance()->setCurrentUISceneNode( sceneNode );
@@ -2002,6 +2004,33 @@ UTEST( UIHTML, HeightExpansion_FixedDoesNotExpand ) {
Engine::destroySingleton();
}
UTEST( UIHTML, BodyHeightMiscalculationFixture ) {
Engine::instance()->createWindow( WindowSettings( 1024, 653, "Body Height Miscalculation Test",
WindowStyle::Default, WindowBackend::Default,
32, {}, 1, false, true ),
ContextSettings( false, 0, 0, GLv_default, true, false ) );
UI::UISceneNode* sceneNode = init_test_inline_block();
sceneNode->setURI( "file://" + Sys::getProcessPath() + "assets/html/" );
std::string html;
FileSystem::fileGet( "assets/html/body_height_miscalculation.html", html );
sceneNode->loadLayoutFromString( HTMLFormatter::HTMLtoXML( html ) );
sceneNode->update( Seconds( 1 ) );
sceneNode->updateDirtyLayouts();
auto bodyNode = sceneNode->getRoot()->findByType( UI_TYPE_HTML_BODY );
ASSERT_TRUE( bodyNode != nullptr );
auto bodyWidget = bodyNode->asType<UIWidget>();
EXPECT_GT( bodyWidget->getPixelsSize().getHeight(), 3000.f );
EXPECT_LT( bodyWidget->getPixelsSize().getHeight(), 6000.f );
Engine::destroySingleton();
}
UTEST( UIHTML, ContactFormLayout ) {
Engine::instance()->createWindow( WindowSettings( 1024, 653, "Contact Form Layout Test",
WindowStyle::Default, WindowBackend::Default,