UICodeEditor minimap colors are now editable as part of the colorscheme.

ecode: LinterModule now supports "notice" color.
This commit is contained in:
Martín Lucas Golini
2022-05-05 00:30:42 -03:00
parent 36bfd081c3
commit e3e2e30d62
6 changed files with 96 additions and 20 deletions

View File

@@ -16,6 +16,11 @@ suggestion = #e1e1e6,#1d1f27
suggestion_selected = #ffffff,#2f3240
error = red
warning = yellow
notice = #8abdff
minimap_current_line = #93DDFA40
minimap_hover = #FFFFFF1A
minimap_selection = #8abdff80
minimap_highlight = #FFFF0080
normal = #e1e1e6
symbol = #e1e1e6

View File

@@ -512,6 +512,10 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client {
Color mSelectionMatchColor;
Color mErrorColor;
Color mWarningColor;
Color mMinimapCurrentLineColor;
Color mMinimapHoverColor;
Color mMinimapSelectionColor;
Color mMinimapHighlightColor;
SyntaxColorScheme mColorScheme;
SyntaxHighlighter mHighlighter;
UIScrollBar* mVScrollBar;

View File

@@ -26,6 +26,7 @@ namespace EE { namespace UI { namespace Doc {
// "suggestion_selected" (the auto-complete selected suggestion box text and background color
// "error" (error underline color)
// "warning" (warning underline color)
// "notice" (notice underline color)
SyntaxColorScheme SyntaxColorScheme::getDefault() {
return { "eepp",
@@ -60,7 +61,12 @@ SyntaxColorScheme SyntaxColorScheme::getDefault() {
{ "suggestion", { Color( "#e1e1e6" ), Color( "#1d1f27" ), Text::Regular } },
{ "suggestion_selected", { Color( "#ffffff" ), Color( "#2f3240" ), Text::Regular } },
{ "error", { Color::Red } },
{ "warning", { Color::Yellow } } } };
{ "warning", { Color::Yellow } },
{ "notice", Color( "#8abdff" ) },
{ "minimap_current_line", Color( "#93DDFA40" ) },
{ "minimap_hover", Color( "#FFFFFF1A" ) },
{ "minimap_selection", Color( "#8abdff80" ) },
{ "minimap_highlight", Color( "#FFFF0040" ) } } };
}
std::vector<SyntaxColorScheme> SyntaxColorScheme::loadFromStream( IOStream& stream ) {
@@ -201,6 +207,16 @@ SyntaxColorScheme::getEditorSyntaxStyle( const std::string& type ) const {
return StyleDefault.getEditorSyntaxStyle( "error" );
else if ( type == "warning" )
return StyleDefault.getEditorSyntaxStyle( "warning" );
else if ( type == "notice" )
return StyleDefault.getEditorSyntaxStyle( "notice" );
else if ( type == "minimap_current_line" )
return StyleDefault.getEditorSyntaxStyle( "minimap_current_line" );
else if ( type == "minimap_hover" )
return StyleDefault.getEditorSyntaxStyle( "minimap_hover" );
else if ( type == "minimap_selection" )
return StyleDefault.getEditorSyntaxStyle( "minimap_selection" );
else if ( type == "minimap_highlight" )
return StyleDefault.getEditorSyntaxStyle( "minimap_highlight" );
return StyleEmpty;
}

View File

@@ -709,8 +709,11 @@ void UICodeEditor::updateColorScheme() {
mLineBreakColumnColor = mColorScheme.getEditorColor( "line_break_column" );
mMatchingBracketColor = mColorScheme.getEditorColor( "matching_bracket" );
mSelectionMatchColor = mColorScheme.getEditorColor( "matching_selection" );
mErrorColor = mColorScheme.getEditorColor( "error" );
mWarningColor = mColorScheme.getEditorColor( "warning" );
mMinimapCurrentLineColor = mColorScheme.getEditorColor( "minimap_current_line" );
mMinimapHoverColor = mColorScheme.getEditorColor( "minimap_hover" );
mMinimapSelectionColor = mColorScheme.getEditorColor( "minimap_hover" );
mMinimapHighlightColor = mColorScheme.getEditorColor( "minimap_highlight" );
mMinimapSelectionColor = mColorScheme.getEditorColor( "minimap_selection" );
}
void UICodeEditor::setColorScheme( const SyntaxColorScheme& colorScheme ) {
@@ -2688,7 +2691,7 @@ void UICodeEditor::drawMinimap( const Vector2f& start,
primitives.drawRectangle(
{ { rect.Left, visibleY }, Sizef( rect.getWidth(), scrollerHeight ) } );
if ( mMinimapHover || mMinimapDragging ) {
primitives.setColor( Color( 255, 255, 255, 26 ).blendAlpha( mAlpha ) );
primitives.setColor( Color( mMinimapHoverColor ).blendAlpha( mAlpha ) );
primitives.drawRectangle(
{ { rect.Left, visibleY }, Sizef( rect.getWidth(), scrollerHeight ) } );
}
@@ -2729,7 +2732,7 @@ void UICodeEditor::drawMinimap( const Vector2f& start,
const String& line( mDoc->line( ln ).getText() );
if ( line.size() > 300 )
return;
primitives.setColor( Color( mWarningColor ).blendAlpha( mAlpha ) );
primitives.setColor( Color( mMinimapHighlightColor ).blendAlpha( mAlpha ) );
do {
pos = line.find( text, pos );
@@ -2750,9 +2753,47 @@ void UICodeEditor::drawMinimap( const Vector2f& start,
} while ( true );
};
Float minimapStart = rect.Left + gutterWidth;
auto drawTextRange = [&]( const TextRange& range, const Int64& ln,
const Color& backgroundColor ) {
if ( !( ln >= range.start().line() && ln <= range.end().line() ) )
return;
primitives.setColor( backgroundColor );
const String& line = mDoc->line( ln ).getText();
Rectf selRect;
selRect.Top = lineY;
selRect.Bottom = lineY + charHeight;
if ( range.start().line() == ln ) {
selRect.Left =
minimapStart + getXOffsetCol( { ln, range.start().column() } ) * widthScale;
if ( range.end().line() == ln ) {
selRect.Right =
minimapStart + getXOffsetCol( { ln, range.end().column() } ) * widthScale;
} else {
selRect.Right =
minimapStart +
getXOffsetCol( { ln, static_cast<Int64>( line.length() ) } ) * widthScale;
}
} else if ( range.end().line() == ln ) {
selRect.Left = minimapStart + getXOffsetCol( { ln, 0 } ) * widthScale;
selRect.Right =
minimapStart + getXOffsetCol( { ln, range.end().column() } ) * widthScale;
} else {
selRect.Left = minimapStart + getXOffsetCol( { ln, 0 } ) * widthScale;
selRect.Right =
minimapStart +
getXOffsetCol( { ln, static_cast<Int64>( line.length() ) } ) * widthScale;
}
primitives.drawRectangle( selRect );
};
String selectionString;
if ( mDoc->hasSelection() ) {
if ( mDoc->hasSelection() &&
mDoc->getSelection().start().line() == mDoc->getSelection().end().line() ) {
TextRange selection = mDoc->getSelection( true );
const String& selectionLine = mDoc->line( selection.start().line() ).getText();
if ( selection.start().column() >= 0 &&
@@ -2775,6 +2816,7 @@ void UICodeEditor::drawMinimap( const Vector2f& start,
if ( !mHighlightWord.empty() )
drawWordMatch( mHighlightWord, index );
if ( !selectionString.empty() )
drawWordMatch( selectionString, index );
@@ -2803,6 +2845,12 @@ void UICodeEditor::drawMinimap( const Vector2f& start,
}
}
flushBatch( "normal" );
if ( mDoc->hasSelection() ) {
drawTextRange( mDoc->getSelection( true ), index,
Color( mMinimapSelectionColor ).blendAlpha( mAlpha ) );
}
lineY = lineY + lineSpacing;
}
} else {
@@ -2839,14 +2887,7 @@ void UICodeEditor::drawMinimap( const Vector2f& start,
Float selectionY =
rect.Top + ( mDoc->getSelection().start().line() - minimapStartLine ) * lineSpacing;
Float selectionY2 =
rect.Top + ( mDoc->getSelection().end().line() - minimapStartLine ) * lineSpacing;
Float selectionMinY = eemin( selectionY, selectionY2 );
Float selectionH = eeabs( selectionY2 - selectionY ) + 1;
primitives.setColor(
Color( mFontStyleConfig.getFontSelectionBackColor(), 64 ).blendAlpha( mAlpha ) );
primitives.drawRectangle( { { rect.Left, selectionMinY }, { rect.getWidth(), selectionH } } );
primitives.setColor( Color( mCaretColor, 64 ).blendAlpha( mAlpha ) );
primitives.setColor( Color( mMinimapCurrentLineColor ).blendAlpha( mAlpha ) );
primitives.drawRectangle( { { rect.Left, selectionY }, { rect.getWidth(), lineSpacing } } );
primitives.setForceDraw( true );

View File

@@ -283,6 +283,18 @@ void LinterModule::runLinter( std::shared_ptr<TextDocument> doc, const Linter& l
}
}
std::string LinterModule::getMatchString( const LinterType& type ) {
switch ( type ) {
case LinterType::Warning:
return "warning";
case LinterType::Notice:
return "notice";
default:
break;
}
return "error";
}
void LinterModule::drawAfterLineText( UICodeEditor* editor, const Int64& index, Vector2f position,
const Float& /*fontSize*/, const Float& lineHeight ) {
mMatchesMutex.lock();
@@ -305,12 +317,8 @@ void LinterModule::drawAfterLineText( UICodeEditor* editor, const Int64& index,
Text line( "", editor->getFont(), editor->getFontSize() );
line.setTabWidth( editor->getTabWidth() );
line.setStyleConfig( editor->getFontStyleConfig() );
line.setColor( editor->getColorScheme()
.getEditorSyntaxStyle( match.type == LinterType::Warning ||
match.type == LinterType::Notice
? "warning"
: "error" )
.color );
line.setColor(
editor->getColorScheme().getEditorSyntaxStyle( getMatchString( match.type ) ).color );
const String& text = doc->line( index ).getText();
size_t minCol = text.find_first_not_of( " \t\f\v\n\r", match.pos.column() );
if ( minCol == String::InvalidPos )

View File

@@ -92,6 +92,8 @@ class LinterModule : public UICodeEditorModule {
void setDocDirty( UICodeEditor* editor );
void invalidateEditors( TextDocument* doc );
std::string getMatchString( const LinterType& type );
};
#endif // EE_TOOLS_LINTER_HPP