diff --git a/include/eepp/graphics/linewrap.hpp b/include/eepp/graphics/linewrap.hpp index c24e650b3..a86412bb8 100644 --- a/include/eepp/graphics/linewrap.hpp +++ b/include/eepp/graphics/linewrap.hpp @@ -32,12 +32,22 @@ class EE_API LineWrap { Uint32 textHints = TextHints::None, bool tabStops = false, Float initialXOffset = 0.f ); + static LineWrapInfo computeLineBreaks( + const String::View& string, Font* font, Uint32 characterSize, Float maxWidth, + LineWrapMode mode, Uint32 fontStyle, Float outlineThickness, bool keepIndentation, + Uint32 tabWidth = 4, Float whiteSpaceWidth = 0.f /* 0 = should calculate it */, + Uint32 textHints = TextHints::None, bool tabStops = false, Float initialXOffset = 0.f ); + static LineWrapInfo computeLineBreaks( const String& string, const FontStyleConfig& fontStyle, Float maxWidth, LineWrapMode mode, bool keepIndentation, Uint32 tabWidth = 4, Float whiteSpaceWidth = 0.f, Uint32 textHints = TextHints::None, bool tabStops = false, Float initialXOffset = 0.f ); + static Float computeOffsets( const String::View& string, Font* font, Uint32 characterSize, + Uint32 fontStyle, Float outlineThickness, Uint32 tabWidth = 0.f, + Float maxWidth = 0.f, bool tabStops = false ); + static Float computeOffsets( const String::View& string, const FontStyleConfig& fontStyle, Uint32 tabWidth, Float maxWidth = 0.f, bool tabStops = false ); }; diff --git a/src/eepp/graphics/linewrap.cpp b/src/eepp/graphics/linewrap.cpp index d68e65bb5..3a1200981 100644 --- a/src/eepp/graphics/linewrap.cpp +++ b/src/eepp/graphics/linewrap.cpp @@ -44,68 +44,75 @@ std::string LineWrap::fromLineWrapType( LineWrapType type ) { Float LineWrap::computeOffsets( const String::View& string, const FontStyleConfig& fontStyle, Uint32 tabWidth, Float maxWidth, bool tabStops ) { + return LineWrap::computeOffsets( string, fontStyle.Font, fontStyle.CharacterSize, + fontStyle.Style, fontStyle.OutlineThickness, tabWidth, + maxWidth, tabStops ); +} + +Float LineWrap::computeOffsets( const String::View& string, Font* font, Uint32 characterSize, + Uint32 fontStyle, Float outlineThickness, Uint32 tabWidth, + Float maxWidth, bool tabStops ) { static const String sepSpaces = " \t\n\v\f\r"; auto nonIndentPos = string.find_first_not_of( sepSpaces.data() ); if ( nonIndentPos != String::View::npos ) { - Float w = Text::getTextWidth( string.substr( 0, nonIndentPos ), fontStyle, tabWidth, - TextHints::AllAscii, TextDirection::LeftToRight, - tabStops ? 0 : std::optional{} ); + Float w = + Text::getTextWidth( font, characterSize, string.substr( 0, nonIndentPos ), fontStyle, + tabWidth, outlineThickness, TextHints::AllAscii, + TextDirection::LeftToRight, tabStops ? 0 : std::optional{} ); return maxWidth != 0.f ? ( w > maxWidth ? 0.f : w ) : w; } return 0.f; } -LineWrapInfo LineWrap::computeLineBreaks( const String::View& string, - const FontStyleConfig& fontStyle, Float maxWidth, - LineWrapMode mode, bool keepIndentation, Uint32 tabWidth, - Float whiteSpaceWidth, Uint32 textDrawHints, - bool tabStops, Float initialXOffset ) { +LineWrapInfo LineWrap::computeLineBreaks( const String::View& string, Font* font, + Uint32 characterSize, Float maxWidth, LineWrapMode mode, + Uint32 fontStyle, Float outlineThickness, + bool keepIndentation, Uint32 tabWidth, + Float whiteSpaceWidth /* 0 = should calculate it */, + Uint32 textDrawHints, bool tabStops, + Float initialXOffset ) { LineWrapInfo info; info.wraps.push_back( 0 ); - if ( string.empty() || nullptr == fontStyle.Font || mode == LineWrapMode::NoWrap ) + if ( string.empty() || nullptr == font || mode == LineWrapMode::NoWrap ) return info; - bool bold = ( fontStyle.Style & Text::Style::Bold ) != 0; - bool italic = ( fontStyle.Style & Text::Style::Italic ) != 0; - Float outlineThickness = fontStyle.OutlineThickness; - Float hspace = whiteSpaceWidth == 0.f ? fontStyle.Font - ->getGlyph( L' ', fontStyle.CharacterSize, bold, - italic, outlineThickness ) - .advance - : whiteSpaceWidth; + bool bold = ( fontStyle & Text::Style::Bold ) != 0; + bool italic = ( fontStyle & Text::Style::Italic ) != 0; + Float hspace = + whiteSpaceWidth == 0.f + ? font->getGlyph( L' ', characterSize, bold, italic, outlineThickness ).advance + : whiteSpaceWidth; if ( keepIndentation ) { - info.paddingStart = computeOffsets( string, fontStyle, tabWidth, - eemax( maxWidth - hspace, hspace ), tabStops ); + info.paddingStart = + LineWrap::computeOffsets( string, font, characterSize, fontStyle, outlineThickness, + tabWidth, eemax( maxWidth - hspace, hspace ), tabStops ); } Float xoffset = initialXOffset; Float lastWidth = 0.f; - bool isMonospace = - fontStyle.Font && - ( fontStyle.Font->isMonospace() || - ( fontStyle.Font->getType() == FontType::TTF && - static_cast( fontStyle.Font )->isIdentifiedAsMonospace() && - Text::canSkipShaping( textDrawHints ) ) ); + bool isMonospace = font && ( font->isMonospace() || + ( font->getType() == FontType::TTF && + static_cast( font )->isIdentifiedAsMonospace() && + Text::canSkipShaping( textDrawHints ) ) ); size_t lastSpace = 0; Uint32 prevChar = 0; size_t idx = 0; for ( const auto& curChar : string ) { - Float w = !isMonospace ? fontStyle.Font - ->getGlyph( curChar, fontStyle.CharacterSize, bold, italic, - outlineThickness ) - .advance - : hspace; + Float w = + !isMonospace + ? font->getGlyph( curChar, characterSize, bold, italic, outlineThickness ).advance + : hspace; if ( curChar == '\t' ) w = Text::tabAdvance( hspace, tabWidth, tabStops ? xoffset : std::optional{} ); if ( !isMonospace && curChar != '\r' ) { if ( !( textDrawHints & TextHints::NoKerning ) ) { - w += fontStyle.Font->getKerning( prevChar, curChar, fontStyle.CharacterSize, bold, - italic, outlineThickness ); + w += font->getKerning( prevChar, curChar, characterSize, bold, italic, + outlineThickness ); } prevChar = curChar; } @@ -132,6 +139,17 @@ LineWrapInfo LineWrap::computeLineBreaks( const String::View& string, return info; } +LineWrapInfo LineWrap::computeLineBreaks( const String::View& string, + const FontStyleConfig& fontStyle, Float maxWidth, + LineWrapMode mode, bool keepIndentation, Uint32 tabWidth, + Float whiteSpaceWidth, Uint32 textDrawHints, + bool tabStops, Float initialXOffset ) { + return LineWrap::computeLineBreaks( string, fontStyle.Font, fontStyle.CharacterSize, maxWidth, + mode, fontStyle.Style, fontStyle.OutlineThickness, + keepIndentation, tabWidth, whiteSpaceWidth, textDrawHints, + tabStops, initialXOffset ); +} + LineWrapInfo LineWrap::computeLineBreaks( const String& string, const FontStyleConfig& fontStyle, Float maxWidth, LineWrapMode mode, bool keepIndentation, Uint32 tabWidth, Float whiteSpaceWidth, Uint32 textHints, diff --git a/src/tools/ecode/statusbuildoutputcontroller.cpp b/src/tools/ecode/statusbuildoutputcontroller.cpp index 2a61e0943..827bed229 100644 --- a/src/tools/ecode/statusbuildoutputcontroller.cpp +++ b/src/tools/ecode/statusbuildoutputcontroller.cpp @@ -222,7 +222,9 @@ void StatusBuildOutputController::runBuild( const std::string& buildName, if ( enableCleanButton && cleanButton ) cleanButton->runOnMainThread( [cleanButton] { cleanButton->setEnabled( true ); } ); - buildAndRunButton->setEnabled( true ); + if ( buildAndRunButton ) + buildAndRunButton->setEnabled( true ); + mBuildButton->setEnabled( true ); mStopButton->setEnabled( false ); };