diff --git a/include/eepp/ui/uicontrol.hpp b/include/eepp/ui/uicontrol.hpp index 4c3c2553c..f6f829438 100644 --- a/include/eepp/ui/uicontrol.hpp +++ b/include/eepp/ui/uicontrol.hpp @@ -90,10 +90,6 @@ class EE_API UIControl { void centerVertical(); - void centerVerticalUp(); - - void centerVerticalDown(); - void center(); virtual void close(); @@ -227,7 +223,7 @@ class EE_API UIControl { std::string getId() const; - void setId( const std::string & id ); + UIControl * setId( const std::string & id ); Uint32 getIdHash() const; diff --git a/include/eepp/ui/uihelper.hpp b/include/eepp/ui/uihelper.hpp index 8d329468c..c4119a444 100644 --- a/include/eepp/ui/uihelper.hpp +++ b/include/eepp/ui/uihelper.hpp @@ -157,6 +157,14 @@ enum LayoutSizeRules { WRAP_CONTENT }; +enum LayoutPositionRules { + NONE, + LEFT_OF, + RIGHT_OF, + TOP_OF, + BOTTOM_OF +}; + static const Uint32 UI_CONTROL_DEFAULT_ALIGN = UI_HALIGN_LEFT | UI_VALIGN_CENTER; static const Uint32 UI_CONTROL_ALIGN_CENTER = UI_HALIGN_CENTER | UI_VALIGN_CENTER; diff --git a/include/eepp/ui/uiwidget.hpp b/include/eepp/ui/uiwidget.hpp index cdb3e1b2f..28123a122 100644 --- a/include/eepp/ui/uiwidget.hpp +++ b/include/eepp/ui/uiwidget.hpp @@ -63,6 +63,12 @@ class EE_API UIWidget : public UIControlAnim { UIWidget * setLayoutHeightRules(const LayoutSizeRules & layoutHeightRules); UIWidget * setLayoutSizeRules( const LayoutSizeRules & layoutWidthRules, const LayoutSizeRules & layoutHeightRules ); + + UIWidget * setLayoutPositionRule( const LayoutPositionRules& layoutPositionRule, UIWidget * of ); + + UIWidget * getLayoutPositionRuleWidget() const; + + LayoutPositionRules getLayoutPositionRule() const; protected: friend class UILinearLayout; @@ -75,6 +81,8 @@ class EE_API UIWidget : public UIControlAnim { Uint32 mLayoutGravity; LayoutSizeRules mLayoutWidthRules; LayoutSizeRules mLayoutHeightRules; + LayoutPositionRules mLayoutPositionRule; + UIWidget * mLayoutPositionRuleWidget; void createTooltip(); diff --git a/src/eepp/ui/uicontrol.cpp b/src/eepp/ui/uicontrol.cpp index 8353fb9b8..e7c777a49 100644 --- a/src/eepp/ui/uicontrol.cpp +++ b/src/eepp/ui/uicontrol.cpp @@ -307,20 +307,6 @@ void UIControl::centerVertical(){ setPosition( mPos.x, ( Ctrl->getSize().getHeight() - mSize.getHeight() ) / 2 ); } -void UIControl::centerVerticalUp(){ - UIControl * Ctrl = getParent(); - - if ( NULL != Ctrl ) - setPosition( mPos.x, ( Ctrl->getSize().getHeight() - mSize.getHeight() ) / 2 - mSize.getHeight() / 2 ); -} - -void UIControl::centerVerticalDown(){ - UIControl * Ctrl = getParent(); - - if ( NULL != Ctrl ) - setPosition( mPos.x, ( Ctrl->getSize().getHeight() - mSize.getHeight() ) / 2 + mSize.getHeight() / 2 ); -} - void UIControl::center() { centerHorizontal(); centerVertical(); @@ -911,9 +897,10 @@ std::string UIControl::getId() const { return mId; } -void UIControl::setId(const std::string & id) { +UIControl * UIControl::setId(const std::string & id) { mId = id; mIdHash = String::hash( id ); + return this; } Uint32 UIControl::getIdHash() const { diff --git a/src/eepp/ui/uirelativelayout.cpp b/src/eepp/ui/uirelativelayout.cpp index bcce8549f..18e7fcb06 100644 --- a/src/eepp/ui/uirelativelayout.cpp +++ b/src/eepp/ui/uirelativelayout.cpp @@ -58,30 +58,55 @@ void UIRelativeLayout::fixChilds() { void UIRelativeLayout::fixChildPos( UIWidget * widget ) { Vector2i pos( widget->getPosition() ); - switch ( fontHAlignGet( widget->getLayoutGravity() ) ) { - case UI_HALIGN_CENTER: - pos.x = ( mSize.getWidth() - widget->getSize().getWidth() ) / 2; - break; - case UI_HALIGN_RIGHT: - pos.x = mSize.getWidth() - widget->getSize().getWidth() - widget->getLayoutMargin().Right; - break; - case UI_HALIGN_LEFT: - default: - pos.x = widget->getLayoutMargin().Left; - break; - } + if ( widget->getLayoutPositionRule() != LayoutPositionRules::NONE && widget->getParent() == widget->getLayoutPositionRuleWidget()->getParent() ) { + UIWidget * of = widget->getLayoutPositionRuleWidget(); - switch ( fontVAlignGet( widget->getLayoutGravity() ) ) { - case UI_VALIGN_CENTER: - pos.y = ( mSize.getHeight() - widget->getSize().getHeight() ) / 2; - break; - case UI_VALIGN_BOTTOM: - pos.y = mSize.getHeight() - widget->getSize().getHeight() - widget->getLayoutMargin().Bottom; - break; - case UI_VALIGN_TOP: - default: - pos.y = widget->getLayoutMargin().Left; - break; + switch ( widget->getLayoutPositionRule() ) { + case LEFT_OF: + pos.x = of->getPosition().x - widget->getSize().getWidth() - widget->getLayoutMargin().Right - of->getLayoutMargin().Left; + pos.y = of->getPosition().y; + break; + case RIGHT_OF: + pos.x = of->getPosition().x + of->getSize().getWidth() + widget->getLayoutMargin().Left + of->getLayoutMargin().Right; + pos.y = of->getPosition().y; + break; + case TOP_OF: + pos.x = of->getPosition().x; + pos.y = of->getPosition().y - widget->getSize().getHeight() - widget->getLayoutMargin().Bottom - of->getLayoutMargin().Top; + break; + case BOTTOM_OF: + pos.x = of->getPosition().x; + pos.y = of->getPosition().y + of->getSize().getHeight() + widget->getLayoutMargin().Top + of->getLayoutMargin().Bottom; + break; + default: + break; + } + } else { + switch ( fontHAlignGet( widget->getLayoutGravity() ) ) { + case UI_HALIGN_CENTER: + pos.x = ( mSize.getWidth() - widget->getSize().getWidth() ) / 2; + break; + case UI_HALIGN_RIGHT: + pos.x = mSize.getWidth() - widget->getSize().getWidth() - widget->getLayoutMargin().Right; + break; + case UI_HALIGN_LEFT: + default: + pos.x = widget->getLayoutMargin().Left; + break; + } + + switch ( fontVAlignGet( widget->getLayoutGravity() ) ) { + case UI_VALIGN_CENTER: + pos.y = ( mSize.getHeight() - widget->getSize().getHeight() ) / 2; + break; + case UI_VALIGN_BOTTOM: + pos.y = mSize.getHeight() - widget->getSize().getHeight() - widget->getLayoutMargin().Bottom; + break; + case UI_VALIGN_TOP: + default: + pos.y = widget->getLayoutMargin().Left; + break; + } } widget->setPosition( pos ); diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index 910bc25d5..62f73f2b5 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -14,7 +14,9 @@ UIWidget::UIWidget() : mLayoutWeight(0), mLayoutGravity(0), mLayoutWidthRules(WRAP_CONTENT), - mLayoutHeightRules(WRAP_CONTENT) + mLayoutHeightRules(WRAP_CONTENT), + mLayoutPositionRule(LayoutPositionRules::NONE), + mLayoutPositionRuleWidget(NULL) { mControlFlags |= UI_CTRL_FLAG_COMPLEX; @@ -91,6 +93,20 @@ UIWidget * UIWidget::setLayoutSizeRules(const LayoutSizeRules & layoutWidthRules return this; } +UIWidget * UIWidget::setLayoutPositionRule(const LayoutPositionRules & layoutPositionRule, UIWidget * of) { + mLayoutPositionRule = layoutPositionRule; + mLayoutPositionRuleWidget = of; + return this; +} + +UIWidget * UIWidget::getLayoutPositionRuleWidget() const { + return mLayoutPositionRuleWidget; +} + +LayoutPositionRules UIWidget::getLayoutPositionRule() const { + return mLayoutPositionRule; +} + void UIWidget::update() { if ( mVisible && NULL != mTooltip && mTooltip->getText().size() ) { if ( isMouseOverMeOrChilds() ) { diff --git a/src/eepp/ui/uiwindow.cpp b/src/eepp/ui/uiwindow.cpp index e7dda7bf3..f849b5656 100644 --- a/src/eepp/ui/uiwindow.cpp +++ b/src/eepp/ui/uiwindow.cpp @@ -49,6 +49,7 @@ UIWindow::UIWindow( UIWindow::WindowBaseContainerType type ) : break; } + mContainer->setLayoutSizeRules( FIXED, FIXED ); mContainer->setParent( this ); mContainer->setFlags( UI_REPORT_SIZE_CHANGE_TO_CHILDS ); mContainer->setSize( mSize ); diff --git a/src/test/eetest.cpp b/src/test/eetest.cpp index afd9a8381..21626442f 100644 --- a/src/test/eetest.cpp +++ b/src/test/eetest.cpp @@ -699,8 +699,11 @@ void EETest::createNewUI() { rlay->setLayoutMargin( Recti( 16, 16, 16, 16 ) ); rlay->setBackgroundFillEnabled( true )->setColor( 0x333333CC ); - UIPushButton::New()->setText( "OK" )->setLayoutGravity( UI_VALIGN_BOTTOM | UI_HALIGN_RIGHT )->setLayoutMargin( Recti( 0, 0, 16, 16 ) )->setParent( rlay ); - UIPushButton::New()->setText( "Cancel" )->setLayoutGravity( UI_VALIGN_BOTTOM | UI_HALIGN_RIGHT )->setLayoutMargin( Recti( 0, 0, 16 + 32, 16 ) )->setParent( rlay ); + UIPushButton * ofBut = UIPushButton::New(); + ofBut->setText( "OK" )->setLayoutGravity( UI_VALIGN_BOTTOM | UI_HALIGN_RIGHT )->setLayoutMargin( Recti( 0, 0, 16, 16 ) )->setParent( rlay ); + + UIPushButton::New()->setText( "Cancel" )->setLayoutGravity( UI_VALIGN_BOTTOM | UI_HALIGN_RIGHT )->setLayoutMargin( Recti( 0, 0, 8, 0 ) ) + ->setLayoutPositionRule( LayoutPositionRules::LEFT_OF, ofBut )->setParent( rlay ); win2->show(); /**/