diff --git a/include/eepp/ui/uicombobox.hpp b/include/eepp/ui/uicombobox.hpp index 75bb53778..f42a0c5f6 100644 --- a/include/eepp/ui/uicombobox.hpp +++ b/include/eepp/ui/uicombobox.hpp @@ -21,7 +21,7 @@ class EE_API UIComboBox : public UIWidget { UIDropDownList* getDropDownList() const { return mDropDownList; } - UINode* getButton() const { return mButton; } + UIWidget* getButton() const { return mButton; } const String& getText(); @@ -38,7 +38,7 @@ class EE_API UIComboBox : public UIWidget { protected: UIDropDownList* mDropDownList; - UINode* mButton; + UIWidget* mButton; UIComboBox(); diff --git a/include/eepp/ui/uidropdown.hpp b/include/eepp/ui/uidropdown.hpp index 06659d6db..faa91803b 100644 --- a/include/eepp/ui/uidropdown.hpp +++ b/include/eepp/ui/uidropdown.hpp @@ -51,15 +51,24 @@ class EE_API UIDropDown : public UITextInput { const Uint32& propertyIndex = 0 ) const; virtual std::vector getPropertiesImplemented() const; + void addRelatedWidget( UIWidget* widget ) { mRelatedWidgets.push_back( widget ); } + + void removeRelatedWidget( UIWidget* widget ) { + mRelatedWidgets.erase( + std::find( mRelatedWidgets.begin(), mRelatedWidgets.end(), widget ) ); + } + protected: StyleConfig mStyleConfig; UINode* mFriendNode{ nullptr }; + Uint64 mLastFocusLoss{ 0 }; + std::vector mRelatedWidgets; UIDropDown( const std::string& tag ); virtual UIWidget* getPopUpWidget() const; - void onPopUpFocusLoss( const Event* Event ); + virtual void onPopUpFocusLoss(); virtual void onItemSelected( const Event* Event ); virtual void show(); diff --git a/include/eepp/ui/uihelper.hpp b/include/eepp/ui/uihelper.hpp index 8f3d6d8a9..e967685fb 100644 --- a/include/eepp/ui/uihelper.hpp +++ b/include/eepp/ui/uihelper.hpp @@ -47,6 +47,7 @@ enum UIFlag : Int64 { UI_HTML_ELEMENT = ( 1ULL << 31 ), UI_CREATING_NODE = ( 1ULL << 32 ), UI_IGNORE_GLOBAL_CSS = ( 1ULL << 33 ), + UI_AUTO_SIZING = ( 1ULL << 34 ), }; enum UINodeType { diff --git a/src/eepp/ui/uicombobox.cpp b/src/eepp/ui/uicombobox.cpp index a89b7b3ff..67c0651d5 100644 --- a/src/eepp/ui/uicombobox.cpp +++ b/src/eepp/ui/uicombobox.cpp @@ -24,6 +24,7 @@ UIComboBox::UIComboBox() : UIWidget( "combobox" ), mDropDownList( NULL ), mButto mButton->setVisible( true ); mButton->setEnabled( true ); mButton->on( Event::OnSizeChange, [this]( const Event* ) { onSizeChange(); } ); + mDropDownList->addRelatedWidget( mButton ); applyDefaultTheme(); } diff --git a/src/eepp/ui/uidropdown.cpp b/src/eepp/ui/uidropdown.cpp index b19b1d97d..3ba5229d4 100644 --- a/src/eepp/ui/uidropdown.cpp +++ b/src/eepp/ui/uidropdown.cpp @@ -75,14 +75,21 @@ void UIDropDown::setFriendNode( UINode* friendNode ) { } void UIDropDown::onAutoSize() { + if ( mFlags & UI_AUTO_SIZING ) + return; + + mFlags |= UI_AUTO_SIZING; + Float max = eemax( PixelDensity::dpToPxI( getSkinSize().getHeight() ), mTextCache.getLineSpacing() ); - if ( mHeightPolicy == SizePolicy::WrapContent && mLayoutWeight == 0 ) { + if ( mHeightPolicy == SizePolicy::WrapContent ) { setInternalPixelsHeight( eeceil( max + mPaddingPx.Top + mPaddingPx.Bottom ) ); } else if ( ( mFlags & UI_AUTO_SIZE ) && 0 == getSize().getHeight() && max > 0 ) { setInternalPixelsHeight( eeceil( max ) ); } + + mFlags &= ~UI_AUTO_SIZING; } UIWidget* UIDropDown::getPopUpWidget() const { @@ -207,15 +214,21 @@ void UIDropDown::onItemKeyDown( const Event* Event ) { } } -void UIDropDown::onPopUpFocusLoss( const Event* ) { +void UIDropDown::onPopUpFocusLoss() { if ( NULL == getEventDispatcher() ) return; - bool frienIsFocus = NULL != mFriendNode && mFriendNode == getEventDispatcher()->getFocusNode(); + bool friendIsFocus = NULL != mFriendNode && mFriendNode == getEventDispatcher()->getFocusNode(); bool isChildFocus = isChild( getEventDispatcher()->getFocusNode() ); + bool isRelatedWidget = + std::find( mRelatedWidgets.begin(), mRelatedWidgets.end(), + getEventDispatcher()->getFocusNode() ) != mRelatedWidgets.end(); - if ( getEventDispatcher()->getFocusNode() != this && !isChildFocus && !frienIsFocus ) { + if ( getEventDispatcher()->getFocusNode() != this && !isChildFocus && !friendIsFocus && + !isRelatedWidget ) { hide(); + + mLastFocusLoss = Sys::getTicks(); } } diff --git a/src/eepp/ui/uidropdownlist.cpp b/src/eepp/ui/uidropdownlist.cpp index 294f808df..beee2b959 100644 --- a/src/eepp/ui/uidropdownlist.cpp +++ b/src/eepp/ui/uidropdownlist.cpp @@ -31,7 +31,7 @@ UIDropDownList::UIDropDownList( const std::string& tag ) : UIDropDown( tag ), mL // This will force to change the parent when shown, and force the CSS style reload. mListBox->setParent( this ); - mListBox->on( Event::OnWidgetFocusLoss, [this]( auto event ) { onPopUpFocusLoss( event ); } ); + mListBox->on( Event::OnWidgetFocusLoss, [this]( auto event ) { onPopUpFocusLoss(); } ); mListBox->on( Event::OnItemSelected, [this]( auto event ) { onItemSelected( event ); } ); mListBox->on( Event::OnItemClicked, [this]( auto event ) { onItemClicked( event ); } ); mListBox->on( Event::OnItemKeyDown, [this]( auto event ) { onItemKeyDown( event ); } ); @@ -99,16 +99,22 @@ Uint32 UIDropDownList::onKeyDown( const KeyEvent& Event ) { } void UIDropDownList::onAutoSize() { + if ( mFlags & UI_AUTO_SIZING ) + return; + UIDropDown::onAutoSize(); - Float max = eemax( PixelDensity::dpToPxI( getSkinSize().getWidth() ), - getTextWidth() ); + mFlags |= UI_AUTO_SIZING; - if ( mWidthPolicy == SizePolicy::WrapContent && mLayoutWeight == 0 ) { + Float max = eemax( PixelDensity::dpToPxI( getSkinSize().getWidth() ), getTextWidth() ); + + if ( mWidthPolicy == SizePolicy::WrapContent ) { setInternalPixelsWidth( eeceil( max + mPaddingPx.Left + mPaddingPx.Right ) ); } else if ( ( mFlags & UI_AUTO_SIZE ) && 0 == getSize().getWidth() && max > 0 ) { setInternalPixelsWidth( eeceil( max ) ); } + + mFlags &= ~UI_AUTO_SIZING; } UIDropDownList* UIDropDownList::showList() { diff --git a/src/eepp/ui/uidropdownmodellist.cpp b/src/eepp/ui/uidropdownmodellist.cpp index 8fc7e4b7e..880f9a7a1 100644 --- a/src/eepp/ui/uidropdownmodellist.cpp +++ b/src/eepp/ui/uidropdownmodellist.cpp @@ -29,7 +29,7 @@ UIDropDownModelList::UIDropDownModelList( const std::string& tag ) : mListView->setParent( this ); mListView->setSingleClickNavigation( true ); - mListView->on( Event::OnWidgetFocusLoss, [this]( auto event ) { onPopUpFocusLoss( event ); } ); + mListView->on( Event::OnWidgetFocusLoss, [this]( auto event ) { onPopUpFocusLoss(); } ); mListView->on( Event::OnModelEvent, [this]( auto event ) { onItemSelected( event ); } ); mListView->on( Event::KeyDown, [this]( auto event ) { onItemKeyDown( event ); } ); mListView->on( Event::OnClear, [this]( auto event ) { onWidgetClear( event ); } ); @@ -87,7 +87,7 @@ void UIDropDownModelList::setListView( UIAbstractTableView* listView ) { mListView->setVisible( false ); mListView->setParent( this ); - mListView->on( Event::OnWidgetFocusLoss, [this]( auto event ) { onPopUpFocusLoss( event ); } ); + mListView->on( Event::OnWidgetFocusLoss, [this]( auto event ) { onPopUpFocusLoss(); } ); mListView->on( Event::OnModelEvent, [this]( auto event ) { onItemSelected( event ); } ); mListView->on( Event::KeyDown, [this]( auto event ) { onItemKeyDown( event ); } ); mListView->on( Event::OnClear, [this]( auto event ) { onWidgetClear( event ); } ); diff --git a/src/eepp/ui/uifiledialog.cpp b/src/eepp/ui/uifiledialog.cpp index 0314c2b44..6e6b0701b 100644 --- a/src/eepp/ui/uifiledialog.cpp +++ b/src/eepp/ui/uifiledialog.cpp @@ -110,7 +110,7 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa mPath = UITextInput::New(); mPath->setText( mCurPath ) - ->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::WrapContent ) + ->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::WrapContent ) ->setLayoutWeight( 1 ) ->setParent( hLayout ); mPath->on( Event::OnPressEnter, [this]( auto event ) { onPressEnter( event ); } ); @@ -176,7 +176,7 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa mMultiView = UIMultiModelView::New(); mMultiView->setParent( linearLayout ); - mMultiView->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::WrapContent ) + mMultiView->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::Fixed ) ->setLayoutWeight( 1 ) ->setLayoutMargin( Rectf( 0, 0, 0, 4 ) ); mMultiView->on( Event::KeyDown, [this]( const Event* event ) { @@ -245,7 +245,7 @@ UIFileDialog::UIFileDialog( Uint32 dialogFlags, const std::string& defaultFilePa ->setEnabled( false ); mFile = UITextInput::New(); - mFile->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::MatchParent ) + mFile->setLayoutSizePolicy( SizePolicy::Fixed, SizePolicy::MatchParent ) ->setLayoutWeight( 1 ) ->setParent( hLayout ); mFile->setLayoutMargin( Rectf( 0, 0, 4, 0 ) );