Fix a bug when changing themes (some properties where not updated due to cached properties).

Fix a bug when displaying sub-menus, it was sometimes incorrectly positioned.
This commit is contained in:
Martín Lucas Golini
2025-04-20 12:41:36 -03:00
parent 53aba9d887
commit 5f9d2bd5ea
13 changed files with 77 additions and 28 deletions

View File

@@ -35,7 +35,8 @@ class EE_API StyleSheetProperty {
StyleSheetProperty();
explicit StyleSheetProperty( const PropertyDefinition* definition, const std::string& value,
const Uint32& index = 0, bool trimValue = true );
const Uint32& index = 0, bool trimValue = true,
bool cachedProperty = false );
explicit StyleSheetProperty( const std::string& name, const std::string& value,
const bool& trimValue = true, const Uint32& specificity = 0,
@@ -177,6 +178,10 @@ class EE_API StyleSheetProperty {
const std::vector<VariableFunctionCache>& getVarCache() const;
StyleSheetProperty& setCachedProperty( bool cached );
bool isCachedProperty() const;
protected:
std::string mName;
String::HashType mNameHash;
@@ -187,6 +192,7 @@ class EE_API StyleSheetProperty {
bool mVolatile;
bool mImportant;
bool mIsVarValue;
bool mCachedProperty{ false };
const PropertyDefinition* mPropertyDefinition;
const ShorthandDefinition* mShorthandDefinition;
std::vector<StyleSheetProperty> mIndexedProperty;

View File

@@ -39,6 +39,8 @@ class EE_API StyleSheetStyle {
void clearProperties();
void clearCachedProperties();
bool hasProperties() const;
bool hasProperty( PropertyId id ) const;

View File

@@ -157,7 +157,8 @@ class EE_API UISceneNode : public SceneNode {
void nodeToWorldTranslation( Vector2f& Pos ) const;
void reloadStyle( bool disableAnimations = false, bool forceReApplyProperties = false );
void reloadStyle( bool disableAnimations = false, bool forceReApplyProperties = false,
bool resetPropertiesCache = false );
bool hasThreadPool() const;

View File

@@ -77,6 +77,8 @@ class EE_API UIStyle : public UIState {
void resetGlobalDefinition();
void resetCachedProperties();
protected:
UIWidget* mWidget;
std::shared_ptr<CSS::StyleSheetStyle> mElementStyle;

View File

@@ -197,9 +197,9 @@ class EE_API UIWidget : public UINode {
UIStyle* getUIStyle() const;
void reloadStyle( const bool& reloadChilds = true, const bool& disableAnimations = false,
const bool& reportStateChange = true,
const bool& forceReApplyProperties = false );
void reloadStyle( bool reloadChilds = true, bool disableAnimations = false,
bool reportStateChange = true, bool forceReApplyProperties = false,
bool resetPropertyCache = false );
void beginAttributesTransaction();

View File

@@ -18,7 +18,7 @@ StyleSheetProperty::StyleSheetProperty() :
StyleSheetProperty::StyleSheetProperty( const PropertyDefinition* definition,
const std::string& value, const Uint32& index,
bool trimValue ) :
bool trimValue, bool cachedProperty ) :
mName( definition->getName() ),
mNameHash( definition->getId() ),
mValue( trimValue ? String::trim( value ) : value ),
@@ -28,6 +28,7 @@ StyleSheetProperty::StyleSheetProperty( const PropertyDefinition* definition,
mVolatile( false ),
mImportant( false ),
mIsVarValue( false ),
mCachedProperty( cachedProperty ),
mPropertyDefinition( definition ),
mShorthandDefinition( NULL ) {
if ( trimValue )
@@ -406,17 +407,14 @@ Vector2f StyleSheetProperty::asVector2f( const Vector2f& defaultValue ) const {
if ( xySplit.size() == 2 ) {
Float val;
vector.x =
String::fromString( val, String::trim( xySplit[0] ) ) ? val : defaultValue.x;
vector.y =
String::fromString( val, String::trim( xySplit[1] ) ) ? val : defaultValue.y;
vector.x = String::fromString( val, String::trim( xySplit[0] ) ) ? val : defaultValue.x;
vector.y = String::fromString( val, String::trim( xySplit[1] ) ) ? val : defaultValue.y;
return vector;
} else if ( xySplit.size() == 1 ) {
Float val;
vector.x = vector.y =
String::fromString( val, xySplit[0] ) ? val : defaultValue.x;
vector.x = vector.y = String::fromString( val, xySplit[0] ) ? val : defaultValue.x;
return vector;
}
@@ -433,10 +431,8 @@ Vector2i StyleSheetProperty::asVector2i( const Vector2i& defaultValue ) const {
if ( xySplit.size() == 2 ) {
int val;
vector.x =
String::fromString( val, String::trim( xySplit[0] ) ) ? val : defaultValue.x;
vector.y =
String::fromString( val, String::trim( xySplit[1] ) ) ? val : defaultValue.y;
vector.x = String::fromString( val, String::trim( xySplit[0] ) ) ? val : defaultValue.x;
vector.y = String::fromString( val, String::trim( xySplit[1] ) ) ? val : defaultValue.y;
return vector;
} else if ( xySplit.size() == 1 ) {
@@ -669,4 +665,13 @@ const std::vector<VariableFunctionCache>& StyleSheetProperty::getVarCache() cons
return mVarCache;
}
StyleSheetProperty& StyleSheetProperty::setCachedProperty( bool cached ) {
mCachedProperty = cached;
return *this;
}
bool StyleSheetProperty::isCachedProperty() const {
return mCachedProperty;
}
}}} // namespace EE::UI::CSS

View File

@@ -145,6 +145,17 @@ void StyleSheetStyle::clearProperties() {
mProperties.clear();
}
void StyleSheetStyle::clearCachedProperties() {
StyleSheetProperties::iterator it;
do {
it = std::find_if(
mProperties.begin(), mProperties.end(),
[]( const auto& model ) { return model.second.isCachedProperty(); } );
if ( it != mProperties.end() )
mProperties.erase( it );
} while ( it != mProperties.end() );
}
bool StyleSheetStyle::hasProperties() const {
return !mProperties.empty();
}

View File

@@ -768,6 +768,14 @@ void UIMenu::findBestMenuPos( Vector2f& pos, UIWidget* menu, UIMenu* parent,
pos.x = 0;
if ( pos.y < 0 )
pos.y = 0;
qPos.Left = qParent.Right;
qPos.Top = pos.y;
qPos.Right = qPos.Left + menu->getPixelsSize().getWidth();
qPos.Bottom = qPos.Top + menu->getPixelsSize().getHeight();
if ( qScreen.contains( qPos ) && ( !clipMenu || !qPrevMenu.overlap( qPos ) ) ) {
pos.x = qPos.Left;
}
}
}
}

View File

@@ -396,14 +396,15 @@ bool UISceneNode::hasStyleSheet() {
return !mStyleSheet.isEmpty();
}
void UISceneNode::reloadStyle( bool disableAnimations, bool forceReApplyProperties ) {
void UISceneNode::reloadStyle( bool disableAnimations, bool forceReApplyProperties,
bool resetPropertiesCache ) {
if ( NULL != mChild ) {
Node* child = mChild;
while ( NULL != child ) {
if ( child->isWidget() ) {
child->asType<UIWidget>()->reloadStyle( true, disableAnimations, true,
forceReApplyProperties );
child->asType<UIWidget>()->reloadStyle(
true, disableAnimations, true, forceReApplyProperties, resetPropertiesCache );
}
child = child->getNextNode();

View File

@@ -68,6 +68,10 @@ void UIStyle::resetGlobalDefinition() {
mLoadedVersion = stylesheet.getVersion();
}
void UIStyle::resetCachedProperties() {
mElementStyle->clearCachedProperties();
}
void UIStyle::load() {
removeStructurallyVolatileWidgetFromParent();
@@ -423,8 +427,8 @@ void UIStyle::applyStyleSheetProperty( const StyleSheetProperty& property,
std::string value(
mWidget->getPropertyString( propertyDefinition, property.getIndex() ) );
if ( !value.empty() ) {
setStyleSheetProperty(
StyleSheetProperty( propertyDefinition, value, property.getIndex() ) );
setStyleSheetProperty( StyleSheetProperty( propertyDefinition, value,
property.getIndex(), true, true ) );
}
}
}

View File

@@ -568,7 +568,8 @@ void UIWidget::notifyLayoutAttrChange() {
}
void UIWidget::notifyLayoutAttrChangeParent() {
if ( NULL == mParentNode ) return;
if ( NULL == mParentNode )
return;
if ( 0 == mAttributesTransactionCount ) {
NodeMessage msg( this, NodeMessage::LayoutAttributeChange );
@@ -1100,8 +1101,8 @@ UIStyle* UIWidget::getUIStyle() const {
return mStyle;
}
void UIWidget::reloadStyle( const bool& reloadChilds, const bool& disableAnimations,
const bool& reportStateChange, const bool& forceReApplyProperties ) {
void UIWidget::reloadStyle( bool reloadChilds, bool disableAnimations, bool reportStateChange,
bool forceReApplyProperties, bool resetPropertyCache ) {
createStyle();
if ( NULL == mStyle )
@@ -1109,13 +1110,17 @@ void UIWidget::reloadStyle( const bool& reloadChilds, const bool& disableAnimati
mStyle->load();
if ( resetPropertyCache )
mStyle->resetCachedProperties();
if ( NULL != getFirstChild() && reloadChilds ) {
Node* child = getFirstChild();
while ( NULL != child ) {
if ( child->isWidget() )
child->asType<UIWidget>()->reloadStyle( reloadChilds, disableAnimations,
reportStateChange, forceReApplyProperties );
reportStateChange, forceReApplyProperties,
resetPropertyCache );
child = child->getNextNode();
}

View File

@@ -1669,7 +1669,7 @@ void App::setTheme( const std::string& path ) {
mTheme = theme;
mUISceneNode->reloadStyle( true, true );
mUISceneNode->reloadStyle( true, true, true );
if ( !firstFrame )
mPluginManager->setUIThemeReloaded();

View File

@@ -233,9 +233,11 @@ UIMenu* SettingsMenu::createFileTypeMenu( bool emptyMenu ) {
mSplitter->getCurEditor()->getSyntaxDefinition().getLanguageName() == name );
if ( mFileTypeMenues.size() == 1 && menu->getCount() == 1 ) {
auto menuBar = mUISceneNode->findByType( UI_TYPE_MENUBAR );
menu->reloadStyle( true, true );
Float height = menu->getPixelsSize().getHeight();
Float tHeight = mUISceneNode->getPixelsSize().getHeight();
Float tHeight = mUISceneNode->getPixelsSize().getHeight() -
( menuBar ? menuBar->getPixelsSize().getHeight() : 0 );
maxItems = (int)eeceil( tHeight / height ) - 2;
}
@@ -276,9 +278,11 @@ UIMenu* SettingsMenu::createColorSchemeMenu( bool emptyMenu ) {
mSplitter->getCurrentColorSchemeName() == colorScheme.first );
if ( mColorSchemeMenues.size() == 1 && menu->getCount() == 1 ) {
auto menuBar = mUISceneNode->findByType( UI_TYPE_MENUBAR );
menu->reloadStyle( true, true );
Float height = menu->getPixelsSize().getHeight();
Float tHeight = mUISceneNode->getPixelsSize().getHeight();
Float tHeight = mUISceneNode->getPixelsSize().getHeight() -
( menuBar ? menuBar->getPixelsSize().getHeight() : 0 );
maxItems = (int)eeceil( tHeight / height ) - 2;
}