mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-04 20:46:29 +03:00
CSS: Inline-block layout, line-height inheritance, and font shorthand fixes
Core problem
Three interconnected bugs caused incorrect rendering of display: inline-block elements:
1. Inline-block elements with explicit width/height (e.g. share buttons with width: 20px; height: 20px) had zero dimensions — their internal children were never laid out.
2. Text-based inline-blocks (e.g. <a href="...">Download</a> styled as display: inline-block) were affected by an incorrect font shorthand that failed to reset line-height to normal, allowing an inherited line-height: 10 on <body> to inflate element heights via the line box strut.
3. Inline-block elements with long text did not wrap atomically to the next line when they exceeded the container width.
Changes by file
include/eepp/graphics/richtext.hpp / src/eepp/graphics/richtext.cpp
- Added lineHeight (Float) and isAtomic (bool) fields to SpanBlock. The lineHeight field provides per-span line-height overriding the global mLineHeight — this is used by inline-block spans to set their line height to the font's em height rather than inheriting the container's line-height. The isAtomic flag marks a span as an atomic inline-level box: during RichText Pass 1 (both the non-float and float-aware paths), atomic spans check whether the full text width plus margins fits on the current line; if not, they push to the next line before any text wrapping occurs. This matches the CSS behavior where an inline-block drops to a new line as an opaque unit rather than having its text wrap within the parent line.
- Updated addSpan() to accept lineHeight and isAtomic parameters (with defaults of 0 and false to preserve existing call sites).
- Added per-span line-height priority (3-tier cascade): a span's own lineHeight takes precedence over the global mLineHeight, which takes precedence over the font's intrinsic line spacing. This ensures inline-block spans use font em height (set by UIRichText::rebuildRichText), pure inline text uses the container's line-height, and all fall back to font metrics.
- Added line box strut in Pass 2 (both paths): line.height = std::max(line.height, mLineHeight) ensures every line box respects the containing block's line-height, per CSS 2.1 §10.8.1. Previously a line box's height was determined solely by the tallest inline element on that line; now the container's line-height acts as a minimum.
- Propagated pText->lineHeight and pText->isAtomic through to the SpanBlock construction in RenderSpan creation in both the non-float and float-aware paths, so the per-span values persist from addSpan() through to layout.
include/eepp/ui/uitextspan.hpp / src/eepp/ui/uitextspan.cpp
- isMergeable() now returns true for both CSSDisplay::Inline and CSSDisplay::InlineBlock. Previously only Inline was mergeable. This allows text-based inline-block content to participate in the parent container's RichText flow (baseline-aligned), while the widget still draws its own border and background independently.
- Added isInlineBlock() helper method that returns mDisplay == CSSDisplay::InlineBlock, used by callers throughout the layouter and RichText code to distinguish inline-block treatment from pure inline.
- Fixed drawBorder(): inline-block widgets now draw their border at the widget bounds (mScreenPos, mSize) without expanding by padding, because padding has already been incorporated into the widget's size via the RichText bounds expansion. Pure inline spans continue to draw the border expanded by padding (the old behavior).
src/eepp/ui/uirichtext.cpp
- In rebuildRichText(), inline-block widgets are now handled via two distinct code paths:
- Text-based inline-block (has its own text content): treated as mergeable — text flows into the parent container's RichText as a SpanBlock with isAtomic = true for atomic line-wrapping, and the span's lineHeight set to the font's em height. Padding and margins are propagated through the SpanBlock. The widget's size and hit-boxes are computed from the parent RichText's layout (via BlockLayouter::positionRichTextChildren bounds expansion).
- Inline-block without text (has only child widgets, e.g. share buttons containing nested <span> elements): diverted to the CustomBlock path — the widget runs its own BlockLayouter::updateLayout() to process internal children and determine its intrinsic size, and is added to the parent's RichText as a CustomBlock (atomic inline-level box). This ensures inner children are properly laid out rather than left at zero dimensions.
- Whitespace collapse logic around inline-block spans now accounts for whether the adjacent nodes are inline, preventing incorrect stripping of leading/trailing spaces.
src/eepp/ui/blocklayouter.cpp
- BlockLayouter::updateLayout(): the early return for mergeable widgets now makes an exception for inline-block widgets that have no text of their own — these still need their internal children laid out, so the layouter proceeds rather than returning early.
- BlockLayouter::positionRichTextChildren(): inline-block widgets are processed in two ways depending on whether they have text:
- Text-based: bounds computed from the parent RichText's span positions, expanded by padding. The widget's position and size are set from these bounds.
- No-text (CustomBlock): positioned via getNextCustomSpan() from the parent RichText's CustomBlock spans, with padding expansion for bounds.
Both paths expand the widget's pixel bounds by padding for inline-block styling. A bool handled flag replaces the previous goto-based control flow.
- Added bounds and hit-box padding expansion for inline-block widgets in the CustomBlock positioning path (previously only the mergeable path had this).
src/eepp/ui/css/stylesheetspecification.cpp
- Fixed font shorthand registration: changed the component list from { font-style, font-size, line-spacing, font-family } to { font-style, font-weight, font-size, line-height, font-family }. The line-spacing property does not participate in the font shorthand per the CSS Fonts specification (§3.1); line-height does.
- Fixed font shorthand parser:
- font-weight keywords (bold, bolder, lighter) are now emitted as a separate font-weight property instead of being incorrectly merged into the font-style property string.
- When the font shorthand does not include an explicit /line-height value, the parser now always emits line-height: normal to reset any previously inherited line-height. Previously it emitted nothing, allowing an inherited line-height (e.g. line-height: 10 on <body>) to leak into child elements that used the font shorthand.
src/tests/unit_tests/uihtml_tests.cpp
- Added UIRichText.anchorPadding test: verifies that an inline-block <a> tag with padding and border renders correctly at the expected size (81×28 px for "Download" text in 11px Noto Sans with padding: 6px 14px and border: 1px solid), using both pixel-diff comparison and explicit size assertions. The HTML uses line-height: 1.5 on <body> and font: 11px on the inline-block anchor.
- Added UIRichText.anchorPaddingLineHeight test: same layout but with line-height: 10 on <body>, verifying that the per-span line-height prevents the inherited line-height: 10 from inflating the inline-block anchor's dimensions.
- Added UIBackground.InlineBlockImageSpans test: verifies that inline-block <a> elements with fixed width/height (20×20 px share buttons) and nested child <span> elements (with display: block and text-indent: -9999px) have non-zero dimensions and render correctly with pixel-diff comparison. This covers the CustomBlock path for inline-blocks without text of their own.
This commit is contained in:
65
bin/unit_tests/assets/html/anchor_padding.html
Normal file
65
bin/unit_tests/assets/html/anchor_padding.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #1E2A38;
|
||||
font: 13px 'Noto Sans', Sans-Serif;
|
||||
color: #D0D8E0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #60C0E0;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
background-color: #2A3A4A;
|
||||
color: #80D8F0;
|
||||
}
|
||||
|
||||
.download-card {
|
||||
background-color: #1A2838;
|
||||
border: 1px solid #2A3A4A;
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.download-card h3 {
|
||||
font: bold 12px 'Noto Sans', Sans-Serif;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.download-card a {
|
||||
display: inline-block;
|
||||
padding: 6px 14px;
|
||||
background-color: #162028;
|
||||
color: #60C0E0;
|
||||
text-decoration: none;
|
||||
font: 11px 'Noto Sans', Sans-Serif;
|
||||
border: 1px solid #2A3A4A;
|
||||
}
|
||||
|
||||
.download-card a:hover {
|
||||
background-color: #2A3A4A;
|
||||
color: #80D8F0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<section id="downloads">
|
||||
<div class="download-grid">
|
||||
<div class="download-card">
|
||||
<h3>Windows</h3>
|
||||
<a href="https://zsnes.com/files/SuperZSNES_v0.110.zip">Download</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</body></html>
|
||||
65
bin/unit_tests/assets/html/anchor_padding_lineheight.html
Normal file
65
bin/unit_tests/assets/html/anchor_padding_lineheight.html
Normal file
@@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
background-color: #1E2A38;
|
||||
font: 13px 'Noto Sans', Sans-Serif;
|
||||
color: #D0D8E0;
|
||||
line-height: 10;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #60C0E0;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
background-color: #2A3A4A;
|
||||
color: #80D8F0;
|
||||
}
|
||||
|
||||
.download-card {
|
||||
background-color: #1A2838;
|
||||
border: 1px solid #2A3A4A;
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.download-card h3 {
|
||||
font: bold 12px 'Noto Sans', Sans-Serif;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.download-card a {
|
||||
display: inline-block;
|
||||
padding: 6px 14px;
|
||||
background-color: #162028;
|
||||
color: #60C0E0;
|
||||
text-decoration: none;
|
||||
font: 11px 'Noto Sans', Sans-Serif;
|
||||
border: 1px solid #2A3A4A;
|
||||
}
|
||||
|
||||
.download-card a:hover {
|
||||
background-color: #2A3A4A;
|
||||
color: #80D8F0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<section id="downloads">
|
||||
<div class="download-grid">
|
||||
<div class="download-card">
|
||||
<h3>Windows</h3>
|
||||
<a href="https://zsnes.com/files/SuperZSNES_v0.110.zip">Download</a>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</body></html>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
bin/unit_tests/assets/html/eepp-ui-anchor-padding.webp
Normal file
BIN
bin/unit_tests/assets/html/eepp-ui-anchor-padding.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.2 KiB |
BIN
bin/unit_tests/assets/html/eepp-ui-inline-block-image-spans.webp
Normal file
BIN
bin/unit_tests/assets/html/eepp-ui-inline-block-image-spans.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
137
bin/unit_tests/assets/html/inline_block.html
Normal file
137
bin/unit_tests/assets/html/inline_block.html
Normal file
File diff suppressed because one or more lines are too long
@@ -35,7 +35,7 @@ class EE_API RichText : public Drawable {
|
||||
void addSpan( const String& text, const FontStyleConfig& style );
|
||||
|
||||
void addSpan( const String& text, const FontStyleConfig& style, const Rectf& margin,
|
||||
const Rectf& padding );
|
||||
const Rectf& padding, Float lineHeight = 0, bool isAtomic = false );
|
||||
|
||||
/**
|
||||
* @brief Adds a text span with individual style parameters.
|
||||
@@ -92,6 +92,8 @@ class EE_API RichText : public Drawable {
|
||||
std::shared_ptr<Text> text;
|
||||
Rectf margin;
|
||||
Rectf padding;
|
||||
Float lineHeight{ 0 };
|
||||
bool isAtomic{ false };
|
||||
};
|
||||
|
||||
using Block = std::variant<SpanBlock, std::shared_ptr<Drawable>, CustomBlock>;
|
||||
|
||||
@@ -43,6 +43,8 @@ class EE_API UITextSpan : public UIRichText {
|
||||
|
||||
virtual bool isMergeable() const;
|
||||
|
||||
virtual bool isInlineBlock() const;
|
||||
|
||||
virtual void draw();
|
||||
|
||||
virtual bool applyProperty( const StyleSheetProperty& attribute );
|
||||
|
||||
@@ -302,14 +302,14 @@ Sizef RichText::getPixelsSize() {
|
||||
}
|
||||
|
||||
void RichText::addSpan( const String& text, const FontStyleConfig& style, const Rectf& margin,
|
||||
const Rectf& padding ) {
|
||||
if ( text.empty() && margin == Rectf::Zero && padding == Rectf::Zero )
|
||||
const Rectf& padding, Float lineHeight, bool isAtomic ) {
|
||||
if ( text.empty() && margin == Rectf::Zero && padding == Rectf::Zero && lineHeight == 0 )
|
||||
return;
|
||||
|
||||
auto span = std::make_shared<Text>();
|
||||
span->setString( text );
|
||||
span->setStyleConfig( style );
|
||||
mBlocks.push_back( SpanBlock{ span, margin, padding } );
|
||||
mBlocks.push_back( SpanBlock{ span, margin, padding, lineHeight, isAtomic } );
|
||||
invalidateLayout();
|
||||
}
|
||||
|
||||
@@ -512,6 +512,18 @@ void RichText::updateLayout() {
|
||||
if ( !mLines.empty() )
|
||||
mLines.back().width += extraLeft;
|
||||
|
||||
if ( pText->isAtomic && curX > extraLeft && mMaxWidth > 0 ) {
|
||||
Float extraRight = pText->margin.Right + pText->padding.Right;
|
||||
Float fullTextWidth = span->getTextWidth();
|
||||
if ( curX + fullTextWidth + extraRight > mMaxWidth ) {
|
||||
maxWidth = std::max( maxWidth, curX - extraLeft );
|
||||
mLines.push_back( RenderParagraph() );
|
||||
curX = extraLeft;
|
||||
if ( !mLines.empty() )
|
||||
mLines.back().width += extraLeft;
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 textHints = span->getTextHints();
|
||||
|
||||
// Compute where lines break within this text span.
|
||||
@@ -538,18 +550,20 @@ void RichText::updateLayout() {
|
||||
renderSpanText->setStyleConfig( fontStyle );
|
||||
|
||||
Float ascent = fontStyle.Font->getAscent( fontStyle.CharacterSize );
|
||||
Float height = mLineHeight > 0
|
||||
? mLineHeight
|
||||
: fontStyle.Font->getLineSpacing( fontStyle.CharacterSize );
|
||||
Float height =
|
||||
pText->lineHeight > 0 ? pText->lineHeight
|
||||
: mLineHeight > 0
|
||||
? mLineHeight
|
||||
: fontStyle.Font->getLineSpacing( fontStyle.CharacterSize );
|
||||
Float spanWidth = renderSpanText->getTextWidth();
|
||||
|
||||
RenderSpan renderSpan;
|
||||
renderSpan.block =
|
||||
SpanBlock{ renderSpanText, pText->margin, pText->padding };
|
||||
renderSpan.position = { curX, 0 };
|
||||
renderSpan.size = Sizef( spanWidth, height );
|
||||
renderSpan.startCharIndex = curCharIdx;
|
||||
renderSpan.endCharIndex = curCharIdx + ( endIdx - startIdx );
|
||||
RenderSpan renderSpan{
|
||||
SpanBlock{ renderSpanText, pText->margin, pText->padding,
|
||||
pText->lineHeight, pText->isAtomic },
|
||||
{ curX, 0 },
|
||||
Sizef( spanWidth, height ),
|
||||
curCharIdx,
|
||||
static_cast<Int64>( curCharIdx + ( endIdx - startIdx ) ) };
|
||||
curCharIdx = renderSpan.endCharIndex;
|
||||
|
||||
RenderParagraph& currentLine = mLines.back();
|
||||
@@ -619,12 +633,7 @@ void RichText::updateLayout() {
|
||||
curX = 0;
|
||||
}
|
||||
|
||||
RenderSpan renderSpan;
|
||||
renderSpan.block = block;
|
||||
renderSpan.position = { curX, 0 };
|
||||
renderSpan.size = blockSize;
|
||||
renderSpan.startCharIndex = curCharIdx;
|
||||
renderSpan.endCharIndex = curCharIdx + 1;
|
||||
RenderSpan renderSpan{ block, { curX, 0 }, blockSize, curCharIdx, curCharIdx + 1 };
|
||||
curCharIdx = renderSpan.endCharIndex;
|
||||
|
||||
RenderParagraph& currentLine = mLines.back();
|
||||
@@ -688,6 +697,8 @@ void RichText::updateLayout() {
|
||||
}
|
||||
|
||||
line.height = std::max( line.height, maxLineHeight );
|
||||
if ( mLineHeight > 0 )
|
||||
line.height = std::max( line.height, mLineHeight );
|
||||
curY += line.height;
|
||||
}
|
||||
|
||||
@@ -788,6 +799,18 @@ void RichText::updateLayout() {
|
||||
if ( !mLines.empty() )
|
||||
mLines.back().width += extraLeft;
|
||||
|
||||
if ( pText->isAtomic && curX > extraLeft && mMaxWidth > 0 ) {
|
||||
Float extraRight = pText->margin.Right + pText->padding.Right;
|
||||
Float fullTextWidth = span->getTextWidth();
|
||||
if ( curX + fullTextWidth + extraRight > mMaxWidth ) {
|
||||
maxWidth = std::max( maxWidth, curX - extraLeft );
|
||||
mLines.push_back( RenderParagraph() );
|
||||
curX = extraLeft;
|
||||
if ( !mLines.empty() )
|
||||
mLines.back().width += extraLeft;
|
||||
}
|
||||
}
|
||||
|
||||
// Shift curX inside to the left edge — text starts
|
||||
// to the right of any left floats.
|
||||
Float le = floatLeftEdge( curY );
|
||||
@@ -821,17 +844,20 @@ void RichText::updateLayout() {
|
||||
renderSpanText->setStyleConfig( fontStyle );
|
||||
|
||||
Float ascent = fontStyle.Font->getAscent( fontStyle.CharacterSize );
|
||||
Float height = mLineHeight > 0
|
||||
Float height = pText->lineHeight > 0 ? pText->lineHeight
|
||||
: mLineHeight > 0
|
||||
? mLineHeight
|
||||
: fontStyle.Font->getLineSpacing( fontStyle.CharacterSize );
|
||||
Float spanWidth = renderSpanText->getTextWidth();
|
||||
|
||||
RenderSpan renderSpan;
|
||||
renderSpan.block = SpanBlock{ renderSpanText, pText->margin, pText->padding };
|
||||
renderSpan.position = { curX, 0 };
|
||||
renderSpan.size = Sizef( spanWidth, height );
|
||||
renderSpan.startCharIndex = curCharIdx;
|
||||
renderSpan.endCharIndex = curCharIdx + ( endIdx - startIdx );
|
||||
RenderSpan renderSpan{
|
||||
SpanBlock{ renderSpanText, pText->margin, pText->padding, pText->lineHeight,
|
||||
pText->isAtomic },
|
||||
{ curX, 0 },
|
||||
Sizef( spanWidth, height ),
|
||||
curCharIdx,
|
||||
static_cast<Int64>( curCharIdx + ( endIdx - startIdx ) ) };
|
||||
|
||||
curCharIdx = renderSpan.endCharIndex;
|
||||
|
||||
RenderParagraph& currentLine = mLines.back();
|
||||
@@ -844,7 +870,8 @@ void RichText::updateLayout() {
|
||||
currentLine.width += spanWidth;
|
||||
}
|
||||
|
||||
// Trailing margin may force a wrap.
|
||||
// After the last segment, add trailing margin and check if the
|
||||
// margin itself forces a wrap.
|
||||
if ( i == wrapInfo.wraps.size() - 2 && !isNewline ) {
|
||||
Float extraRight = pText->margin.Right + pText->padding.Right;
|
||||
curX += extraRight;
|
||||
@@ -916,20 +943,14 @@ void RichText::updateLayout() {
|
||||
posX = le;
|
||||
}
|
||||
|
||||
RenderSpan renderSpan;
|
||||
renderSpan.block = block;
|
||||
renderSpan.position = { posX, 0 };
|
||||
renderSpan.size = blockSize;
|
||||
renderSpan.startCharIndex = curCharIdx;
|
||||
renderSpan.endCharIndex = curCharIdx + 1;
|
||||
RenderSpan renderSpan{ block, { posX, 0 }, blockSize, curCharIdx, curCharIdx + 1 };
|
||||
curCharIdx = renderSpan.endCharIndex;
|
||||
|
||||
mLines.back().spans.push_back( renderSpan );
|
||||
|
||||
// Record the float's bounding box so subsequent
|
||||
// content can wrap around it.
|
||||
Rectf fr( posX, curY, posX + blockSize.getWidth(),
|
||||
curY + blockSize.getHeight() );
|
||||
Rectf fr( posX, curY, posX + blockSize.getWidth(), curY + blockSize.getHeight() );
|
||||
if ( floatType == UI::CSSFloat::Left )
|
||||
leftFloats.push_back( fr );
|
||||
else
|
||||
@@ -956,12 +977,7 @@ void RichText::updateLayout() {
|
||||
curX = 0;
|
||||
}
|
||||
|
||||
RenderSpan renderSpan;
|
||||
renderSpan.block = block;
|
||||
renderSpan.position = { curX, 0 };
|
||||
renderSpan.size = blockSize;
|
||||
renderSpan.startCharIndex = curCharIdx;
|
||||
renderSpan.endCharIndex = curCharIdx + 1;
|
||||
RenderSpan renderSpan{ block, { curX, 0 }, blockSize, curCharIdx, curCharIdx + 1 };
|
||||
curCharIdx = renderSpan.endCharIndex;
|
||||
|
||||
RenderParagraph& currentLine = mLines.back();
|
||||
@@ -1032,6 +1048,8 @@ void RichText::updateLayout() {
|
||||
}
|
||||
|
||||
line.height = std::max( line.height, maxLineHeight );
|
||||
if ( mLineHeight > 0 )
|
||||
line.height = std::max( line.height, mLineHeight );
|
||||
accumY += line.height;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,10 @@ void BlockLayouter::updateLayout() {
|
||||
auto* rt = widget->getRichTextPtr();
|
||||
if ( rt == nullptr || mPacking )
|
||||
return;
|
||||
|
||||
if ( widget->isMergeable() )
|
||||
return;
|
||||
|
||||
mResizedCount = 0;
|
||||
mPacking = true;
|
||||
|
||||
@@ -235,11 +239,14 @@ void BlockLayouter::positionRichTextChildren( Graphics::RichText* rt ) {
|
||||
p = p->getParent();
|
||||
}
|
||||
|
||||
bool handled = false;
|
||||
|
||||
if ( widget->isType( UI_TYPE_HTML_WIDGET ) &&
|
||||
widget->asType<UIHTMLWidget>()->isMergeable() ) {
|
||||
UITextSpan* textSpan = widget->asType<UITextSpan>();
|
||||
Int64 startChar = curCharIdx;
|
||||
Int64 endChar = curCharIdx;
|
||||
|
||||
if ( !textSpan->getText().empty() ) {
|
||||
endChar += textSpan->getText().length();
|
||||
curCharIdx = endChar;
|
||||
@@ -280,6 +287,20 @@ void BlockLayouter::positionRichTextChildren( Graphics::RichText* rt ) {
|
||||
spanChild = spanChild->getNextNode();
|
||||
}
|
||||
|
||||
if ( textSpan->isInlineBlock() ) {
|
||||
Rectf pad = textSpan->getPixelsPadding();
|
||||
bounds.Left -= pad.Left;
|
||||
bounds.Top -= pad.Top;
|
||||
bounds.Right += pad.Right;
|
||||
bounds.Bottom += pad.Bottom;
|
||||
for ( auto& hb : hitBoxes ) {
|
||||
hb.Left -= pad.Left;
|
||||
hb.Top -= pad.Top;
|
||||
hb.Right += pad.Right;
|
||||
hb.Bottom += pad.Bottom;
|
||||
}
|
||||
}
|
||||
|
||||
if ( bounds.Left <= bounds.Right && bounds.Top <= bounds.Bottom ) {
|
||||
Vector2f boundsPos = bounds.getPosition();
|
||||
|
||||
@@ -296,34 +317,55 @@ void BlockLayouter::positionRichTextChildren( Graphics::RichText* rt ) {
|
||||
hitBoxes.clear();
|
||||
}
|
||||
|
||||
} else if ( widget->isType( UI_TYPE_BR ) ) {
|
||||
curCharIdx += 1;
|
||||
Vector2f pos;
|
||||
if ( widget->getPrevNode() && widget->getPrevNode()->isWidget() ) {
|
||||
pos = widget->getPrevNode()->asType<UIWidget>()->getPixelsPosition();
|
||||
pos.y += widget->getPrevNode()->getPixelsSize().getHeight();
|
||||
}
|
||||
widget->setPixelsPosition( pos );
|
||||
widget->setPixelsSize( { eemax( 0.f, mContainer->getPixelsSize().getWidth() -
|
||||
mContainer->getPixelsContentOffset().Left -
|
||||
mContainer->getPixelsContentOffset().Right ),
|
||||
0 } );
|
||||
} else {
|
||||
curCharIdx += 1;
|
||||
const auto* span = getNextCustomSpan();
|
||||
if ( span ) {
|
||||
size_t lineIdx = currentSpan > 0 ? currentLine : currentLine - 1;
|
||||
Float lineY = lines[lineIdx].y;
|
||||
Rectf margin = widget->getLayoutPixelsMargin();
|
||||
handled = true;
|
||||
}
|
||||
|
||||
Vector2f targetPos( mContainer->getPixelsContentOffset().Left + span->position.x +
|
||||
margin.Left,
|
||||
mContainer->getPixelsContentOffset().Top + lineY +
|
||||
span->position.y + margin.Top );
|
||||
if ( !handled ) {
|
||||
if ( widget->isType( UI_TYPE_BR ) ) {
|
||||
curCharIdx += 1;
|
||||
Vector2f pos;
|
||||
if ( widget->getPrevNode() && widget->getPrevNode()->isWidget() ) {
|
||||
pos = widget->getPrevNode()->asType<UIWidget>()->getPixelsPosition();
|
||||
pos.y += widget->getPrevNode()->getPixelsSize().getHeight();
|
||||
}
|
||||
widget->setPixelsPosition( pos );
|
||||
widget->setPixelsSize(
|
||||
{ eemax( 0.f, mContainer->getPixelsSize().getWidth() -
|
||||
mContainer->getPixelsContentOffset().Left -
|
||||
mContainer->getPixelsContentOffset().Right ),
|
||||
0 } );
|
||||
} else {
|
||||
curCharIdx += 1;
|
||||
const auto* span = getNextCustomSpan();
|
||||
if ( span ) {
|
||||
size_t lineIdx = currentSpan > 0 ? currentLine : currentLine - 1;
|
||||
Float lineY = lines[lineIdx].y;
|
||||
Rectf margin = widget->getLayoutPixelsMargin();
|
||||
|
||||
widget->setPixelsPosition( targetPos - offset );
|
||||
Vector2f targetPos( mContainer->getPixelsContentOffset().Left +
|
||||
span->position.x + margin.Left,
|
||||
mContainer->getPixelsContentOffset().Top + lineY +
|
||||
span->position.y + margin.Top );
|
||||
|
||||
bounds = Rectf( targetPos, span->size );
|
||||
widget->setPixelsPosition( targetPos - offset );
|
||||
|
||||
bounds = Rectf( targetPos, span->size );
|
||||
|
||||
if ( widget->isType( UI_TYPE_TEXTSPAN ) &&
|
||||
widget->asType<UITextSpan>()->isInlineBlock() ) {
|
||||
Rectf pad = widget->getPixelsPadding();
|
||||
bounds.Left -= pad.Left;
|
||||
bounds.Top -= pad.Top;
|
||||
bounds.Right += pad.Right;
|
||||
bounds.Bottom += pad.Bottom;
|
||||
Vector2f boundsPos = bounds.getPosition();
|
||||
widget->setPixelsPosition( boundsPos - offset );
|
||||
if ( bounds.getSize() != widget->getPixelsSize() ) {
|
||||
widget->setPixelsSize( bounds.getSize() );
|
||||
mResizedCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return bounds;
|
||||
|
||||
@@ -563,7 +563,8 @@ void StyleSheetSpecification::registerDefaultProperties() {
|
||||
registerShorthand( "list-style",
|
||||
{ "list-style-type", "list-style-position", "list-style-image" },
|
||||
"list-style" );
|
||||
registerShorthand( "font", { "font-style", "font-size", "line-spacing", "font-family" },
|
||||
registerShorthand( "font",
|
||||
{ "font-style", "font-weight", "font-size", "line-height", "font-family" },
|
||||
"font" );
|
||||
}
|
||||
|
||||
@@ -1356,8 +1357,9 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() {
|
||||
|
||||
int stylePos = getIndexEndingWith( propNames, "-style" );
|
||||
int sizePos = getIndexEndingWith( propNames, "-size" );
|
||||
int linePos = getIndexEndingWith( propNames, "-spacing" );
|
||||
int linePos = getIndexEndingWith( propNames, "-height" );
|
||||
int familyPos = getIndexEndingWith( propNames, "-family" );
|
||||
int weightPos = getIndexEndingWith( propNames, "-weight" );
|
||||
|
||||
static const std::string sizeKeywords[] = {
|
||||
"xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "xxx-large" };
|
||||
@@ -1394,6 +1396,7 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() {
|
||||
std::string sizeStr;
|
||||
std::string lineStr;
|
||||
std::string familyStr;
|
||||
std::string weightStr;
|
||||
bool inLineHeight = false;
|
||||
|
||||
for ( size_t i = 0; i < tokens.size(); i++ ) {
|
||||
@@ -1446,11 +1449,8 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() {
|
||||
|
||||
if ( isWeightWord( tok ) ) {
|
||||
std::string lt = String::toLower( tok );
|
||||
if ( lt != "normal" ) {
|
||||
if ( !styleStr.empty() )
|
||||
styleStr += "|";
|
||||
styleStr += "bold";
|
||||
}
|
||||
if ( lt != "normal" )
|
||||
weightStr = "bold";
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1465,10 +1465,13 @@ void StyleSheetSpecification::registerDefaultShorthandParsers() {
|
||||
if ( !sizeStr.empty() ) {
|
||||
if ( stylePos != -1 && !styleStr.empty() )
|
||||
properties.emplace_back( StyleSheetProperty( propNames[stylePos], styleStr ) );
|
||||
if ( weightPos != -1 && !weightStr.empty() )
|
||||
properties.emplace_back( StyleSheetProperty( propNames[weightPos], weightStr ) );
|
||||
if ( sizePos != -1 )
|
||||
properties.emplace_back( StyleSheetProperty( propNames[sizePos], sizeStr ) );
|
||||
if ( linePos != -1 && !lineStr.empty() )
|
||||
properties.emplace_back( StyleSheetProperty( propNames[linePos], lineStr ) );
|
||||
if ( linePos != -1 )
|
||||
properties.emplace_back( StyleSheetProperty(
|
||||
propNames[linePos], lineStr.empty() ? "normal" : lineStr ) );
|
||||
if ( familyPos != -1 && !familyStr.empty() ) {
|
||||
String::trimInPlace( familyStr );
|
||||
if ( familyStr.size() >= 2 &&
|
||||
|
||||
@@ -941,6 +941,8 @@ void UIRichText::rebuildRichText( UILayout* container, RichText& richText, Intri
|
||||
|
||||
UIWidget* widget = node->asType<UIWidget>();
|
||||
|
||||
bool handled = false;
|
||||
|
||||
if ( widget->isType( UI_TYPE_HTML_WIDGET ) &&
|
||||
widget->asType<UIHTMLWidget>()->isMergeable() ) {
|
||||
UITextSpan* span = widget->asType<UITextSpan>();
|
||||
@@ -948,6 +950,14 @@ void UIRichText::rebuildRichText( UILayout* container, RichText& richText, Intri
|
||||
Rectf padding = span->getPixelsPadding();
|
||||
bool hasOwnText = !span->getText().empty() && NULL != span->getFontStyleConfig().Font;
|
||||
|
||||
Float spanLineHeight = 0;
|
||||
if ( span->isInlineBlock() ) {
|
||||
auto& fontStyle = span->getFontStyleConfig();
|
||||
if ( fontStyle.Font )
|
||||
spanLineHeight =
|
||||
(Float)fontStyle.Font->getFontHeight( fontStyle.CharacterSize );
|
||||
}
|
||||
|
||||
if ( hasOwnText ) {
|
||||
String::View spanText = span->getText().view();
|
||||
|
||||
@@ -969,7 +979,8 @@ void UIRichText::rebuildRichText( UILayout* container, RichText& richText, Intri
|
||||
spanText = spanText.substr( 1 );
|
||||
|
||||
if ( !spanText.empty() ) {
|
||||
richText.addSpan( spanText, span->getFontStyleConfig(), margin, padding );
|
||||
richText.addSpan( spanText, span->getFontStyleConfig(), margin, padding,
|
||||
spanLineHeight, span->isInlineBlock() );
|
||||
if ( shouldCollapse )
|
||||
lastSpanEndsWithSpace = spanText.back() == ' ';
|
||||
}
|
||||
@@ -994,68 +1005,80 @@ void UIRichText::rebuildRichText( UILayout* container, RichText& richText, Intri
|
||||
Rectf padRightOnly( 0, 0, padding.Right, padding.Bottom );
|
||||
richText.addSpan( "", span->getFontStyleConfig(), rightOnly, padRightOnly );
|
||||
}
|
||||
} else if ( widget->isType( UI_TYPE_BR ) ) {
|
||||
richText.addSpan( "\n",
|
||||
widget->asType<UILineBreak>()->getRichText().getFontStyleConfig() );
|
||||
lastSpanEndsWithSpace = false;
|
||||
} else {
|
||||
Rectf margin = widget->getLayoutPixelsMargin();
|
||||
bool isBlock = widget->getLayoutWidthPolicy() == SizePolicy::MatchParent;
|
||||
if ( widget->isType( UI_TYPE_HTML_WIDGET ) ) {
|
||||
CSSDisplay display = widget->asType<UIHTMLWidget>()->getDisplay();
|
||||
if ( display == CSSDisplay::Inline || display == CSSDisplay::InlineBlock )
|
||||
isBlock = false;
|
||||
else if ( display == CSSDisplay::ListItem )
|
||||
isBlock = true;
|
||||
}
|
||||
|
||||
if ( mode == IntrinsicMode::None ) {
|
||||
if ( isBlock ) {
|
||||
if ( container->getPixelsSize().getWidth() != 0 ) {
|
||||
Float maxSize = eemax( 0.f, container->getPixelsSize().getWidth() -
|
||||
container->getPixelsContentOffset().Left -
|
||||
container->getPixelsContentOffset().Right -
|
||||
margin.Left - margin.Right );
|
||||
widget->setPixelsSize( eemax( 0.f, maxSize ),
|
||||
widget->getPixelsSize().getHeight() );
|
||||
} else {
|
||||
handled = true;
|
||||
}
|
||||
|
||||
if ( !handled ) {
|
||||
if ( widget->isType( UI_TYPE_BR ) ) {
|
||||
richText.addSpan(
|
||||
"\n", widget->asType<UILineBreak>()->getRichText().getFontStyleConfig() );
|
||||
lastSpanEndsWithSpace = false;
|
||||
} else {
|
||||
Rectf margin = widget->getLayoutPixelsMargin();
|
||||
bool isBlock = widget->getLayoutWidthPolicy() == SizePolicy::MatchParent;
|
||||
if ( widget->isType( UI_TYPE_HTML_WIDGET ) ) {
|
||||
CSSDisplay display = widget->asType<UIHTMLWidget>()->getDisplay();
|
||||
if ( display == CSSDisplay::Inline || display == CSSDisplay::InlineBlock )
|
||||
isBlock = false;
|
||||
else if ( display == CSSDisplay::ListItem )
|
||||
isBlock = true;
|
||||
}
|
||||
|
||||
if ( mode == IntrinsicMode::None ) {
|
||||
if ( isBlock ) {
|
||||
if ( container->getPixelsSize().getWidth() != 0 ) {
|
||||
Float maxSize =
|
||||
eemax( 0.f, container->getPixelsSize().getWidth() -
|
||||
container->getPixelsContentOffset().Left -
|
||||
container->getPixelsContentOffset().Right -
|
||||
margin.Left - margin.Right );
|
||||
widget->setPixelsSize( eemax( 0.f, maxSize ),
|
||||
widget->getPixelsSize().getHeight() );
|
||||
} else {
|
||||
container->onAutoSizeChild( widget );
|
||||
}
|
||||
} else if ( widget->getLayoutWidthPolicy() == SizePolicy::WrapContent ||
|
||||
widget->getLayoutHeightPolicy() == SizePolicy::WrapContent ) {
|
||||
container->onAutoSizeChild( widget );
|
||||
}
|
||||
} else if ( widget->getLayoutWidthPolicy() == SizePolicy::WrapContent ||
|
||||
widget->getLayoutHeightPolicy() == SizePolicy::WrapContent ) {
|
||||
container->onAutoSizeChild( widget );
|
||||
|
||||
if ( widget->isType( UI_TYPE_TEXTSPAN ) &&
|
||||
widget->asType<UITextSpan>()->isInlineBlock() &&
|
||||
widget->getPixelsSize().getWidth() == 0 )
|
||||
widget->asType<UIRichText>()->updateLayout();
|
||||
}
|
||||
}
|
||||
|
||||
Sizef size;
|
||||
if ( mode == IntrinsicMode::Min ) {
|
||||
size = Sizef( widget->getMinIntrinsicWidth(), 0 );
|
||||
} else if ( mode == IntrinsicMode::Max ) {
|
||||
size = Sizef( widget->getMaxIntrinsicWidth(), 0 );
|
||||
} else {
|
||||
size = widget->getPixelsSize();
|
||||
}
|
||||
Sizef size;
|
||||
if ( mode == IntrinsicMode::Min ) {
|
||||
size = Sizef( widget->getMinIntrinsicWidth(), 0 );
|
||||
} else if ( mode == IntrinsicMode::Max ) {
|
||||
size = Sizef( widget->getMaxIntrinsicWidth(), 0 );
|
||||
} else {
|
||||
size = widget->getPixelsSize();
|
||||
}
|
||||
|
||||
Float w = size.getWidth();
|
||||
if ( isBlock && mode == IntrinsicMode::None &&
|
||||
container->getPixelsSize().getWidth() != 0 ) {
|
||||
w = eemax( 0.f, container->getPixelsSize().getWidth() -
|
||||
container->getPixelsContentOffset().Left -
|
||||
container->getPixelsContentOffset().Right - margin.Left -
|
||||
margin.Right );
|
||||
}
|
||||
Float w = size.getWidth();
|
||||
if ( isBlock && mode == IntrinsicMode::None &&
|
||||
container->getPixelsSize().getWidth() != 0 ) {
|
||||
w = eemax( 0.f, container->getPixelsSize().getWidth() -
|
||||
container->getPixelsContentOffset().Left -
|
||||
container->getPixelsContentOffset().Right - margin.Left -
|
||||
margin.Right );
|
||||
}
|
||||
|
||||
CSSFloat floatType = CSSFloat::None;
|
||||
CSSClear clearType = CSSClear::None;
|
||||
if ( widget->isType( UI_TYPE_HTML_WIDGET ) ) {
|
||||
floatType = widget->asType<UIHTMLWidget>()->getCSSFloat();
|
||||
clearType = widget->asType<UIHTMLWidget>()->getCSSClear();
|
||||
}
|
||||
CSSFloat floatType = CSSFloat::None;
|
||||
CSSClear clearType = CSSClear::None;
|
||||
if ( widget->isType( UI_TYPE_HTML_WIDGET ) ) {
|
||||
floatType = widget->asType<UIHTMLWidget>()->getCSSFloat();
|
||||
clearType = widget->asType<UIHTMLWidget>()->getCSSClear();
|
||||
}
|
||||
|
||||
richText.addCustomSize( Sizef( w + margin.Left + margin.Right,
|
||||
size.getHeight() + margin.Top + margin.Bottom ),
|
||||
isBlock, floatType, clearType );
|
||||
lastSpanEndsWithSpace = false;
|
||||
richText.addCustomSize( Sizef( w + margin.Left + margin.Right,
|
||||
size.getHeight() + margin.Top + margin.Bottom ),
|
||||
isBlock, floatType, clearType );
|
||||
lastSpanEndsWithSpace = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1289,5 +1312,4 @@ void UIRichText::selCurEnd( const Int64& end ) {
|
||||
invalidateDraw();
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace EE::UI
|
||||
|
||||
@@ -62,16 +62,29 @@ bool UITextSpan::isType( const Uint32& type ) const {
|
||||
}
|
||||
|
||||
bool UITextSpan::isMergeable() const {
|
||||
return mDisplay == CSSDisplay::Inline;
|
||||
if ( mDisplay == CSSDisplay::Inline )
|
||||
return true;
|
||||
if ( mDisplay == CSSDisplay::InlineBlock )
|
||||
return !getText().empty() && NULL != getFontStyleConfig().Font;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UITextSpan::isInlineBlock() const {
|
||||
return mDisplay == CSSDisplay::InlineBlock;
|
||||
}
|
||||
|
||||
void UITextSpan::drawBorder() {
|
||||
if ( ( mFlags & UI_BORDER ) && NULL != mBorder ) {
|
||||
mBorder->setAlpha( mAlpha );
|
||||
mBorder->draw( { std::trunc( mScreenPos.x - mPaddingPx.Left ),
|
||||
std::trunc( mScreenPos.y - mPaddingPx.Top ) },
|
||||
{ std::floor( mSize.x + mPaddingPx.Left + mPaddingPx.Right ),
|
||||
std::floor( mSize.y + mPaddingPx.Top + mPaddingPx.Bottom ) } );
|
||||
if ( isInlineBlock() ) {
|
||||
mBorder->draw( Vector2f( std::trunc( mScreenPos.x ), std::trunc( mScreenPos.y ) ),
|
||||
Sizef( std::floor( mSize.x ), std::floor( mSize.y ) ) );
|
||||
} else {
|
||||
mBorder->draw( { std::trunc( mScreenPos.x - mPaddingPx.Left ),
|
||||
std::trunc( mScreenPos.y - mPaddingPx.Top ) },
|
||||
{ std::floor( mSize.x + mPaddingPx.Left + mPaddingPx.Right ),
|
||||
std::floor( mSize.y + mPaddingPx.Top + mPaddingPx.Bottom ) } );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -209,6 +209,86 @@ UTEST( UIRichText, spanPadding ) {
|
||||
Engine::destroySingleton();
|
||||
}
|
||||
|
||||
UTEST( UIRichText, anchorPadding ) {
|
||||
auto win = Engine::instance()->createWindow(
|
||||
WindowSettings( 800, 600, "Anchor Span Padding Test", WindowStyle::Default,
|
||||
WindowBackend::Default, 32, {}, 1, false, true ),
|
||||
ContextSettings( false, 0, 0, GLv_default, true, false ) );
|
||||
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
|
||||
|
||||
FontTrueType* font = FontTrueType::New( "NotoSans-Regular" );
|
||||
font->loadFromFile( "../assets/fonts/NotoSans-Regular.ttf" );
|
||||
ASSERT_TRUE( font != nullptr && font->loaded() );
|
||||
FontFamily::loadFromRegular( font );
|
||||
|
||||
UI::UISceneNode* sceneNode = UI::UISceneNode::New();
|
||||
SceneManager::instance()->add( sceneNode );
|
||||
UI::UIThemeManager* themeManager = sceneNode->getUIThemeManager();
|
||||
themeManager->setDefaultFont( font );
|
||||
sceneNode->setURI( "file://" + Sys::getProcessPath() + "assets/html/" );
|
||||
std::string html;
|
||||
FileSystem::fileGet( "assets/html/anchor_padding.html", html );
|
||||
sceneNode->loadLayoutFromString( HTMLFormatter::HTMLtoXML( html ) );
|
||||
win->setClearColor( Color::White );
|
||||
|
||||
win->getInput()->update();
|
||||
SceneManager::instance()->update();
|
||||
|
||||
win->clear();
|
||||
SceneManager::instance()->draw();
|
||||
win->display();
|
||||
|
||||
compareImages( utest_state, utest_result, win, "eepp-ui-anchor-padding", "html" );
|
||||
|
||||
auto anchors = sceneNode->getRoot()->findAllByTag( "a" );
|
||||
ASSERT_GE( anchors.size(), (size_t)1 );
|
||||
auto downloadLink = anchors[0]->asType<UIWidget>();
|
||||
EXPECT_NEAR( downloadLink->getPixelsSize().getWidth(), 81.f, 3.f );
|
||||
EXPECT_NEAR( downloadLink->getPixelsSize().getHeight(), 28.f, 3.f );
|
||||
|
||||
Engine::destroySingleton();
|
||||
}
|
||||
|
||||
UTEST( UIRichText, anchorPaddingLineHeight ) {
|
||||
auto win = Engine::instance()->createWindow(
|
||||
WindowSettings( 800, 600, "Anchor Padding LineHeight Test", WindowStyle::Default,
|
||||
WindowBackend::Default, 32, {}, 1, false, true ),
|
||||
ContextSettings( false, 0, 0, GLv_default, true, false ) );
|
||||
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
|
||||
|
||||
FontTrueType* font = FontTrueType::New( "NotoSans-Regular" );
|
||||
font->loadFromFile( "../assets/fonts/NotoSans-Regular.ttf" );
|
||||
ASSERT_TRUE( font != nullptr && font->loaded() );
|
||||
FontFamily::loadFromRegular( font );
|
||||
|
||||
UI::UISceneNode* sceneNode = UI::UISceneNode::New();
|
||||
SceneManager::instance()->add( sceneNode );
|
||||
UI::UIThemeManager* themeManager = sceneNode->getUIThemeManager();
|
||||
themeManager->setDefaultFont( font );
|
||||
sceneNode->setURI( "file://" + Sys::getProcessPath() + "assets/html/" );
|
||||
std::string html;
|
||||
FileSystem::fileGet( "assets/html/anchor_padding_lineheight.html", html );
|
||||
sceneNode->loadLayoutFromString( HTMLFormatter::HTMLtoXML( html ) );
|
||||
win->setClearColor( Color::White );
|
||||
|
||||
win->getInput()->update();
|
||||
SceneManager::instance()->update();
|
||||
|
||||
win->clear();
|
||||
SceneManager::instance()->draw();
|
||||
win->display();
|
||||
|
||||
compareImages( utest_state, utest_result, win, "eepp-ui-anchor-padding-lineheight", "html" );
|
||||
|
||||
auto anchors = sceneNode->getRoot()->findAllByTag( "a" );
|
||||
ASSERT_GE( anchors.size(), (size_t)1 );
|
||||
auto downloadLink = anchors[0]->asType<UIWidget>();
|
||||
EXPECT_NEAR( downloadLink->getPixelsSize().getWidth(), 81.f, 3.f );
|
||||
EXPECT_NEAR( downloadLink->getPixelsSize().getHeight(), 28.f, 3.f );
|
||||
|
||||
Engine::destroySingleton();
|
||||
}
|
||||
|
||||
UTEST( UIHTMLTable, complexLayout3 ) {
|
||||
auto win = Engine::instance()->createWindow(
|
||||
WindowSettings( 1024, 650, "HTML Tables Test 3", WindowStyle::Default,
|
||||
@@ -1391,3 +1471,47 @@ UTEST( UIBackground, imageAtlasPositioningPixelDensity2 ) {
|
||||
Engine::destroySingleton();
|
||||
EE::Graphics::PixelDensity::setPixelDensity( 1.0f );
|
||||
}
|
||||
|
||||
UTEST( UIBackground, InlineBlockImageSpans ) {
|
||||
auto win = Engine::instance()->createWindow(
|
||||
WindowSettings( 1024, 653, "inline-block image spans", WindowStyle::Default,
|
||||
WindowBackend::Default, 32, {}, 1, false, true ),
|
||||
ContextSettings( false, 0, 0, GLv_default, true, false ) );
|
||||
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
|
||||
|
||||
UI::UISceneNode* sceneNode = init_test_inline_block();
|
||||
|
||||
sceneNode->setURI( "file://" + Sys::getProcessPath() + "assets/html/" );
|
||||
|
||||
std::string html;
|
||||
FileSystem::fileGet( "assets/html/inline_block.html", html );
|
||||
sceneNode->loadLayoutFromString( HTMLFormatter::HTMLtoXML( html ) );
|
||||
win->setClearColor( Color::White );
|
||||
|
||||
win->getInput()->update();
|
||||
SceneManager::instance()->update();
|
||||
|
||||
win->clear();
|
||||
SceneManager::instance()->draw();
|
||||
win->display();
|
||||
|
||||
auto anchors = sceneNode->getRoot()->findAllByTag( "a" );
|
||||
auto spans = sceneNode->getRoot()->querySelectorAll( "a > span" );
|
||||
|
||||
EXPECT_GT( anchors.size(), (size_t)0 );
|
||||
EXPECT_GT( spans.size(), (size_t)0 );
|
||||
|
||||
for ( auto anchor : anchors ) {
|
||||
EXPECT_GT( anchor->getPixelsSize().getWidth(), 0 );
|
||||
EXPECT_GT( anchor->getPixelsSize().getHeight(), 0 );
|
||||
}
|
||||
|
||||
for ( auto span : spans ) {
|
||||
EXPECT_GT( span->getPixelsSize().getWidth(), 0 );
|
||||
EXPECT_GT( span->getPixelsSize().getHeight(), 0 );
|
||||
}
|
||||
|
||||
compareImages( utest_state, utest_result, win, "eepp-ui-inline-block-image-spans", "html", 4 );
|
||||
|
||||
Engine::destroySingleton();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user