diff --git a/include/eepp/network/uri.hpp b/include/eepp/network/uri.hpp index 0f87917a4..5bd52b9f5 100644 --- a/include/eepp/network/uri.hpp +++ b/include/eepp/network/uri.hpp @@ -122,7 +122,7 @@ class EE_API URI { const std::string& getHost() const; /** Sets the host part of the URI. */ - void getHost( const std::string& host ); + void setHost( const std::string& host ); /** @returns the port number part of the URI. * If no port number (0) has been specified, the diff --git a/include/eepp/ui/uigridlayout.hpp b/include/eepp/ui/uigridlayout.hpp index 56b5a8d06..ad10a2e32 100644 --- a/include/eepp/ui/uigridlayout.hpp +++ b/include/eepp/ui/uigridlayout.hpp @@ -1,4 +1,4 @@ -#ifndef EE_UI_UIGRIDLAYOUT +#ifndef EE_UI_UIGRIDLAYOUT #define EE_UI_UIGRIDLAYOUT #include @@ -63,6 +63,8 @@ class EE_API UIGridLayout : public UILayout { virtual Uint32 onMessage( const NodeMessage* Msg ); + virtual void onParentSizeChange( const Vector2f& size ); + Sizef getTargetElementSize() const; }; diff --git a/include/eepp/ui/uilayout.hpp b/include/eepp/ui/uilayout.hpp index 8b2e2532f..97af1a395 100644 --- a/include/eepp/ui/uilayout.hpp +++ b/include/eepp/ui/uilayout.hpp @@ -40,6 +40,7 @@ class EE_API UILayout : public UIWidget { std::unordered_set mLayouts; bool mDirtyLayout; + bool mPacking; }; }} // namespace EE::UI diff --git a/include/eepp/ui/uilinearlayout.hpp b/include/eepp/ui/uilinearlayout.hpp index 8a8d828dc..1d4f15850 100644 --- a/include/eepp/ui/uilinearlayout.hpp +++ b/include/eepp/ui/uilinearlayout.hpp @@ -36,7 +36,6 @@ class EE_API UILinearLayout : public UILayout { protected: UIOrientation mOrientation; - bool mPacking; virtual Uint32 onMessage( const NodeMessage* Msg ); diff --git a/src/eepp/network/uri.cpp b/src/eepp/network/uri.cpp index 5b7e43f46..e4c9f7899 100644 --- a/src/eepp/network/uri.cpp +++ b/src/eepp/network/uri.cpp @@ -178,7 +178,7 @@ void URI::setUserInfo( const std::string& userInfo ) { decode( userInfo, mUserInfo ); } -void URI::getHost( const std::string& host ) { +void URI::setHost( const std::string& host ) { mHost = host; } diff --git a/src/eepp/ui/tools/uicolorpicker.cpp b/src/eepp/ui/tools/uicolorpicker.cpp index 220656b0c..2f0f10f61 100644 --- a/src/eepp/ui/tools/uicolorpicker.cpp +++ b/src/eepp/ui/tools/uicolorpicker.cpp @@ -347,8 +347,7 @@ Texture* UIColorPicker::createHueTexture( const Sizef& size ) { hsva.hsv.h = 360.f - 360.f * y / image.getHeight(); hsva.hsv.s = 1.f; hsva.hsv.v = 1.f; - Color color( Color::fromHsv( hsva ) ); - image.setPixel( 0, y, color ); + image.setPixel( 0, y, Color::fromHsv( hsva ) ); } TextureFactory* TF = TextureFactory::instance(); diff --git a/src/eepp/ui/uidropdownlist.cpp b/src/eepp/ui/uidropdownlist.cpp index d74d107d5..1ac89102d 100644 --- a/src/eepp/ui/uidropdownlist.cpp +++ b/src/eepp/ui/uidropdownlist.cpp @@ -46,6 +46,9 @@ UIDropDownList::UIDropDownList( const std::string& tag ) : mListBox->addEventListener( Event::KeyDown, cb::Make1( this, &UIDropDownList::onItemKeyDown ) ); mListBox->addEventListener( Event::OnControlClear, cb::Make1( this, &UIDropDownList::onControlClear ) ); + mListBox->addEventListener( Event::OnClose, [&]( const Event*) { + mListBox = NULL; + } ); } UIDropDownList::~UIDropDownList() { @@ -99,7 +102,7 @@ UIListBox* UIDropDownList::getListBox() const { } Uint32 UIDropDownList::onMouseUp( const Vector2i& Pos, const Uint32& Flags ) { - if ( mEnabled && mVisible && isMouseOver() ) { + if ( mEnabled && mVisible && isMouseOver() && NULL != mListBox ) { if ( Flags & EE_BUTTONS_WUWD ) { if ( Flags & EE_BUTTON_WUMASK ) { mListBox->selectPrev(); @@ -128,6 +131,9 @@ Uint32 UIDropDownList::onMouseClick( const Vector2i& Pos, const Uint32& Flags ) } void UIDropDownList::showList() { + if ( NULL == mListBox ) + return; + if ( !mListBox->isVisible() ) { if ( !mStyleConfig.PopUpToRoot ) mListBox->setParent( getWindowContainer() ); @@ -196,8 +202,9 @@ void UIDropDownList::setMaxNumVisibleItems( const Uint32& maxNumVisibleItems ) { if ( maxNumVisibleItems != mStyleConfig.MaxNumVisibleItems ) { mStyleConfig.MaxNumVisibleItems = maxNumVisibleItems; - mListBox->setSize( getSize().getWidth(), - mStyleConfig.MaxNumVisibleItems * mListBox->getRowHeight() ); + if ( NULL != mListBox ) + mListBox->setSize( getSize().getWidth(), + mStyleConfig.MaxNumVisibleItems * mListBox->getRowHeight() ); } } @@ -251,6 +258,9 @@ void UIDropDownList::onItemSelected( const Event* ) { } void UIDropDownList::show() { + if ( NULL == mListBox ) + return; + mListBox->setEnabled( true ); mListBox->setVisible( true ); @@ -264,6 +274,9 @@ void UIDropDownList::show() { } void UIDropDownList::hide() { + if ( NULL == mListBox ) + return; + if ( NULL != getUISceneNode() && getUISceneNode()->getUIThemeManager()->getDefaultEffectsEnabled() ) { mListBox->runAction( Actions::Sequence::New( @@ -293,13 +306,14 @@ Uint32 UIDropDownList::onMouseLeave( const Vector2i& position, const Uint32& fla } Uint32 UIDropDownList::onKeyDown( const KeyEvent& Event ) { - mListBox->onKeyDown( Event ); + if ( NULL != mListBox ) + mListBox->onKeyDown( Event ); return UITextInput::onKeyDown( Event ); } void UIDropDownList::destroyListBox() { - if ( !SceneManager::instance()->isShootingDown() ) { + if ( !SceneManager::instance()->isShootingDown() && NULL != mListBox ) { mListBox->close(); } } @@ -321,7 +335,10 @@ bool UIDropDownList::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::RowHeight: case PropertyId::VScrollMode: case PropertyId::HScrollMode: - return mListBox->applyProperty( attribute ); + if ( NULL != mListBox ) + return mListBox->applyProperty( attribute ); + else + return false; default: return UITextInput::applyProperty( attribute ); } @@ -345,16 +362,20 @@ std::string UIDropDownList::getPropertyString( const PropertyDefinition* propert case PropertyId::RowHeight: case PropertyId::VScrollMode: case PropertyId::HScrollMode: - return mListBox->getPropertyString( propertyDef, propertyIndex ); + if ( NULL != mListBox ) + return mListBox->getPropertyString( propertyDef, propertyIndex ); default: return UITextInput::getPropertyString( propertyDef, propertyIndex ); } + + return ""; } void UIDropDownList::loadFromXmlNode( const pugi::xml_node& node ) { beginAttributesTransaction(); - mListBox->loadItemsFromXmlNode( node ); + if ( NULL != mListBox ) + mListBox->loadItemsFromXmlNode( node ); UITextInput::loadFromXmlNode( node ); diff --git a/src/eepp/ui/uigridlayout.cpp b/src/eepp/ui/uigridlayout.cpp index b3131e4bf..38a98054b 100644 --- a/src/eepp/ui/uigridlayout.cpp +++ b/src/eepp/ui/uigridlayout.cpp @@ -107,6 +107,9 @@ UIGridLayout* UIGridLayout::setRowWeight( const Float& rowWeight ) { } void UIGridLayout::updateLayout() { + if ( mPacking ) + return; + mPacking = true; Sizef oldSize( getSize() ); if ( getParent()->isUINode() && !getParent()->asType()->ownsChildPosition() ) { @@ -191,6 +194,7 @@ void UIGridLayout::updateLayout() { invalidateDraw(); mDirtyLayout = false; + mPacking = false; } Uint32 UIGridLayout::onMessage( const NodeMessage* Msg ) { @@ -204,6 +208,11 @@ Uint32 UIGridLayout::onMessage( const NodeMessage* Msg ) { return 0; } +void UIGridLayout::onParentSizeChange( const Vector2f& size ) { + tryUpdateLayout(); + UILayout::onParentSizeChange( size ); +} + Sizef UIGridLayout::getTargetElementSize() const { return Sizef( mColumnMode == Size ? mColumnWidth : ( ( getLayoutHeightPolicy() == SizePolicy::WrapContent diff --git a/src/eepp/ui/uilayout.cpp b/src/eepp/ui/uilayout.cpp index 4cf4689a1..f655952ed 100644 --- a/src/eepp/ui/uilayout.cpp +++ b/src/eepp/ui/uilayout.cpp @@ -7,11 +7,12 @@ UILayout* UILayout::New() { return eeNew( UILayout, () ); } -UILayout::UILayout() : UIWidget( "layout" ), mDirtyLayout( false ) { +UILayout::UILayout() : UIWidget( "layout" ), mDirtyLayout( false ), mPacking( false ) { mNodeFlags |= NODE_FLAG_LAYOUT; } -UILayout::UILayout( const std::string& tag ) : UIWidget( tag ), mDirtyLayout( false ) { +UILayout::UILayout( const std::string& tag ) : + UIWidget( tag ), mDirtyLayout( false ), mPacking( false ) { mNodeFlags |= NODE_FLAG_LAYOUT; } @@ -42,7 +43,10 @@ void UILayout::onPaddingChange() { void UILayout::onParentSizeChange( const Vector2f& ) { UIWidget::onParentChange(); - tryUpdateLayout(); + if ( !getParent()->isLayout() ) { + mPacking = false; + tryUpdateLayout(); + } } void UILayout::onLayoutUpdate() { diff --git a/src/eepp/ui/uilinearlayout.cpp b/src/eepp/ui/uilinearlayout.cpp index 186f0a3b1..598cc90ec 100644 --- a/src/eepp/ui/uilinearlayout.cpp +++ b/src/eepp/ui/uilinearlayout.cpp @@ -17,7 +17,7 @@ UILinearLayout* UILinearLayout::NewHorizontal() { } UILinearLayout::UILinearLayout() : - UILayout( "linearlayout" ), mOrientation( UIOrientation::Vertical ), mPacking( false ) { + UILayout( "linearlayout" ), mOrientation( UIOrientation::Vertical ) { mFlags |= UI_OWNS_CHILDS_POSITION; clipEnable(); } diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index 8a117c718..33482a42f 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -40,7 +40,7 @@ UIListBox::UIListBox( const std::string& tag ) : mSmoothScroll( true ) { setFlags( UI_AUTO_PADDING ); - auto cb = [&]( const Event* event ) { containerResize(); }; + auto cb = [&]( const Event* ) { containerResize(); }; mContainer = eeNew( UIItemContainer, () ); mContainer->setParent( this ); @@ -84,7 +84,9 @@ UIListBox::UIListBox( const std::string& tag ) : UIListBox::UIListBox() : UIListBox( "listbox" ) {} -UIListBox::~UIListBox() {} +UIListBox::~UIListBox() { + onClose(); +} Uint32 UIListBox::getType() const { return UI_TYPE_LISTBOX; diff --git a/src/eepp/ui/uirelativelayout.cpp b/src/eepp/ui/uirelativelayout.cpp index 52fc26705..8d9873581 100644 --- a/src/eepp/ui/uirelativelayout.cpp +++ b/src/eepp/ui/uirelativelayout.cpp @@ -25,6 +25,9 @@ UIRelativeLayout* UIRelativeLayout::add( UIWidget* widget ) { } void UIRelativeLayout::updateLayout() { + if ( mPacking ) + return; + mPacking = true; if ( getParent()->isUINode() && !getParent()->asType()->ownsChildPosition() ) { setInternalPosition( Vector2f( mLayoutMargin.Left, mLayoutMargin.Top ) ); } @@ -64,6 +67,7 @@ void UIRelativeLayout::updateLayout() { } mDirtyLayout = false; + mPacking = false; } void UIRelativeLayout::fixChildPos( UIWidget* widget ) { diff --git a/src/examples/http_request/http_request.cpp b/src/examples/http_request/http_request.cpp index 4bd319716..bc2429f77 100644 --- a/src/examples/http_request/http_request.cpp +++ b/src/examples/http_request/http_request.cpp @@ -150,7 +150,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { totalBytes != currentBytes ) return true; tickElapsed.restart(); - double progress = currentBytes / static_cast( totalBytes ); + double progress = + totalBytes > 0 ? currentBytes / static_cast( totalBytes ) : 0; Time eta( elapsed.getElapsedTime() / progress - elapsed.getElapsedTime() ); int percent = static_cast( eefloor( progress * 100. ) ); std::string bytesProgress( String::format( @@ -194,7 +195,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { httpProxy = proxy.Get(); } - if ( httpProxy.find( "://" ) == std::string::npos ) { + if ( !httpProxy.empty() && httpProxy.find( "://" ) == std::string::npos ) { httpProxy = "http://" + httpProxy; }