mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-28 17:16:29 +03:00
Fix padding and margin in empty spans with children.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@@ -289,7 +289,7 @@ Sizef RichText::getPixelsSize() {
|
||||
|
||||
void RichText::addSpan( const String& text, const FontStyleConfig& style, const Rectf& margin,
|
||||
const Rectf& padding ) {
|
||||
if ( text.empty() )
|
||||
if ( text.empty() && margin == Rectf::Zero && padding == Rectf::Zero )
|
||||
return;
|
||||
|
||||
auto span = std::make_shared<Text>();
|
||||
@@ -312,7 +312,7 @@ void RichText::addCustomSize( const Sizef& size, bool isBlock ) {
|
||||
}
|
||||
|
||||
void RichText::addSpan( const String& text, const FontStyleConfig& style ) {
|
||||
addSpan( text, style, Rectf(), Rectf() );
|
||||
addSpan( text, style, Rectf::Zero, Rectf::Zero );
|
||||
}
|
||||
|
||||
void RichText::addSpan( const String& text, Font* font, Uint32 characterSize, Color color,
|
||||
@@ -457,9 +457,20 @@ void RichText::updateLayout() {
|
||||
for ( auto& block : mBlocks ) {
|
||||
if ( auto pText = std::get_if<SpanBlock>( &block ) ) {
|
||||
auto& span = pText->text;
|
||||
if ( !span || span->getString().empty() )
|
||||
if ( !span )
|
||||
continue;
|
||||
|
||||
if ( span->getString().empty() ) {
|
||||
Float l = pText->margin.Left + pText->padding.Left;
|
||||
Float r = pText->margin.Right + pText->padding.Right;
|
||||
if ( l <= 0 && r <= 0 )
|
||||
continue;
|
||||
curX += l + r;
|
||||
if ( !mLines.empty() )
|
||||
mLines.back().width += l + r;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto& fontStyle = span->getFontStyleConfig();
|
||||
if ( !fontStyle.Font )
|
||||
continue;
|
||||
|
||||
@@ -659,11 +659,18 @@ void UIRichText::rebuildRichText( UILayout* container, RichText& richText, Intri
|
||||
if ( widget->isType( UI_TYPE_HTML_WIDGET ) &&
|
||||
widget->asType<UIHTMLWidget>()->isMergeable() ) {
|
||||
UITextSpan* span = widget->asType<UITextSpan>();
|
||||
if ( !span->getText().empty() && NULL != span->getFontStyleConfig().Font ) {
|
||||
Rectf margin = span->getLayoutPixelsMargin();
|
||||
Rectf padding = span->getPixelsPadding();
|
||||
Rectf margin = span->getLayoutPixelsMargin();
|
||||
Rectf padding = span->getPixelsPadding();
|
||||
bool hasOwnText = !span->getText().empty() && NULL != span->getFontStyleConfig().Font;
|
||||
|
||||
if ( hasOwnText ) {
|
||||
richText.addSpan( span->getText(), span->getFontStyleConfig(), margin, padding );
|
||||
} else if ( margin.Left > 0 || margin.Top > 0 || padding.Left > 0 || padding.Top > 0 ) {
|
||||
Rectf leftOnly( margin.Left, margin.Top, 0, 0 );
|
||||
Rectf padLeftOnly( padding.Left, padding.Top, 0, 0 );
|
||||
richText.addSpan( "", span->getFontStyleConfig(), leftOnly, padLeftOnly );
|
||||
}
|
||||
|
||||
Node* spanChild = span->getFirstChild();
|
||||
while ( spanChild != NULL ) {
|
||||
bool isOutOfFlow = spanChild->isType( UI_TYPE_HTML_WIDGET ) &&
|
||||
@@ -672,6 +679,13 @@ void UIRichText::rebuildRichText( UILayout* container, RichText& richText, Intri
|
||||
processNodeRef( spanChild, processNodeRef );
|
||||
spanChild = spanChild->getNextNode();
|
||||
}
|
||||
|
||||
if ( !hasOwnText && ( margin.Right > 0 || margin.Bottom > 0 || padding.Right > 0 ||
|
||||
padding.Bottom > 0 ) ) {
|
||||
Rectf rightOnly( 0, 0, margin.Right, margin.Bottom );
|
||||
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() );
|
||||
|
||||
Reference in New Issue
Block a user