mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-05-31 10:36:30 +03:00
Added position rules for widgets in the relative layout.
--HG-- branch : dev
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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() ) {
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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();
|
||||
/**/
|
||||
|
||||
Reference in New Issue
Block a user