Minor changes.

--HG--
branch : dev
This commit is contained in:
Martín Lucas Golini
2019-11-26 23:22:56 -03:00
parent 246fa4bf80
commit c22194c554
5 changed files with 112 additions and 12 deletions

View File

@@ -197,7 +197,7 @@ class EE_API UINode : public Node {
virtual void setFocus();
virtual Float lengthAsPixels( const CSS::StyleSheetLength& length, const Sizef& drawableSize, const bool& percentAsWidth = true );
virtual Float convertLength( const CSS::StyleSheetLength& length, const Sizef& drawableSize, const bool& percentAsWidth = true );
Float lengthAsDp( const CSS::StyleSheetLength& length, const Sizef& drawableSize, const bool& percentAsWidth = true );
protected:

View File

@@ -63,6 +63,14 @@ class EE_API UIWidget : public UINode, public CSS::StyleSheetElement {
UIWidget * setLayoutMargin(const Rect & margin);
UIWidget * setLayoutMarginLeft(const Float& marginLeft);
UIWidget * setLayoutMarginRight(const Float& marginRight);
UIWidget * setLayoutMarginTop(const Float& marginTop);
UIWidget * setLayoutMarginBottom(const Float& marginBottom);
Float getLayoutWeight() const;
UIWidget * setLayoutWeight(const Float & weight);
@@ -101,6 +109,14 @@ class EE_API UIWidget : public UINode, public CSS::StyleSheetElement {
UIWidget * setPadding(const Rectf& padding);
UIWidget * setPaddingLeft(const Float& paddingLeft);
UIWidget * setPaddingRight(const Float& paddingRight);
UIWidget * setPaddingTop(const Float& paddingTop);
UIWidget * setPaddingBottom(const Float& paddingBottom);
const std::string& getStyleSheetTag() const;
const std::string& getStyleSheetId() const;

View File

@@ -986,7 +986,7 @@ Uint32 UINode::onFocusLoss() {
return Node::onFocusLoss();
}
Float UINode::lengthAsPixels( const CSS::StyleSheetLength& length, const Sizef& drawableSize, const bool& percentAsWidth ) {
Float UINode::convertLength( const CSS::StyleSheetLength& length, const Sizef& drawableSize, const bool& percentAsWidth ) {
return length.asPixels(
percentAsWidth ? getPixelsSize().getWidth() - drawableSize.getWidth() :
getPixelsSize().getHeight() - drawableSize.getHeight(),
@@ -995,7 +995,7 @@ Float UINode::lengthAsPixels( const CSS::StyleSheetLength& length, const Sizef&
}
Float UINode::lengthAsDp( const CSS::StyleSheetLength& length, const Sizef& drawableSize, const bool& percentAsWidth ) {
return PixelDensity::pxToDp( lengthAsPixels( length, drawableSize, percentAsWidth ) );
return PixelDensity::pxToDp( convertLength( length, drawableSize, percentAsWidth ) );
}
}}

View File

@@ -372,18 +372,18 @@ Sizef UINodeDrawable::LayerDrawable::calcDrawableSize( const std::string& drawab
}
} else if ( sizePart[0] != "auto" ) {
CSS::StyleSheetLength wl( sizePart[0] );
size.x = mContainer->getOwner()->lengthAsPixels( wl, Sizef::Zero, true );
size.x = mContainer->getOwner()->convertLength( wl, Sizef::Zero, true );
if ( sizePart[1] == "auto" ) {
Sizef drawableSize( mDrawable->getSize() );
size.y = drawableSize.getHeight() * ( size.getWidth() / drawableSize.getWidth() );
} else {
CSS::StyleSheetLength hl( sizePart[1] );
size.y = mContainer->getOwner()->lengthAsPixels( hl, Sizef::Zero, false );
size.y = mContainer->getOwner()->convertLength( hl, Sizef::Zero, false );
}
} else {
CSS::StyleSheetLength hl( sizePart[1] );
size.y = mContainer->getOwner()->lengthAsPixels( hl, Sizef::Zero, false );
size.y = mContainer->getOwner()->convertLength( hl, Sizef::Zero, false );
Sizef drawableSize( mDrawable->getSize() );
size.x = drawableSize.getWidth() * ( size.getHeight() / drawableSize.getHeight() );
@@ -412,8 +412,8 @@ Vector2f UINodeDrawable::LayerDrawable::calcPosition( const std::string& positio
CSS::StyleSheetLength xl( pos[xFloatIndex] );
CSS::StyleSheetLength yl( pos[yFloatIndex] );
position.x = mContainer->getOwner()->lengthAsPixels( xl, mDrawableSize, true );
position.y = mContainer->getOwner()->lengthAsPixels( yl, mDrawableSize, false );
position.x = mContainer->getOwner()->convertLength( xl, mDrawableSize, true );
position.y = mContainer->getOwner()->convertLength( yl, mDrawableSize, false );
} else if ( pos.size() > 2 ) {
if ( pos.size() == 3 ) {
pos.push_back( "0dp" );
@@ -432,14 +432,14 @@ Vector2f UINodeDrawable::LayerDrawable::calcPosition( const std::string& positio
CSS::StyleSheetLength yl1( pos[yFloatIndex] );
CSS::StyleSheetLength yl2( pos[yFloatIndex+1] );
position.x = mContainer->getOwner()->lengthAsPixels( xl1, mDrawableSize, true );
position.x = mContainer->getOwner()->convertLength( xl1, mDrawableSize, true );
Float xl2Val = mContainer->getOwner()->lengthAsPixels( xl2, mDrawableSize, true );
Float xl2Val = mContainer->getOwner()->convertLength( xl2, mDrawableSize, true );
position.x += ( pos[xFloatIndex] == "right" ) ? -xl2Val : xl2Val;
position.y = mContainer->getOwner()->lengthAsPixels( yl1, mDrawableSize, false );
position.y = mContainer->getOwner()->convertLength( yl1, mDrawableSize, false );
Float yl2Val = mContainer->getOwner()->lengthAsPixels( yl2, mDrawableSize, false );
Float yl2Val = mContainer->getOwner()->convertLength( yl2, mDrawableSize, false );
position.y += ( pos[yFloatIndex] == "bottom" ) ? -yl2Val : yl2Val;
}

View File

@@ -84,6 +84,42 @@ UIWidget * UIWidget::setLayoutMargin(const Rect & margin) {
return this;
}
UIWidget * UIWidget::setLayoutMarginLeft(const Float& marginLeft) {
if ( mLayoutMargin.Left != marginLeft ) {
mLayoutMargin.Left = marginLeft;
notifyLayoutAttrChange();
}
return this;
}
UIWidget * UIWidget::setLayoutMarginRight(const Float& marginRight) {
if ( mLayoutMargin.Right != marginRight ) {
mLayoutMargin.Right = marginRight;
notifyLayoutAttrChange();
}
return this;
}
UIWidget * UIWidget::setLayoutMarginTop(const Float& marginTop) {
if ( mLayoutMargin.Top != marginTop ) {
mLayoutMargin.Top = marginTop;
notifyLayoutAttrChange();
}
return this;
}
UIWidget * UIWidget::setLayoutMarginBottom(const Float& marginBottom) {
if ( mLayoutMargin.Bottom != marginBottom ) {
mLayoutMargin.Bottom = marginBottom;
notifyLayoutAttrChange();
}
return this;
}
Float UIWidget::getLayoutWeight() const {
return mLayoutWeight;
}
@@ -463,6 +499,54 @@ UIWidget * UIWidget::setPadding(const Rectf& padding) {
return this;
}
UIWidget * UIWidget::setPaddingLeft(const Float& paddingLeft) {
if ( paddingLeft != mPadding.Left ) {
mPadding.Left = paddingLeft;
mRealPadding.Left = PixelDensity::dpToPx( mPadding.Left );
onAutoSize();
onPaddingChange();
notifyLayoutAttrChange();
}
return this;
}
UIWidget * UIWidget::setPaddingRight(const Float& paddingRight) {
if ( paddingRight != mPadding.Right ) {
mPadding.Right = paddingRight;
mRealPadding.Right = PixelDensity::dpToPx( mPadding.Right );
onAutoSize();
onPaddingChange();
notifyLayoutAttrChange();
}
return this;
}
UIWidget * UIWidget::setPaddingTop(const Float& paddingTop) {
if ( paddingTop != mPadding.Top ) {
mPadding.Top = paddingTop;
mRealPadding.Top = PixelDensity::dpToPx( mPadding.Top );
onAutoSize();
onPaddingChange();
notifyLayoutAttrChange();
}
return this;
}
UIWidget * UIWidget::setPaddingBottom(const Float& paddingBottom) {
if ( paddingBottom != mPadding.Bottom ) {
mPadding.Bottom = paddingBottom;
mRealPadding.Bottom = PixelDensity::dpToPx( mPadding.Bottom );
onAutoSize();
onPaddingChange();
notifyLayoutAttrChange();
}
return this;
}
const std::string &UIWidget::getStyleSheetId() const {
return mId;
}