Made function for filling rect in word wrap

This commit is contained in:
James Johnson 2018-01-11 19:55:28 -05:00
parent d28eab7e9d
commit 3463fec39d
1 changed files with 20 additions and 27 deletions

View File

@ -3317,9 +3317,20 @@ class EditBox : EditWidgetBase {
rc.right = _clientRect.left + endrc.right; rc.right = _clientRect.left + endrc.right;
if (_wordWrap && !rc.empty) if (_wordWrap && !rc.empty)
{ {
wordWrapFillRect(buf, r.start.line, rc, color);
}
else if (!rc.empty) {
// draw selection rect for matching bracket
buf.fillRect(rc, color);
}
}
void wordWrapFillRect(DrawBuf buf, int line, Rect lineToDivide, uint color)
{
Rect rc = lineToDivide;
auto limitNumber = (int num, int limit) => num > limit ? limit : num; auto limitNumber = (int num, int limit) => num > limit ? limit : num;
LineSpan curSpan = getSpan(r.start.line); LineSpan curSpan = getSpan(line);
int yOffset = _lineHeight * (wrapsUpTo(r.start.line)); int yOffset = _lineHeight * (wrapsUpTo(line));
rc.offset(0, yOffset); rc.offset(0, yOffset);
Rect[] wrappedSelection; Rect[] wrappedSelection;
wrappedSelection.length = curSpan.len; wrappedSelection.length = curSpan.len;
@ -3328,15 +3339,9 @@ class EditBox : EditWidgetBase {
wrapLineRect = rc; wrapLineRect = rc;
wrapLineRect.offset(-1 * curSpan.accumulation(i, LineSpan.WrapPointInfo.Width), i * _lineHeight); wrapLineRect.offset(-1 * curSpan.accumulation(i, LineSpan.WrapPointInfo.Width), i * _lineHeight);
wrapLineRect.right = limitNumber(wrapLineRect.right,(rc.left + curSpan.wrapPoints[i].wrapWidth)); wrapLineRect.right = limitNumber(wrapLineRect.right,(rc.left + curSpan.wrapPoints[i].wrapWidth));
//buf.fillRect(wrapLineRect, focused ? _selectionColorFocused : _selectionColorNormal);
buf.fillRect(wrapLineRect, color); buf.fillRect(wrapLineRect, color);
} }
} }
else if (!rc.empty) {
// draw selection rect for matching bracket
buf.fillRect(rc, color);
}
}
/// override to custom highlight of line background /// override to custom highlight of line background
protected void drawLineBackground(DrawBuf buf, int lineIndex, Rect lineRect, Rect visibleRect) { protected void drawLineBackground(DrawBuf buf, int lineIndex, Rect lineRect, Rect visibleRect) {
@ -3355,19 +3360,7 @@ class EditBox : EditWidgetBase {
rc.right = endx; rc.right = endx;
if (!rc.empty && _wordWrap) if (!rc.empty && _wordWrap)
{ {
auto limitNumber = (int num, int limit) => num > limit ? limit : num; wordWrapFillRect(buf, lineIndex, rc, focused ? _selectionColorFocused : _selectionColorNormal);
LineSpan curSpan = getSpan(lineIndex);
int yOffset = _lineHeight * (wrapsUpTo(lineIndex));
rc.offset(0, yOffset);
Rect[] wrappedSelection;
wrappedSelection.length = curSpan.len;
foreach (int i, wrapLineRect; wrappedSelection)
{
wrapLineRect = rc;
wrapLineRect.offset(-1 * curSpan.accumulation(i, LineSpan.WrapPointInfo.Width), i * _lineHeight);
wrapLineRect.right = limitNumber(wrapLineRect.right,(rc.left + curSpan.wrapPoints[i].wrapWidth));
buf.fillRect(wrapLineRect, focused ? _selectionColorFocused : _selectionColorNormal);
}
} }
else if (!rc.empty) { else if (!rc.empty) {
// draw selection rect for line // draw selection rect for line