diff --git a/include/eepp/graphics/text.hpp b/include/eepp/graphics/text.hpp index f652c8de3..5c140015b 100644 --- a/include/eepp/graphics/text.hpp +++ b/include/eepp/graphics/text.hpp @@ -56,6 +56,8 @@ class EE_API Text { void setString( const String& string ); + void setString( String&& string ); + void setFont( Font* font ); void setFontSize( unsigned int size ); @@ -229,6 +231,8 @@ class EE_API Text { BlendMode effect, const OriginPoint& rotationCenter, const OriginPoint& scaleCenter, const std::vector& colors, const std::vector& outlineColors, const Color& backgroundColor ); + + void onNewString(); }; }} // namespace EE::Graphics diff --git a/include/eepp/ui/doc/syntaxcolorscheme.hpp b/include/eepp/ui/doc/syntaxcolorscheme.hpp index 8586042b5..a88d04f41 100644 --- a/include/eepp/ui/doc/syntaxcolorscheme.hpp +++ b/include/eepp/ui/doc/syntaxcolorscheme.hpp @@ -52,14 +52,14 @@ class EE_API SyntaxColorScheme { SyntaxColorScheme(); SyntaxColorScheme( const std::string& name, - const std::unordered_map& syntaxColors, - const std::unordered_map& editorColors ); + const UnorderedMap& syntaxColors, + const UnorderedMap& editorColors ); const Style& getSyntaxStyle( const std::string& type ) const; bool hasSyntaxStyle( const std::string& type ) const; - void setSyntaxStyles( const std::unordered_map& styles ); + void setSyntaxStyles( const UnorderedMap& styles ); void setSyntaxStyle( const std::string& type, const Style& style ); @@ -67,7 +67,7 @@ class EE_API SyntaxColorScheme { const Color& getEditorColor( const std::string& type ) const; - void setEditorSyntaxStyles( const std::unordered_map& styles ); + void setEditorSyntaxStyles( const UnorderedMap& styles ); void setEditorSyntaxStyle( const std::string& type, const Style& style ); @@ -77,9 +77,9 @@ class EE_API SyntaxColorScheme { protected: std::string mName; - std::unordered_map mSyntaxColors; - std::unordered_map mEditorColors; - mutable std::unordered_map mStyleCache; + UnorderedMap mSyntaxColors; + UnorderedMap mEditorColors; + mutable UnorderedMap mStyleCache; }; }}} // namespace EE::UI::Doc diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index 1cecb6342..9c97938a8 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -112,20 +112,31 @@ void Text::create( Font* font, const String& text, Color FontColor, Color FontSh invalidate(); } +void Text::onNewString() { + mColorsNeedUpdate = true; + mGeometryNeedUpdate = true; + mCachedWidthNeedUpdate = true; + mContainsColorEmoji = false; + if ( FontManager::instance()->getColorEmojiFont() != nullptr ) { + if ( mFontStyleConfig.Font->getType() == FontType::TTF ) { + FontTrueType* fontTrueType = static_cast( mFontStyleConfig.Font ); + if ( fontTrueType->isColorEmojiFont() || !fontTrueType->isEmojiFont() ) + mContainsColorEmoji = Font::containsEmojiCodePoint( mString ); + } + } +} + void Text::setString( const String& string ) { if ( mString != string ) { mString = string; - mColorsNeedUpdate = true; - mGeometryNeedUpdate = true; - mCachedWidthNeedUpdate = true; - mContainsColorEmoji = false; - if ( FontManager::instance()->getColorEmojiFont() != nullptr ) { - if ( mFontStyleConfig.Font->getType() == FontType::TTF ) { - FontTrueType* fontTrueType = static_cast( mFontStyleConfig.Font ); - if ( fontTrueType->isColorEmojiFont() || !fontTrueType->isEmojiFont() ) - mContainsColorEmoji = Font::containsEmojiCodePoint( string ); - } - } + onNewString(); + } +} + +void Text::setString( String&& string ) { + if ( mString != string ) { + mString = std::move( string ); + onNewString(); } } diff --git a/src/eepp/ui/doc/syntaxcolorscheme.cpp b/src/eepp/ui/doc/syntaxcolorscheme.cpp index 68fdb9f1e..bd943cfbe 100644 --- a/src/eepp/ui/doc/syntaxcolorscheme.cpp +++ b/src/eepp/ui/doc/syntaxcolorscheme.cpp @@ -84,7 +84,7 @@ SyntaxColorScheme SyntaxColorScheme::getDefault() { SyntaxColorScheme::Style parseStyle( const std::string& value, bool* colorWasSet = nullptr, - const std::unordered_map* syntaxColors = nullptr ) { + const UnorderedMap* syntaxColors = nullptr ) { auto values = String::split( value, ',' ); SyntaxColorScheme::Style style; bool colorSet = false; @@ -192,8 +192,8 @@ std::vector SyntaxColorScheme::loadFromPack( Pack* pack, SyntaxColorScheme::SyntaxColorScheme() {} SyntaxColorScheme::SyntaxColorScheme( const std::string& name, - const std::unordered_map& syntaxColors, - const std::unordered_map& editorColors ) : + const UnorderedMap& syntaxColors, + const UnorderedMap& editorColors ) : mName( name ), mSyntaxColors( syntaxColors ), mEditorColors( editorColors ) {} static const SyntaxColorScheme::Style StyleEmpty = { Color::Transparent }; @@ -230,7 +230,7 @@ bool SyntaxColorScheme::hasSyntaxStyle( const std::string& type ) const { return mSyntaxColors.find( type ) != mSyntaxColors.end(); } -void SyntaxColorScheme::setSyntaxStyles( const std::unordered_map& styles ) { +void SyntaxColorScheme::setSyntaxStyles( const UnorderedMap& styles ) { mSyntaxColors.insert( styles.begin(), styles.end() ); } @@ -279,7 +279,7 @@ const Color& SyntaxColorScheme::getEditorColor( const std::string& type ) const } void SyntaxColorScheme::setEditorSyntaxStyles( - const std::unordered_map& styles ) { + const UnorderedMap& styles ) { mEditorColors.insert( styles.begin(), styles.end() ); } diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index a066c8b1c..fd83f5136 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -616,8 +616,7 @@ void UICodeEditor::setShowIndentationGuides( bool showIndentationGuides ) { UICodeEditor* UICodeEditor::setFontSize( const Float& size ) { if ( mFontStyleConfig.CharacterSize != size ) { mFontStyleConfig.CharacterSize = - eeabs( size - (int)size ) == 0.5f || (int)size == size ? size - : eefloor( size ); + eeabs( size - (int)size ) == 0.5f || (int)size == size ? size : eefloor( size ); mFontSize = mFontStyleConfig.CharacterSize; udpateGlyphWidth(); invalidateDraw(); @@ -3050,6 +3049,7 @@ void UICodeEditor::drawLineNumbers( const std::pair& lineRange, primitives.drawRectangle( Rectf( screenStart, Sizef( lineNumberWidth, mSize.getHeight() ) ) ); TextRange selection = mDoc->getSelection( true ); Float lineOffset = getLineOffset(); + Text& line = mLineTextCache; for ( int i = lineRange.first; i <= lineRange.second; i++ ) { String pos; @@ -3059,11 +3059,12 @@ void UICodeEditor::drawLineNumbers( const std::pair& lineRange, } else { pos = String( String::toString( i + 1 ) ).padLeft( lineNumberDigits, ' ' ); } - Text line( std::move( pos ), mFont, fontSize ); line.setStyleConfig( mFontStyleConfig ); + line.setFontSize( fontSize ); line.setColor( ( i >= selection.start().line() && i <= selection.end().line() ) ? mLineNumberActiveFontColor : mLineNumberFontColor ); + line.setString( std::move( pos ) ); line.draw( screenStart.x + mLineNumberPaddingLeft, startScroll.y + lineHeight * (double)i + lineOffset ); }