Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: draw a cursor in UICode elements. #155

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions luigi2.h
Original file line number Diff line number Diff line change
Expand Up @@ -2600,8 +2600,9 @@ int UIDrawStringHighlighted(UIPainter *painter, UIRectangle lineBounds, const ch
ui.theme.codePreprocessor,
};

int lineHeight = UIMeasureStringHeight();
int x = lineBounds.l;
int y = (lineBounds.t + lineBounds.b - UIMeasureStringHeight()) / 2;
int y = (lineBounds.t + lineBounds.b - lineHeight) / 2;
int ti = 0;
_UICodeTokenType tokenType = UI_CODE_TOKEN_TYPE_DEFAULT;
bool inComment = false, inIdentifier = false, inChar = false, startedString = false, startedPreprocessor = false;
Expand Down Expand Up @@ -2677,11 +2678,15 @@ int UIDrawStringHighlighted(UIPainter *painter, UIRectangle lineBounds, const ch
x += ui.activeFont->glyphWidth, ti++;
}

if (selection && j >= selection->carets[0] && j <= selection->carets[1]) {
UIDrawBlock(painter, UI_RECT_4(oldX, x, y, y + UIMeasureStringHeight()), selection->colorBackground);
if (selection && selection->carets[0] != selection->carets[1] && j >= selection->carets[0] && j < selection->carets[1]) {
UIDrawBlock(painter, UI_RECT_4(oldX, x, y, y + lineHeight), selection->colorBackground);
if (c != '\t') UIDrawGlyph(painter, oldX, y, c, selection->colorText);
}

if (selection && selection->carets[0] == j) {
UIDrawInvert(painter, UI_RECT_4(x, x + 1, y, y + lineHeight));
}

j++;
}

Expand Down Expand Up @@ -2888,7 +2893,7 @@ int _UICodeMessage(UIElement *element, UIMessage message, int di, void *dp) {

if (from != to) {
char *pasteText = (char *) UI_CALLOC(to - from + 2);
for (int i = from; i <= to; i++) pasteText[i - from] = code->content[i];
for (int i = from; i < to; i++) pasteText[i - from] = code->content[i];
_UIClipboardWriteText(element->window, pasteText);
}

Expand Down
Loading