diff --git a/include/eepp/ui/css/propertydefinition.hpp b/include/eepp/ui/css/propertydefinition.hpp index 00880c69f..ef54837ef 100644 --- a/include/eepp/ui/css/propertydefinition.hpp +++ b/include/eepp/ui/css/propertydefinition.hpp @@ -212,6 +212,8 @@ enum class PropertyId : Uint32 { Href = String::hash( "href" ), Focusable = String::hash( "focusable" ), InnerWidgetOrientation = String::hash( "inner-widget-orientation" ), + Glyph = String::hash( "glyph" ), + Name = String::hash( "name" ), }; enum class PropertyType : Uint32 { diff --git a/include/eepp/ui/css/stylesheetstyle.hpp b/include/eepp/ui/css/stylesheetstyle.hpp index d0aaffcab..a72d768d2 100644 --- a/include/eepp/ui/css/stylesheetstyle.hpp +++ b/include/eepp/ui/css/stylesheetstyle.hpp @@ -9,7 +9,7 @@ namespace EE { namespace UI { namespace CSS { -enum class AtRuleType : Uint32 { None, FontFace }; +enum class AtRuleType : Uint32 { None, FontFace, GlyphIcon }; class EE_API StyleSheetStyle { public: diff --git a/include/eepp/ui/uiscenenode.hpp b/include/eepp/ui/uiscenenode.hpp index d99d1ad55..3ce1697d8 100644 --- a/include/eepp/ui/uiscenenode.hpp +++ b/include/eepp/ui/uiscenenode.hpp @@ -227,6 +227,8 @@ class EE_API UISceneNode : public SceneNode { void loadFontFaces( const CSS::StyleSheetStyleVector& styles ); + void loadGlyphIcon( const CSS::StyleSheetStyleVector& styles ); + virtual Uint32 onKeyDown( const KeyEvent& event ); void onWidgetDelete( Node* node ); diff --git a/src/eepp/ui/css/stylesheet.cpp b/src/eepp/ui/css/stylesheet.cpp index 18dbef9e7..3b041ae5e 100644 --- a/src/eepp/ui/css/stylesheet.cpp +++ b/src/eepp/ui/css/stylesheet.cpp @@ -288,13 +288,9 @@ void StyleSheet::addMediaQueryList( MediaQueryList::ptr list ) { StyleSheetStyleVector StyleSheet::getStyleSheetStyleByAtRule( const AtRuleType& atRuleType ) const { StyleSheetStyleVector vector; - - for ( auto& node : mNodes ) { - if ( node->getAtRuleType() == atRuleType ) { + for ( auto& node : mNodes ) + if ( node->getAtRuleType() == atRuleType ) vector.push_back( node.get() ); - } - } - return vector; } diff --git a/src/eepp/ui/css/stylesheetspecification.cpp b/src/eepp/ui/css/stylesheetspecification.cpp index a7856edbb..be1e3b8f7 100644 --- a/src/eepp/ui/css/stylesheetspecification.cpp +++ b/src/eepp/ui/css/stylesheetspecification.cpp @@ -400,6 +400,9 @@ void StyleSheetSpecification::registerDefaultProperties() { registerProperty( "inner-widget-orientation", "widgeticontextbox" ) .setType( PropertyType::String ); + registerProperty( "glyph", "" ).setType( PropertyType::String ); + registerProperty( "name", "" ).setType( PropertyType::String ); + // Shorthands registerShorthand( "margin", { "margin-top", "margin-right", "margin-bottom", "margin-left" }, "box" ); diff --git a/src/eepp/ui/css/stylesheetstyle.cpp b/src/eepp/ui/css/stylesheetstyle.cpp index 5a10f9ea1..6c66cf7b9 100644 --- a/src/eepp/ui/css/stylesheetstyle.cpp +++ b/src/eepp/ui/css/stylesheetstyle.cpp @@ -203,6 +203,8 @@ void StyleSheetStyle::setMarker( const Uint32& marker ) { AtRuleType StyleSheetStyle::checkAtRule() { if ( mSelector.getName() == "@font-face" ) { return AtRuleType::FontFace; + } else if ( mSelector.getName() == "@glyph-icon" ) { + return AtRuleType::GlyphIcon; } return AtRuleType::None; diff --git a/src/eepp/ui/uicheckbox.cpp b/src/eepp/ui/uicheckbox.cpp index 8e2c77b3f..07e324614 100644 --- a/src/eepp/ui/uicheckbox.cpp +++ b/src/eepp/ui/uicheckbox.cpp @@ -251,6 +251,9 @@ bool UICheckBox::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::Value: setChecked( attribute.asBool() ); break; + case PropertyId::Tooltip: + if ( mActiveButton ) + mActiveButton->applyProperty( attribute ); default: return UITextView::applyProperty( attribute ); } diff --git a/src/eepp/ui/uilistboxitem.cpp b/src/eepp/ui/uilistboxitem.cpp index ac1253b5e..5f5b3686c 100644 --- a/src/eepp/ui/uilistboxitem.cpp +++ b/src/eepp/ui/uilistboxitem.cpp @@ -92,6 +92,8 @@ void UIListBoxItem::select() { LBParent->onSelected(); } else { + popState( UIState::StateSelected ); + mNodeFlags &= ~NODE_FLAG_SELECTED; LBParent->mSelected.remove( LBParent->getItemIndex( this ) ); diff --git a/src/eepp/ui/uipushbutton.cpp b/src/eepp/ui/uipushbutton.cpp index c98e5bd20..324bedadd 100644 --- a/src/eepp/ui/uipushbutton.cpp +++ b/src/eepp/ui/uipushbutton.cpp @@ -350,8 +350,10 @@ void UIPushButton::onThemeLoaded() { } void UIPushButton::updateTextBox() { - if ( mTextBox->isVisible() != ( !getText().empty() && !mTextAsFallback ) ) { - mTextBox->setVisible( !getText().empty() && !mTextAsFallback ); + bool mustBeVisible = ( !getText().empty() && !mTextAsFallback ) || + ( nullptr == mIcon || nullptr == mIcon->getDrawable() ); + if ( mTextBox->isVisible() != mustBeVisible ) { + mTextBox->setVisible( mustBeVisible ); onAutoSize(); updateLayout(); } diff --git a/src/eepp/ui/uiscenenode.cpp b/src/eepp/ui/uiscenenode.cpp index 0e0a0390e..108f164c3 100644 --- a/src/eepp/ui/uiscenenode.cpp +++ b/src/eepp/ui/uiscenenode.cpp @@ -873,6 +873,45 @@ void UISceneNode::onSizeChange() { void UISceneNode::processStyleSheetAtRules( const StyleSheet& styleSheet ) { loadFontFaces( styleSheet.getStyleSheetStyleByAtRule( AtRuleType::FontFace ) ); + loadGlyphIcon( styleSheet.getStyleSheetStyleByAtRule( AtRuleType::GlyphIcon ) ); +} + +void UISceneNode::loadGlyphIcon( const StyleSheetStyleVector& styles ) { + for ( auto& style : styles ) { + auto family = style->getPropertyById( PropertyId::FontFamily ); + auto name = style->getPropertyById( PropertyId::Name ); + auto glyph = style->getPropertyById( PropertyId::Glyph ); + if ( name == nullptr || family == nullptr || glyph == nullptr ) + return; + CSS::StyleSheetProperty familyProp( *family ); + CSS::StyleSheetProperty nameProp( *name ); + CSS::StyleSheetProperty glyphProp( *glyph ); + + if ( !familyProp.isEmpty() && !nameProp.isEmpty() && !glyphProp.isEmpty() ) { + Font* fontSearch = FontManager::instance()->getByName( familyProp.getValue() ); + + if ( nullptr == fontSearch ) + continue; + + if ( nullptr == getUIIconThemeManager()->getCurrentTheme() || + fontSearch->getType() != FontType::TTF ) + break; + + Uint32 codePoint = 0; + std::string buffer( glyphProp.asString() ); + Uint32 value; + if ( String::startsWith( buffer, "0x" ) ) { + if ( String::fromString( value, buffer, std::hex ) ) + codePoint = value; + } else if ( String::fromString( value, buffer ) ) { + codePoint = value; + } + + if ( codePoint ) + getUIIconThemeManager()->getCurrentTheme()->add( UIGlyphIcon::New( + nameProp.asString(), static_cast( fontSearch ), codePoint ) ); + } + } } void UISceneNode::loadFontFaces( const StyleSheetStyleVector& styles ) {