Fix two list-marker issues:

- Decimal/text markers now inherit the current list-item font color.
  - Marker X/Y coordinates are pixel-snapped, eliminating blurry rendering.
  - The behavior is shared by <li> and textual <summary> markers.
  - Added focused tests for inherited color and integer positioning.
This commit is contained in:
Martín Lucas Golini
2026-08-23 18:50:45 -03:00
parent e269d65e01
commit 65a389aa96
5 changed files with 51 additions and 11 deletions

View File

@@ -6,6 +6,10 @@
#include <eepp/math/rect.hpp>
#include <eepp/ui/csslayouttypes.hpp>
namespace EE { namespace Graphics {
class Text;
}} // namespace EE::Graphics
namespace EE { namespace UI {
class EE_API UIHTMLListStyle {
@@ -16,6 +20,11 @@ class EE_API UIHTMLListStyle {
static String getTextMarkerString( CSSListStyleType type, int index );
static void syncTextMarkerColor( Graphics::Text& marker, const Color& color );
static Vector2f getTextMarkerPosition( const Vector2f& screenPos, const Rectf& paddingPx,
Float textWidth, Float fontSize );
static void drawPrimitiveMarker( CSSListStyleType type, const Vector2f& screenPos,
const Rectf& paddingPx,
const Graphics::FontStyleConfig& style );

View File

@@ -225,12 +225,12 @@ void UIHTMLSummary::draw() {
UIHTMLListStyle::drawPrimitiveMarker( markerType, mScreenPos, mPaddingPx,
mRichText.getFontStyleConfig() );
} else if ( mListMarkerText && !mListMarkerText->getString().empty() ) {
const Float fontSize = mRichText.getFontStyleConfig().CharacterSize;
const Float offset = 0.25f * fontSize;
const Float markerX =
mScreenPos.x + mPaddingPx.Left - mListMarkerText->getTextWidth() - offset;
mListMarkerText->draw( markerX, mScreenPos.y + mPaddingPx.Top, Vector2f::One, 0.f,
getBlendMode() );
const FontStyleConfig& style = mRichText.getFontStyleConfig();
UIHTMLListStyle::syncTextMarkerColor( *mListMarkerText, style.FontColor );
const Float fontSize = style.CharacterSize;
const Vector2f markerPos = UIHTMLListStyle::getTextMarkerPosition(
mScreenPos, mPaddingPx, mListMarkerText->getTextWidth(), fontSize );
mListMarkerText->draw( markerPos.x, markerPos.y, Vector2f::One, 0.f, getBlendMode() );
}
}
}

View File

@@ -40,15 +40,14 @@ void UIHTMLListItem::draw() {
if ( mVisible && 0.f != mAlpha && mDisplay == CSSDisplay::ListItem ) {
const FontStyleConfig& style = mRichText.getFontStyleConfig();
Float fontSize = style.CharacterSize;
Float offset = 0.25f * fontSize;
Float lineTop = mScreenPos.y + mPaddingPx.Top;
if ( UIHTMLListStyle::isPrimitiveMarker( mListStyleType ) ) {
UIHTMLListStyle::drawPrimitiveMarker( mListStyleType, mScreenPos, mPaddingPx, style );
} else if ( mListMarkerText && !mListMarkerText->getString().empty() ) {
Float markerX =
mScreenPos.x + mPaddingPx.Left - mListMarkerText->getTextWidth() - offset;
mListMarkerText->draw( markerX, lineTop, Vector2f::One, 0.f, getBlendMode() );
UIHTMLListStyle::syncTextMarkerColor( *mListMarkerText, style.FontColor );
const Vector2f markerPos = UIHTMLListStyle::getTextMarkerPosition(
mScreenPos, mPaddingPx, mListMarkerText->getTextWidth(), fontSize );
mListMarkerText->draw( markerPos.x, markerPos.y, Vector2f::One, 0.f, getBlendMode() );
}
}
}

View File

@@ -1,5 +1,6 @@
#include <eepp/graphics/font.hpp>
#include <eepp/graphics/primitives.hpp>
#include <eepp/graphics/text.hpp>
#include <eepp/ui/uihtmlliststyle.hpp>
namespace EE { namespace UI {
@@ -50,6 +51,17 @@ String UIHTMLListStyle::getTextMarkerString( CSSListStyleType type, int index )
}
}
void UIHTMLListStyle::syncTextMarkerColor( Graphics::Text& marker, const Color& color ) {
if ( marker.getFillColor() != color )
marker.setFillColor( color );
}
Vector2f UIHTMLListStyle::getTextMarkerPosition( const Vector2f& screenPos, const Rectf& paddingPx,
Float textWidth, Float fontSize ) {
return { std::floor( screenPos.x + paddingPx.Left - textWidth - 0.25f * fontSize ),
std::floor( screenPos.y + paddingPx.Top ) };
}
void UIHTMLListStyle::drawPrimitiveMarker( CSSListStyleType type, const Vector2f& screenPos,
const Rectf& paddingPx,
const Graphics::FontStyleConfig& style ) {

View File

@@ -26,6 +26,7 @@
#include <eepp/ui/uihtmldetails.hpp>
#include <eepp/ui/uihtmlimage.hpp>
#include <eepp/ui/uihtmlinput.hpp>
#include <eepp/ui/uihtmlliststyle.hpp>
#include <eepp/ui/uihtmltable.hpp>
#include <eepp/ui/uihtmltextarea.hpp>
#include <eepp/ui/uihtmltextinput.hpp>
@@ -2402,6 +2403,25 @@ UTEST( UILayout, listStyleTypeDecimal ) {
Engine::destroySingleton();
}
UTEST( UILayout, textListMarkerTracksInheritedColor ) {
FontStyleConfig inheritedStyle;
inheritedStyle.FontColor = Color( 224, 230, 237 );
inheritedStyle.CharacterSize = 19;
Text marker;
marker.setString( "1." );
UIHTMLListStyle::syncTextMarkerColor( marker, inheritedStyle.FontColor );
EXPECT_TRUE( marker.getFillColor() == inheritedStyle.FontColor );
}
UTEST( UILayout, textListMarkerPositionIsPixelAligned ) {
const Vector2f markerPos = UIHTMLListStyle::getTextMarkerPosition(
{ 100.75f, 40.5f }, Rectf( 0.25f, 1.75f, 0.f, 0.f ), 12.4f, 17.f );
EXPECT_TRUE( markerPos == markerPos.floor() );
}
UTEST( UILayout, listStyleTypeDisc ) {
init_ui_test();
auto* sceneNode = SceneManager::instance()->getUISceneNode();