diff --git a/vstgui/lib/ctexteditor.cpp b/vstgui/lib/ctexteditor.cpp index a18c28711..5baadfe9d 100644 --- a/vstgui/lib/ctexteditor.cpp +++ b/vstgui/lib/ctexteditor.cpp @@ -606,7 +606,7 @@ bool TextEditorView::attached (CView* parent) md.scrollView->registerViewEventListener (this); if (auto sb = md.scrollView->getVerticalScrollbar ()) sb->registerViewEventListener (this); - if (md.style->showLineNumbers) + if (md.style->flags & Style::Flags::ShowLineNumbers) { md.lineNumberView = makeOwned (this); md.lineNumberView->setStyle (md.style, md.lineHeight); @@ -767,7 +767,7 @@ void TextEditorView::onStyleChanged () const if (md.lineNumberView) { - if (md.style->showLineNumbers) + if (md.style->flags & Style::Flags::ShowLineNumbers) { md.lineNumberView->setStyle (md.style, md.lineHeight); updateLineNumbersView (); @@ -778,7 +778,7 @@ void TextEditorView::onStyleChanged () const md.lineNumberView = nullptr; } } - else if (md.style->showLineNumbers && md.scrollView) + else if (md.style->flags & Style::Flags::ShowLineNumbers && md.scrollView) { md.lineNumberView = makeOwned (&mutableThis ()); md.lineNumberView->setStyle (md.style, md.lineHeight); @@ -972,6 +972,8 @@ void TextEditorView::drawRect (CDrawContext* context, const CRect& dirtyRect) context->setFillColor (md.style->backColor); context->setDrawMode (kAntiAliasing); context->drawRect (dirtyRect, kDrawFilled); + bool drawCursorLineHighlight = (md.editState.select_start == md.editState.select_end) && + (md.style->flags & Style::Flags::HighlightCursorLine); auto styleProvider = dynamic_cast (md.controller); if (styleProvider) @@ -986,6 +988,13 @@ void TextEditorView::drawRect (CDrawContext* context, const CRect& dirtyRect) y += md.lineHeight; if (y < dirtyRect.top) continue; + if (drawCursorLineHighlight && md.selectedLines.start == index) + { + auto lineRect = calculateLineRect (index); + lineRect.right = getViewSize ().right; + context->setFillColor (md.style->highlightCursorLineColor); + context->drawRect (lineRect, kDrawFilled); + } context->setFontColor (md.style->textColor); context->setFont (md.style->font); auto selRange = @@ -1091,7 +1100,12 @@ void TextEditorView::invalidLine (Lines::const_iterator it, bool completeWidth) } //------------------------------------------------------------------------ -void TextEditorView::invalidSelectedLines () const { invalidateRect (calculateSelectionRect ()); } +void TextEditorView::invalidSelectedLines () const +{ + if (md.selectedLines.length == 0 && (md.style->flags & Style::Flags::HighlightCursorLine)) + invalidLine (md.selectedLines.start, true); + invalidateRect (calculateSelectionRect ()); +} //------------------------------------------------------------------------ CRect TextEditorView::calculateLineRect (size_t index) const diff --git a/vstgui/lib/ctexteditor.h b/vstgui/lib/ctexteditor.h index 1d3c8539a..522ceeadf 100644 --- a/vstgui/lib/ctexteditor.h +++ b/vstgui/lib/ctexteditor.h @@ -47,10 +47,18 @@ struct ITextEditor struct Style { + enum class Flags : uint32_t + { + ShowLineNumbers, + HighlightCursorLine + }; + using FlagsBitset = EnumBitset; + SharedPointer font {kNormalFont}; SharedPointer lineNumbersFont {kNormalFontSmall}; CColor textColor {kBlackCColor}; CColor backColor {kWhiteCColor}; + CColor highlightCursorLineColor {0, 0, 0, 10}; CColor selectionBackColor {kGreyCColor}; CColor frameColor {kGreyCColor}; CColor lineNumberTextColor {127, 127, 127, 100}; @@ -62,7 +70,7 @@ struct ITextEditor CCoord lineNumberRightMargin {2.}; uint32_t cursorBlinkTime {500}; // in milliseconds uint32_t tabWidth {4}; - bool showLineNumbers {true}; + FlagsBitset flags {{Flags::ShowLineNumbers, Flags::HighlightCursorLine}}; }; virtual void setStyle (const Style& style) const = 0; diff --git a/vstgui/standalone/examples/standalone/resource/test.uidesc b/vstgui/standalone/examples/standalone/resource/test.uidesc index 29c4f6a9f..553e0f5c2 100644 --- a/vstgui/standalone/examples/standalone/resource/test.uidesc +++ b/vstgui/standalone/examples/standalone/resource/test.uidesc @@ -951,7 +951,7 @@ "auto-drag-scrolling": "false", "auto-hide-scrollbars": "true", "autosize": "left right top bottom ", - "background-color": "~ TransparentCColor", + "background-color": "control.back", "background-color-draw-style": "filled and stroked", "bordered": "true", "class": "CScrollView", @@ -965,7 +965,7 @@ "scrollbar-background-color": "~ TransparentCColor", "scrollbar-frame-color": "~ TransparentCColor", "scrollbar-min-scroller-size": "18", - "scrollbar-scroller-color": "~ WhiteCColor", + "scrollbar-scroller-color": "control.frame", "scrollbar-width": "12", "size": "270, 140", "transparent": "false",