From b2fff897bef5dba4c955fb92b9962c7979913127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 16 Feb 2024 18:27:18 -0300 Subject: [PATCH] Revert round() of UIDrawable position. Re-subscribe on model change for Git tree view styling --- include/eepp/scene/event.hpp | 1 + src/eepp/ui/abstract/uiabstractview.cpp | 1 + src/eepp/ui/uinodedrawable.cpp | 17 ++++++++++++++++- src/tools/ecode/plugins/git/gitplugin.cpp | 19 +++++++++++++++++-- src/tools/ecode/plugins/git/gitplugin.hpp | 1 + src/tools/ecode/settingsmenu.cpp | 5 +++-- 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/include/eepp/scene/event.hpp b/include/eepp/scene/event.hpp index 0c4808ce7..5650038ae 100644 --- a/include/eepp/scene/event.hpp +++ b/include/eepp/scene/event.hpp @@ -110,6 +110,7 @@ class EE_API Event { OnCopy, OnRowCreated, OnScrollChange, + OnModelChanged, NoEvent = eeINDEX_NOT_FOUND }; diff --git a/src/eepp/ui/abstract/uiabstractview.cpp b/src/eepp/ui/abstract/uiabstractview.cpp index 457b82796..691b13ff0 100644 --- a/src/eepp/ui/abstract/uiabstractview.cpp +++ b/src/eepp/ui/abstract/uiabstractview.cpp @@ -121,6 +121,7 @@ void UIAbstractView::setModel( const std::shared_ptr& model ) { if ( mModel ) mModel->registerView( this ); onModelUpdate( Model::InvalidateAllIndexes ); + sendCommonEvent( Event::OnModelChanged ); } void UIAbstractView::modelUpdate( unsigned flags ) { diff --git a/src/eepp/ui/uinodedrawable.cpp b/src/eepp/ui/uinodedrawable.cpp index cf196c9c0..cdde11d6e 100644 --- a/src/eepp/ui/uinodedrawable.cpp +++ b/src/eepp/ui/uinodedrawable.cpp @@ -547,6 +547,9 @@ Vector2f UINodeDrawable::LayerDrawable::calcPosition( const std::string& positio if ( pos.size() == 1 ) pos.push_back( "center" ); + bool needsRoundingX = false; + bool needsRoundingY = false; + if ( pos.size() == 2 ) { int xFloatIndex = 0; int yFloatIndex = 1; @@ -562,6 +565,9 @@ Vector2f UINodeDrawable::LayerDrawable::calcPosition( const std::string& positio xl, mContainer->getOwner()->getPixelsSize().getWidth() - mDrawableSize.getWidth() ); position.y = mContainer->getOwner()->convertLength( yl, mContainer->getOwner()->getPixelsSize().getHeight() - mDrawableSize.getHeight() ); + + needsRoundingX = pos[xFloatIndex][pos[xFloatIndex].size() - 1] == '%'; + needsRoundingY = pos[yFloatIndex][pos[yFloatIndex].size() - 1] == '%'; } else if ( pos.size() > 2 ) { if ( pos.size() == 3 ) { pos.push_back( "0dp" ); @@ -593,9 +599,18 @@ Vector2f UINodeDrawable::LayerDrawable::calcPosition( const std::string& positio Float yl2Val = mContainer->getOwner()->convertLength( yl2, mContainer->getOwner()->getPixelsSize().getWidth() - mDrawableSize.getHeight() ); position.y += ( pos[yFloatIndex] == "bottom" ) ? -yl2Val : yl2Val; + + needsRoundingX = pos[xFloatIndex][pos[xFloatIndex].size() - 1] == '%'; + needsRoundingY = pos[yFloatIndex][pos[yFloatIndex].size() - 1] == '%'; } - return position.round(); + if ( needsRoundingX ) + position.x = Math::round( position.x ); + + if ( needsRoundingY ) + position.y = Math::round( position.y ); + + return position; } const std::string& UINodeDrawable::LayerDrawable::getSizeEq() const { diff --git a/src/tools/ecode/plugins/git/gitplugin.cpp b/src/tools/ecode/plugins/git/gitplugin.cpp index c5f011eb4..c5f814360 100644 --- a/src/tools/ecode/plugins/git/gitplugin.cpp +++ b/src/tools/ecode/plugins/git/gitplugin.cpp @@ -239,6 +239,11 @@ void GitPlugin::initModelStyler() { if ( !projectView || !projectView->getModel() ) return; + if ( mModelChangedId == 0 ) { + mModelChangedId = + projectView->on( Event::OnModelChanged, [this]( auto ) { initModelStyler(); } ); + } + mModelStylerId = projectView->getModel()->subsribeModelStyler( [this]( const ModelIndex& index, const void* data ) -> Variant { static const char* STYLE_MODIFIED = "git_highlight_style"; @@ -258,10 +263,20 @@ void GitPlugin::endModelStyler() { if ( !mFileTreeHighlightChanges || mModelStylerId == 0 || !SceneManager::existsSingleton() || SceneManager::instance()->isShuttingDown() ) return; + auto projectView = getUISceneNode()->getRoot()->find( "project_view" ); - if ( !projectView || !projectView->getModel() ) + if ( !projectView ) return; - projectView->getModel()->unsubsribeModelStyler( mModelStylerId ); + + if ( mModelChangedId ) { + projectView->removeEventListener( mModelChangedId ); + mModelChangedId = 0; + } + + if ( projectView->getModel() ) { + projectView->getModel()->unsubsribeModelStyler( mModelStylerId ); + mModelStylerId = 0; + } } void GitPlugin::updateUINow( bool force ) { diff --git a/src/tools/ecode/plugins/git/gitplugin.hpp b/src/tools/ecode/plugins/git/gitplugin.hpp index 9f84472f7..008b091a8 100644 --- a/src/tools/ecode/plugins/git/gitplugin.hpp +++ b/src/tools/ecode/plugins/git/gitplugin.hpp @@ -130,6 +130,7 @@ class GitPlugin : public PluginBase { }; std::optional mStatusCustomTokenizer; std::optional mTooltipCustomSyntaxDef; + Uint32 mModelChangedId{ 0 }; Uint32 mModelStylerId{ 0 }; GitPlugin( PluginManager* pluginManager, bool sync ); diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index 2d566540a..b8539275d 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -1343,9 +1343,10 @@ UIPopUpMenu* SettingsMenu::createToolsMenu() { UIMenu* SettingsMenu::createHelpMenu() { UIPopUpMenu* helpMenu = UIPopUpMenu::New(); - helpMenu->add( i18n( "ecode_source", "ecode source code..." ), findIcon( "github" ) ) + helpMenu->add( i18n( "ecode_source_ellipsis", "ecode source code..." ), findIcon( "github" ) ) ->setId( "ecode-source" ); - helpMenu->add( i18n( "check_for_updates", "Check for Updates..." ), findIcon( "refresh" ) ) + helpMenu + ->add( i18n( "check_for_updates_ellipsis", "Check for Updates..." ), findIcon( "refresh" ) ) ->setId( "check-for-updates" ); helpMenu->add( i18n( "about_ecode", "About ecode..." ), findIcon( "ecode" ) ) ->setId( "about-ecode" );