diff --git a/.ecode/project_build.json b/.ecode/project_build.json index 1fd345583..ba696adfc 100644 --- a/.ecode/project_build.json +++ b/.ecode/project_build.json @@ -24,49 +24,16 @@ } ], "config": { - "clear_sys_env": false, - "enabled": true + "clear_sys_env": false }, "os": [ "linux" ], "output_parser": { "config": { + "preset": "generic", "relative_file_paths": true - }, - "error": [ - { - "pattern": "([^:]+):(%d+):(%d+):%s?[%w%s]*error:%s?(.*)", - "pattern_order": { - "col": 3, - "file": 1, - "line": 2, - "message": 4 - } - } - ], - "notice": [ - { - "pattern": "([^:]+):(%d+):(%d+):%s?[%w%s]*notice:%s?(.*)", - "pattern_order": { - "col": 3, - "file": 1, - "line": 2, - "message": 4 - } - } - ], - "warning": [ - { - "pattern": "([^:]+):(%d+):(%d+):%s?[%w%s]*warning:%s?(.*)", - "pattern_order": { - "col": 3, - "file": 1, - "line": 2, - "message": 4 - } - } - ] + } }, "var": { "build_dir": "${project_root}/make/${os}" diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index 33d8aa80c..d6028f2a4 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -372,6 +372,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { void setSyntaxDefinition( const SyntaxDefinition& definition ); + void resetSyntaxDefinition(); + const SyntaxDefinition& getSyntaxDefinition() const; const bool& getHorizontalScrollBarEnabled() const; diff --git a/include/eepp/ui/uilayout.hpp b/include/eepp/ui/uilayout.hpp index 447482117..b7d32ab63 100644 --- a/include/eepp/ui/uilayout.hpp +++ b/include/eepp/ui/uilayout.hpp @@ -24,6 +24,11 @@ class EE_API UILayout : public UIWidget { protected: friend class UISceneNode; + std::unordered_set mLayouts; + bool mDirtyLayout{ false }; + bool mPacking{ false }; + bool mGravityOwner{ false }; + explicit UILayout( const std::string& tag ); virtual void onSizeChange(); @@ -42,12 +47,11 @@ class EE_API UILayout : public UIWidget { void setLayoutDirty(); - std::unordered_set mLayouts; - bool mDirtyLayout{ false }; - bool mPacking{ false }; - bool mGravityOwner{ false }; - Sizef getSizeFromLayoutPolicy(); + + Float getMatchParentWidth() const; + + Float getMatchParentHeight() const; }; }} // namespace EE::UI diff --git a/include/eepp/ui/uinode.hpp b/include/eepp/ui/uinode.hpp index f311ac0ac..d4339fedd 100644 --- a/include/eepp/ui/uinode.hpp +++ b/include/eepp/ui/uinode.hpp @@ -270,7 +270,7 @@ class EE_API UINode : public Node { void setMinSize( const Sizef& size ); - const Sizef& getMinSize() const; + const Sizef& getCurMinSize() const; Rectf getLocalDpBounds() const; @@ -308,9 +308,13 @@ class EE_API UINode : public Node { void setMaxHeightEq( const std::string& maxHeightEq ); - Sizef getMinSize(); + Sizef getMinSize() const; - Sizef getMaxSize(); + Sizef getMaxSize() const; + + Sizef getMinSizePx() const; + + Sizef getMaxSizePx() const; Sizef fitMinMaxSizeDp( const Sizef& size ) const; diff --git a/include/eepp/ui/uistacklayout.hpp b/include/eepp/ui/uistacklayout.hpp index 97e03357c..ec2909a11 100644 --- a/include/eepp/ui/uistacklayout.hpp +++ b/include/eepp/ui/uistacklayout.hpp @@ -32,6 +32,9 @@ class EE_API UIStackLayout : public UILayout { protected: RowValign mRowValign{ RowValign::Bottom }; + Node* mParentRef{ nullptr }; + Uint32 mParentSizeChangeCb{ 0 }; + Uint32 mParentCloseCb{ 0 }; UIStackLayout(); @@ -44,6 +47,11 @@ class EE_API UIStackLayout : public UILayout { void setRowValign( const std::string& rowValign ); static std::string rowValignToStr( const RowValign& rowValign ); + + virtual void onParentChange(); + + void listenParent(); + }; }} // namespace EE::UI diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index d5375868f..bbf72cb27 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -934,7 +934,7 @@ 2 - %{buildDir}../../../bin/eepp-test-debug + %{buildDir}/../../bin/eepp-test-debug eepp-test-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -958,7 +958,7 @@ 2 - %{buildDir}../../../bin/eepp-test + %{buildDir}/../../bin/eepp-test eepp-test-release ProjectExplorer.CustomExecutableRunConfiguration @@ -982,7 +982,7 @@ 2 - %{buildDir}../../../bin/eepp-physics-demo-debug + %{buildDir}/../../bin/eepp-physics-demo-debug eepp-physics-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1006,7 +1006,7 @@ 2 - %{buildDir}../../../bin/eepp-http-request-debug + %{buildDir}/../../bin/eepp-http-request-debug eepp-http-request-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1054,7 +1054,7 @@ 2 - %{buildDir}../../../bin/eepp-TextureAtlasEditor-debug + %{buildDir}/../../bin/eepp-TextureAtlasEditor-debug eepp-TextureAtlasEditor-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1078,7 +1078,7 @@ 2 - %{buildDir}../../../bin/eepp-MapEditor-debug + %{buildDir}/../../bin/eepp-MapEditor-debug eepp-MapEditor-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1128,7 +1128,7 @@ 2 - %{buildDir}../../../bin/eepp-ui-hello-world-debug + %{buildDir}/../../bin/eepp-ui-hello-world-debug eepp-ui-hello-world-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1152,7 +1152,7 @@ 2 - %{buildDir}../../../bin/eepp-TexturePacker-debug + %{buildDir}/../../bin/eepp-TexturePacker-debug eepp-TexturePacker-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1177,7 +1177,7 @@ 2 - %{buildDir}../../../bin/eepp-ui-perf-test-debug + %{buildDir}/../../bin/eepp-ui-perf-test-debug eepp-ui-perf-test-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1225,7 +1225,7 @@ 2 - %{buildDir}../../../bin/eepp-empty-window-debug + %{buildDir}/../../bin/eepp-empty-window-debug eepp-empty-window-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1249,7 +1249,7 @@ 2 - %{buildDir}../../../bin/eterm-debug + %{buildDir}/../../bin/eterm-debug eterm-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1258,7 +1258,7 @@ false false false - %{buildDir}../../../bin/ + %{buildDir}/../../bin dwarf @@ -1273,7 +1273,7 @@ 2 - %{buildDir}../../../bin/eepp-empty-window + %{buildDir}/../../bin/eepp-empty-window eepp-empty-window-release ProjectExplorer.CustomExecutableRunConfiguration @@ -1297,7 +1297,7 @@ 2 - %{buildDir}../../../bin/eepp-external-shader-debug + %{buildDir}/../../bin/eepp-external-shader-debug eepp-external-shader-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1321,7 +1321,7 @@ 2 - %{buildDir}../../../bin/eepp-external-shader + %{buildDir}/../../bin/eepp-external-shader eepp-external-shader-release ProjectExplorer.CustomExecutableRunConfiguration @@ -1345,7 +1345,7 @@ 2 - %{buildDir}../../../bin/eepp-sound-debug + %{buildDir}/../../bin/eepp-sound-debug eepp-sound-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1369,7 +1369,7 @@ 2 - %{buildDir}../../../bin/eepp-sprites-debug + %{buildDir}/../../bin/eepp-sprites-debug eepp-sprites-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1393,7 +1393,7 @@ 2 - %{buildDir}../../../bin/eepp-fonts-debug + %{buildDir}/../../bin/eepp-fonts-debug eepp-fonts-debug ProjectExplorer.CustomExecutableRunConfiguration @@ -1417,7 +1417,7 @@ 2 - %{buildDir}../../../bin/eepp-vbo-fbo-batch-debug + %{buildDir}/../../bin/eepp-vbo-fbo-batch-debug eepp-vbo-fbo-batch-debug ProjectExplorer.CustomExecutableRunConfiguration diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index e4a8bbfa6..51aee1593 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -2198,6 +2198,18 @@ void UICodeEditor::setSyntaxDefinition( const SyntaxDefinition& definition ) { sendEvent( &event ); } +void UICodeEditor::resetSyntaxDefinition() { + std::string oldLang( mDoc->getSyntaxDefinition().getLanguageName() ); + mDoc->resetSyntax(); + if ( oldLang != mDoc->getSyntaxDefinition().getLanguageName() ) { + mDoc->getHighlighter()->reset(); + invalidateDraw(); + DocSyntaxDefEvent event( this, mDoc.get(), Event::OnDocumentSyntaxDefinitionChange, oldLang, + mDoc->getSyntaxDefinition().getLanguageName() ); + sendEvent( &event ); + } +} + const SyntaxDefinition& UICodeEditor::getSyntaxDefinition() const { return mDoc->getSyntaxDefinition(); } diff --git a/src/eepp/ui/uigridlayout.cpp b/src/eepp/ui/uigridlayout.cpp index 685453087..b600a3ac6 100644 --- a/src/eepp/ui/uigridlayout.cpp +++ b/src/eepp/ui/uigridlayout.cpp @@ -117,15 +117,11 @@ void UIGridLayout::updateLayout() { setInternalPosition( Vector2f( mLayoutMargin.Left, mLayoutMargin.Top ) ); } - if ( getLayoutWidthPolicy() == SizePolicy::MatchParent ) { - setInternalWidth( getParent()->getSize().getWidth() - mLayoutMargin.Left - - mLayoutMargin.Right ); - } + if ( getLayoutWidthPolicy() == SizePolicy::MatchParent ) + setInternalPixelsWidth( getMatchParentWidth() ); - if ( getLayoutHeightPolicy() == SizePolicy::MatchParent ) { - setInternalHeight( getParent()->getSize().getHeight() - mLayoutMargin.Top - - mLayoutMargin.Bottom ); - } + if ( getLayoutHeightPolicy() == SizePolicy::MatchParent ) + setInternalPixelsHeight( getMatchParentHeight() ); Node* ChildLoop = mChild; diff --git a/src/eepp/ui/uilayout.cpp b/src/eepp/ui/uilayout.cpp index 14e7faf7b..93ef8cce9 100644 --- a/src/eepp/ui/uilayout.cpp +++ b/src/eepp/ui/uilayout.cpp @@ -72,35 +72,60 @@ Sizef UILayout::getSizeFromLayoutPolicy() { Sizef size( getPixelsSize() ); if ( getLayoutWidthPolicy() == SizePolicy::MatchParent ) { - Float w = - getParent()->getPixelsSize().getWidth() - mLayoutMarginPx.Left - mLayoutMarginPx.Right; - - if ( getParent()->isType( UI_TYPE_LAYOUT ) ) { - UILayout* pLay = static_cast( getParent() ); - w = w - pLay->getPixelsPadding().Left - pLay->getPixelsPadding().Right; - } + Float w = getMatchParentWidth(); if ( (int)w != (int)getPixelsSize().getWidth() ) size.setWidth( w ); } if ( getLayoutHeightPolicy() == SizePolicy::MatchParent ) { - Float h = - getParent()->getPixelsSize().getHeight() - mLayoutMarginPx.Top - mLayoutMarginPx.Bottom; + Float h = getMatchParentHeight(); - if ( getParent()->isType( UI_TYPE_LAYOUT ) ) { - UILayout* pLay = static_cast( getParent() ); - h = h - pLay->getPixelsPadding().Top - pLay->getPixelsPadding().Bottom; - } - - if ( (int)h != (int)getPixelsSize().getHeight() ) { + if ( (int)h != (int)getPixelsSize().getHeight() ) size.setHeight( h ); - } } return size; } +Float UILayout::getMatchParentWidth() const { + Rectf padding = Rectf(); + + if ( getParent()->isWidget() ) + padding = static_cast( getParent() )->getPixelsPadding(); + + Float width = getParent()->getPixelsSize().getWidth() - mLayoutMarginPx.Left - + mLayoutMarginPx.Right - padding.Left - padding.Right; + + if ( !mMaxWidthEq.empty() ) { + Float maxWidth( getMaxSizePx().getWidth() - mLayoutMarginPx.Left - mLayoutMarginPx.Right - + padding.Left - padding.Right ); + if ( maxWidth > 0 && maxWidth < width ) + width = maxWidth; + } + + return eemax( 0.f, width ); +} + +Float UILayout::getMatchParentHeight() const { + Rectf padding = Rectf(); + + if ( getParent()->isWidget() ) + padding = static_cast( getParent() )->getPadding(); + + Float height = getParent()->getPixelsSize().getHeight() - mLayoutMarginPx.Top - + mLayoutMarginPx.Bottom - padding.Top - padding.Bottom; + + if ( !mMaxHeightEq.empty() ) { + Float maxHeight( getMaxSizePx().getHeight() - mLayoutMarginPx.Left - mLayoutMarginPx.Right - + padding.Left - padding.Right ); + if ( maxHeight > 0 && maxHeight < height ) + height = maxHeight; + } + + return eemax( 0.f, height ); +} + bool UILayout::isGravityOwner() const { return mGravityOwner; } diff --git a/src/eepp/ui/uilinearlayout.cpp b/src/eepp/ui/uilinearlayout.cpp index dbc176117..c844847ea 100644 --- a/src/eepp/ui/uilinearlayout.cpp +++ b/src/eepp/ui/uilinearlayout.cpp @@ -163,40 +163,25 @@ void UILinearLayout::packVertical() { Sizef size( getPixelsSize() ); if ( getLayoutWidthPolicy() == SizePolicy::MatchParent && 0 == getLayoutWeight() ) { - Float w = - getParent()->getPixelsSize().getWidth() - mLayoutMarginPx.Left - mLayoutMarginPx.Right; - - if ( getParent()->isType( UI_TYPE_LAYOUT ) ) { - UILayout* pLay = static_cast( getParent() ); - w = w - pLay->getPixelsPadding().Left - pLay->getPixelsPadding().Right; - } + Float w = getMatchParentWidth(); if ( (int)w != (int)getPixelsSize().getWidth() ) { sizeChanged = true; - size.setWidth( w ); } } if ( getLayoutHeightPolicy() == SizePolicy::MatchParent ) { - Float h = - getParent()->getPixelsSize().getHeight() - mLayoutMarginPx.Top - mLayoutMarginPx.Bottom; - - if ( getParent()->isType( UI_TYPE_LAYOUT ) ) { - UILayout* pLay = static_cast( getParent() ); - h = h - pLay->getPixelsPadding().Top - pLay->getPixelsPadding().Bottom; - } + Float h = getMatchParentHeight(); if ( (int)h != (int)getPixelsSize().getHeight() ) { sizeChanged = true; - size.setHeight( h ); } } - if ( sizeChanged ) { + if ( sizeChanged ) setInternalPixelsSize( size ); - } applyWidthPolicyOnChilds(); @@ -305,40 +290,25 @@ void UILinearLayout::packHorizontal() { Sizef size( getPixelsSize() ); if ( getLayoutWidthPolicy() == SizePolicy::MatchParent ) { - Float w = - getParent()->getPixelsSize().getWidth() - mLayoutMarginPx.Left - mLayoutMarginPx.Right; - - if ( getParent()->isType( UI_TYPE_LAYOUT ) ) { - UILayout* pLay = static_cast( getParent() ); - w = w - pLay->getPixelsPadding().Left - pLay->getPixelsPadding().Right; - } + Float w = getMatchParentWidth(); if ( (int)w != (int)getPixelsSize().getWidth() ) { sizeChanged = true; - size.setWidth( w ); } } if ( getLayoutHeightPolicy() == SizePolicy::MatchParent && 0 == getLayoutWeight() ) { - Float h = - getParent()->getPixelsSize().getHeight() - mLayoutMarginPx.Top - mLayoutMarginPx.Bottom; - - if ( getParent()->isType( UI_TYPE_LAYOUT ) ) { - UILayout* pLay = static_cast( getParent() ); - h = h - pLay->getPixelsPadding().Top - pLay->getPixelsPadding().Bottom; - } + Float h = getMatchParentHeight(); if ( (int)h != (int)getPixelsSize().getHeight() ) { sizeChanged = true; - size.setHeight( h ); } } - if ( sizeChanged ) { + if ( sizeChanged ) setInternalPixelsSize( size ); - } applyHeightPolicyOnChilds(); @@ -409,14 +379,7 @@ void UILinearLayout::packHorizontal() { notifyLayoutAttrChangeParent(); } } else if ( getLayoutWidthPolicy() == SizePolicy::MatchParent ) { - int w = - getParent()->getPixelsSize().getWidth() - mLayoutMarginPx.Left - mLayoutMarginPx.Right; - - if ( getParent()->isType( UI_TYPE_LAYOUT ) ) { - UILayout* pLay = static_cast( getParent() ); - w = w - pLay->getPixelsPadding().Left - pLay->getPixelsPadding().Right; - } - + int w = getMatchParentWidth(); if ( w != (int)getPixelsSize().getWidth() ) setInternalPixelsWidth( w ); } diff --git a/src/eepp/ui/uilistbox.cpp b/src/eepp/ui/uilistbox.cpp index 67c7b9d11..7d2571ec6 100644 --- a/src/eepp/ui/uilistbox.cpp +++ b/src/eepp/ui/uilistbox.cpp @@ -1141,10 +1141,8 @@ void UIListBox::loadItemsFromXmlNode( const pugi::xml_node& node ) { std::vector items; for ( pugi::xml_node item = node.child( "item" ); item; item = item.next_sibling( "item" ) ) { - std::string data = item.text().as_string(); - - if ( !data.empty() ) - items.push_back( getTranslatorString( data ) ); + std::string data( item.text().as_string() ); + items.push_back( getTranslatorString( data ) ); } if ( !items.empty() ) { diff --git a/src/eepp/ui/uinode.cpp b/src/eepp/ui/uinode.cpp index bac6de883..18de2effb 100644 --- a/src/eepp/ui/uinode.cpp +++ b/src/eepp/ui/uinode.cpp @@ -260,7 +260,7 @@ void UINode::setMinHeight( const Float& height ) { } } -const Sizef& UINode::getMinSize() const { +const Sizef& UINode::getCurMinSize() const { return mMinSize; } @@ -347,7 +347,7 @@ void UINode::setMaxHeightEq( const std::string& maxHeightEq ) { } } -Sizef UINode::getMaxSize() { +Sizef UINode::getMaxSize() const { Sizef s; if ( !mMaxWidthEq.empty() ) { @@ -365,14 +365,26 @@ Sizef UINode::getMaxSize() { return s; } -Sizef UINode::getMinSize() { +Sizef UINode::getMaxSizePx() const { Sizef s; - if ( s.x < mMinSize.x ) - s.x = mMinSize.x; + if ( !mMaxWidthEq.empty() ) { + Float length = + lengthFromValue( mMaxWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); + s.x = eemax( s.x, length ); + } - if ( s.y < mMinSize.y ) - s.y = mMinSize.y; + if ( !mMaxHeightEq.empty() ) { + Float length = + lengthFromValue( mMaxHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); + s.y = eemax( s.y, length ); + } + + return s; +} + +Sizef UINode::getMinSize() const { + Sizef s; if ( !mMinWidthEq.empty() ) { Float length = @@ -385,6 +397,25 @@ Sizef UINode::getMinSize() { lengthFromValueAsDp( mMinHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); s.y = eemax( s.y, length ); } + + return s; +} + +Sizef UINode::getMinSizePx() const { + Sizef s; + + if ( !mMinWidthEq.empty() ) { + Float length = + lengthFromValue( mMinWidthEq, CSS::PropertyRelativeTarget::ContainingBlockWidth ); + s.x = eemax( s.x, length ); + } + + if ( !mMinHeightEq.empty() ) { + Float length = + lengthFromValue( mMinHeightEq, CSS::PropertyRelativeTarget::ContainingBlockHeight ); + s.y = eemax( s.y, length ); + } + return s; } diff --git a/src/eepp/ui/uirelativelayout.cpp b/src/eepp/ui/uirelativelayout.cpp index aec875098..6f944a898 100644 --- a/src/eepp/ui/uirelativelayout.cpp +++ b/src/eepp/ui/uirelativelayout.cpp @@ -32,48 +32,16 @@ void UIRelativeLayout::updateLayout() { if ( mPacking ) return; mPacking = true; + if ( getParent()->isUINode() && ( !getParent()->asType()->ownsChildPosition() || isGravityOwner() ) ) { setInternalPosition( Vector2f( mLayoutMargin.Left, mLayoutMargin.Top ) ); } - if ( getLayoutWidthPolicy() == SizePolicy::MatchParent ) { - Rectf padding = Rectf(); + Sizef s( getSizeFromLayoutPolicy() ); - if ( getParent()->isWidget() ) - padding = static_cast( getParent() )->getPadding(); - - Float width = getParent()->getSize().getWidth() - mLayoutMargin.Left - mLayoutMargin.Right - - padding.Left - padding.Right; - - if ( !mMaxWidthEq.empty() || !mMaxHeightEq.empty() ) { - Float maxWidth( getMaxSize().getWidth() - mLayoutMargin.Left - mLayoutMargin.Right - - padding.Left - padding.Right ); - if ( maxWidth > 0 && maxWidth < width ) - width = maxWidth; - } - - setInternalWidth( width ); - } - - if ( getLayoutHeightPolicy() == SizePolicy::MatchParent ) { - Rectf padding = Rectf(); - - if ( getParent()->isWidget() ) - padding = static_cast( getParent() )->getPadding(); - - Float height = getParent()->getSize().getHeight() - mLayoutMargin.Top - - mLayoutMargin.Bottom - padding.Top - padding.Bottom; - - if ( !mMaxHeightEq.empty() || !mMaxHeightEq.empty() ) { - Float maxHeight( getMaxSize().getHeight() - mLayoutMargin.Left - mLayoutMargin.Right - - padding.Left - padding.Right ); - if ( maxHeight > 0 && maxHeight < height ) - height = maxHeight; - } - - setInternalHeight( height ); - } + if ( s != getPixelsSize() ) + setInternalPixelsSize( s ); Node* child = mChild; diff --git a/src/eepp/ui/uistacklayout.cpp b/src/eepp/ui/uistacklayout.cpp index 48cd0453f..8bb4b8152 100644 --- a/src/eepp/ui/uistacklayout.cpp +++ b/src/eepp/ui/uistacklayout.cpp @@ -1,3 +1,4 @@ +#include #include namespace EE { namespace UI { @@ -16,6 +17,7 @@ UIStackLayout::UIStackLayout( const std::string& tag ) : UILayout( tag ) { mFlags |= UI_OWNS_CHILDS_POSITION; setClipType( ClipType::ContentBox ); setGravity( UI_HALIGN_LEFT | UI_VALIGN_TOP ); + listenParent(); } Uint32 UIStackLayout::getType() const { @@ -100,6 +102,28 @@ std::string UIStackLayout::rowValignToStr( const RowValign& rowValign ) { } } +void UIStackLayout::listenParent() { + if ( mParentRef ) { + mParentRef->removeEventListener( mParentSizeChangeCb ); + mParentRef->removeEventListener( mParentCloseCb ); + } + + mParentRef = getParent(); + mParentRef->addEventListener( Event::OnSizeChange, [this]( const Event* ) { + if ( getLayoutWidthPolicy() == SizePolicy::WrapContent && + getUISceneNode()->isUpdatingLayouts() && getParent()->getPixelsSize().getWidth() > 0 && + mSize.x != getMatchParentWidth() ) { + runOnMainThread( [this]() { setLayoutDirty(); } ); + } + } ); + mParentRef->addEventListener( Event::OnClose, + [this]( const Event* ) { mParentRef = nullptr; } ); +} + +void UIStackLayout::onParentChange() { + listenParent(); +} + std::string UIStackLayout::getPropertyString( const PropertyDefinition* propertyDef, const Uint32& propertyIndex ) const { if ( NULL == propertyDef ) @@ -164,10 +188,13 @@ void UIStackLayout::updateLayout() { return; mPacking = true; - Sizef size( getPixelsSize() ); - Sizef nsize( getSizeFromLayoutPolicy() ); - if ( size != nsize ) - setInternalPixelsSize( nsize ); + Sizef size( getSizeFromLayoutPolicy() ); + + if ( getLayoutWidthPolicy() == SizePolicy::WrapContent ) + size.x = getMatchParentWidth(); + + if ( size != getPixelsSize() ) + setInternalPixelsSize( size ); applySizePolicyOnChilds(); @@ -291,6 +318,13 @@ void UIStackLayout::updateLayout() { maxY += line.maxY; } + if ( getLayoutWidthPolicy() == SizePolicy::WrapContent && curX < mSize.getWidth() && + ( ( lines.size() == 1 && !lines[0].nodes.empty() ) || + ( lines.size() == 2 && lines[1].nodes.empty() ) ) ) { + setInternalPixelsWidth( curX ); + notifyLayoutAttrChangeParent(); + } + if ( getLayoutHeightPolicy() == SizePolicy::WrapContent ) { if ( totHeight != (int)getPixelsSize().getHeight() ) { setInternalPixelsHeight( totHeight ); diff --git a/src/thirdparty/efsw b/src/thirdparty/efsw index 5d0fa1b41..527ddca9a 160000 --- a/src/thirdparty/efsw +++ b/src/thirdparty/efsw @@ -1 +1 @@ -Subproject commit 5d0fa1b4103ddb091ab418566e6220b2faec7260 +Subproject commit 527ddca9a95d6d3a01975849e7e09cdec7752921 diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index aef885a5c..6b804b42d 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -3715,6 +3715,7 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe if ( terminal && file.empty() && fileToOpen.empty() ) { showSidePanel( false ); + showStatusBar( false ); mTerminalManager->createNewTerminal(); } else { initProjectTreeView( file ); @@ -3796,7 +3797,8 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { parser, "css", "Sets the path for a custom stylesheet to load at the start of the application", { "css" } ); - args::Flag terminal( parser, "terminal", "Open a new terminal", { 't', "terminal" } ); + args::Flag terminal( parser, "terminal", "Open a new terminal / Open ecode in terminal mode", + { 't', "terminal" } ); args::MapFlag logLevel( parser, "log-level", "The level of details that the application will emmit logs.", { 'l', "log-level" }, Log::getMapFlag(), Log::getDefaultLogLevel() ); diff --git a/src/tools/ecode/projectbuild.cpp b/src/tools/ecode/projectbuild.cpp index 519c4b5ef..4f3ce0118 100644 --- a/src/tools/ecode/projectbuild.cpp +++ b/src/tools/ecode/projectbuild.cpp @@ -275,7 +275,6 @@ bool ProjectBuildManager::load() { } if ( buildObj.contains( "config" ) && buildObj["config"].is_object() ) { - b.mConfig.enabled = buildObj.value( "enabled", true ); b.mConfig.clearSysEnv = buildObj.value( "clear_sys_env", false ); } @@ -298,6 +297,7 @@ bool ProjectBuildManager::load() { bstep.cmd = step.value( "command", "" ); bstep.args = step.value( "args", "" ); bstep.workingDir = step.value( "working_dir", "" ); + bstep.enabled = step.value( "enabled", true ); b.mBuild.emplace_back( std::move( bstep ) ); } } @@ -309,6 +309,7 @@ bool ProjectBuildManager::load() { bstep.cmd = step.value( "command", "" ); bstep.args = step.value( "args", "" ); bstep.workingDir = step.value( "working_dir", "" ); + bstep.enabled = step.value( "enabled", true ); b.mClean.emplace_back( std::move( bstep ) ); } } @@ -318,11 +319,23 @@ bool ProjectBuildManager::load() { ProjectBuildOutputParser outputParser; + if ( op.contains( "config" ) ) { + const auto& config = op["config"]; + outputParser.mRelativeFilePaths = config.value( "relative_file_paths", true ); + + if ( config.contains( "preset" ) ) { + auto preset = config.value( "preset", "" ); + if ( !preset.empty() ) { + auto presets = ProjectBuildOutputParser::getPresets(); + if ( presets.find( preset ) != presets.end() ) { + outputParser = presets[preset]; + } + } + } + } + for ( const auto& item : op.items() ) { - if ( item.key() == "config" ) { - const auto& config = item.value(); - outputParser.mRelativeFilePaths = config.value( "relative_file_paths", true ); - } else { + if ( item.key() != "config" ) { auto typeStr = String::toLower( item.key() ); if ( !isValidType( typeStr ) ) @@ -463,8 +476,12 @@ void ProjectBuildManager::runBuild( const std::string& buildName, const std::str } int c = 0; + int totSteps = 0; + for ( const auto& cmd : res.cmds ) + totSteps += cmd.enabled ? 1 : 0; + for ( const auto& cmd : res.cmds ) { - int progress = c > 0 ? c / (Float)res.cmds.size() : 0; + int progress = c > 0 ? c / (Float)totSteps : 0; mProcess = std::make_unique(); auto options = Process::SearchUserPath | Process::NoWindow | Process::CombinedStdoutStderr; std::unordered_map env; @@ -478,6 +495,12 @@ void ProjectBuildManager::runBuild( const std::string& buildName, const std::str } else { env = cmd.envs; } + + if ( !cmd.enabled ) { + c++; + continue; + } + if ( mProcess->create( cmd.cmd, cmd.args, options, env, cmd.workingDir ) ) { if ( progressFn ) progressFn( progress, @@ -681,4 +704,33 @@ void ProjectBuildManager::updateBuildType() { } ); } +std::map ProjectBuildOutputParser::getPresets() { + std::map presets; + presets["generic"] = getGeneric(); + return presets; +} + +ProjectBuildOutputParser ProjectBuildOutputParser::getGeneric() { + ProjectBuildOutputParser parser; + + ProjectBuildOutputParserConfig cfg; + cfg.pattern = "([^:]+):(%d+):(%d+):%s?[%w%s]*error:%s?(.*)"; + cfg.patternOrder.col = 3; + cfg.patternOrder.file = 1; + cfg.patternOrder.line = 2; + cfg.patternOrder.message = 4; + cfg.type = ProjectOutputParserTypes::Error; + parser.mConfig.push_back( cfg ); + + cfg.pattern = "([^:]+):(%d+):(%d+):%s?[%w%s]*warning:%s?(.*)"; + cfg.type = ProjectOutputParserTypes::Warning; + parser.mConfig.push_back( cfg ); + + cfg.pattern = "([^:]+):(%d+):(%d+):%s?[%w%s]*notice:%s?(.*)"; + cfg.type = ProjectOutputParserTypes::Notice; + parser.mConfig.emplace_back( cfg ); + + return parser; +} + } // namespace ecode diff --git a/src/tools/ecode/projectbuild.hpp b/src/tools/ecode/projectbuild.hpp index f1933f164..f4c89cd0f 100644 --- a/src/tools/ecode/projectbuild.hpp +++ b/src/tools/ecode/projectbuild.hpp @@ -84,6 +84,7 @@ struct ProjectBuildStep { std::string cmd; std::string args; std::string workingDir; + bool enabled{ true }; }; using ProjectBuildSteps = std::vector; @@ -109,6 +110,10 @@ struct ProjectBuildOutputParserConfig { class ProjectBuildOutputParser { public: + static std::map getPresets(); + + static ProjectBuildOutputParser getGeneric(); + const std::vector& getConfig() const { return mConfig; } bool useRelativeFilePaths() const { return mRelativeFilePaths; } diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index 3d12a37f3..fd236473e 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -94,9 +94,19 @@ void SettingsMenu::createSettingsMenu( App* app ) { colorSchemeMenu->setSubMenu( newMenu ); } } ); + + mProjectMenu = UIPopUpMenu::New(); + mSettingsMenu + ->addSubMenu( i18n( "folder_settings", "Folder/Project Settings" ), + findIcon( "folder-user" ), mProjectMenu ) + ->setId( "project_settings" ); + mSettingsMenu ->addSubMenu( i18n( "document", "Document" ), findIcon( "file" ), createDocumentMenu() ) ->setId( "doc-menu" ); + + createProjectMenu(); + mSettingsMenu ->addSubMenu( i18n( "terminal", "Terminal" ), findIcon( "terminal" ), createTerminalMenu() ) ->setId( "term-menu" ); @@ -542,14 +552,14 @@ UIMenu* SettingsMenu::createDocumentMenu() { mDocMenu->addSeparator(); // **** PROJECT SETTINGS **** - mProjectMenu = UIPopUpMenu::New(); - mProjectMenu + mProjectDocMenu = UIPopUpMenu::New(); + mProjectDocMenu ->addCheckBox( i18n( "use_global_settings", "Use Global Settings" ), mApp->getProjectDocConfig().useGlobalSettings ) ->setOnShouldCloseCb( shouldCloseCb ) ->setId( "use_global_settings" ); - mProjectMenu + mProjectDocMenu ->addCheckBox( i18n( "auto_detect_indent_type_and_width", "Auto Detect Indent Type & Width" ), mApp->getConfig().doc.autoDetectIndentType ) @@ -563,7 +573,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { tabTypeMenuProject->addRadioButton( i18n( "spaces", "Spaces" ) ) ->setActive( mApp->getProjectDocConfig().doc.indentSpaces ) ->setId( "spaces" ); - mProjectMenu + mProjectDocMenu ->addSubMenu( i18n( "indentation_type", "Indentation Type" ), nullptr, tabTypeMenuProject ) ->setId( "indent_type" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); @@ -579,7 +589,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { mApp->getProjectDocConfig().doc.indentWidth == w ) ->setId( String::format( "indent_width_%d", w ) ) ->setData( w ); - mProjectMenu + mProjectDocMenu ->addSubMenu( i18n( "indent_width", "Indent Width" ), nullptr, indentWidthMenuProject ) ->setId( "indent_width" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); @@ -594,7 +604,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->addRadioButton( String::toString( w ), mApp->getProjectDocConfig().doc.tabWidth == w ) ->setId( String::format( "tab_width_%d", w ) ) ->setData( w ); - mProjectMenu->addSubMenu( i18n( "tab_width", "Tab Width" ), nullptr, tabWidthMenuProject ) + mProjectDocMenu->addSubMenu( i18n( "tab_width", "Tab Width" ), nullptr, tabWidthMenuProject ) ->setId( "tab_width" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); tabWidthMenuProject->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { @@ -615,7 +625,7 @@ UIMenu* SettingsMenu::createDocumentMenu() { ->addRadioButton( "Macintosh (CR)", mApp->getProjectDocConfig().doc.lineEndings == TextDocument::LineEnding::CR ) ->setId( "CR" ); - mProjectMenu + mProjectDocMenu ->addSubMenu( i18n( "line_endings", "Line Endings" ), nullptr, lineEndingsProjectMenu ) ->setId( "line_endings" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); @@ -624,30 +634,30 @@ UIMenu* SettingsMenu::createDocumentMenu() { TextDocument::stringToLineEnding( event->getNode()->asType()->getId() ); } ); - mProjectMenu + mProjectDocMenu ->addCheckBox( i18n( "trim_trailing_whitespaces", "Trim Trailing Whitespaces" ), mApp->getConfig().doc.trimTrailingWhitespaces ) ->setId( "trim_whitespaces" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); - mProjectMenu + mProjectDocMenu ->addCheckBox( i18n( "force_new_line_at_end_of_file", "Force New Line at End of File" ), mApp->getConfig().doc.forceNewLineAtEndOfFile ) ->setId( "force_nl" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); - mProjectMenu + mProjectDocMenu ->addCheckBox( i18n( "write_unicode_bom", "Write Unicode BOM" ), mApp->getConfig().doc.writeUnicodeBOM ) ->setId( "write_bom" ) ->setEnabled( !mApp->getProjectDocConfig().useGlobalSettings ); - mProjectMenu->addSeparator(); + mProjectDocMenu->addSeparator(); - mProjectMenu->add( i18n( "line_breaking_column", "Line Breaking Column" ) ) + mProjectDocMenu->add( i18n( "line_breaking_column", "Line Breaking Column" ) ) ->setId( "line_breaking_column" ); - mProjectMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + mProjectDocMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { if ( !mSplitter->curEditorExistsAndFocused() || event->getNode()->isType( UI_TYPE_MENU_SEPARATOR ) || event->getNode()->isType( UI_TYPE_MENUSUBMENU ) ) @@ -694,8 +704,8 @@ UIMenu* SettingsMenu::createDocumentMenu() { mDocMenu ->addSubMenu( i18n( "folder_project_settings", "Folder/Project Settings" ), - findIcon( "folder-user" ), mProjectMenu ) - ->setId( "project_settings" ); + findIcon( "folder-user" ), mProjectDocMenu ) + ->setId( "project_doc_settings" ); return mDocMenu; } @@ -1351,11 +1361,18 @@ void SettingsMenu::toggleSettingsMenu() { } void SettingsMenu::updateProjectSettingsMenu() { - mDocMenu->getItemId( "project_settings" )->setEnabled( !mApp->getCurrentProject().empty() ); + mSettingsMenu->getItemId( "project_settings" ) + ->setEnabled( !mApp->getCurrentProject().empty() ); - for ( size_t i = 0; i < mProjectMenu->getCount(); i++ ) { - mProjectMenu->getItem( i )->setEnabled( !mApp->getCurrentProject().empty() && - !mApp->getProjectDocConfig().useGlobalSettings ); + mProjectMenu->getItemId( "h_as_cpp" ) + ->asType() + ->setActive( mApp->getProjectDocConfig().hAsCPP ); + + mDocMenu->getItemId( "project_doc_settings" )->setEnabled( !mApp->getCurrentProject().empty() ); + + for ( size_t i = 0; i < mProjectDocMenu->getCount(); i++ ) { + mProjectDocMenu->getItem( i )->setEnabled( !mApp->getCurrentProject().empty() && + !mApp->getProjectDocConfig().useGlobalSettings ); } mSplitter->forEachEditor( [&]( UICodeEditor* editor ) { @@ -1365,23 +1382,23 @@ void SettingsMenu::updateProjectSettingsMenu() { : mApp->getConfig().doc.lineBreakingColumn ); } ); - mProjectMenu->getItemId( "trim_whitespaces" ) + mProjectDocMenu->getItemId( "trim_whitespaces" ) ->asType() ->setActive( mApp->getProjectDocConfig().doc.trimTrailingWhitespaces ); - mProjectMenu->getItemId( "force_nl" ) + mProjectDocMenu->getItemId( "force_nl" ) ->asType() ->setActive( mApp->getProjectDocConfig().doc.forceNewLineAtEndOfFile ); - mProjectMenu->getItemId( "write_bom" ) + mProjectDocMenu->getItemId( "write_bom" ) ->asType() ->setActive( mApp->getProjectDocConfig().doc.writeUnicodeBOM ); - mProjectMenu->getItemId( "auto_indent" ) + mProjectDocMenu->getItemId( "auto_indent" ) ->asType() ->setActive( mApp->getProjectDocConfig().doc.autoDetectIndentType ); - auto* curIndent = mProjectMenu->find( "indent_width" ) + auto* curIndent = mProjectDocMenu->find( "indent_width" ) ->asType() ->getSubMenu() ->find( String::format( "indent_width_%d", @@ -1390,28 +1407,28 @@ void SettingsMenu::updateProjectSettingsMenu() { if ( curIndent ) curIndent->asType()->setActive( true ); - mProjectMenu->find( "indent_type" ) + mProjectDocMenu->find( "indent_type" ) ->asType() ->getSubMenu() ->find( !mApp->getProjectDocConfig().doc.indentSpaces ? "tabs" : "spaces" ) ->asType() ->setActive( true ); - mProjectMenu->find( "tab_width" ) + mProjectDocMenu->find( "tab_width" ) ->asType() ->getSubMenu() ->find( String::format( "tab_width_%d", mApp->getProjectDocConfig().doc.tabWidth ) ) ->asType() ->setActive( true ); - mProjectMenu->find( "line_endings" ) + mProjectDocMenu->find( "line_endings" ) ->asType() ->getSubMenu() ->find( TextDocument::lineEndingToString( mApp->getProjectDocConfig().doc.lineEndings ) ) ->asType() ->setActive( true ); - mProjectMenu->getItemId( "use_global_settings" ) + mProjectDocMenu->getItemId( "use_global_settings" ) ->setEnabled( true ) ->asType() ->setActive( mApp->getProjectDocConfig().useGlobalSettings ); @@ -1797,4 +1814,39 @@ void SettingsMenu::deleteFileDialog( const FileInfo& file ) { msgBox->showWhenReady(); } +void SettingsMenu::createProjectMenu() { + mProjectMenu + ->addSubMenu( i18n( "documents_settings", "Documents Settings" ), findIcon( "file" ), + mProjectDocMenu ) + ->setId( "project_doc_settings" ); + + mProjectMenu + ->addCheckBox( i18n( "h_as_cpp", "Treat .h files as C++ code." ), + mApp->getProjectDocConfig().hAsCPP ) + ->setId( "h_as_cpp" ); + + mProjectMenu->addEventListener( Event::OnItemClicked, [&]( const Event* event ) { + if ( event->getNode()->isType( UI_TYPE_MENU_SEPARATOR ) || + event->getNode()->isType( UI_TYPE_MENUSUBMENU ) ) + return; + const String& id = event->getNode()->getId(); + + if ( event->getNode()->isType( UI_TYPE_MENUCHECKBOX ) ) { + UIMenuCheckBox* item = event->getNode()->asType(); + if ( "h_as_cpp" == id ) { + mApp->getProjectDocConfig().hAsCPP = item->isActive(); + mApp->getSplitter()->forEachEditor( [this]( UICodeEditor* editor ) { + editor->getDocument().setHAsCpp( mApp->getProjectDocConfig().hAsCPP ); + if ( editor->getDocument().getFileInfo().getExtension() == "h" ) { + editor->resetSyntaxDefinition(); + if ( mSplitter->isCurEditor( editor ) ) + updateCurrentFileType(); + } + } ); + updateProjectSettingsMenu(); + } + } + } ); +} + } // namespace ecode diff --git a/src/tools/ecode/settingsmenu.hpp b/src/tools/ecode/settingsmenu.hpp index e937c8c3f..d8217e294 100644 --- a/src/tools/ecode/settingsmenu.hpp +++ b/src/tools/ecode/settingsmenu.hpp @@ -68,6 +68,8 @@ class SettingsMenu { void deleteFileDialog( const FileInfo& file ); + void createProjectMenu(); + protected: App* mApp{ nullptr }; UIPopUpMenu* mSettingsMenu{ nullptr }; @@ -82,12 +84,12 @@ class SettingsMenu { UIPopUpMenu* mRendererMenu{ nullptr }; UIPopUpMenu* mToolsMenu{ nullptr }; UIPopUpMenu* mProjectTreeMenu{ nullptr }; + UIPopUpMenu* mProjectDocMenu{ nullptr }; UIPopUpMenu* mProjectMenu{ nullptr }; std::vector mFileTypeMenues; Float mFileTypeMenuesCreatedWithHeight{ 0 }; std::vector mColorSchemeMenues; Float mColorSchemeMenuesCreatedWithHeight{ 0 }; - }; } // namespace ecode diff --git a/src/tools/eterm/eterm.cpp b/src/tools/eterm/eterm.cpp index 64fc39462..93d65ce3b 100644 --- a/src/tools/eterm/eterm.cpp +++ b/src/tools/eterm/eterm.cpp @@ -104,13 +104,12 @@ void mainLoop() { if ( terminal ) termNeedsUpdate = !terminal->update(); - if ( terminal && ( benchmarkMode || terminal->isDirty() ) && !termNeedsUpdate ) { - if ( lastRender.getElapsedTime() >= frameTime ) { - lastRender.restart(); - win->clear(); - terminal->draw(); - win->display(); - } + if ( terminal && ( benchmarkMode || terminal->isDirty() ) && + ( !termNeedsUpdate || lastRender.getElapsedTime() >= frameTime ) ) { + lastRender.restart(); + win->clear(); + terminal->draw(); + win->display(); } else if ( !benchmarkMode && !termNeedsUpdate ) { win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) ); }