From c88ec38c1ee756f30350b1d8132edf89891f4bd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Sun, 6 Jan 2019 22:21:49 -0300 Subject: [PATCH] More WIP. --HG-- branch : dev --- bin/assets/layouts/test.css | 4 ++- src/eepp/ui/uistyle.cpp | 4 +-- src/eepp/ui/uiwidget.cpp | 55 ++++++++++++++++++++++--------------- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/bin/assets/layouts/test.css b/bin/assets/layouts/test.css index edcc288a3..31f31cee1 100644 --- a/bin/assets/layouts/test.css +++ b/bin/assets/layouts/test.css @@ -70,10 +70,12 @@ Tooltip { #tpad { scale: 1; rotation: 0; - transition: scale 0.25s, rotation 0.25s; + layout_margin: 0; + transition: scale 0.25s, rotation 0.25s 0.25s, layout_margin 0.25s; } #tpad:hover { scale: 1.1; rotation: 3; + layout_margin: 8dp 0 0 0; } diff --git a/src/eepp/ui/uistyle.cpp b/src/eepp/ui/uistyle.cpp index 6b94d0c27..8909b11db 100644 --- a/src/eepp/ui/uistyle.cpp +++ b/src/eepp/ui/uistyle.cpp @@ -78,7 +78,7 @@ bool UIStyle::hasTransition( const Uint32& state, const std::string& propertyNam // When transitions are declared without state are global if ( !ret && state != StateFlagNormal ) { - ret = mTransitions.find( StateFlagNormal ) != mTransitions.end() && mTransitions[ StateFlagNormal ].find( propertyName ) != mTransitions[ state ].end(); + ret = mTransitions.find( StateFlagNormal ) != mTransitions.end() && mTransitions[ StateFlagNormal ].find( propertyName ) != mTransitions[ StateFlagNormal ].end(); } return ret; @@ -93,7 +93,7 @@ UIStyle::TransitionInfo UIStyle::getTransition( const Uint32& state, const std:: } else if ( mTransitions.find( StateFlagNormal ) != mTransitions.end() ) { propertyTransitionIt = mTransitions[ StateFlagNormal ].find( propertyName ); - if ( propertyTransitionIt != mTransitions[ state ].end() ) { + if ( propertyTransitionIt != mTransitions[ StateFlagNormal ].end() ) { return propertyTransitionIt->second; } } diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index 846ef0901..cac5dab71 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -688,16 +688,31 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state } } } - } else if ( "layout_margin" == name ) { - setLayoutMargin( attribute.asRect() ); - } else if ( "layout_marginleft" == name ) { - setLayoutMargin( Rect( attribute.asDpDimensionI(), mLayoutMargin.Top, mLayoutMargin.Right, mLayoutMargin.Bottom ) ); - } else if ( "layout_marginright" == name ) { - setLayoutMargin( Rect( mLayoutMargin.Left, mLayoutMargin.Top, attribute.asDpDimensionI(), mLayoutMargin.Bottom ) ); - } else if ( "layout_margintop" == name ) { - setLayoutMargin( Rect( mLayoutMargin.Left, attribute.asDpDimensionI(), mLayoutMargin.Right, mLayoutMargin.Bottom ) ); - } else if ( "layout_marginbottom" == name ) { - setLayoutMargin( Rect( mLayoutMargin.Left, mLayoutMargin.Top, mLayoutMargin.Right, attribute.asDpDimensionI() ) ); + } else if ( String::startsWith( name, "layout_margin" ) ) { + Rect margin; + + if ( "layout_margin" == name ) + margin = attribute.asRect(); + else if ( "layout_marginleft" == name ) + margin = Rect( attribute.asDpDimensionI(), mLayoutMargin.Top, mLayoutMargin.Right, mLayoutMargin.Bottom ); + else if ( "layout_marginright" == name ) + margin = Rect( mLayoutMargin.Left, mLayoutMargin.Top, attribute.asDpDimensionI(), mLayoutMargin.Bottom ); + else if ( "layout_margintop" == name ) + margin = Rect( mLayoutMargin.Left, attribute.asDpDimensionI(), mLayoutMargin.Right, mLayoutMargin.Bottom ); + else if ( "layout_marginbottom" == name ) + margin = Rect( mLayoutMargin.Left, mLayoutMargin.Top, mLayoutMargin.Right, attribute.asDpDimensionI() ); + + if ( NULL != mStyle && mStyle->hasTransition( state, attribute.getName() ) ) { + UIStyle::TransitionInfo transitionInfo( mStyle->getTransition( state, attribute.getName() ) ); + Action * action = Actions::MarginMove::New( mLayoutMargin, margin, transitionInfo.duration, transitionInfo.timingFunction ); + + if ( Time::Zero != transitionInfo.delay ) + action = Actions::Sequence::New( Actions::Delay::New( transitionInfo.delay ), action ); + + runAction( action ); + } else { + setLayoutMargin( margin ); + } } else if ( "tooltip" == name ) { setTooltipText( attribute.asString() ); } else if ( "layout_weight" == name ) { @@ -791,14 +806,12 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state if ( NULL != mStyle && mStyle->hasTransition( state, attribute.getName() ) ) { UIStyle::TransitionInfo transitionInfo( mStyle->getTransition( state, attribute.getName() ) ); Float newRotation( mStyle->getAttribute( state, { attribute.getName() } ).asFloat() ); - Action * action = NULL; + Action * action = Actions::Rotate::New( mRotation, newRotation, transitionInfo.duration, transitionInfo.timingFunction ); - if ( Time::Zero == transitionInfo.delay ) { - action = Actions::Rotate::New( mRotation, newRotation, transitionInfo.duration, transitionInfo.timingFunction ); - } + if ( Time::Zero != transitionInfo.delay ) + action = Actions::Sequence::New( Actions::Delay::New( transitionInfo.delay ), action ); - if ( NULL != action ) - runAction( action ); + runAction( action ); } else { setRotation( attribute.asFloat() ); } @@ -806,14 +819,12 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state if ( NULL != mStyle && mStyle->hasTransition( state, attribute.getName() ) ) { UIStyle::TransitionInfo transitionInfo( mStyle->getTransition( state, attribute.getName() ) ); Vector2f newScale( mStyle->getAttribute( state, { attribute.getName() } ).asVector2f() ); - Action * action = NULL; + Action * action = Actions::Scale::New( mScale, newScale, transitionInfo.duration, transitionInfo.timingFunction ); - if ( Time::Zero == transitionInfo.delay ) { - action = Actions::Scale::New( mScale, newScale, transitionInfo.duration, transitionInfo.timingFunction ); - } + if ( Time::Zero != transitionInfo.delay ) + action = Actions::Sequence::New( Actions::Delay::New( transitionInfo.delay ), action ); - if ( NULL != action ) - runAction( action ); + runAction( action ); } else { setScale( attribute.asVector2f() ); }