Coherent UI  2.5.3
A modern user interface library for games
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Input Method Editor (IME) support

Coherent UI has full support for Input Method Editor (IME) that enable an application handle Asian language input.

With IME the user can input text in East Asian languages as Chinese, Korean and Japanese. It translates multiple keystrokes to to characters from the respective languages that otherwise can't be represented individually on keyboards.

Although IME is an OS feature, any application (and middleware like Coherent UI) has to provide some methods in order to make the user interaction work correctly.

A great explanation on IME for windows and how it could work in a generic game is available here: http://msdn.microsoft.com/en-us/library/windows/desktop/ee419002%28v=vs.85%29.aspx Other OSes differ somewhat but the principles remain the same. Coherent UI's IME API is OS agnostic and the user should just bridge the OS-specific logic to Coherent UI. A very detailed sample - "Sample_IME" is available and shows integrations for all platforms.

Detailed explanation

The IME-related functionality is exposed through some View methods and ViewListener events: View::IMEActivate must be called with true in order to tell the view that it should handle IME events and should trigger IME-related callbacks in the listener. The IME-related callbacks are never triggered on Views that are not IME-activated in order to not waste resources when they are not needed. The View contains 3 methods that deal with the current IME composition directly: View::IMESetComposition is used to show the client the state of the current composition - it will be underlined to give a visual clue that the composition is still in-progress. View::IMEConfirmComposition tells the View that the passed composition must be accepted - it will appear in the text box as final. View::IMECancelComposition tells the View to discard the current composition.

Coherent UI provides also some events called on the ViewListener that allow for the correct composition and positiong of the IME windows:

Note
The callbacks will be triggered only on Views that have IME activated (View::IMEActivate). ViewListener::OnTextInputTypeChanged is called whenever the input focus in the view changes. The application should tell the OS that it accepts IME input when the user has focused a text field but it should not do it when for example the user has clicked on a picture or is not writing text anywhere. ViewListener::OnCaretRectChanged informs where the caret is currently in the View. This allows for a correct positioning of the IME candidate list - it usually appears just below the text being composed. ViewListener::OnIMEShouldCancelComposition informs that the application should cancel the current composition and signal the OS accordingly. This can happen for instance when the user clicks somewhere and changes the focus from a text box when a composition is still in-progress.

OS integration

Drawing the candidate list is usually the most challenging part of an IME integration. The Windows version of the "Sample_IME" sample shows how you can retrieve and draw the candidate list in a second Coherent UI View. On other OSes the default behavior is used without any custom drawing.