From cbce68e2099e7d922560476ea7741197cb6d7e18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Fri, 24 Feb 2023 21:30:13 -0300 Subject: [PATCH] eepp: Don't instantiate a tooltip until it's really required by the widget (setting the tooltip text won't instantiate the tooltip). ecode: Closes SpartanJ/ecode#64 (Fix LSP rootPath initialization). --- include/eepp/ui/models/csspropertiesmodel.hpp | 3 +- include/eepp/ui/uiwidget.hpp | 3 +- src/eepp/ui/tools/uiwidgetinspector.cpp | 20 ++++++++++-- src/eepp/ui/uiwidget.cpp | 32 ++++++++----------- src/tools/ecode/globalsearchcontroller.cpp | 4 +-- .../ecode/plugins/lsp/lspclientplugin.cpp | 2 +- .../ecode/plugins/lsp/lspclientserver.cpp | 4 ++- 7 files changed, 41 insertions(+), 27 deletions(-) diff --git a/include/eepp/ui/models/csspropertiesmodel.hpp b/include/eepp/ui/models/csspropertiesmodel.hpp index c71e76891..7722cb54d 100644 --- a/include/eepp/ui/models/csspropertiesmodel.hpp +++ b/include/eepp/ui/models/csspropertiesmodel.hpp @@ -29,7 +29,8 @@ class CSSPropertiesModel final : public Model { } virtual Variant data( const ModelIndex& index, ModelRole role = ModelRole::Display ) const { - if ( mWidget == nullptr ) + eeASSERT( index.row() < (Int64)mData.size() ); + if ( mWidget == nullptr || index.row() >= (Int64)mData.size() ) return {}; PropertyId propId = mData[index.row()]; const PropertyDefinition* def = mProps.at( propId ); diff --git a/include/eepp/ui/uiwidget.hpp b/include/eepp/ui/uiwidget.hpp index b2d0ecd97..3ea3b9bc2 100644 --- a/include/eepp/ui/uiwidget.hpp +++ b/include/eepp/ui/uiwidget.hpp @@ -213,7 +213,7 @@ class EE_API UIWidget : public UINode { void reportStyleStateChangeRecursive( bool disableAnimations = false, bool forceReApplyStyles = false ); - void createTooltip(); + UITooltip* createTooltip(); bool isTabStop() const; @@ -251,6 +251,7 @@ class EE_API UIWidget : public UINode { std::string mSkinName; std::vector mClasses; std::vector mPseudoClasses; + String mTooltipText; explicit UIWidget( const std::string& tag ); diff --git a/src/eepp/ui/tools/uiwidgetinspector.cpp b/src/eepp/ui/tools/uiwidgetinspector.cpp index db19042f4..390209af7 100644 --- a/src/eepp/ui/tools/uiwidgetinspector.cpp +++ b/src/eepp/ui/tools/uiwidgetinspector.cpp @@ -29,10 +29,12 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc UIWidget* cont = sceneNode->loadLayoutFromString( R"xml( - + - + " + + @@ -104,6 +106,20 @@ UIWindow* UIWidgetInspector::create( UISceneNode* sceneNode, const Float& menuIc } } ); + cont->find( "widget-tree-search-collapse" ) + ->addEventListener( Event::MouseClick, [widgetTree]( const Event* event ) { + if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) { + widgetTree->collapseAll(); + } + } ); + + cont->find( "widget-tree-search-expand" ) + ->addEventListener( Event::MouseClick, [widgetTree]( const Event* event ) { + if ( event->asMouseEvent()->getFlags() & EE_BUTTON_LMASK ) { + widgetTree->expandAll(); + } + } ); + uiWin->center(); Uint32 winCb = sceneNode->addEventListener( Event::OnWindowAdded, [&, sceneNode, uiWin]( diff --git a/src/eepp/ui/uiwidget.cpp b/src/eepp/ui/uiwidget.cpp index 2608f42ee..8e2d0eea4 100644 --- a/src/eepp/ui/uiwidget.cpp +++ b/src/eepp/ui/uiwidget.cpp @@ -237,13 +237,16 @@ PositionPolicy UIWidget::getLayoutPositionPolicy() const { return mLayoutPositionPolicy; } -void UIWidget::createTooltip() { +UITooltip* UIWidget::createTooltip() { if ( NULL != mTooltip ) - return; + return mTooltip; mTooltip = UITooltip::New(); mTooltip->setVisible( false )->setEnabled( false ); mTooltip->setTooltipOf( this ); + if ( !mTooltipText.empty() ) + mTooltip->setText( mTooltipText ); + return mTooltip; } void UIWidget::onChildCountChange( Node* child, const bool& removed ) { @@ -256,7 +259,7 @@ void UIWidget::onChildCountChange( Node* child, const bool& removed ) { } } - if ( !isSceneNodeLoading() && mUISceneNode != NULL && mStyle != NULL ) { + if ( !isSceneNodeLoading() && mUISceneNode != NULL &&mStyle != NULL ) { // Childs that are structurally volatile can change states when a new // element is added to the parent. We pre-store them and invalidate its // state if that's the case. @@ -314,13 +317,14 @@ Uint32 UIWidget::onMouseOver( const Vector2i& position, const Uint32& flags ) { updateDebugData(); } - if ( mVisible && NULL != mTooltip && isTooltipEnabled() && !mTooltip->getText().empty() ) { + if ( mVisible && isTooltipEnabled() && !mTooltipText.empty() ) { UIThemeManager* themeManager = getUISceneNode()->getUIThemeManager(); if ( NULL == themeManager ) return UINode::onMouseOver( position, flags ); if ( Time::Zero == themeManager->getTooltipTimeToShow() ) { + createTooltip(); if ( !mTooltip->isVisible() || themeManager->getTooltipFollowMouse() ) mTooltip->setPosition( getTooltipPosition() ); mTooltip->show(); @@ -329,6 +333,7 @@ Uint32 UIWidget::onMouseOver( const Vector2i& position, const Uint32& flags ) { [&] { if ( isTooltipEnabled() && getEventDispatcher()->getMouseOverNode() == this ) { + createTooltip(); mTooltip->setPixelsPosition( getTooltipPosition() ); mTooltip->show(); } @@ -336,7 +341,7 @@ Uint32 UIWidget::onMouseOver( const Vector2i& position, const Uint32& flags ) { themeManager->getTooltipTimeToShow() ) ); } - if ( themeManager->getTooltipFollowMouse() ) { + if ( mTooltip && themeManager->getTooltipFollowMouse() ) { mTooltip->setPixelsPosition( getTooltipPosition() ); } } @@ -358,25 +363,14 @@ Uint32 UIWidget::onMouseLeave( const Vector2i& Pos, const Uint32& Flags ) { } UIWidget* UIWidget::setTooltipText( const String& text ) { - // If the tooltip wasn't created it will avoid to create a new one if the string is "" - if ( NULL == mTooltip ) { - if ( !text.empty() ) { - createTooltip(); - - mTooltip->setText( text ); - } - } else { // but if it's created, i will allow it + mTooltipText = text; + if ( mTooltip ) mTooltip->setText( text ); - } - return this; } String UIWidget::getTooltipText() { - if ( NULL != mTooltip ) - return mTooltip->getText(); - - return String(); + return mTooltipText; } void UIWidget::tooltipRemove() { diff --git a/src/tools/ecode/globalsearchcontroller.cpp b/src/tools/ecode/globalsearchcontroller.cpp index be3d0c5d7..d6639dac9 100644 --- a/src/tools/ecode/globalsearchcontroller.cpp +++ b/src/tools/ecode/globalsearchcontroller.cpp @@ -201,8 +201,8 @@ void GlobalSearchController::initGlobalSearchBar( - - + + diff --git a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp index b9ebdc910..787ae3d15 100644 --- a/src/tools/ecode/plugins/lsp/lspclientplugin.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientplugin.cpp @@ -910,7 +910,7 @@ void LSPClientPlugin::displayTooltip( UICodeEditor* editor, const LSPHover& resp const Vector2f& position ) { editor->setTooltipText( resp.contents[0].value ); // HACK: Gets the old font style to restore it when the tooltip is hidden - UITooltip* tooltip = editor->getTooltip(); + UITooltip* tooltip = editor->createTooltip(); if ( tooltip == nullptr ) return; mOldTextStyle = tooltip->getFontStyle(); diff --git a/src/tools/ecode/plugins/lsp/lspclientserver.cpp b/src/tools/ecode/plugins/lsp/lspclientserver.cpp index af3d7c91e..38d5adf6f 100644 --- a/src/tools/ecode/plugins/lsp/lspclientserver.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientserver.cpp @@ -942,7 +942,9 @@ void LSPClientServer::initialize() { { "capabilities", capabilities }, { "initializationOptions", mLSP.initializationOptions } }; - URI rootPath( String::startsWith( mRootPath, "file://" ) ? mRootPath : "file://" + mRootPath ); + URI rootPath( String::startsWith( mRootPath, "file://" ) && mRootPath != "file://" + ? mRootPath + : ( !mRootPath.empty() ? "file://" + mRootPath : "" ) ); if ( rootPath.empty() ) { if ( !mManager->getLSPWorkspaceFolder().uri.empty() ) { rootPath = mManager->getLSPWorkspaceFolder().uri;