Skip to content

Commit 6e7180b

Browse files
committed
Added basic support for properties inheritance in CSS.
Added support for "style" property in widgets. Fixed a crash in Text when trying to render a shadow from an outlined text.
1 parent ceef753 commit 6e7180b

18 files changed

Lines changed: 213 additions & 58 deletions

include/eepp/ui/css/propertydefinition.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class EE_API PropertyDefinition {
280280

281281
const std::string& getDefaultValue() const;
282282

283-
bool getInherited() const;
283+
bool isInherited() const;
284284

285285
const PropertyRelativeTarget& getRelativeTarget() const;
286286

include/eepp/ui/css/propertyspecification.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ class EE_API PropertySpecification {
3131

3232
bool isShorthand( const Uint32& id ) const;
3333

34+
const SmallVector<PropertyId>& getInheritableProperties() const;
35+
3436
protected:
3537
friend class PropertyDefinition;
3638

3739
std::unordered_map<Uint32, std::shared_ptr<PropertyDefinition>> mProperties;
3840
std::unordered_map<Uint32, std::shared_ptr<ShorthandDefinition>> mShorthands;
41+
SmallVector<PropertyId> mInheritableProperties;
3942

4043
const PropertyDefinition* addPropertyAlias( Uint32 aliasId, const PropertyDefinition* propDef );
4144
};

include/eepp/ui/css/stylesheetpropertiesparser.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ namespace EE { namespace UI { namespace CSS {
99

1010
class EE_API StyleSheetPropertiesParser {
1111
public:
12-
StyleSheetPropertiesParser();
12+
StyleSheetPropertiesParser() = default;
1313

14-
explicit StyleSheetPropertiesParser( const std::string& propsstr );
14+
explicit StyleSheetPropertiesParser( std::string_view propsstr );
1515

16-
void parse( const std::string& propsstr );
16+
void parse( std::string_view propsstr );
1717

1818
void print();
1919

@@ -24,18 +24,18 @@ class EE_API StyleSheetPropertiesParser {
2424
protected:
2525
enum ReadState { ReadingPropertyName, ReadingPropertyValue, ReadingComment };
2626

27-
ReadState mPrevRs;
27+
ReadState mPrevRs{ ReadingPropertyName };
2828

2929
StyleSheetProperties mProperties;
3030
StyleSheetVariables mVariables;
3131

3232
int readPropertyName( ReadState& rs, std::size_t pos, std::string& buffer,
33-
const std::string& str );
33+
std::string_view str );
3434

3535
int readPropertyValue( ReadState& rs, std::size_t pos, std::string& buffer,
36-
const std::string& str );
36+
std::string_view str );
3737

38-
int readComment( ReadState& rs, std::size_t pos, std::string& buffer, const std::string& str );
38+
int readComment( ReadState& rs, std::size_t pos, std::string& buffer, std::string_view str );
3939

4040
void addProperty( std::string name, std::string value );
4141
};

include/eepp/ui/css/stylesheetspecification.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <eepp/system/functionstring.hpp>
66
#include <eepp/system/singleton.hpp>
77
#include <eepp/ui/css/drawableimageparser.hpp>
8+
#include <eepp/ui/css/propertydefinition.hpp>
89
#include <eepp/ui/css/shorthanddefinition.hpp>
910
#include <functional>
1011

@@ -43,6 +44,8 @@ class EE_API StyleSheetSpecification {
4344

4445
const PropertyDefinition* getProperty( const std::string& name ) const;
4546

47+
const SmallVector<CSS::PropertyId>& getInheritableProperties() const;
48+
4649
ShorthandDefinition& registerShorthand( const std::string& name,
4750
const std::vector<std::string>& properties,
4851
const std::string& shorthandFuncName );

include/eepp/ui/uistyle.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class EE_API UIStyle : public UIState {
7373

7474
bool hasProperty( const CSS::PropertyId& propertyId ) const;
7575

76+
bool hasLocalProperty( CSS::PropertyId propId ) const;
77+
78+
CSS::StyleSheetProperty* getInheritedProperty( CSS::PropertyId propId ) const;
79+
7680
void resetGlobalDefinition();
7781

7882
void resetCachedProperties();
@@ -122,6 +126,8 @@ class EE_API UIStyle : public UIState {
122126
void applyStyleSheetProperty( const CSS::StyleSheetProperty& property,
123127
std::shared_ptr<CSS::ElementDefinition> prevDefinition );
124128

129+
void applyInheritedProperties();
130+
125131
void updateAnimationsPlayState();
126132

127133
void updateAnimations();

include/eepp/ui/uitextspan.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace EE { namespace UI {
88

9+
using SpanHitBoxes = SmallVector<Rectf, 4>;
10+
911
class EE_API UITextSpan : public UIWidget {
1012
public:
1113
static UITextSpan* New();
@@ -115,19 +117,19 @@ class EE_API UITextSpan : public UIWidget {
115117
bool hasFontShadowOffset() const;
116118
bool hasFontBackgroundColor() const;
117119

118-
std::vector<Rectf>& getHitBoxes();
120+
SpanHitBoxes& getHitBoxes();
119121

120-
const std::vector<Rectf>& getHitBoxes() const;
122+
const SpanHitBoxes& getHitBoxes() const;
121123

122-
void setHitBoxes( std::vector<Rectf>&& hitBoxes );
124+
void setHitBoxes( SpanHitBoxes&& hitBoxes );
123125

124126
virtual Node* overFind( const Vector2f& point );
125127

126128
protected:
127129
Uint32 mStyleState{ StyleStateNone };
128130
String mText;
129131
UIFontStyleConfig mFontStyleConfig;
130-
std::vector<Rectf> mHitBoxes;
132+
SpanHitBoxes mHitBoxes;
131133

132134
explicit UITextSpan( const std::string& tag = "span" );
133135

include/eepp/ui/uiwidget.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,8 @@ class EE_API UIWidget : public UINode {
543543
*/
544544
virtual bool applyProperty( const StyleSheetProperty& attribute );
545545

546+
void propagateInheritedProperty( const CSS::StyleSheetProperty& property );
547+
546548
/**
547549
* @brief Gets the padding in density-independent pixels (dp).
548550
*

src/eepp/graphics/text.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,12 +1760,15 @@ void Text::draw( const Float& X, const Float& Y, const Vector2f& scale, const Fl
17601760
if ( mFontStyleConfig.Style & Shadow ) {
17611761
std::vector<Color> colors;
17621762
Color shadowColor( getShadowColor() );
1763-
if ( getFillColor().a != 255 )
1763+
if ( getFillColor().a != 255 ) {
17641764
shadowColor.a =
17651765
(Uint8)( (Float)shadowColor.a * ( (Float)getFillColor().a / (Float)255 ) );
1766+
}
17661767
colors.assign( mColors.size(), shadowColor );
17671768
draw( X + mFontStyleConfig.ShadowOffset.x, Y + mFontStyleConfig.ShadowOffset.y, scale,
1768-
rotation, effect, rotationCenter, scaleCenter, colors, {}, Color::Transparent );
1769+
rotation, effect, rotationCenter, scaleCenter, colors,
1770+
mFontStyleConfig.OutlineThickness > 0 ? mOutlineColors : std::vector<Color>{},
1771+
Color::Transparent );
17691772
}
17701773

17711774
draw( X, Y, scale, rotation, effect, rotationCenter, scaleCenter, mColors, mOutlineColors,

src/eepp/ui/css/propertydefinition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const std::string& PropertyDefinition::getDefaultValue() const {
3030
return mDefaultValue;
3131
}
3232

33-
bool PropertyDefinition::getInherited() const {
33+
bool PropertyDefinition::isInherited() const {
3434
return mInherited;
3535
}
3636

src/eepp/ui/css/propertyspecification.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ PropertyDefinition& PropertySpecification::registerProperty( const std::string&
2222

2323
mProperties[propDef->getId()] = std::shared_ptr<PropertyDefinition>( propDef );
2424

25-
for ( auto& sep : {"-", "_"} ) {
25+
if ( inherited )
26+
mInheritableProperties.push_back( propDef->getPropertyId() );
27+
28+
for ( auto& sep : { "-", "_" } ) {
2629
if ( propDef->getName().find( sep ) != std::string::npos ) {
2730
std::string alias( propDef->getName() );
2831
String::replaceAll( alias, sep, "" );
@@ -33,6 +36,10 @@ PropertyDefinition& PropertySpecification::registerProperty( const std::string&
3336
return *propDef;
3437
}
3538

39+
const SmallVector<PropertyId>& PropertySpecification::getInheritableProperties() const {
40+
return mInheritableProperties;
41+
}
42+
3643
const PropertyDefinition* PropertySpecification::getProperty( const Uint32& id ) const {
3744
auto it = mProperties.find( id );
3845

0 commit comments

Comments
 (0)