mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-01 11:06:30 +03:00
UIMessageBox with layouts.
LinearLayout fixes. Some minor refactor. --HG-- branch : dev
This commit is contained in:
@@ -67,8 +67,6 @@ class EE_API TextureAtlasEditor {
|
||||
|
||||
void onSubTextureChange( const UIEvent * Event );
|
||||
|
||||
UITextView * createTextBox( Vector2i Pos, const String& Text );
|
||||
|
||||
void updateControls();
|
||||
|
||||
void fillSubTextureList();
|
||||
|
||||
@@ -106,6 +106,8 @@ class EE_API UIControl {
|
||||
|
||||
UIControl * setVerticalAlign( Uint32 valign );
|
||||
|
||||
UIControl * setGravity( Uint32 hvalign );
|
||||
|
||||
UIBackground * setBackgroundFillEnabled( bool enabled );
|
||||
|
||||
UIBorder * setBorderEnabled( bool enabled );
|
||||
|
||||
@@ -106,6 +106,8 @@ class EE_API UIWidget : public UIControlAnim {
|
||||
|
||||
void notifyLayoutAttrChange();
|
||||
|
||||
void notifyLayoutAttrChangeParent();
|
||||
|
||||
void updateAnchors( const Vector2i & SizeChange );
|
||||
|
||||
void alignAgainstLayout();
|
||||
|
||||
@@ -8,11 +8,11 @@ namespace EE { namespace UI {
|
||||
|
||||
class EE_API UIWidgetCreator {
|
||||
public:
|
||||
typedef cb::Callback1<UIWidget*, std::string> CreateUIWidgetCb;
|
||||
typedef cb::Callback1<UIWidget*, std::string> CustomWidgetCb;
|
||||
|
||||
static UIWidget * createUIWidgetFromName( std::string name );
|
||||
static UIWidget * createFromName( std::string widgetName );
|
||||
|
||||
static void addCustomWidgetCallback( std::string widgetName, const CreateUIWidgetCb& cb );
|
||||
static void addCustomWidgetCallback( std::string widgetName, const CustomWidgetCb& cb );
|
||||
|
||||
static void removeCustomWidgetCallback( std::string widgetName );
|
||||
|
||||
|
||||
@@ -206,16 +206,6 @@ void TextureAtlasEditor::onDestHChange( const UIEvent * Event ) {
|
||||
}
|
||||
}
|
||||
|
||||
UITextView * TextureAtlasEditor::createTextBox( Vector2i Pos, const String& Text ) {
|
||||
UITextView * txtBox = UITextView::New();
|
||||
txtBox->setFontStyle( Text::Shadow );
|
||||
txtBox->resetFlags( UI_CONTROL_DEFAULT_ALIGN | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_AUTO_SIZE );
|
||||
txtBox->setParent( mUIContainer );
|
||||
txtBox->setPosition( Pos );
|
||||
txtBox->setText( Text );
|
||||
return txtBox;
|
||||
}
|
||||
|
||||
void TextureAtlasEditor::windowClose( const UIEvent * Event ) {
|
||||
if ( mCloseCb.IsSet() )
|
||||
mCloseCb();
|
||||
|
||||
@@ -553,6 +553,14 @@ UIControl * UIControl::setVerticalAlign( Uint32 valign ) {
|
||||
return this;
|
||||
}
|
||||
|
||||
UIControl * UIControl::setGravity( Uint32 hvalign ) {
|
||||
mFlags &= ~( UI_VALIGN_MASK | UI_HALIGN_MASK );
|
||||
mFlags |= ( hvalign & ( UI_VALIGN_MASK | UI_HALIGN_MASK ) ) ;
|
||||
|
||||
onAlignChange();
|
||||
return this;
|
||||
}
|
||||
|
||||
UIBackground * UIControl::setBackgroundFillEnabled( bool enabled ) {
|
||||
writeFlag( UI_FILL_BACKGROUND, enabled ? 1 : 0 );
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ void UILinearLayout::packVertical() {
|
||||
UIControl * ChildLoop = mChild;
|
||||
|
||||
while ( NULL != ChildLoop ) {
|
||||
if ( ChildLoop->isWidget() ) {
|
||||
if ( ChildLoop->isWidget() && ChildLoop->isVisible() ) {
|
||||
UIWidget * widget = static_cast<UIWidget*>( ChildLoop );
|
||||
|
||||
if ( widget->getLayoutHeightRules() == WRAP_CONTENT ) {
|
||||
@@ -153,6 +153,7 @@ void UILinearLayout::packVertical() {
|
||||
|
||||
if ( getLayoutHeightRules() == WRAP_CONTENT ) {
|
||||
setInternalHeight( curY );
|
||||
notifyLayoutAttrChangeParent();
|
||||
} else if ( getLayoutHeightRules() == MATCH_PARENT ) {
|
||||
setInternalHeight( getParent()->getSize().getHeight() - mLayoutMargin.Top - mLayoutMargin.Bottom );
|
||||
}
|
||||
@@ -160,6 +161,7 @@ void UILinearLayout::packVertical() {
|
||||
if ( getLayoutWidthRules() == WRAP_CONTENT && mSize.getWidth() != maxX ) {
|
||||
setInternalWidth( maxX );
|
||||
packVertical();
|
||||
notifyLayoutAttrChangeParent();
|
||||
}
|
||||
|
||||
alignAgainstLayout();
|
||||
@@ -212,7 +214,7 @@ void UILinearLayout::packHorizontal() {
|
||||
ChildLoop = mChild;
|
||||
|
||||
while ( NULL != ChildLoop ) {
|
||||
if ( ChildLoop->isWidget() ) {
|
||||
if ( ChildLoop->isWidget() && ChildLoop->isVisible() ) {
|
||||
UIWidget * widget = static_cast<UIWidget*>( ChildLoop );
|
||||
Recti margin = widget->getLayoutMargin();
|
||||
|
||||
@@ -236,7 +238,7 @@ void UILinearLayout::packHorizontal() {
|
||||
break;
|
||||
case UI_VALIGN_TOP:
|
||||
default:
|
||||
pos.y = widget->getLayoutMargin().Left;
|
||||
pos.y = widget->getLayoutMargin().Top;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -252,6 +254,7 @@ void UILinearLayout::packHorizontal() {
|
||||
|
||||
if ( getLayoutWidthRules() == WRAP_CONTENT ) {
|
||||
setInternalWidth( curX );
|
||||
notifyLayoutAttrChangeParent();
|
||||
} else if ( getLayoutWidthRules() == MATCH_PARENT ) {
|
||||
setInternalWidth( getParent()->getSize().getWidth() - mLayoutMargin.Left - mLayoutMargin.Right );
|
||||
}
|
||||
@@ -259,6 +262,7 @@ void UILinearLayout::packHorizontal() {
|
||||
if ( getLayoutHeightRules() == WRAP_CONTENT && mSize.getHeight() != maxY ) {
|
||||
setInternalHeight( maxY );
|
||||
packHorizontal();
|
||||
notifyLayoutAttrChangeParent();
|
||||
}
|
||||
|
||||
alignAgainstLayout();
|
||||
|
||||
@@ -511,7 +511,7 @@ void UIManager::loadLayoutNodes( pugi::xml_node node, UIControl * parent ) {
|
||||
parent = getMainControl();
|
||||
|
||||
for ( pugi::xml_node widget = node; widget; widget = widget.next_sibling() ) {
|
||||
UIWidget * uiwidget = UIWidgetCreator::createUIWidgetFromName( widget.name() );
|
||||
UIWidget * uiwidget = UIWidgetCreator::createFromName( widget.name() );
|
||||
|
||||
if ( NULL != uiwidget ) {
|
||||
uiwidget->setParent( parent );
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <eepp/ui/uimessagebox.hpp>
|
||||
#include <eepp/ui/uimanager.hpp>
|
||||
#include <eepp/ui/uilinearlayout.hpp>
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
@@ -12,42 +13,34 @@ UIMessageBox::UIMessageBox( UI_MSGBOX_TYPE type , String message ) :
|
||||
mMsgBoxType( type ),
|
||||
mCloseWithKey( KEY_UNKNOWN )
|
||||
{
|
||||
setInternalSize( Sizei( 1024, 1024 ) );
|
||||
|
||||
mTextBox = UITextView::New();
|
||||
mTextBox->setParent( getContainer() )
|
||||
->setHorizontalAlign( UI_HALIGN_CENTER )
|
||||
->setVerticalAlign( UI_VALIGN_CENTER );
|
||||
mTextBox->setText( message );
|
||||
|
||||
mButtonOK = UIPushButton::New();
|
||||
mButtonOK->setParent( getContainer() )
|
||||
->setFlags( UI_AUTO_SIZE )
|
||||
->setSize( 90, 0 )
|
||||
->setPosition( getContainer()->getSize().getWidth() - 96, getContainer()->getSize().getHeight() - mButtonOK->getSize().getHeight() - 8 );
|
||||
mButtonOK->setAnchors( UI_ANCHOR_RIGHT );
|
||||
|
||||
mButtonCancel = UIPushButton::New();
|
||||
mButtonCancel->setParent( getContainer() )
|
||||
->setFlags( UI_AUTO_SIZE )
|
||||
->setSize( 90, 0 )
|
||||
->setPosition( mButtonOK->getPosition().x - mButtonOK->getSize().getWidth() - 8, getContainer()->getSize().getHeight() - mButtonOK->getSize().getHeight() - 8 );
|
||||
mButtonCancel->setAnchors( UI_ANCHOR_RIGHT );
|
||||
|
||||
applyDefaultTheme();
|
||||
|
||||
mTextBox->setPosition( 0, 8 );
|
||||
mTextBox->setSize( PixelDensity::pxToDpI( mTextBox->getTextWidth() ) + 24, mTextBox->getTextHeight() );
|
||||
setSize( mTextBox->getSize().getWidth() + 24, mTextBox->getSize().getHeight() + mButtonOK->getSize().getHeight() + mStyleConfig.DecorationSize.getHeight() + 16 );
|
||||
mTextBox->centerHorizontal();
|
||||
mTextBox->setAnchors( UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT );
|
||||
|
||||
setMinWindowSize( getSize() );
|
||||
|
||||
mStyleConfig.WinFlags &= ~UI_WIN_RESIZEABLE;
|
||||
|
||||
updateWinFlags();
|
||||
|
||||
UILinearLayout * rlay = UILinearLayout::New();
|
||||
rlay->setLayoutSizeRules( WRAP_CONTENT, WRAP_CONTENT )->setParent( mContainer );
|
||||
|
||||
UILinearLayout * vlay = UILinearLayout::NewVertical();
|
||||
vlay->setLayoutSizeRules( WRAP_CONTENT, WRAP_CONTENT )
|
||||
->setLayoutMargin( Recti( 8, 8, 8, 8) )->setParent( rlay );
|
||||
|
||||
mTextBox = UITextView::New();
|
||||
mTextBox->setText( message )
|
||||
->setLayoutSizeRules( WRAP_CONTENT, WRAP_CONTENT )
|
||||
->setParent( vlay );
|
||||
|
||||
UILinearLayout * hlay = UILinearLayout::NewHorizontal();
|
||||
hlay->setLayoutMargin( Recti( 0, 8, 0, 0 ) )
|
||||
->setLayoutSizeRules( WRAP_CONTENT, WRAP_CONTENT )
|
||||
->setLayoutGravity( UI_HALIGN_RIGHT | UI_VALIGN_CENTER )
|
||||
->setParent( vlay );
|
||||
|
||||
mButtonOK = UIPushButton::New();
|
||||
mButtonOK->setSize( 90, 0 )->setParent( hlay );
|
||||
|
||||
mButtonCancel = UIPushButton::New();
|
||||
mButtonCancel->setLayoutMargin( Recti( 8, 0, 0, 0 ) )->setSize( 90, 0 )->setParent( hlay );
|
||||
|
||||
switch ( mMsgBoxType ) {
|
||||
case MSGBOX_OKCANCEL:
|
||||
{
|
||||
@@ -76,8 +69,9 @@ UIMessageBox::UIMessageBox( UI_MSGBOX_TYPE type , String message ) :
|
||||
}
|
||||
}
|
||||
|
||||
mButtonCancel->toFront();
|
||||
mButtonOK->toFront();
|
||||
applyDefaultTheme();
|
||||
|
||||
setMinWindowSize( rlay->getSize() );
|
||||
}
|
||||
|
||||
UIMessageBox::~UIMessageBox() {
|
||||
@@ -98,9 +92,6 @@ void UIMessageBox::setTheme( UITheme * Theme ) {
|
||||
mButtonCancel->setIcon( CancelIcon );
|
||||
}
|
||||
}
|
||||
|
||||
mButtonOK->setPosition( mButtonOK->getPosition().x, getContainer()->getSize().getHeight() - mButtonOK->getSize().getHeight() - 8 );
|
||||
mButtonCancel->setPosition( mButtonCancel->getPosition().x, mButtonOK->getPosition().y );
|
||||
}
|
||||
|
||||
Uint32 UIMessageBox::onMessage( const UIMessage * Msg ) {
|
||||
@@ -155,13 +146,11 @@ bool UIMessageBox::show() {
|
||||
return b;
|
||||
}
|
||||
|
||||
Uint32 UIMessageBox::getCloseWithKey() const
|
||||
{
|
||||
Uint32 UIMessageBox::getCloseWithKey() const {
|
||||
return mCloseWithKey;
|
||||
}
|
||||
|
||||
void UIMessageBox::setCloseWithKey(const Uint32 & closeWithKey)
|
||||
{
|
||||
void UIMessageBox::setCloseWithKey(const Uint32 & closeWithKey) {
|
||||
mCloseWithKey = closeWithKey;
|
||||
}
|
||||
|
||||
|
||||
@@ -266,6 +266,7 @@ void UIWidget::onPositionChange() {
|
||||
|
||||
void UIWidget::onVisibilityChange() {
|
||||
updateAnchorsDistances();
|
||||
notifyLayoutAttrChange();
|
||||
UIControlAnim::onVisibilityChange();
|
||||
}
|
||||
|
||||
@@ -277,6 +278,13 @@ void UIWidget::notifyLayoutAttrChange() {
|
||||
messagePost( &msg );
|
||||
}
|
||||
|
||||
void UIWidget::notifyLayoutAttrChangeParent() {
|
||||
if ( NULL != mParentCtrl ) {
|
||||
UIMessage msg( this, UIMessage::MsgLayoutAttributeChange );
|
||||
mParentCtrl->messagePost( &msg );
|
||||
}
|
||||
}
|
||||
|
||||
void UIWidget::updateAnchors( const Vector2i& SizeChange ) {
|
||||
if ( !( mFlags & ( UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_ANCHOR_RIGHT | UI_ANCHOR_BOTTOM ) ) )
|
||||
return;
|
||||
|
||||
@@ -28,79 +28,79 @@
|
||||
|
||||
namespace EE { namespace UI {
|
||||
|
||||
typedef std::map<std::string, UIWidgetCreator::CreateUIWidgetCb> widgetCallbackMap;
|
||||
typedef std::map<std::string, UIWidgetCreator::CustomWidgetCb> widgetCallbackMap;
|
||||
|
||||
static widgetCallbackMap widgetCallback;
|
||||
|
||||
UIWidget * UIWidgetCreator::createUIWidgetFromName( std::string name ) {
|
||||
String::toLowerInPlace( name );
|
||||
UIWidget * UIWidgetCreator::createFromName( std::string widgetName ) {
|
||||
String::toLowerInPlace( widgetName );
|
||||
|
||||
if ( name == "widget" ) {
|
||||
if ( widgetName == "widget" ) {
|
||||
return UIWidget::New();
|
||||
} else if ( name == "horizontallinearlayout" || name == "hll" ) {
|
||||
} else if ( widgetName == "horizontallinearlayout" || widgetName == "hll" ) {
|
||||
return UILinearLayout::NewHorizontal();
|
||||
} else if ( name == "linearlayout" || name == "verticallinearlayout" || name == "vll" ) {
|
||||
} else if ( widgetName == "linearlayout" || widgetName == "verticallinearlayout" || widgetName == "vll" ) {
|
||||
return UILinearLayout::NewVertical();
|
||||
} else if ( name == "relativelayout" ) {
|
||||
} else if ( widgetName == "relativelayout" ) {
|
||||
return UIRelativeLayout::New();
|
||||
} else if ( name == "textview" ) {
|
||||
} else if ( widgetName == "textview" ) {
|
||||
return UITextView::New();
|
||||
} else if ( name == "pushbutton" ) {
|
||||
} else if ( widgetName == "pushbutton" ) {
|
||||
return UIPushButton::New();
|
||||
} else if ( name == "checkbox" ) {
|
||||
} else if ( widgetName == "checkbox" ) {
|
||||
return UICheckBox::New();
|
||||
} else if ( name == "radiobutton" ) {
|
||||
} else if ( widgetName == "radiobutton" ) {
|
||||
return UIRadioButton::New();
|
||||
} else if ( name == "combobox" ) {
|
||||
} else if ( widgetName == "combobox" ) {
|
||||
return UIComboBox::New();
|
||||
} else if ( name == "dropdownlist" ) {
|
||||
} else if ( widgetName == "dropdownlist" ) {
|
||||
return UIDropDownList::New();
|
||||
} else if ( name == "image" ) {
|
||||
} else if ( widgetName == "image" ) {
|
||||
return UISubTexture::New();
|
||||
} else if ( name == "listbox" ) {
|
||||
} else if ( widgetName == "listbox" ) {
|
||||
return UIListBox::New();
|
||||
} else if ( name == "winmenu" ) {
|
||||
} else if ( widgetName == "winmenu" ) {
|
||||
return UIWinMenu::New();
|
||||
} else if ( name == "progressbar" ) {
|
||||
} else if ( widgetName == "progressbar" ) {
|
||||
return UIProgressBar::New();
|
||||
} else if ( name == "scrollbar" ) {
|
||||
} else if ( widgetName == "scrollbar" ) {
|
||||
return UIScrollBar::New();
|
||||
} else if ( name == "slider" ) {
|
||||
} else if ( widgetName == "slider" ) {
|
||||
return UISlider::New();
|
||||
} else if ( name == "spinbox" ) {
|
||||
} else if ( widgetName == "spinbox" ) {
|
||||
return UISpinBox::New();
|
||||
} else if ( name == "sprite" ) {
|
||||
} else if ( widgetName == "sprite" ) {
|
||||
return UISprite::New();
|
||||
} else if ( name == "tab" ) {
|
||||
} else if ( widgetName == "tab" ) {
|
||||
return UITab::New();
|
||||
} else if ( name == "table" ) {
|
||||
} else if ( widgetName == "table" ) {
|
||||
return UITable::New();
|
||||
} else if ( name == "tablecell" ) {
|
||||
} else if ( widgetName == "tablecell" ) {
|
||||
return UITableCell::New();
|
||||
} else if ( name == "tabwidget" ) {
|
||||
} else if ( widgetName == "tabwidget" ) {
|
||||
return UITabWidget::New();
|
||||
} else if ( name == "textedit" ) {
|
||||
} else if ( widgetName == "textedit" ) {
|
||||
return UITextEdit::New();
|
||||
} else if ( name == "textinput" || name == "input" ) {
|
||||
} else if ( widgetName == "textinput" || widgetName == "input" ) {
|
||||
return UITextInput::New();
|
||||
} else if ( name == "textinputpassword" || name == "inputpassword" ) {
|
||||
} else if ( widgetName == "textinputpassword" || widgetName == "inputpassword" ) {
|
||||
return UITextInputPassword::New();
|
||||
} else if ( name == "loader" ) {
|
||||
} else if ( widgetName == "loader" ) {
|
||||
return UILoader::New();
|
||||
} else if ( name == "selectbutton" ) {
|
||||
} else if ( widgetName == "selectbutton" ) {
|
||||
return UISelectButton::New();
|
||||
} else if ( name == "window" ) {
|
||||
} else if ( widgetName == "window" ) {
|
||||
return UIWindow::New();
|
||||
}
|
||||
|
||||
if ( widgetCallback.find( name ) != widgetCallback.end() ) {
|
||||
return widgetCallback[ name ].Call( name );
|
||||
if ( widgetCallback.find( widgetName ) != widgetCallback.end() ) {
|
||||
return widgetCallback[ widgetName ].Call( widgetName );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void UIWidgetCreator::addCustomWidgetCallback( std::string widgetName, const UIWidgetCreator::CreateUIWidgetCb& cb ) {
|
||||
void UIWidgetCreator::addCustomWidgetCallback( std::string widgetName, const UIWidgetCreator::CustomWidgetCb& cb ) {
|
||||
widgetCallback[ String::toLower( widgetName ) ] = cb;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user