# SDL\_ttf: Draw the candidate list next to the active composition clause

**URL:** <https://discourse.libsdl.org/t/sdl-ttf-draw-the-candidate-list-next-to-the-active-composition-clause/54789>\
**Category:** SDL Commits\
**Created:** [October 7, 2024, 6:03am UTC](https://discourse.libsdl.org/t/sdl-ttf-draw-the-candidate-list-next-to-the-active-composition-clause/54789 "2024-10-07T06:03:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [October 7, 2024, 6:03am UTC](https://discourse.libsdl.org/t/sdl-ttf-draw-the-candidate-list-next-to-the-active-composition-clause/54789/1 "2024-10-07T06:03:39Z")

</div>

> <https://github.com/libsdl-org/SDL_ttf/commit/ac26c5d06e35adba81d10d6296825e2014d18a0c>

```diff
From ac26c5d06e35adba81d10d6296825e2014d18a0c Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 6 Oct 2024 22:56:09 -0700
Subject: [PATCH] Draw the candidate list next to the active composition clause

---
 examples/editbox.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/examples/editbox.c b/examples/editbox.c
index 3a2c4ad9..112c6541 100644
--- a/examples/editbox.c
+++ b/examples/editbox.c
@@ -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;
@@ -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) {

```
