Class: Nuklear::UI::EditString
- Defined in:
- lib/nuklear/ui/edit_string.rb
Instance Attribute Summary collapse
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#max_length ⇒ Object
Returns the value of attribute max_length.
-
#text ⇒ Object
Returns the value of attribute text.
-
#text_was ⇒ Object
readonly
Returns the value of attribute text_was.
Instance Method Summary collapse
- #demand_focus? ⇒ Boolean
- #focus ⇒ Object
-
#initialize(text: "", flags: :simple, max_length: 255, filter: nil, enabled: true, &on_change) ⇒ EditString
constructor
A new instance of EditString.
- #result(result, context) ⇒ Object
- #to_command ⇒ Object
- #to_commands ⇒ Object
Methods inherited from Base
Methods included from Enableable
#disable, #disabled=, #disabled?, #enable, #enabled=, #enabled?
Methods included from Events
#event_listeners_for, #on, #trigger
Constructor Details
#initialize(text: "", flags: :simple, max_length: 255, filter: nil, enabled: true, &on_change) ⇒ EditString
Returns a new instance of EditString.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/nuklear/ui/edit_string.rb', line 7 def initialize(text: "", flags: :simple, max_length: 255, filter: nil, enabled: true, &on_change) super enabled: enabled @text = text @flags = Nuklear.parse_flags :edit, flags @max_length = max_length @filter = filter @demand_focus = false @text_was = text.dup on(:change, &on_change) if block_given? end |
Instance Attribute Details
#filter ⇒ Object
Returns the value of attribute filter.
4 5 6 |
# File 'lib/nuklear/ui/edit_string.rb', line 4 def filter @filter end |
#flags ⇒ Object
Returns the value of attribute flags.
4 5 6 |
# File 'lib/nuklear/ui/edit_string.rb', line 4 def flags @flags end |
#max_length ⇒ Object
Returns the value of attribute max_length.
4 5 6 |
# File 'lib/nuklear/ui/edit_string.rb', line 4 def max_length @max_length end |
#text ⇒ Object
Returns the value of attribute text.
4 5 6 |
# File 'lib/nuklear/ui/edit_string.rb', line 4 def text @text end |
#text_was ⇒ Object (readonly)
Returns the value of attribute text_was.
5 6 7 |
# File 'lib/nuklear/ui/edit_string.rb', line 5 def text_was @text_was end |
Instance Method Details
#demand_focus? ⇒ Boolean
19 20 21 |
# File 'lib/nuklear/ui/edit_string.rb', line 19 def demand_focus? @demand_focus end |
#focus ⇒ Object
23 24 25 |
# File 'lib/nuklear/ui/edit_string.rb', line 23 def focus @demand_focus = true end |
#result(result, context) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nuklear/ui/edit_string.rb', line 43 def result(result, context) trigger(:activated) if (result & Nuklear::NK_EDIT_ACTIVATED) > 0 trigger(:deactivated) if (result & Nuklear::NK_EDIT_DEACTIVATED) > 0 trigger(:committed) if (result & Nuklear::NK_EDIT_COMMITED) > 0 trigger(:active) if (result & Nuklear::NK_EDIT_ACTIVE) > 0 trigger(:inactive) if (result & Nuklear::NK_EDIT_INACTIVE) > 0 if @text != @text_was trigger :change @text_was.clear @text_was.concat @text end end |
#to_command ⇒ Object
39 40 41 |
# File 'lib/nuklear/ui/edit_string.rb', line 39 def to_command [:ui_edit_string, flags, text, max_length, filter] end |
#to_commands ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/nuklear/ui/edit_string.rb', line 27 def to_commands if demand_focus? @demand_focus = false [ [:ui_edit_focus, flags], self, ] else [self] end end |