Class: UI::UserInput

Inherits:
Text show all
Defined in:
scripts/01450 Systems/00000 General/00100 UI Generics/00700 UserInput.rb

Overview

Class responsive of dealing with Keyboard user input (for search or other stuff like that).

This is a Text that takes the same parameters as regular texts but has a `init` method allowing to tell how much characters are allowed, what kind of character to use for empty chars and give the handler

Example

```ruby
  @search = add_text(x, y, width, height, 'default_text', type: UI::UserInput)
  @search.init(25, '', on_new_char: method(:add_char), on_remove_char: method(:del_char))
  # ...
  def add_char(complete_string, new_char)
  # ...
  def del_char(complete_string, removed_char)
```

Constant Summary collapse

CTRL_V =

Code used to detect CTRL+V

"\u0016"
BACK =

Code used to detect backspace

"\b"

Instance Attribute Summary

Attributes inherited from LiteRGSS::Text

#__index__, #align, #bold, #draw_shadow, #fill_color, #height, #italic, #nchar_draw, #opacity, #outline_color, #outline_thickness, #real_width, #size, #text, #viewport, #visible, #width, #x, #y, #z

Instance Method Summary collapse

Methods inherited from Text

#simple_mouse_in?, #translate_mouse_coords

Methods inherited from LiteRGSS::Text

#load_color, #multiline_text=, new, #set_position, #text_width

Methods inherited from LiteRGSS::Disposable

#dispose, #disposed?

Instance Method Details

#init(max_size, empty_char = '_', on_new_char: nil, on_remove_char: nil)

Init the user input

Parameters:

  • max_size (Integer)

    maximum size of the user input

  • empty_char (String) (defaults to: '_')

    char used to replace all the remaining empty char

  • on_new_char (#call, nil) (defaults to: nil)

    called when a char is added

  • on_remove_char (#call, nil) (defaults to: nil)

    called when a char is removed



26
27
28
29
30
31
32
33
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00700 UserInput.rb', line 26

def init(max_size, empty_char = '_', on_new_char: nil, on_remove_char: nil)
  @current_text = ''
  @max_size = max_size.abs
  @empty_char = empty_char
  @on_new_char = on_new_char
  @on_remove_char = on_remove_char
  load_text(text)
end

#update

Update the user input



36
37
38
39
40
# File 'scripts/01450 Systems/00000 General/00100 UI Generics/00700 UserInput.rb', line 36

def update
  return unless @max_size
  return unless (text = Input.get_text)
  load_text(text)
end