Class: Tuile::Component::IntegerField::Field

Inherits:
TextField show all
Defined in:
lib/tuile/component/integer_field.rb,
sig/tuile.rbs

Overview

The face: a TextField that admits only the buffers an integer can be typed through, however the characters arrive.

Constant Summary collapse

TYPEABLE =

Buffers reachable by typing an integer: an optional leading -, then digits. Looser than the parse on purpose — the half-typed "" and "-" are members, or no value could be typed at all, and Tuile::Component::IntegerField#value reads both back as nil.

Returns:

  • (Regexp)
/\A-?\d*\z/

Instance Attribute Summary

Attributes inherited from TextField

#left_column, #max_text_length

Attributes inherited from AbstractStringField

#caret, #escape_clears_focus, #text

Instance Method Summary collapse

Methods inherited from TextField

#adjust_left_column, #column_at, #cursor_position, #display_text, #handle_caret_mutated, #handle_mouse_down?, #handle_text_input_key?, #handle_text_mutated, #index_at, #initialize, #insert, #inspect_details, #on_enter, #on_key_down, #on_key_up, #placeholder, #placeholder=, #placeholder_row, #preprocess_paste, #relayout, #repaint, #show_placeholder?, #snap_to_glyph_start, #text_columns, #visible_text

Methods included from HasPlaceholder

#inspect_details, #placeholder, #placeholder=

Methods inherited from AbstractStringField

#clear, #cluster_boundary_after, #cluster_boundary_before, #columns_of, #delete_at_caret, #delete_back_to, #delete_before_caret, #empty?, #empty_value, #error_bg_color, #error_ink?, #error_message, #error_message=, #focusable?, #handle_caret_mutated, #handle_key?, #handle_paste, #handle_text_input_key?, #handle_text_mutated, #initialize, #inspect_details, #on_error_message_change, #on_escape, #on_value_change, #preprocess_paste, #preprocess_text, #set_value, #shown_message, #snap_to_cluster, #tab_stop?, #value, #value=, #word_left, #word_right

Methods included from HasValue

#clear, #empty?, #empty_value, #error_bg_color, #error_ink?, #error_message, #error_message=, #focusable?, #inspect_details, listener, #on_error_message_change, #on_value_change, #set_value, #shown_message, #value, #value=

Methods included from Listeners::Declare

#listener

Methods included from HasValidation

#error_bg_color, #error_ink?, #error_message, #error_message=, #inspect_details, listener, #on_error_message_change, #shown_message

Constructor Details

This class inherits a constructor from Tuile::Component::TextField

Instance Method Details

#insert_text(str) ⇒ Boolean

Accepts the insertion only if the whole resulting buffer is still typeable, so "12abc34" is dropped rather than sieved into "1234".

@param str

@return — true if the text changed.

Parameters:

  • str (String)

Returns:

  • (Boolean)


60
61
62
63
64
# File 'lib/tuile/component/integer_field.rb', line 60

def insert_text(str)
  return false unless TYPEABLE.match?(@text.dup.insert(@caret, str))

  super
end