From 59c5e72f4dec1fb1e7b1226bf8c628db8f219675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 10 Mar 2024 23:27:59 -0300 Subject: [PATCH] Add hint-display property to UITextInput. Minor refactor in ProjectDirectoryTree. --- docs/articles/cssspecification.md | 13 +++++++++ include/eepp/ui/css/propertydefinition.hpp | 1 + include/eepp/ui/uifontstyleconfig.hpp | 5 ---- include/eepp/ui/uihelper.hpp | 5 ++++ include/eepp/ui/uitextinput.hpp | 5 ++++ src/eepp/ui/css/stylesheetspecification.cpp | 1 + src/eepp/ui/uicombobox.cpp | 3 ++ src/eepp/ui/uispinbox.cpp | 3 ++ src/eepp/ui/uitextinput.cpp | 21 ++++++++++++-- src/tools/ecode/ecode.cpp | 4 ++- src/tools/ecode/projectdirectorytree.cpp | 32 ++++++++++++--------- src/tools/ecode/projectdirectorytree.hpp | 12 ++++---- 12 files changed, 78 insertions(+), 27 deletions(-) diff --git a/docs/articles/cssspecification.md b/docs/articles/cssspecification.md index 0ba74abc7..14c8601ab 100644 --- a/docs/articles/cssspecification.md +++ b/docs/articles/cssspecification.md @@ -752,6 +752,19 @@ Sets the hint font color. --- +### hint-display + +Sets the hint display mode. + +* Applicable to: EE::UI::UITextInput (TextInput) +* Data Type: [string-list](#string-list-data-type) +* Value List: + * `always`: Always visible + * `focus`: Visible on focus +* Default value: `always` + +--- + ### hint-font-family Sets the hint font family. diff --git a/include/eepp/ui/css/propertydefinition.hpp b/include/eepp/ui/css/propertydefinition.hpp index ed13d3080..0942aa768 100644 --- a/include/eepp/ui/css/propertydefinition.hpp +++ b/include/eepp/ui/css/propertydefinition.hpp @@ -165,6 +165,7 @@ enum class PropertyId : Uint32 { HintFontStyle = String::hash( "hint-font-style" ), HintStrokeWidth = String::hash( "hint-stroke-width" ), HintStrokeColor = String::hash( "hint-stroke-color" ), + HintDisplay = String::hash( "hint-display" ), Transition = String::hash( "transition" ), TransitionDelay = String::hash( "transition-delay" ), TransitionDuration = String::hash( "transition-duration" ), diff --git a/include/eepp/ui/uifontstyleconfig.hpp b/include/eepp/ui/uifontstyleconfig.hpp index ee69cee5b..2250f5e8e 100644 --- a/include/eepp/ui/uifontstyleconfig.hpp +++ b/include/eepp/ui/uifontstyleconfig.hpp @@ -26,11 +26,6 @@ class UIFontStyleConfig : public FontStyleConfig { UIFontStyleConfig( const FontStyleConfig& fontStyleConfig ) : FontStyleConfig( fontStyleConfig ) {} -// UIFontStyleConfig( const UIFontStyleConfig& fontStyleConfig ) : -// FontStyleConfig( fontStyleConfig ), -// FontSelectedColor( fontStyleConfig.FontSelectedColor ), -// FontSelectionBackColor( fontStyleConfig.FontSelectionBackColor ) {} - virtual void updateStyleConfig( const UIFontStyleConfig& fontStyleConfig ) { FontStyleConfig::updateFontStyleConfig( fontStyleConfig ); FontSelectedColor = fontStyleConfig.FontSelectedColor; diff --git a/include/eepp/ui/uihelper.hpp b/include/eepp/ui/uihelper.hpp index a22e78307..a47602470 100644 --- a/include/eepp/ui/uihelper.hpp +++ b/include/eepp/ui/uihelper.hpp @@ -132,6 +132,11 @@ static const Uint32 UI_NODE_DEFAULT_FLAGS = static const Uint32 UI_NODE_DEFAULT_FLAGS_CENTERED = UI_ANCHOR_LEFT | UI_ANCHOR_TOP | UI_HALIGN_CENTER | UI_VALIGN_CENTER; +enum class HintDisplay { + Always, + Focus +}; + }} // namespace EE::UI #endif diff --git a/include/eepp/ui/uitextinput.hpp b/include/eepp/ui/uitextinput.hpp index 4a34b8dfd..b281de7de 100644 --- a/include/eepp/ui/uitextinput.hpp +++ b/include/eepp/ui/uitextinput.hpp @@ -115,6 +115,10 @@ class EE_API UITextInput : public UITextView, public TextDocument::Client { void setEscapePastedText( bool escapePastedText ); + void setHintDisplay( HintDisplay ); + + HintDisplay getHintDisplay() const; + protected: TextDocument mDoc; Float mWaitCursorTime; @@ -136,6 +140,7 @@ class EE_API UITextInput : public UITextView, public TextDocument::Client { size_t mMenuIconSize{ 16 }; UIPopUpMenu* mCurrentMenu{ nullptr }; Uint64 mLastExecuteEventId{ 0 }; + HintDisplay mHintDisplay{ HintDisplay::Always }; void resetWaitCursor(); diff --git a/src/eepp/ui/css/stylesheetspecification.cpp b/src/eepp/ui/css/stylesheetspecification.cpp index e4dfefd24..1952a52d2 100644 --- a/src/eepp/ui/css/stylesheetspecification.cpp +++ b/src/eepp/ui/css/stylesheetspecification.cpp @@ -323,6 +323,7 @@ void StyleSheetSpecification::registerDefaultProperties() { .addAlias( "hintoutlinethickness" ); registerProperty( "hint-stroke-color", "" ).setType( PropertyType::Color ); registerProperty( "hint-font-family", "" ).addAlias( "hint-font-name" ); + registerProperty( "hint-display", "" ).setType( PropertyType::String ); registerProperty( "transition", "" ).setIndexed(); registerProperty( "transition-duration", "" ); diff --git a/src/eepp/ui/uicombobox.cpp b/src/eepp/ui/uicombobox.cpp index 295ca7767..4522d366c 100644 --- a/src/eepp/ui/uicombobox.cpp +++ b/src/eepp/ui/uicombobox.cpp @@ -171,6 +171,7 @@ bool UIComboBox::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::HintFontStyle: case PropertyId::HintStrokeWidth: case PropertyId::HintStrokeColor: + case PropertyId::HintDisplay: case PropertyId::PopUpToRoot: case PropertyId::MaxVisibleItems: case PropertyId::SelectedIndex: @@ -220,6 +221,7 @@ std::string UIComboBox::getPropertyString( const PropertyDefinition* propertyDef case PropertyId::HintFontStyle: case PropertyId::HintStrokeWidth: case PropertyId::HintStrokeColor: + case PropertyId::HintDisplay: case PropertyId::PopUpToRoot: case PropertyId::MaxVisibleItems: case PropertyId::SelectedIndex: @@ -264,6 +266,7 @@ std::vector UIComboBox::getPropertiesImplemented() const { PropertyId::HintFontStyle, PropertyId::HintStrokeWidth, PropertyId::HintStrokeColor, + PropertyId::HintDisplay, PropertyId::PopUpToRoot, PropertyId::MaxVisibleItems, PropertyId::SelectedIndex, diff --git a/src/eepp/ui/uispinbox.cpp b/src/eepp/ui/uispinbox.cpp index 70a52c9ea..d227818a5 100644 --- a/src/eepp/ui/uispinbox.cpp +++ b/src/eepp/ui/uispinbox.cpp @@ -306,6 +306,7 @@ std::string UISpinBox::getPropertyString( const PropertyDefinition* propertyDef, case PropertyId::HintFontStyle: case PropertyId::HintStrokeWidth: case PropertyId::HintStrokeColor: + case PropertyId::HintDisplay: case PropertyId::Color: case PropertyId::TextShadowColor: case PropertyId::TextShadowOffset: @@ -343,6 +344,7 @@ std::vector UISpinBox::getPropertiesImplemented() const { PropertyId::HintFontStyle, PropertyId::HintStrokeWidth, PropertyId::HintStrokeColor, + PropertyId::HintDisplay, PropertyId::Color, PropertyId::TextShadowColor, PropertyId::TextShadowOffset, @@ -394,6 +396,7 @@ bool UISpinBox::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::HintFontStyle: case PropertyId::HintStrokeWidth: case PropertyId::HintStrokeColor: + case PropertyId::HintDisplay: case PropertyId::Color: case PropertyId::TextShadowColor: case PropertyId::TextShadowOffset: diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index bbdb85b9f..55d8721c1 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -139,7 +139,8 @@ void UITextInput::draw() { mFontLineCenter + (Float)mScreenPosi.y + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, Vector2f::One, 0.f, getBlendMode() ); - } else if ( !mHintCache->getString().empty() ) { + } else if ( !mHintCache->getString().empty() && + ( mHintDisplay == HintDisplay::Always || hasFocus() ) ) { mHintCache->draw( (Float)mScreenPosi.x + (int)mRealAlignOffset.x + (int)mPaddingPx.Left, mFontLineCenter + (Float)mScreenPosi.y + (int)mRealAlignOffset.y + (int)mPaddingPx.Top, @@ -480,6 +481,8 @@ std::string UITextInput::getPropertyString( const PropertyDefinition* propertyDe return String::fromFloat( PixelDensity::dpToPx( getHintOutlineThickness() ), "px" ); case PropertyId::HintStrokeColor: return getHintOutlineColor().toHexString(); + case PropertyId::HintDisplay: + return mHintDisplay == HintDisplay::Always ? "always" : "focus"; default: return UITextView::getPropertyString( propertyDef, propertyIndex ); } @@ -500,7 +503,8 @@ std::vector UITextInput::getPropertiesImplemented() const { PropertyId::HintFontFamily, PropertyId::HintFontStyle, PropertyId::HintStrokeWidth, - PropertyId::HintStrokeColor }; + PropertyId::HintStrokeColor, + PropertyId::HintDisplay }; props.insert( props.end(), local.begin(), local.end() ); return props; } @@ -552,6 +556,11 @@ bool UITextInput::applyProperty( const StyleSheetProperty& attribute ) { case PropertyId::HintStrokeColor: setHintOutlineColor( attribute.asColor() ); break; + case PropertyId::HintDisplay: + setHintDisplay( String::toLower( attribute.asString() ) == "focus" + ? HintDisplay::Focus + : HintDisplay::Always ); + break; default: return UITextView::applyProperty( attribute ); } @@ -943,4 +952,12 @@ bool UITextInput::onCreateContextMenu( const Vector2i& position, const Uint32& f return true; } +void UITextInput::setHintDisplay( HintDisplay display ) { + mHintDisplay = display; +} + +HintDisplay UITextInput::getHintDisplay() const { + return mHintDisplay; +} + }} // namespace EE::UI diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 08fdd7336..869f8249d 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2735,7 +2735,9 @@ void App::removeFolderWatches() { void App::loadDirTree( const std::string& path ) { Clock* clock = eeNew( Clock, () ); mDirTreeReady = false; - mDirTree = std::make_shared( path, mThreadPool, this ); + mDirTree = std::make_shared( + path, mThreadPool, mPluginManager.get(), + [this]( auto path ) { loadFileFromPathOrFocus( path ); } ); Log::info( "Loading DirTree: %s", path ); mDirTree->scan( [this, clock]( ProjectDirectoryTree& dirTree ) { diff --git a/src/tools/ecode/projectdirectorytree.cpp b/src/tools/ecode/projectdirectorytree.cpp index 3508e9440..4472839a5 100644 --- a/src/tools/ecode/projectdirectorytree.cpp +++ b/src/tools/ecode/projectdirectorytree.cpp @@ -1,5 +1,4 @@ #include "projectdirectorytree.hpp" -#include "ecode.hpp" #include #include #include @@ -8,8 +7,9 @@ namespace ecode { #define PRJ_ALLOWED_PATH ".ecode/.prjallowed" -ProjectDirectoryTree::ProjectDirectoryTree( const std::string& path, - std::shared_ptr threadPool, App* app ) : +ProjectDirectoryTree::ProjectDirectoryTree( + const std::string& path, std::shared_ptr threadPool, PluginManager* pluginManager, + std::function loadFileFromPathOrFocusFn ) : mPath( path ), mPool( threadPool ), mRunning( false ), @@ -17,14 +17,15 @@ ProjectDirectoryTree::ProjectDirectoryTree( const std::string& path, mIgnoreHidden( true ), mClosing( false ), mIgnoreMatcher( path ), - mApp( app ) { + mPluginManager( pluginManager ), + mLoadFileFromPathOrFocusFn( std::move( loadFileFromPathOrFocusFn ) ) { FileSystem::dirAddSlashAtEnd( mPath ); } ProjectDirectoryTree::~ProjectDirectoryTree() { mClosing = true; - if ( mApp->getPluginManager() ) - mApp->getPluginManager()->unsubscribeMessages( "ProjectDirectoryTree" ); + if ( mPluginManager ) + mPluginManager->unsubscribeMessages( "ProjectDirectoryTree" ); Lock rl( mMatchingMutex ); if ( mRunning ) { mRunning = false; @@ -79,10 +80,13 @@ void ProjectDirectoryTree::scan( const ProjectDirectoryTree::ScanCompleteEvent& mAllowedMatcher.get() ); } mIsReady = true; - mApp->getPluginManager()->subscribeMessages( - "ProjectDirectoryTree", [this]( const PluginMessage& msg ) -> PluginRequestHandle { - return processMessage( msg ); - } ); + if ( mPluginManager ) { + mPluginManager->subscribeMessages( + "ProjectDirectoryTree", + [this]( const PluginMessage& msg ) -> PluginRequestHandle { + return processMessage( msg ); + } ); + } #if EE_PLATFORM == EE_PLATFORM_EMSCRIPTEN && !defined( __EMSCRIPTEN_PTHREADS__ ) if ( scanComplete ) scanComplete( *this ); @@ -530,9 +534,11 @@ PluginRequestHandle ProjectDirectoryTree::processMessage( const PluginMessage& m } if ( !matchesMap.empty() ) { - std::string filePath( matchesMap.begin()->second ); - mApp->getUISceneNode()->runOnMainThread( - [this, filePath]() { mApp->loadFileFromPathOrFocus( filePath ); } ); + if ( mPluginManager && mLoadFileFromPathOrFocusFn ) { + std::string filePath( matchesMap.begin()->second ); + mPluginManager->getUISceneNode()->runOnMainThread( + [this, filePath]() { mLoadFileFromPathOrFocusFn( filePath ); } ); + } } return PluginRequestHandle::broadcast(); diff --git a/src/tools/ecode/projectdirectorytree.hpp b/src/tools/ecode/projectdirectorytree.hpp index c47c5d797..11021672d 100644 --- a/src/tools/ecode/projectdirectorytree.hpp +++ b/src/tools/ecode/projectdirectorytree.hpp @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -23,8 +22,6 @@ using namespace EE::UI::Models; namespace ecode { -class App; - class FileListModel : public Model { public: FileListModel( const std::vector& files, const std::vector& names ) : @@ -97,8 +94,10 @@ class ProjectDirectoryTree { typedef std::function ScanCompleteEvent; typedef std::function )> MatchResultCb; - ProjectDirectoryTree( const std::string& path, std::shared_ptr threadPool, - App* app ); + ProjectDirectoryTree( + const std::string& path, std::shared_ptr threadPool, + PluginManager* pluginManager = nullptr, + std::function loadFileFromPathOrFocusFn = {} ); ~ProjectDirectoryTree(); @@ -161,7 +160,8 @@ class ProjectDirectoryTree { mutable Mutex mMatchingMutex; Mutex mDoneMutex; IgnoreMatcherManager mIgnoreMatcher; - App* mApp{ nullptr }; + PluginManager* mPluginManager{ nullptr }; + std::function mLoadFileFromPathOrFocusFn; void getDirectoryFiles( std::vector& files, std::vector& names, std::string directory, std::set currentDirs,