Skip to content

Commit

Permalink
Draw the candidate list next to the active composition clause
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Oct 7, 2024
1 parent 954037f commit ac26c5d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions examples/editbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ static void SaveCandidates(EditBox *edit, const SDL_Event *event)
if (i == selected_candidate) {
edit->selected_candidate_start = (int)(uintptr_t)(dst - candidate_text);
edit->selected_candidate_length = length;
SDL_Log("Selected candidate: %d/%d\n", edit->selected_candidate_start, edit->selected_candidate_length);
}
SDL_memcpy(dst, event->edit_candidates.candidates[i], length);
dst += length;
Expand Down Expand Up @@ -238,10 +237,20 @@ static void DrawCandidates(EditBox *edit)
float x, y;

/* Position the candidate window */
TTF_SubString cursor;
int offset = edit->composition_start;
if (edit->composition_cursor_length > 0) {
// Place the candidates at the active clause
offset += edit->composition_cursor;
}
if (!TTF_GetTextSubString(edit->text, offset, &cursor)) {
return;
}

SDL_GetRenderSafeArea(renderer, &safe_rect);
TTF_GetTextSize(edit->candidates, &candidates_w, &candidates_h);
candidates_rect.x = edit->cursor_rect.x;
candidates_rect.y = edit->cursor_rect.y + edit->cursor_rect.h + 2.0f;
candidates_rect.x = edit->rect.x + cursor.rect.x;
candidates_rect.y = edit->rect.y + cursor.rect.y + cursor.rect.h + 2.0f;
candidates_rect.w = 1.0f + 2.0f + candidates_w + 2.0f + 1.0f;
candidates_rect.h = 1.0f + 2.0f + candidates_h + 2.0f + 1.0f;
if ((candidates_rect.x + candidates_rect.w) > safe_rect.w) {
Expand Down

0 comments on commit ac26c5d

Please sign in to comment.