Skip to content

Commit d641bc1

Browse files
committed
Improve text input docs
Cross reference with TextInput class Add examples
1 parent 651f58f commit d641bc1

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tcod/event.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,11 @@ def __str__(self) -> str:
674674
class TextInput(Event):
675675
"""SDL text input event.
676676
677+
.. warning::
678+
These events are not enabled by default since `19.0`.
679+
680+
Use :any:`Window.start_text_input` to enable this event.
681+
677682
Attributes:
678683
type (str): Always "TEXTINPUT".
679684
text (str): A Unicode string with the input.

tcod/sdl/video.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ def __init__(self, pixels: ArrayLike) -> None:
167167

168168

169169
class Window:
170-
"""An SDL2 Window object."""
170+
"""An SDL2 Window object.
171+
172+
Created from :any:`tcod.sdl.video.new_window` when working with SDL directly.
173+
174+
When using the libtcod :any:`Context` you can access its `Window` via :any:`Context.sdl_window`.
175+
"""
171176

172177
def __init__(self, sdl_window_p: Any) -> None: # noqa: ANN401
173178
if ffi.typeof(sdl_window_p) is not ffi.typeof("struct SDL_Window*"):
@@ -444,9 +449,21 @@ def start_text_input(
444449
multiline: Allow multiple lines of text.
445450
android_type: Input type for Android, see SDL docs.
446451
452+
Example::
453+
454+
context: tcod.context.Context # Assuming tcod context is used
455+
456+
if context.sdl_window:
457+
context.sdl_window.start_text_input()
458+
459+
... # Handle Unicode input using TextInput events
460+
461+
context.sdl_window.stop_text_input() # Close on-screen keyboard when done
462+
447463
.. seealso::
448464
:any:`stop_text_input`
449465
:any:`set_text_input_area`
466+
:any:`TextInput`
450467
https://wiki.libsdl.org/SDL3/SDL_StartTextInputWithProperties
451468
452469
.. versionadded:: 19.1

0 commit comments

Comments
 (0)