10000 added text_input feature by Watita · Pull Request #269 · ruby2d/ruby2d · GitHub
[go: up one dir, main page]

Skip to content

added text_input feature #269

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

Watita
Copy link
@Watita Watita commented Mar 11, 2023

This feature brings SDL's TextInput feature into Ruby2D.
It adds the new TextInput class that inherits from Text and has the following attributes:

TextInput.new(
  'Hello',
  x: 150, y: 470,
  font: 'vera.ttf',
  style: 'bold',
  size: 20,
  color: 'blue',
  opacity: 1,
  rotate: 90,
  z: 10,
  show: true,
  maxlen: 20,
  maxwidth: 260,
  caret_color: 'red'
)

To enable input you call TextInput.focus to gain the focus and catch the keyboard. When you are done, call TextInput.unfocus to release the focus. You can also query the focus status by calling TextInput.focused?.
The entered text is available in TextInput.text.
TextInput is just a simple text field, it is not a text area and it handles the following special keys: 'left', 'right', 'home', 'end', 'backspace', 'delete'.
It is up to you to release the focus - for example when 'enter' or 'esc' are pressed or the mouse is clicked outside its area.

See attached example program
example.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0