From 2fb07e09aa95ec8b5fe0b8699bd0417e8d0ff3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 25 May 2022 21:34:09 -0300 Subject: [PATCH] Minor clean up. --- include/eepp/graphics/text.hpp | 2 +- include/eepp/system/translator.hpp | 14 ++--- include/eepp/ui/uicodeeditor.hpp | 6 +- include/eepp/ui/uitextedit.hpp | 2 +- include/eepp/ui/uitextinput.hpp | 2 +- include/eepp/ui/uitextview.hpp | 2 +- src/eepp/graphics/text.cpp | 2 +- src/eepp/system/translator.cpp | 44 +++++++++----- src/eepp/ui/doc/syntaxdefinitionmanager.cpp | 38 +++++++----- src/eepp/ui/doc/syntaxtokenizer.cpp | 5 +- src/eepp/ui/uicodeeditor.cpp | 58 +++++++++---------- src/eepp/ui/uitextedit.cpp | 6 +- src/eepp/ui/uitextinput.cpp | 2 +- src/eepp/ui/uitextview.cpp | 8 +-- src/examples/fonts/fonts.cpp | 2 +- .../ecode/modules/linter/lintermodule.cpp | 29 ++++++++-- 16 files changed, 133 insertions(+), 89 deletions(-) diff --git a/include/eepp/graphics/text.hpp b/include/eepp/graphics/text.hpp index 41af48b40..b6be4f6da 100644 --- a/include/eepp/graphics/text.hpp +++ b/include/eepp/graphics/text.hpp @@ -130,7 +130,7 @@ class EE_API Text { /** Shrink the String to a max width * @param MaxWidth The maximum possible width */ - void shrinkText( const Uint32& maxWidth ); + void wrapText( const Uint32& maxWidth ); /** Invalidates the color cache */ void invalidateColors(); diff --git a/include/eepp/system/translator.hpp b/include/eepp/system/translator.hpp index c66c3d624..c16c7acf6 100644 --- a/include/eepp/system/translator.hpp +++ b/include/eepp/system/translator.hpp @@ -16,17 +16,17 @@ class EE_API Translator { public: Translator( const std::locale& locale = std::locale() ); - void loadFromDirectory( std::string dirPath, std::string ext = "xml" ); + bool loadFromDirectory( std::string dirPath, std::string ext = "xml" ); - void loadFromFile( const std::string& path, std::string lang = "" ); + bool loadFromFile( const std::string& path, std::string lang = "" ); - void loadFromString( const std::string& string, std::string lang = "" ); + bool loadFromString( const std::string& string, std::string lang = "" ); - void loadFromMemory( const void* buffer, Int32 bufferSize, std::string lang = "" ); + bool loadFromMemory( const void* buffer, Int32 bufferSize, std::string lang = "" ); - void loadFromStream( IOStream& stream, std::string lang = "" ); + bool loadFromStream( IOStream& stream, std::string lang = "" ); - void loadFromPack( Pack* pack, const std::string& FilePackPath, std::string lang = "" ); + bool loadFromPack( Pack* pack, const std::string& FilePackPath, std::string lang = "" ); String getString( const std::string& key, const String& defaultValue = String() ); @@ -50,7 +50,7 @@ class EE_API Translator { std::string mCurrentLanguage; StringLocaleDictionary mDictionary; - void loadNodes( pugi::xml_node node, std::string lang = "" ); + bool loadNodes( pugi::xml_node node, std::string lang = "" ); }; }} // namespace EE::System diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index 60c21caf9..f7ac6b31d 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -643,15 +643,15 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { virtual void drawMatchingBrackets( const Vector2f& startScroll, const Float& lineHeight ); + virtual void drawLineText( const Int64& line, Vector2f position, const Float& fontSize, + const Float& lineHeight ); + virtual void drawSelectionMatch( const std::pair& lineRange, const Vector2f& startScroll, const Float& lineHeight ); virtual void drawWordMatch( const String& text, const std::pair& lineRange, const Vector2f& startScroll, const Float& lineHeight ); - virtual void drawLineText( const Int64& index, Vector2f position, const Float& fontSize, - const Float& lineHeight ); - virtual void drawWhitespaces( const std::pair& lineRange, const Vector2f& startScroll, const Float& lineHeight ); diff --git a/include/eepp/ui/uitextedit.hpp b/include/eepp/ui/uitextedit.hpp index 050d1ae31..337c2ebb2 100644 --- a/include/eepp/ui/uitextedit.hpp +++ b/include/eepp/ui/uitextedit.hpp @@ -20,7 +20,7 @@ class EE_API UITextEdit : public UICodeEditor { virtual void setTheme( UITheme* Theme ); - virtual void shrinkText( const Float& maxWidth ); + virtual void wrapText( const Float& maxWidth ); String getText() const; diff --git a/include/eepp/ui/uitextinput.hpp b/include/eepp/ui/uitextinput.hpp index 651c3cef6..75543f234 100644 --- a/include/eepp/ui/uitextinput.hpp +++ b/include/eepp/ui/uitextinput.hpp @@ -44,7 +44,7 @@ class EE_API UITextInput : public UITextView, public TextDocument::Client { virtual UITextView* setText( const String& text ); - virtual void shrinkText( const Uint32& MaxWidth ); + virtual void wrapText( const Uint32& MaxWidth ); UITextInput* setMaxLength( const Uint32& maxLength ); diff --git a/include/eepp/ui/uitextview.hpp b/include/eepp/ui/uitextview.hpp index b11c1cd85..f7fda55e2 100644 --- a/include/eepp/ui/uitextview.hpp +++ b/include/eepp/ui/uitextview.hpp @@ -73,7 +73,7 @@ class EE_API UITextView : public UIWidget { Vector2f getAlignOffset() const; - virtual void shrinkText( const Uint32& MaxWidth ); + virtual void wrapText( const Uint32& maxWidth ); bool isTextSelectionEnabled() const; diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index de888d5c5..77841874f 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -445,7 +445,7 @@ void Text::getWidthInfo() { mNumLines = Lines; } -void Text::shrinkText( const Uint32& maxWidth ) { +void Text::wrapText( const Uint32& maxWidth ) { if ( !mString.size() || NULL == mFont ) return; diff --git a/src/eepp/system/translator.cpp b/src/eepp/system/translator.cpp index a7a5f1832..cf5f21c01 100644 --- a/src/eepp/system/translator.cpp +++ b/src/eepp/system/translator.cpp @@ -15,8 +15,9 @@ Translator::Translator( const std::locale& locale ) : mDefaultLanguage( "en" ) { setLanguageFromLocale( locale ); } -void Translator::loadFromDirectory( std::string dirPath, std::string ext ) { +bool Translator::loadFromDirectory( std::string dirPath, std::string ext ) { FileSystem::dirAddSlashAtEnd( dirPath ); + bool someFailed = false; if ( FileSystem::isDirectory( dirPath ) ) { std::vector files = FileSystem::filesGetInPath( dirPath, true, true ); @@ -28,13 +29,16 @@ void Translator::loadFromDirectory( std::string dirPath, std::string ext ) { if ( FileSystem::fileExtension( path ) == ext ) { std::string lang = FileSystem::fileRemoveExtension( files[i] ); - loadFromFile( path, lang ); + if ( !loadFromFile( path, lang ) ) + someFailed = true; } } } + + return someFailed; } -void Translator::loadNodes( pugi::xml_node node, std::string lang ) { +bool Translator::loadNodes( pugi::xml_node node, std::string lang ) { for ( pugi::xml_node resources = node; resources; resources = resources.next_sibling() ) { std::string name = String::toLower( std::string( resources.name() ) ); @@ -44,7 +48,7 @@ void Translator::loadNodes( pugi::xml_node node, std::string lang ) { if ( lang.empty() || lang.size() != 2 ) { Log::error( "Error: Couldn't load i18n language strings: language not specified in " "file name or resources attribute \"language\"." ); - return; + return false; } for ( pugi::xml_node string = resources.child( "string" ); string; @@ -59,9 +63,10 @@ void Translator::loadNodes( pugi::xml_node node, std::string lang ) { } } } + return true; } -void Translator::loadFromFile( const std::string& path, std::string lang ) { +bool Translator::loadFromFile( const std::string& path, std::string lang ) { if ( FileSystem::fileExists( path ) ) { lang = lang.size() == 2 ? lang @@ -71,7 +76,7 @@ void Translator::loadFromFile( const std::string& path, std::string lang ) { pugi::xml_parse_result result = doc.load_file( path.c_str() ); if ( result ) { - loadNodes( doc.first_child(), lang ); + return loadNodes( doc.first_child(), lang ); } else { Log::error( "Couldn't load i18n file: %s", path.c_str() ); Log::error( "Error description: %s", result.description() ); @@ -82,39 +87,42 @@ void Translator::loadFromFile( const std::string& path, std::string lang ) { Pack* pack = PackManager::instance()->exists( packPath ); if ( NULL != pack ) { - loadFromPack( pack, packPath, lang ); + return loadFromPack( pack, packPath, lang ); } } + return false; } -void Translator::loadFromString( const std::string& string, std::string lang ) { +bool Translator::loadFromString( const std::string& string, std::string lang ) { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_string( string.c_str() ); if ( result ) { - loadNodes( doc.first_child(), lang ); + return loadNodes( doc.first_child(), lang ); } else { Log::error( "Couldn't load i18n file from string: %s", string.c_str() ); Log::error( "Error description: %s", result.description() ); Log::error( "Error offset: %d", result.offset ); } + return false; } -void Translator::loadFromMemory( const void* buffer, Int32 bufferSize, std::string lang ) { +bool Translator::loadFromMemory( const void* buffer, Int32 bufferSize, std::string lang ) { pugi::xml_document doc; pugi::xml_parse_result result = doc.load_buffer( buffer, bufferSize ); if ( result ) { - loadNodes( doc.first_child(), lang ); + return loadNodes( doc.first_child(), lang ); } else { Log::error( "Couldn't load i18n file from buffer" ); Log::error( "Error description: %s", result.description() ); Log::error( "Error offset: %d", result.offset ); } + return false; } -void Translator::loadFromStream( IOStream& stream, std::string lang ) { +bool Translator::loadFromStream( IOStream& stream, std::string lang ) { if ( !stream.isOpen() ) - return; + return false; ios_size bufferSize = stream.getSize(); TScopedBuffer scopedBuffer( bufferSize ); @@ -124,15 +132,17 @@ void Translator::loadFromStream( IOStream& stream, std::string lang ) { pugi::xml_parse_result result = doc.load_buffer( scopedBuffer.get(), scopedBuffer.length() ); if ( result ) { - loadNodes( doc.first_child(), lang ); + return loadNodes( doc.first_child(), lang ); } else { Log::error( "Couldn't load i18n file from stream" ); Log::error( "Error description: %s", result.description() ); Log::error( "Error offset: %d", result.offset ); } + + return false; } -void Translator::loadFromPack( Pack* pack, const std::string& FilePackPath, std::string lang ) { +bool Translator::loadFromPack( Pack* pack, const std::string& FilePackPath, std::string lang ) { ScopedBuffer buffer; if ( pack->isOpen() && pack->extractFileToMemory( FilePackPath, buffer ) ) { @@ -141,8 +151,10 @@ void Translator::loadFromPack( Pack* pack, const std::string& FilePackPath, std: ? lang : FileSystem::fileRemoveExtension( FileSystem::fileNameFromPath( FilePackPath ) ); - loadFromMemory( buffer.get(), buffer.length(), lang ); + return loadFromMemory( buffer.get(), buffer.length(), lang ); } + + return false; } String Translator::getString( const std::string& key, const String& defaultValue ) { diff --git a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp index 02b045bdb..7ece3c2e8 100644 --- a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp +++ b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp @@ -1004,7 +1004,8 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { { { "^%[.-%]" }, "keyword2" }, { { "%s%[.-%]" }, "keyword2" }, { { "=" }, "operator" }, - { { "https?://[%w_.~!*:@&+$/?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/?[%w_.~!*:@&+$/?%%#=-]*" }, + { { "https?://[%w_.~!*:@&+$/?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/?[%w_.~!*:@&+$/" + "?%%#=-]*" }, "link" }, { { "[a-z]+" }, "symbol" } }, { { "true", "literal" }, { "false", "literal" } }, @@ -1875,23 +1876,32 @@ SyntaxDefinitionManager::SyntaxDefinitionManager() { add( { "YAML", { "%.yml$", "%.yaml$" }, { - { { "^#.-\n" }, "comment" }, - { { "%s#.-\n" }, "comment" }, + { { "#", "\n" }, "comment" }, { { "\"", "\"", "\\" }, "string" }, { { "'", "'", "\\" }, "string" }, - { { "!!str", "\n", "\\" }, "string" }, - { { "%s-%-%s+.*\n" }, "keyword2" }, - { { "%s+[%w%s-_]+:%s+" }, "keyword" }, - { { "^[%w%s-_]+:%s+" }, "keyword" }, - { { "%f[%S]%-?0x%x+" }, "number" }, - { { "%f[%S]%-?%d+[%d%.eE]*f?" }, "number" }, - { { "%f[%S]%-?%.?%d+f?" }, "number" }, - { { "!!float", "\n", "\\" }, "number" }, - { { "https?://[%w_.~!*:@&+$/?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/?[%w_.~!*:@&+$/?%%#=-]*" }, + { { "%-?%.inf" }, "number" }, + { { "%.NaN" }, "number" }, + { { "(%&)(%g+)" }, { "keyword", "literal", "" } }, + { { "!%g+" }, "keyword" }, + { { "<<" }, "literal" }, + { { "https?://[%w_.~!*:@&+$/?%%#-]-%w[-.%w]*%.%w%w%w?%w?:?%d*/?[%w_.~!*:@&+$/" + "?%%#=-]*" }, "link" }, - { { "%-%-%-" }, "literal" }, + { { "([%s]%*)([%w%d_]+)" }, { "keyword", "keyword", "keyword2" } }, + { { "(%*)([%w%d_]+)" }, { "keyword", "keyword", "literal" } }, + { { "([%[%{])(%s*[%w%d]+%g+%s*)(:%s)" }, + { "keyword", "operator", "operator", "keyword" } }, + { { "([%s][%w%d]+%g+%s*)(:%s)" }, { "keyword", "keyword", "operator" } }, + { { "([%w%d]+%g+%s*)(:%s)" }, { "keyword", "keyword", "operator" } }, + { { "0%d+" }, "number" }, + { { "0x%x+" }, "number" }, + { { "[%+%-]?%d+[,%.eE:%+%d]*%d+" }, "number" }, + { { "[%*%|%!>%%]" }, "keyword" }, + { { "[%-:%?%*%{%}%[%]]" }, "operator" }, + { { "([%d%a_][%g_]*)([%]%},])" }, { "string", "operator", "operator" } }, + { { "[%d%a$/_][%g_]*" }, "string" }, }, - {}, + { { "true", "number" }, { "false", "number" }, { "y", "number" }, { "n", "number" } }, "#" } ); // Swift diff --git a/src/eepp/ui/doc/syntaxtokenizer.cpp b/src/eepp/ui/doc/syntaxtokenizer.cpp index 0c0d073ab..8be150872 100644 --- a/src/eepp/ui/doc/syntaxtokenizer.cpp +++ b/src/eepp/ui/doc/syntaxtokenizer.cpp @@ -6,9 +6,10 @@ using namespace EE::System; namespace EE { namespace UI { namespace Doc { -// This tokenizer is a direct conversion to C++ from the lite (https://github.com/rxi/lite) +// This tokenizer was a direct conversion to C++ from the lite (https://github.com/rxi/lite) // tokenizer. This allows eepp to support the same color schemes and syntax definitions from -// lite. Making much easier to implement a complete code editor. +// lite. Making much easier to implement a complete code editor. Currently some improvements +// has been made. It's still compatible with lite tokenizer. #define MAX_TOKEN_SIZE ( 512 ) diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 5b0265080..aca113a78 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -2277,9 +2277,9 @@ void UICodeEditor::drawWordMatch( const String& text, const std::pair& primitives.setForceDraw( true ); } -void UICodeEditor::drawLineText( const Int64& index, Vector2f position, const Float& fontSize, +void UICodeEditor::drawLineText( const Int64& line, Vector2f position, const Float& fontSize, const Float& lineHeight ) { - auto& tokens = mHighlighter.getLine( index ); + auto& tokens = mHighlighter.getLine( line ); Primitives primitives; Int64 curChar = 0; Int64 maxWidth = eeceil( mSize.getWidth() / getGlyphWidth() + 1 ); @@ -2291,17 +2291,17 @@ void UICodeEditor::drawLineText( const Int64& index, Vector2f position, const Fl Int64 curCharsWidth = text.size(); Int64 curPositionChar = eefloor( mScroll.x / getGlyphWidth() ); Float curMaxPositionChar = curPositionChar + maxWidth; - Text line( "", mFont, fontSize ); - line.setDisableCacheWidth( true ); - line.setTabWidth( mTabWidth ); + Text txt( "", mFont, fontSize ); + txt.setDisableCacheWidth( true ); + txt.setTabWidth( mTabWidth ); const SyntaxColorScheme::Style& style = mColorScheme.getSyntaxStyle( token.type ); - line.setStyleConfig( mFontStyleConfig ); + txt.setStyleConfig( mFontStyleConfig ); if ( style.style ) - line.setStyle( style.style ); - line.setColor( Color( style.color ).blendAlpha( mAlpha ) ); + txt.setStyle( style.style ); + txt.setColor( Color( style.color ).blendAlpha( mAlpha ) ); if ( mHandShown && mLinkPosition.isValid() && mLinkPosition.inSameLine() && - mLinkPosition.start().line() == index ) { + mLinkPosition.start().line() == line ) { if ( mLinkPosition.start().column() >= curChar && mLinkPosition.end().column() <= curChar + curCharsWidth ) { size_t linkPos = text.find( mLink ); @@ -2310,7 +2310,7 @@ void UICodeEditor::drawLineText( const Int64& index, Vector2f position, const Fl String afterString( text.substr( linkPos + mLink.size() ) ); Float offset = 0.f; - Uint32 lineStyle = line.getStyle(); + Uint32 lineStyle = txt.getStyle(); if ( !beforeString.empty() ) { Float beforeWidth = getTextWidth( beforeString ); @@ -2320,8 +2320,8 @@ void UICodeEditor::drawLineText( const Int64& index, Vector2f position, const Fl primitives.drawRectangle( Rectf( position, Sizef( beforeWidth, lineHeight ) ) ); } - line.setString( beforeString ); - line.draw( position.x, position.y ); + txt.setString( beforeString ); + txt.draw( position.x, position.y ); offset += beforeWidth; } @@ -2330,12 +2330,12 @@ void UICodeEditor::drawLineText( const Int64& index, Vector2f position, const Fl if ( mColorScheme.hasSyntaxStyle( "link_hover" ) ) { linkStyle = mColorScheme.getSyntaxStyle( "link_hover" ); if ( linkStyle.color != Color::Transparent ) - line.setColor( Color( linkStyle.color ).blendAlpha( mAlpha ) ); - line.setStyle( linkStyle.style ); + txt.setColor( Color( linkStyle.color ).blendAlpha( mAlpha ) ); + txt.setStyle( linkStyle.style ); } else { - line.setStyle( ( lineStyle & Text::Underlined ) - ? ( lineStyle | Text::Bold ) - : ( lineStyle | Text::Underlined ) ); + txt.setStyle( ( lineStyle & Text::Underlined ) + ? ( lineStyle | Text::Bold ) + : ( lineStyle | Text::Underlined ) ); } Float linkWidth = getTextWidth( mLink ); @@ -2346,8 +2346,8 @@ void UICodeEditor::drawLineText( const Int64& index, Vector2f position, const Fl Rectf( Vector2f( position.x + offset, position.y ), Sizef( linkWidth, lineHeight ) ) ); } - line.setString( mLink ); - line.draw( position.x + offset, position.y ); + txt.setString( mLink ); + txt.draw( position.x + offset, position.y ); offset += linkWidth; if ( !afterString.empty() ) { @@ -2359,10 +2359,10 @@ void UICodeEditor::drawLineText( const Int64& index, Vector2f position, const Fl Rectf( Vector2f( position.x + offset, position.y ), Sizef( afterWidth, lineHeight ) ) ); } - line.setColor( Color( style.color ).blendAlpha( mAlpha ) ); - line.setStyle( lineStyle ); - line.setString( afterString ); - line.draw( position.x + offset, position.y ); + txt.setColor( Color( style.color ).blendAlpha( mAlpha ) ); + txt.setStyle( lineStyle ); + txt.setString( afterString ); + txt.draw( position.x + offset, position.y ); } position.x += textWidth; @@ -2385,18 +2385,18 @@ void UICodeEditor::drawLineText( const Int64& index, Vector2f position, const Fl Int64 totalChars = curCharsWidth - start; Int64 end = eemin( totalChars, minimumCharsToCoverScreen ); if ( curCharsWidth >= charsToVisible ) { - line.setString( text.substr( start, end ) ); - line.draw( position.x + start * getGlyphWidth(), position.y ); + txt.setString( text.substr( start, end ) ); + txt.draw( position.x + start * getGlyphWidth(), position.y ); if ( minimumCharsToCoverScreen == end ) break; } } else { - line.setString( text.substr( 0, eemin( curCharsWidth, maxWidth ) ) ); - line.draw( position.x, position.y ); + txt.setString( text.substr( 0, eemin( curCharsWidth, maxWidth ) ) ); + txt.draw( position.x, position.y ); } } else { - line.setString( text ); - line.draw( position.x, position.y ); + txt.setString( text ); + txt.draw( position.x, position.y ); } } else if ( position.x > mScreenPos.x + mSize.getWidth() ) { break; diff --git a/src/eepp/ui/uitextedit.cpp b/src/eepp/ui/uitextedit.cpp index 1bf26c822..b9592544e 100644 --- a/src/eepp/ui/uitextedit.cpp +++ b/src/eepp/ui/uitextedit.cpp @@ -61,11 +61,11 @@ void UITextEdit::setTheme( UITheme* Theme ) { onThemeLoaded(); } -void UITextEdit::shrinkText( const Float& maxWidth ) { +void UITextEdit::wrapText( const Float& maxWidth ) { Text text; text.setStyleConfig( mFontStyleConfig ); text.setString( getText() ); - text.shrinkText( maxWidth ); + text.wrapText( maxWidth ); mDoc->reset(); mDoc->textInput( text.getString() ); } @@ -78,7 +78,7 @@ void UITextEdit::setText( const String& text ) { mDoc->reset(); mDoc->textInput( text ); if ( mFlags & UI_WORD_WRAP ) { - shrinkText( getViewportWidth( true ) ); + wrapText( getViewportWidth( true ) ); } if ( !hasFocus() ) { mCursorVisible = false; diff --git a/src/eepp/ui/uitextinput.cpp b/src/eepp/ui/uitextinput.cpp index 34a88d7fa..f4179dd70 100644 --- a/src/eepp/ui/uitextinput.cpp +++ b/src/eepp/ui/uitextinput.cpp @@ -300,7 +300,7 @@ const String& UITextInput::getText() { return UITextView::getText(); } -void UITextInput::shrinkText( const Uint32& ) {} +void UITextInput::wrapText( const Uint32& ) {} void UITextInput::updateText() {} diff --git a/src/eepp/ui/uitextview.cpp b/src/eepp/ui/uitextview.cpp index 4802d1d05..b6e7509ad 100644 --- a/src/eepp/ui/uitextview.cpp +++ b/src/eepp/ui/uitextview.cpp @@ -267,16 +267,16 @@ UITextView* UITextView::setSelectionBackColor( const Color& color ) { void UITextView::autoShrink() { if ( mFlags & UI_WORD_WRAP ) { - shrinkText( mSize.getWidth() ); + wrapText( mSize.getWidth() ); } } -void UITextView::shrinkText( const Uint32& maxWidth ) { +void UITextView::wrapText( const Uint32& maxWidth ) { if ( mFlags & UI_WORD_WRAP ) { mTextCache->setString( mString ); } - mTextCache->shrinkText( maxWidth ); + mTextCache->wrapText( maxWidth ); invalidateDraw(); } @@ -496,7 +496,7 @@ void UITextView::drawSelection( Text* textCache ) { if ( !mSelPosCache.empty() ) { Primitives P; P.setColor( mFontStyleConfig.FontSelectionBackColor ); - Float vspace = textCache->getFont()->getFontHeight( textCache->getCharacterSizePx() ); + Float vspace = textCache->getFont()->getLineSpacing( textCache->getCharacterSizePx() ); for ( size_t i = 0; i < mSelPosCache.size(); i++ ) { initPos = mSelPosCache[i].initPos; diff --git a/src/examples/fonts/fonts.cpp b/src/examples/fonts/fonts.cpp index 70305a915..8362350d3 100644 --- a/src/examples/fonts/fonts.cpp +++ b/src/examples/fonts/fonts.cpp @@ -96,7 +96,7 @@ EE_MAIN_FUNC int main( int argc, char* argv[] ) { text.setFontSize( 24 ); text.setAlign( TEXT_ALIGN_CENTER ); text.setString( Txt ); - text.shrinkText( win->getWidth() - 96 ); + text.wrapText( win->getWidth() - 96 ); // Set the font color to a substring of the text // Create a gradient diff --git a/src/tools/ecode/modules/linter/lintermodule.cpp b/src/tools/ecode/modules/linter/lintermodule.cpp index 69fcfc460..b2eca7657 100644 --- a/src/tools/ecode/modules/linter/lintermodule.cpp +++ b/src/tools/ecode/modules/linter/lintermodule.cpp @@ -227,6 +227,10 @@ void LinterModule::runLinter( std::shared_ptr doc, const Linter& l // Log::info( "Linter result:\n%s", data.c_str() ); std::map> matches; + size_t totalMatches = 0; + size_t totalErrors = 0; + size_t totalWarns = 0; + size_t totalNotice = 0; for ( auto warningPatterm : linter.warningPattern ) { String::replaceAll( warningPatterm, "$FILENAME", path ); @@ -244,7 +248,8 @@ void LinterModule::runLinter( std::shared_ptr doc, const Linter& l String::toLowerInPlace( type ); if ( String::startsWith( type, "warn" ) ) { linterMatch.type = LinterType::Warning; - } else if ( String::startsWith( type, "notice" ) ) { + } else if ( String::startsWith( type, "notice" ) || + String::startsWith( type, "hint" ) ) { linterMatch.type = LinterType::Notice; } } @@ -267,13 +272,29 @@ void LinterModule::runLinter( std::shared_ptr doc, const Linter& l { Lock matchesLock( mMatchesMutex ); - mMatches[doc.get()] = matches; + totalMatches = matches.size(); + for ( const auto& matchLine : matches ) { + for ( const auto& match : matchLine.second ) { + switch ( match.type ) { + case LinterType::Warning: + ++totalWarns; + case LinterType::Notice: + ++totalNotice; + case LinterType::Error: + default: + ++totalErrors; + } + } + } + mMatches[doc.get()] = std::move( matches ); } invalidateEditors( doc.get() ); - Log::info( "LinterModule::runLinter for %s took %.2fms. Found: %d matches.", path.c_str(), - clock.getElapsedTime().asMilliseconds(), matches.size() ); + Log::info( "LinterModule::runLinter for %s took %.2fms. Found: %d matches. Errors: %d, " + "Warnings: %d, Notices: %d.", + path.c_str(), clock.getElapsedTime().asMilliseconds(), totalMatches, totalErrors, + totalWarns, totalNotice ); } }