Class: Gosu::TextInput

Inherits:
Object
  • Object
show all
Defined in:
rdoc/gosu.rb

Overview

A TextInput is an invisible object that handles input using the operating system's input manager.

At its most basic, you only need to set Window#text_input to an instance of this class. The TextInput will then handle all keyboard input until Window#text_input is set to `nil`. Any text the user has typed is available through #text.

This class is purely back-end and does not come with a GUI; drawing the input field is up to you, the programmer. The best way to do that is left completely open. TextInput only aims to provide a foundation for you to build your own GUI.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#caret_posInteger

Returns the position of the editing caret.

Returns:

  • (Integer)

    the position of the editing caret.


683
684
685
# File 'rdoc/gosu.rb', line 683

def caret_pos
  @caret_pos
end

#selection_startInteger

Returns the starting position of the currently selected text.

Returns:

  • (Integer)

    the starting position of the currently selected text.


687
688
689
# File 'rdoc/gosu.rb', line 687

def selection_start
  @selection_start
end

#textString

Returns the text that the user has typed.

Returns:

  • (String)

    the text that the user has typed.


679
680
681
# File 'rdoc/gosu.rb', line 679

def text
  @text
end

Instance Method Details

#delete_backwardObject

Deletes the current selection, if any, or the previous character.


717
# File 'rdoc/gosu.rb', line 717

def delete_backward; end

#delete_forwardObject

Deletes the current selection, if any, or the next character.


713
# File 'rdoc/gosu.rb', line 713

def delete_forward; end

#filterString

This method is an overridable filter that is applied to all newly entered text. This allows for restricting input characters or format, automatic macro or abbreviation expansion and so on.

The return value of this method will be inserted at the current caret position.

The default implementation returns its argument unchanged.

Examples:

Forcing input to all uppercase, alphanumeric characters.

input = TextInput.new
def input.filter(text_in)
  text_in.upcase.gsub(/[^A-Z0-9]/, '')
end

Parameters:

  • text_in (String)

    the text typed by the user.

Returns:

  • (String)

    the string to be inserted.


704
# File 'rdoc/gosu.rb', line 704

def filter; end

#insert_text(str) ⇒ Object

Replaces the current selection (if any) and inserts the given string at the current caret position. The filter method will not be applied before appending the string.


709
# File 'rdoc/gosu.rb', line 709

def insert_text(str); end