eepp: Improvements and fixes to the StackLayout.

This commit is contained in:
Martín Lucas Golini
2023-05-27 00:25:36 -03:00
parent 947648944f
commit f2c30909a8
4 changed files with 70 additions and 20 deletions

View File

@@ -214,6 +214,7 @@ enum class PropertyId : Uint32 {
InnerWidgetOrientation = String::hash( "inner-widget-orientation" ),
Glyph = String::hash( "glyph" ),
Name = String::hash( "name" ),
RowValign = String::hash( "row-valign" ),
};
enum class PropertyType : Uint32 {

View File

@@ -7,6 +7,8 @@ namespace EE { namespace UI {
class EE_API UIStackLayout : public UILayout {
public:
enum class RowValign { Top, Center, Bottom };
static UIStackLayout* New();
static UIStackLayout* NewWithTag( const std::string& tag = "stacklayout" );
@@ -24,15 +26,24 @@ class EE_API UIStackLayout : public UILayout {
void updateLayout();
protected:
UIStackLayout();
const RowValign& getRowValign() const;
virtual Uint32 onMessage( const NodeMessage* Msg );
void setRowValign( const RowValign& rowValign );
protected:
RowValign mRowValign{ RowValign::Bottom };
UIStackLayout();
explicit UIStackLayout( const std::string& tag );
virtual Uint32 onMessage( const NodeMessage* Msg );
void applySizePolicyOnChilds();
void setRowValign( const std::string& rowValign );
static std::string rowValignToStr( const RowValign& rowValign );
};
}} // namespace EE::UI

View File

@@ -402,6 +402,9 @@ void StyleSheetSpecification::registerDefaultProperties() {
registerProperty( "glyph", "" ).setType( PropertyType::String );
registerProperty( "name", "" ).setType( PropertyType::String );
registerProperty( "row-valign", "" )
.addAlias( "row-vertical-align" )
.setType( PropertyType::String );
// Shorthands
registerShorthand( "margin", { "margin-top", "margin-right", "margin-bottom", "margin-left" },

View File

@@ -10,14 +10,12 @@ UIStackLayout* UIStackLayout::New() {
return eeNew( UIStackLayout, () );
}
UIStackLayout::UIStackLayout() : UILayout( "stacklayout" ) {
mFlags |= UI_OWNS_CHILDS_POSITION;
setClipType( ClipType::ContentBox );
}
UIStackLayout::UIStackLayout() : UIStackLayout( "stacklayout" ) {}
UIStackLayout::UIStackLayout( const std::string& tag ) : UILayout( tag ) {
mFlags |= UI_OWNS_CHILDS_POSITION;
setClipType( ClipType::ContentBox );
setGravity( UI_HALIGN_LEFT | UI_VALIGN_TOP );
}
Uint32 UIStackLayout::getType() const {
@@ -80,6 +78,28 @@ void UIStackLayout::applySizePolicyOnChilds() {
}
}
void UIStackLayout::setRowValign( const std::string& rowValign ) {
if ( rowValign == "top" ) {
setRowValign( UIStackLayout::RowValign::Top );
} else if ( rowValign == "center" ) {
setRowValign( UIStackLayout::RowValign::Center );
} else if ( rowValign == "bottom" ) {
setRowValign( UIStackLayout::RowValign::Bottom );
}
}
std::string UIStackLayout::rowValignToStr( const RowValign& rowValign ) {
switch ( rowValign ) {
case UIStackLayout::RowValign::Top:
return "top";
case UIStackLayout::RowValign::Center:
return "center";
case UIStackLayout::RowValign::Bottom:
default:
return "bottom";
}
}
std::string UIStackLayout::getPropertyString( const PropertyDefinition* propertyDef,
const Uint32& propertyIndex ) const {
if ( NULL == propertyDef )
@@ -88,6 +108,8 @@ std::string UIStackLayout::getPropertyString( const PropertyDefinition* property
switch ( propertyDef->getPropertyId() ) {
case PropertyId::GravityOwner:
return isGravityOwner() ? "true" : "false";
case PropertyId::RowValign:
return rowValignToStr( mRowValign );
default:
return UILayout::getPropertyString( propertyDef, propertyIndex );
}
@@ -95,7 +117,7 @@ std::string UIStackLayout::getPropertyString( const PropertyDefinition* property
std::vector<PropertyId> UIStackLayout::getPropertiesImplemented() const {
auto props = UILayout::getPropertiesImplemented();
auto local = { PropertyId::GravityOwner };
auto local = { PropertyId::GravityOwner, PropertyId::RowValign };
props.insert( props.end(), local.begin(), local.end() );
return props;
}
@@ -109,6 +131,10 @@ bool UIStackLayout::applyProperty( const StyleSheetProperty& attribute ) {
setGravityOwner( attribute.asBool() );
break;
}
case PropertyId::RowValign: {
setRowValign( attribute.value() );
break;
}
default:
return UILayout::applyProperty( attribute );
}
@@ -200,13 +226,6 @@ void UIStackLayout::updateLayout() {
}
totHeight += mPaddingPx.Bottom;
if ( getLayoutHeightPolicy() == SizePolicy::WrapContent ) {
if ( totHeight != (int)getPixelsSize().getHeight() ) {
setInternalPixelsHeight( totHeight );
notifyLayoutAttrChangeParent();
}
}
for ( const auto& line : lines ) {
Float xDisplacement = 0.f;
Float yDisplacement = 0.f;
@@ -251,15 +270,16 @@ void UIStackLayout::updateLayout() {
break;
}
switch ( Font::getVerticalAlign( widget->getLayoutGravity() ) ) {
case UI_VALIGN_CENTER:
switch ( mRowValign ) {
case UIStackLayout::RowValign::Center:
pos.y = yDisplacement + maxY +
eeceil( ( line.maxY - widget->getPixelsSize().getHeight() ) * 0.5f );
break;
case UI_VALIGN_BOTTOM:
pos.y = yDisplacement + maxY + line.maxY - widget->getPixelsSize().getHeight();
case UIStackLayout::RowValign::Bottom:
pos.y = yDisplacement + maxY + line.maxY - widget->getPixelsSize().getHeight() -
widget->getLayoutPixelsMargin().Bottom;
break;
case UI_VALIGN_TOP:
case UIStackLayout::RowValign::Top:
default:
pos.y = yDisplacement + maxY + widget->getLayoutPixelsMargin().Top;
break;
@@ -271,6 +291,13 @@ void UIStackLayout::updateLayout() {
maxY += line.maxY;
}
if ( getLayoutHeightPolicy() == SizePolicy::WrapContent ) {
if ( totHeight != (int)getPixelsSize().getHeight() ) {
setInternalPixelsHeight( totHeight );
notifyLayoutAttrChangeParent();
}
}
if ( getParent()->isUINode() &&
( !getParent()->asType<UINode>()->ownsChildPosition() || isGravityOwner() ) ) {
alignAgainstLayout();
@@ -280,4 +307,12 @@ void UIStackLayout::updateLayout() {
mDirtyLayout = false;
}
const UIStackLayout::RowValign& UIStackLayout::getRowValign() const {
return mRowValign;
}
void UIStackLayout::setRowValign( const RowValign& rowValign ) {
mRowValign = rowValign;
}
}} // namespace EE::UI