mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-30 18:16:31 +03:00
Initial support for non-cacheable CSS styles.
Some minor colors refactor. Some minor bug fixes. --HG-- branch : dev-css
This commit is contained in:
@@ -151,23 +151,65 @@ Tooltip {
|
||||
skinColor: #66ff44;
|
||||
}
|
||||
|
||||
|
||||
#rtest {
|
||||
#test_2 > #rtest {
|
||||
padding: 8dp;
|
||||
background: #221122;
|
||||
}
|
||||
|
||||
#rtest #rttv {
|
||||
background:#333;
|
||||
#test_2 > #rtest #rttv {
|
||||
background: #333;
|
||||
textSize: 24dp;
|
||||
borderRadius: 8;
|
||||
padding: 8dp;
|
||||
transition: all 0.125s;
|
||||
}
|
||||
|
||||
#rtest #rttv:hover {
|
||||
background:#666;
|
||||
#test_2 > #rtest #rttv:hover {
|
||||
background: #666;
|
||||
}
|
||||
|
||||
#test_2 > #rtest:hover #rttv {
|
||||
background: #005522;
|
||||
}
|
||||
|
||||
#test_2 > #rtest:hover #rttv:hover {
|
||||
background: #008822;
|
||||
}
|
||||
|
||||
#test_2 > #rtest:hover #rttv:pressed {
|
||||
background: lime;
|
||||
textColor: #333;
|
||||
}
|
||||
|
||||
#rtest:hover #rttv {
|
||||
background:#005522;
|
||||
#test_3 {
|
||||
background: #221122;
|
||||
}
|
||||
|
||||
#test_3 > .rooter {
|
||||
background: red;
|
||||
}
|
||||
|
||||
#test_3 > .rooter .outer {
|
||||
background: blue;
|
||||
}
|
||||
|
||||
#test_3 > .rooter:hover .outer {
|
||||
background: green;
|
||||
}
|
||||
|
||||
#test_3 > .rooter:hover .outer:hover {
|
||||
background: yellow;
|
||||
}
|
||||
|
||||
#test_3 > .rooter .inner {
|
||||
background: #123456;
|
||||
}
|
||||
|
||||
#test_3 > .rooter:hover .outer:hover .inner {
|
||||
background: #DABA22;
|
||||
}
|
||||
|
||||
#test_3 > .rooter:hover .outer:hover .inner:hover {
|
||||
background: #CCC;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,8 +51,16 @@
|
||||
<TextView id="rttv" layout_width="wrap_content" layout_height="wrap_content" text="Hello World!" layout_gravity="center" />
|
||||
</RelativeLayout>
|
||||
</hbox>
|
||||
<hbox id="test_3" layout_width="match_parent" layout_height="match_parent">
|
||||
<RelativeLayout class="rooter" layout_width="300dp" layout_height="300dp">
|
||||
<RelativeLayout class="outer" layout_width="100dp" layout_height="100dp">
|
||||
<RelativeLayout class="inner" layout_width="50dp" layout_height="50dp"></RelativeLayout>
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
</hbox>
|
||||
|
||||
<Tab name="Padding Test" owns="test_1" />
|
||||
<Tab name="Tabs Test" owns="test_2" />
|
||||
<Tab name="Cascade Test" owns="test_3" />
|
||||
</TabWidget>
|
||||
</vbox>
|
||||
|
||||
@@ -21,13 +21,13 @@ class EE_API FontSprite : public Font {
|
||||
|
||||
~FontSprite();
|
||||
|
||||
bool loadFromFile(const std::string& filename, Color key = Color::Magenta, Uint32 firstChar = 32, int spacing = 0);
|
||||
bool loadFromFile(const std::string& filename, Color key = Color::Fuchsia, Uint32 firstChar = 32, int spacing = 0);
|
||||
|
||||
bool loadFromMemory(const void* data, std::size_t sizeInBytes, Color key = Color::Magenta, Uint32 firstChar = 32, int spacing = 0);
|
||||
bool loadFromMemory(const void* data, std::size_t sizeInBytes, Color key = Color::Fuchsia, Uint32 firstChar = 32, int spacing = 0);
|
||||
|
||||
bool loadFromStream( IOStream& stream, Color key = Color::Magenta, Uint32 firstChar = 32, int spacing = 0 );
|
||||
bool loadFromStream( IOStream& stream, Color key = Color::Fuchsia, Uint32 firstChar = 32, int spacing = 0 );
|
||||
|
||||
bool loadFromPack( Pack * pack, std::string filePackPath, Color key = Color::Magenta, Uint32 firstChar = 32, int spacing = 0 );
|
||||
bool loadFromPack( Pack * pack, std::string filePackPath, Color key = Color::Fuchsia, Uint32 firstChar = 32, int spacing = 0 );
|
||||
|
||||
const Font::Info& getInfo() const;
|
||||
|
||||
|
||||
@@ -241,22 +241,22 @@ class EE_API Color : public tColor<Uint8>
|
||||
static bool isColorString( std::string str );
|
||||
|
||||
static const Color Transparent;
|
||||
static const Color White;
|
||||
static const Color Black;
|
||||
static const Color Red;
|
||||
static const Color Green;
|
||||
static const Color Blue;
|
||||
static const Color Yellow;
|
||||
static const Color Cyan;
|
||||
static const Color Magenta;
|
||||
static const Color Silver;
|
||||
static const Color Gray;
|
||||
static const Color White;
|
||||
static const Color Maroon;
|
||||
static const Color Olive;
|
||||
static const Color OfficeGreen;
|
||||
static const Color Red;
|
||||
static const Color Purple;
|
||||
static const Color Teal;
|
||||
static const Color Fuchsia;
|
||||
static const Color Green;
|
||||
static const Color Lime;
|
||||
static const Color Olive;
|
||||
static const Color Yellow;
|
||||
static const Color Navy;
|
||||
static const Color Blue;
|
||||
static const Color Teal;
|
||||
static const Color Aqua;
|
||||
};
|
||||
|
||||
typedef Color ColorA;
|
||||
|
||||
@@ -27,6 +27,8 @@ class EE_API StyleSheetSelector {
|
||||
bool hasPseudoClass(const std::string& cls) const;
|
||||
|
||||
bool hasPseudoClasses() const;
|
||||
|
||||
std::vector<StyleSheetElement*> getRelatedElements( StyleSheetElement * element, const bool& applyPseudo = true ) const;
|
||||
protected:
|
||||
std::string mName;
|
||||
std::string mPseudoClass;
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <eepp/ui/css/stylesheetstyle.hpp>
|
||||
#include <eepp/graphics/fontstyleconfig.hpp>
|
||||
#include <eepp/math/ease.hpp>
|
||||
#include <set>
|
||||
#include <functional>
|
||||
|
||||
using namespace EE::Scene;
|
||||
|
||||
@@ -76,12 +78,26 @@ class EE_API UIStyle : public UIState {
|
||||
CSS::StyleSheetProperties mProperties;
|
||||
std::vector<CSS::StyleSheetProperty> mTransitionAttributes;
|
||||
TransitionsMap mTransitions;
|
||||
std::set<UIWidget*> mRelatedWidgets;
|
||||
std::set<UIWidget*> mSubscribedWidgets;
|
||||
|
||||
void tryApplyStyle( const CSS::StyleSheetStyle& style );
|
||||
|
||||
void updateState();
|
||||
|
||||
void parseTransitions();
|
||||
|
||||
void subscribeNonCacheableStyles();
|
||||
|
||||
void unsubscribeNonCacheableStyles();
|
||||
|
||||
void subscribeRelated( UIWidget * widget );
|
||||
|
||||
void unsubscribeRelated( UIWidget * widget );
|
||||
|
||||
void removeFromSubscribedWidgets( UIWidget * widget );
|
||||
|
||||
void removeRelatedWidgets();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -191,6 +191,8 @@ class EE_API UIWidget : public UINode, public CSS::StyleSheetElement {
|
||||
|
||||
virtual void onThemeLoaded();
|
||||
|
||||
virtual void onParentChange();
|
||||
|
||||
void updateAnchors( const Vector2f & SizeChange );
|
||||
|
||||
void alignAgainstLayout();
|
||||
|
||||
@@ -130,7 +130,7 @@ bool FontSprite::loadFromStream( IOStream& stream, Color key, Uint32 firstChar,
|
||||
xPosToRead = charSpacing;
|
||||
}
|
||||
|
||||
img.createMaskFromColor( Color::Magenta, 0 );
|
||||
img.createMaskFromColor( Color::Fuchsia, 0 );
|
||||
|
||||
Uint32 texId = TextureFactory::instance()->loadFromPixels( img.getPixelsPtr(), img.getWidth(), img.getHeight(), img.getChannels() );
|
||||
|
||||
|
||||
@@ -7,23 +7,25 @@
|
||||
|
||||
namespace EE { namespace System {
|
||||
|
||||
const Color Color::Transparent = Color(0,0,0,0);
|
||||
const Color Color::White = Color(255,255,255);
|
||||
const Color Color::Black = Color(0,0,0);
|
||||
const Color Color::Red = Color(255,0,0);
|
||||
const Color Color::Green = Color(0,255,0);
|
||||
const Color Color::Blue = Color(0,0,255);
|
||||
const Color Color::Yellow = Color(255,255,0);
|
||||
const Color Color::Cyan = Color(0,255,255);
|
||||
const Color Color::Magenta = Color(255,0,255);
|
||||
const Color Color::Silver = Color(192,0,192);
|
||||
const Color Color::Gray = Color(128,128,128);
|
||||
const Color Color::Maroon = Color(128,0,0);
|
||||
const Color Color::Olive = Color(128,128,0);
|
||||
const Color Color::OfficeGreen = Color(0,128,0);
|
||||
const Color Color::Purple = Color(128,0,128);
|
||||
const Color Color::Teal = Color(0,128,128);
|
||||
const Color Color::Navy = Color(0,0,128);
|
||||
// @TODO: Support all CSS3 color keywords.
|
||||
// Reference: https://www.w3.org/TR/2018/REC-css-color-3-20180619/
|
||||
const Color Color::Transparent = Color(0x00000000);
|
||||
const Color Color::Black = Color(0x000000FF);
|
||||
const Color Color::Silver = Color(0xC0C0C0FF);
|
||||
const Color Color::Gray = Color(0x808080FF);
|
||||
const Color Color::White = Color(0xFFFFFFFF);
|
||||
const Color Color::Maroon = Color(0x800000FF);
|
||||
const Color Color::Red = Color(0xFF0000FF);
|
||||
const Color Color::Purple = Color(0x800080FF);
|
||||
const Color Color::Fuchsia = Color(0xFF00FFFF);
|
||||
const Color Color::Green = Color(0x008000FF);
|
||||
const Color Color::Lime = Color(0x00FF00FF);
|
||||
const Color Color::Olive = Color(0x808000FF);
|
||||
const Color Color::Yellow = Color(0xFFFF00FF);
|
||||
const Color Color::Navy = Color(0x000080FF);
|
||||
const Color Color::Blue = Color(0x0000FFFF);
|
||||
const Color Color::Teal = Color(0x008080FF);
|
||||
const Color Color::Aqua = Color(0x00FFFFFF);
|
||||
|
||||
RGB::RGB() : tRGB<Uint8>()
|
||||
{
|
||||
@@ -303,22 +305,22 @@ Color Color::fromString( std::string str ) {
|
||||
} else if ( size >= 3 && isalpha( str[0] ) && isalpha( str[1] ) && isalpha( str[2] ) ) {
|
||||
String::toLowerInPlace( str );
|
||||
if ( "transparent" == str ) return Color::Transparent;
|
||||
else if ( "white" == str ) return Color::White;
|
||||
else if ( "black" == str ) return Color::Black;
|
||||
else if ( "red" == str ) return Color::Red;
|
||||
else if ( "green" == str ) return Color::Green;
|
||||
else if ( "blue" == str ) return Color::Blue;
|
||||
else if ( "yellow" == str ) return Color::Yellow;
|
||||
else if ( "cyan" == str ) return Color::Cyan;
|
||||
else if ( "magenta" == str ) return Color::Magenta;
|
||||
else if ( "silver" == str ) return Color::Silver;
|
||||
else if ( "gray" == str ) return Color::Gray;
|
||||
else if ( "white" == str ) return Color::White;
|
||||
else if ( "maroon" == str ) return Color::Maroon;
|
||||
else if ( "olive" == str ) return Color::Olive;
|
||||
else if ( "officegreen" == str ) return Color::OfficeGreen;
|
||||
else if ( "red" == str ) return Color::Red;
|
||||
else if ( "purple" == str ) return Color::Purple;
|
||||
else if ( "teal" == str ) return Color::Teal;
|
||||
else if ( "fuchsia" == str ) return Color::Fuchsia;
|
||||
else if ( "green" == str ) return Color::Green;
|
||||
else if ( "lime" == str ) return Color::Lime;
|
||||
else if ( "olive" == str ) return Color::Olive;
|
||||
else if ( "yellow" == str ) return Color::Yellow;
|
||||
else if ( "navy" == str ) return Color::Navy;
|
||||
else if ( "blue" == str ) return Color::Blue;
|
||||
else if ( "teal" == str ) return Color::Teal;
|
||||
else if ( "aqua" == str ) return Color::Aqua;
|
||||
}
|
||||
|
||||
if ( size < 6 ) {
|
||||
@@ -343,22 +345,22 @@ bool Color::isColorString( std::string str ) {
|
||||
|
||||
String::toLowerInPlace( str );
|
||||
if ( "transparent" == str ) return true;
|
||||
else if ( "white" == str ) return true;
|
||||
else if ( "black" == str ) return true;
|
||||
else if ( "red" == str ) return true;
|
||||
else if ( "green" == str ) return true;
|
||||
else if ( "blue" == str ) return true;
|
||||
else if ( "yellow" == str ) return true;
|
||||
else if ( "cyan" == str ) return true;
|
||||
else if ( "magenta" == str ) return true;
|
||||
else if ( "silver" == str ) return true;
|
||||
else if ( "gray" == str ) return true;
|
||||
else if ( "white" == str ) return true;
|
||||
else if ( "maroon" == str ) return true;
|
||||
else if ( "olive" == str ) return true;
|
||||
else if ( "officegreen" == str ) return true;
|
||||
else if ( "red" == str ) return true;
|
||||
else if ( "purple" == str ) return true;
|
||||
else if ( "teal" == str ) return true;
|
||||
else if ( "fuchsia" == str ) return true;
|
||||
else if ( "green" == str ) return true;
|
||||
else if ( "lime" == str ) return true;
|
||||
else if ( "olive" == str ) return true;
|
||||
else if ( "yellow" == str ) return true;
|
||||
else if ( "navy" == str ) return true;
|
||||
else if ( "blue" == str ) return true;
|
||||
else if ( "teal" == str ) return true;
|
||||
else if ( "aqua" == str ) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -206,4 +206,113 @@ bool StyleSheetSelector::select( StyleSheetElement * element, const bool& applyP
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<StyleSheetElement*> StyleSheetSelector::getRelatedElements( StyleSheetElement * element, const bool& applyPseudo ) const {
|
||||
static std::vector<StyleSheetElement*> EMPTY_ELEMENTS;
|
||||
std::vector<StyleSheetElement*> elements;
|
||||
if ( mSelectorRules.empty() )
|
||||
return elements;
|
||||
|
||||
StyleSheetElement * curElement = element;
|
||||
|
||||
for ( size_t i = 0; i < mSelectorRules.size(); i++ ) {
|
||||
const StyleSheetSelectorRule& selectorRule = mSelectorRules[i];
|
||||
|
||||
switch ( selectorRule.getPatternMatch() ) {
|
||||
case StyleSheetSelectorRule::ANY:
|
||||
{
|
||||
if ( !selectorRule.matches( curElement, applyPseudo ) )
|
||||
return EMPTY_ELEMENTS;
|
||||
|
||||
break; // continue evaluating
|
||||
}
|
||||
case StyleSheetSelectorRule::DESCENDANT:
|
||||
{
|
||||
bool foundDescendant = false;
|
||||
|
||||
curElement = curElement->getStyleSheetParentElement();
|
||||
|
||||
while ( NULL != curElement && !foundDescendant ) {
|
||||
if ( selectorRule.matches( curElement, applyPseudo ) ) {
|
||||
foundDescendant = true;
|
||||
} else {
|
||||
curElement = curElement->getStyleSheetParentElement();
|
||||
}
|
||||
}
|
||||
|
||||
if ( !foundDescendant )
|
||||
return EMPTY_ELEMENTS;
|
||||
|
||||
if ( 0 != i && ( selectorRule.hasPseudoClasses() || selectorRule.hasStructuralPseudoClasses() ) ) {
|
||||
elements.push_back( curElement );
|
||||
}
|
||||
|
||||
break; // continue evaluating
|
||||
}
|
||||
case StyleSheetSelectorRule::CHILD:
|
||||
{
|
||||
curElement = curElement->getStyleSheetParentElement();
|
||||
|
||||
if ( NULL == curElement || !selectorRule.matches( curElement, applyPseudo ) )
|
||||
return EMPTY_ELEMENTS;
|
||||
|
||||
if ( 0 != i && ( selectorRule.hasPseudoClasses() || selectorRule.hasStructuralPseudoClasses() ) ) {
|
||||
elements.push_back( curElement );
|
||||
}
|
||||
|
||||
break; // continue evaluating
|
||||
}
|
||||
case StyleSheetSelectorRule::DIRECT_SIBLING:
|
||||
{
|
||||
curElement = curElement->getStyleSheetPreviousSiblingElement();
|
||||
|
||||
if ( NULL == curElement || !selectorRule.matches( curElement, applyPseudo ) )
|
||||
return EMPTY_ELEMENTS;
|
||||
|
||||
if ( 0 != i && ( selectorRule.hasPseudoClasses() || selectorRule.hasStructuralPseudoClasses() ) ) {
|
||||
elements.push_back( curElement );
|
||||
}
|
||||
|
||||
break; // continue evaluating
|
||||
}
|
||||
case StyleSheetSelectorRule::SIBLING:
|
||||
{
|
||||
bool foundSibling = false;
|
||||
StyleSheetElement * prevSibling = curElement->getStyleSheetPreviousSiblingElement();
|
||||
StyleSheetElement * nextSibling = curElement->getStyleSheetNextSiblingElement();
|
||||
|
||||
while ( NULL != prevSibling && !foundSibling ) {
|
||||
if ( selectorRule.matches( prevSibling, applyPseudo ) ) {
|
||||
foundSibling = true;
|
||||
curElement = prevSibling;
|
||||
} else {
|
||||
prevSibling = prevSibling->getStyleSheetPreviousSiblingElement();
|
||||
}
|
||||
}
|
||||
|
||||
if ( !foundSibling ) {
|
||||
while ( NULL != nextSibling && !foundSibling ) {
|
||||
if ( selectorRule.matches( nextSibling, applyPseudo ) ) {
|
||||
foundSibling = true;
|
||||
curElement = nextSibling;
|
||||
} else {
|
||||
nextSibling = nextSibling->getStyleSheetNextSiblingElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !foundSibling )
|
||||
return EMPTY_ELEMENTS;
|
||||
|
||||
if ( 0 != i && ( selectorRule.hasPseudoClasses() || selectorRule.hasStructuralPseudoClasses() ) ) {
|
||||
elements.push_back( curElement );
|
||||
}
|
||||
|
||||
break; // continue evaluating
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return elements;
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
@@ -242,8 +242,8 @@ bool StyleSheetSelectorRule::matches( StyleSheetElement * element, const bool& a
|
||||
|
||||
if ( !mClasses.empty() && !element->getStyleSheetClasses().empty() ) {
|
||||
bool hasClasses = true;
|
||||
for ( auto cit = element->getStyleSheetClasses().begin(); cit != element->getStyleSheetClasses().end(); ++cit ) {
|
||||
if ( !hasClass( *cit ) ) {
|
||||
for ( const auto& cls : element->getStyleSheetClasses() ) {
|
||||
if ( !hasClass( cls ) ) {
|
||||
hasClasses = false;
|
||||
break;
|
||||
}
|
||||
@@ -259,8 +259,8 @@ bool StyleSheetSelectorRule::matches( StyleSheetElement * element, const bool& a
|
||||
bool hasPseudoClasses = false;
|
||||
const std::vector<std::string>& elPseudoClasses = element->getStyleSheetPseudoClasses();
|
||||
|
||||
for ( auto cit = elPseudoClasses.begin(); cit != elPseudoClasses.end(); ++cit ) {
|
||||
if ( hasPseudoClass( *cit ) ) {
|
||||
for ( const auto& cls : elPseudoClasses ) {
|
||||
if ( hasPseudoClass( cls ) ) {
|
||||
hasPseudoClasses = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,10 @@ UIStyle::UIStyle( UIWidget * widget ) :
|
||||
load();
|
||||
}
|
||||
|
||||
UIStyle::~UIStyle()
|
||||
{}
|
||||
UIStyle::~UIStyle() {
|
||||
removeRelatedWidgets();
|
||||
unsubscribeNonCacheableStyles();
|
||||
}
|
||||
|
||||
bool UIStyle::stateExists( const EE::Uint32& ) const {
|
||||
return true;
|
||||
@@ -44,6 +46,8 @@ void UIStyle::addStyleSheetProperty( const StyleSheetProperty& attribute ) {
|
||||
}
|
||||
|
||||
void UIStyle::load() {
|
||||
unsubscribeNonCacheableStyles();
|
||||
|
||||
mCacheableStyles.clear();
|
||||
mNoncacheableStyles.clear();
|
||||
|
||||
@@ -64,6 +68,8 @@ void UIStyle::load() {
|
||||
mNoncacheableStyles.push_back( style );
|
||||
}
|
||||
}
|
||||
|
||||
subscribeNonCacheableStyles();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,6 +98,14 @@ UIStyle::TransitionInfo UIStyle::getTransition( const std::string& propertyName
|
||||
return TransitionInfo();
|
||||
}
|
||||
|
||||
void UIStyle::subscribeRelated( UIWidget * widget ) {
|
||||
mRelatedWidgets.insert( widget );
|
||||
}
|
||||
|
||||
void UIStyle::unsubscribeRelated( UIWidget * widget ) {
|
||||
mRelatedWidgets.erase( widget );
|
||||
}
|
||||
|
||||
void UIStyle::tryApplyStyle( const StyleSheetStyle& style ) {
|
||||
if ( style.getSelector().select( mWidget ) ) {
|
||||
for ( const auto& prop : style.getProperties() ) {
|
||||
@@ -134,6 +148,12 @@ void UIStyle::onStateChange() {
|
||||
}
|
||||
|
||||
mWidget->endAttributesTransaction();
|
||||
|
||||
for ( auto& related : mRelatedWidgets ) {
|
||||
if ( NULL != related->getUIStyle() ) {
|
||||
related->getUIStyle()->onStateChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,6 +209,48 @@ void UIStyle::updateState() {
|
||||
onStateChange();
|
||||
}
|
||||
|
||||
void UIStyle::subscribeNonCacheableStyles() {
|
||||
for ( auto& style : mNoncacheableStyles ) {
|
||||
std::vector<CSS::StyleSheetElement*> elements = style.getSelector().getRelatedElements( mWidget, false );
|
||||
|
||||
if ( !elements.empty() ) {
|
||||
for ( auto& element : elements ) {
|
||||
UIWidget * widget = dynamic_cast<UIWidget*>( element );
|
||||
|
||||
if ( NULL != widget && NULL != widget->getUIStyle() ) {
|
||||
widget->getUIStyle()->subscribeRelated( mWidget );
|
||||
|
||||
mSubscribedWidgets.insert( widget );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UIStyle::unsubscribeNonCacheableStyles() {
|
||||
for ( auto& widget : mSubscribedWidgets ) {
|
||||
if ( NULL != widget->getUIStyle() ) {
|
||||
widget->getUIStyle()->unsubscribeRelated( mWidget );
|
||||
}
|
||||
}
|
||||
|
||||
mSubscribedWidgets.clear();
|
||||
}
|
||||
|
||||
void UIStyle::removeFromSubscribedWidgets( UIWidget * widget ) {
|
||||
mSubscribedWidgets.erase( widget );
|
||||
}
|
||||
|
||||
void UIStyle::removeRelatedWidgets() {
|
||||
for ( auto& widget : mRelatedWidgets ) {
|
||||
if ( NULL != widget->getUIStyle() ) {
|
||||
widget->getUIStyle()->removeFromSubscribedWidgets( mWidget );
|
||||
}
|
||||
}
|
||||
|
||||
mRelatedWidgets.clear();
|
||||
}
|
||||
|
||||
void UIStyle::parseTransitions() {
|
||||
std::vector<std::string> properties;
|
||||
std::vector<Time> durations;
|
||||
|
||||
@@ -24,7 +24,7 @@ UIWidget::UIWidget( const std::string & tag ) :
|
||||
UINode(),
|
||||
mTag( tag ),
|
||||
mTheme( NULL ),
|
||||
mStyle( UIStyle::New( this ) ),
|
||||
mStyle( NULL ),
|
||||
mTooltip( NULL ),
|
||||
mMinControlSize(),
|
||||
mLayoutWeight(0),
|
||||
@@ -312,7 +312,7 @@ Node * UIWidget::setSize( const Float& Width, const Float& Height ) {
|
||||
Node * UIWidget::setId( const std::string& id ) {
|
||||
Node::setId( id );
|
||||
|
||||
reloadStyle( false );
|
||||
reloadStyle( true );
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -510,7 +510,7 @@ void UIWidget::addClass( const std::string& cls ) {
|
||||
if ( !cls.empty() && !containsClass( cls ) ) {
|
||||
mClasses.push_back( cls );
|
||||
|
||||
reloadStyle( false );
|
||||
reloadStyle( true );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -524,7 +524,7 @@ void UIWidget::addClasses( const std::vector<std::string>& classes ) {
|
||||
}
|
||||
}
|
||||
|
||||
reloadStyle( false );
|
||||
reloadStyle( true );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -532,7 +532,7 @@ void UIWidget::removeClass( const std::string& cls ) {
|
||||
if ( containsClass( cls ) ) {
|
||||
mClasses.erase( std::find( mClasses.begin(), mClasses.end(), cls ) );
|
||||
|
||||
reloadStyle( false );
|
||||
reloadStyle( true );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,7 +544,7 @@ void UIWidget::setElementTag( const std::string& tag ) {
|
||||
if ( mTag != tag ) {
|
||||
mTag = tag;
|
||||
|
||||
reloadStyle( false );
|
||||
reloadStyle( true );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,7 +611,7 @@ void UIWidget::reloadStyle( const bool& reloadChilds ) {
|
||||
|
||||
while ( NULL != ChildLoop ) {
|
||||
if ( ChildLoop->isWidget() )
|
||||
static_cast<UIWidget*>( ChildLoop )->reloadStyle();
|
||||
static_cast<UIWidget*>( ChildLoop )->reloadStyle( reloadChilds );
|
||||
|
||||
ChildLoop = ChildLoop->getNextNode();
|
||||
}
|
||||
@@ -627,6 +627,10 @@ void UIWidget::onThemeLoaded() {
|
||||
reportStyleStateChange();
|
||||
}
|
||||
|
||||
void UIWidget::onParentChange() {
|
||||
reloadStyle( true );
|
||||
}
|
||||
|
||||
void UIWidget::beginAttributesTransaction() {
|
||||
mAttributesTransactionCount++;
|
||||
}
|
||||
@@ -750,7 +754,7 @@ bool UIWidget::setAttribute( const NodeAttribute& attribute, const Uint32& state
|
||||
} else if ( "background" == name ) {
|
||||
Drawable * res = NULL;
|
||||
|
||||
if ( String::startsWith( attribute.getValue(), "#" ) ) {
|
||||
if ( Color::isColorString( attribute.getValue() ) ) {
|
||||
setAttribute( NodeAttribute( "backgroundcolor", attribute.getValue() ) );
|
||||
} else if ( NULL != ( res = DrawableSearcher::searchByName( attribute.getValue() ) ) ) {
|
||||
setBackgroundDrawable( res, res->getDrawableType() == Drawable::SPRITE );
|
||||
|
||||
@@ -94,7 +94,7 @@ EE_MAIN_FUNC int main (int argc, char * argv []) {
|
||||
text4.setFillColor( Color::Black );
|
||||
|
||||
fontSprite = FontSprite::New( "alagard" ); // Alagard - Hewett Tsoi ( https://www.dafont.com/alagard.font )
|
||||
fontSprite->loadFromFile( "assets/fonts/custom_alagard.png", Color::Magenta, 32, -4 );
|
||||
fontSprite->loadFromFile( "assets/fonts/custom_alagard.png", Color::Fuchsia, 32, -4 );
|
||||
|
||||
text5.setFont( fontSprite );
|
||||
text5.setString( "Lorem ipsum dolor sit amet, consectetur adipisicing elit." );
|
||||
|
||||
@@ -1394,7 +1394,7 @@ void EETest::screen2() {
|
||||
polygon.rotate( ang , polygon.getBounds().getCenter() );
|
||||
shape.setPolygon( polygon );
|
||||
shape.setPosition( Vector2f( 150, 150 ));
|
||||
shape.setColor( Color::Magenta );
|
||||
shape.setColor( Color::Fuchsia );
|
||||
shape.setAlpha( 100 );
|
||||
shape.draw();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user