diff --git a/src/dlangui/graphics/fonts.d b/src/dlangui/graphics/fonts.d index 3e1ba3a0..a8c358bb 100644 --- a/src/dlangui/graphics/fonts.d +++ b/src/dlangui/graphics/fonts.d @@ -82,6 +82,17 @@ immutable dchar UNICODE_NB_HYPHEN = 0x2011; struct CustomCharProps { uint color; uint textFlags; + this(uint color) { + this.color = color; + this.textFlags = 0; + } + this(uint color, bool underline, bool strikeThrough) { + this.color = color; + if (underline) + this.textFlags |= TextFlag.Underline; + if (strikeThrough) + this.textFlags |= TextFlag.StrikeThrough; + } } version (USE_OPENGL) { diff --git a/src/dlangui/widgets/editors.d b/src/dlangui/widgets/editors.d index 567a9538..c0b8422e 100644 --- a/src/dlangui/widgets/editors.d +++ b/src/dlangui/widgets/editors.d @@ -31,6 +31,7 @@ import dlangui.core.linestream; import dlangui.platforms.common.platform; import dlangui.widgets.menu; import dlangui.widgets.popup; +private import dlangui.graphics.colors; import std.algorithm; import std.stream; @@ -2737,8 +2738,30 @@ class EditBox : EditWidgetBase { } } + + protected CustomCharProps[ubyte] _tokenHighlightColors; + void setTokenHightlightColor(ubyte tokenCategory, uint color, bool underline, bool strikeThrough) { + _tokenHighlightColors[tokenCategory] = CustomCharProps(color, underline, strikeThrough); + } + /// custom text color and style highlight (using text highlight) support protected CustomCharProps[] handleCustomLineHighlight(int line, dstring txt) { + TokenPropString tokenProps = _content.lineTokenProps(line); + if (tokenProps.length > 0) { + CustomCharProps[] colors = new CustomCharProps[tokenProps.length]; + for (int i = 0; i < tokenProps.length; i++) { + ubyte p = tokenProps[i]; + if (p in _tokenHighlightColors) + colors[i] = _tokenHighlightColors[p]; + else if ((p & TOKEN_CATEGORY_MASK) in _tokenHighlightColors) + colors[i] = _tokenHighlightColors[(p & TOKEN_CATEGORY_MASK)]; + else + colors[i].color = textColor; + if (isFullyTransparentColor(colors[i].color)) + colors[i].color = textColor; + } + return colors; + } return null; } diff --git a/src/dlangui/widgets/styles.d b/src/dlangui/widgets/styles.d index b6da2378..1a5895e1 100644 --- a/src/dlangui/widgets/styles.d +++ b/src/dlangui/widgets/styles.d @@ -215,7 +215,9 @@ enum TextFlag : uint { /// underline hot key when drawing UnderlineHotKeysWhenAltPressed = 4, /// underline text when drawing - Underline = 8 + Underline = 8, + /// strikethrough text when drawing + StrikeThrough = 16 // TODO: } /// style properties