mirror of https://github.com/buggins/dlangui.git
syntax highlight support, continue
This commit is contained in:
parent
87643a806f
commit
2d1c6601e3
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue