eepp: Minor fixes in widgets and added the at rule: @glyph-icon to register a glyph-icon from the CSS, in order to be able to consume unregistered glyph icons from a CSS file.

This commit is contained in:
Martín Lucas Golini
2023-04-12 18:28:13 -03:00
parent 7756ea7d03
commit a9d0715c8c
10 changed files with 60 additions and 9 deletions

View File

@@ -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 {

View File

@@ -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:

View File

@@ -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 );

View File

@@ -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;
}

View File

@@ -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" );

View File

@@ -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;

View File

@@ -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 );
}

View File

@@ -92,6 +92,8 @@ void UIListBoxItem::select() {
LBParent->onSelected();
} else {
popState( UIState::StateSelected );
mNodeFlags &= ~NODE_FLAG_SELECTED;
LBParent->mSelected.remove( LBParent->getItemIndex( this ) );

View File

@@ -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();
}

View File

@@ -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<FontTrueType*>( fontSearch ), codePoint ) );
}
}
}
void UISceneNode::loadFontFaces( const StyleSheetStyleVector& styles ) {