mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-17 06:25:23 +03:00
Fix background color in Text (should render over text and not the bounding rectangle.
Having fixed this added background color to UIRichText and UITextSpan.
This commit is contained in:
@@ -1434,3 +1434,69 @@ UTEST( FontRendering, TextContiguousOffset ) {
|
||||
runTest();
|
||||
}
|
||||
}
|
||||
|
||||
UTEST( FontRendering, TextBackgroundColor ) {
|
||||
FileSystem::changeWorkingDirectory( Sys::getProcessPath() );
|
||||
|
||||
const auto runTest = [&]() {
|
||||
auto win = Engine::instance()->createWindow(
|
||||
WindowSettings( 512, 400, "eepp - Text Background Color", WindowStyle::Default,
|
||||
WindowBackend::Default, 32, {}, 1, false, true ) );
|
||||
|
||||
ASSERT_TRUE_MSG( win->isOpen(), "Failed to create Window" );
|
||||
|
||||
win->setClearColor( RGB( 255, 255, 255 ) );
|
||||
win->clear();
|
||||
|
||||
FontTrueType* font = FontTrueType::New( "NotoSans-Regular" );
|
||||
font->loadFromFile( "../assets/fonts/NotoSans-Regular.ttf" );
|
||||
|
||||
Vector2f pos{ 20, 20 };
|
||||
Text text;
|
||||
text.setFont( font );
|
||||
text.setFontSize( 20 );
|
||||
text.setFillColor( Color::Black );
|
||||
text.setBackgroundColor( Color::Yellow );
|
||||
text.setString( "Text with background color\nand multiple lines." );
|
||||
text.draw( pos.x, pos.y );
|
||||
|
||||
pos.y += text.getTextHeight() + 20;
|
||||
text.setAlign( TEXT_ALIGN_CENTER );
|
||||
text.setString( "Centered text with\nbackground color." );
|
||||
text.draw( pos.x, pos.y );
|
||||
|
||||
pos.y += text.getTextHeight() + 20;
|
||||
text.setAlign( TEXT_ALIGN_LEFT );
|
||||
text.setLineWrapMode( LineWrapMode::Word );
|
||||
text.setMaxWrapWidth( 200 );
|
||||
text.setString(
|
||||
"Wrapped text with background color that should only cover the text area." );
|
||||
text.draw( pos.x, pos.y );
|
||||
|
||||
pos.y += text.getTextHeight() + 20;
|
||||
text.setLineWrapMode( LineWrapMode::NoWrap );
|
||||
text.setBackgroundColor( Color::cyan );
|
||||
text.setString( " " ); // Only spaces
|
||||
text.draw( pos.x, pos.y );
|
||||
|
||||
compareImages( utest_state, utest_result, win, "eepp-text-background-color" );
|
||||
|
||||
Engine::destroySingleton();
|
||||
};
|
||||
|
||||
UTEST_PRINT_STEP( "Text Shaper disabled" );
|
||||
{
|
||||
BoolScopedOp op( Text::TextShaperEnabled, false );
|
||||
runTest();
|
||||
}
|
||||
|
||||
UTEST_PRINT_STEP( "Text Shaper enabled" );
|
||||
{
|
||||
BoolScopedOp op( Text::TextShaperEnabled, true );
|
||||
runTest();
|
||||
|
||||
UTEST_PRINT_STEP( "Text Shaper enabled w/o optimizations" );
|
||||
BoolScopedOp op2( Text::TextShaperOptimizations, false );
|
||||
runTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user