Class: Nuklear::UI::EditString

Inherits:
Base
  • Object
show all
Defined in:
lib/nuklear/ui/edit_string.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

descendants, #dsl, inherited

Methods included from Enableable

#disable, #disabled=, #disabled?, #enable, #enabled=, #enabled?

Methods included from Events

#event_listeners_for, #on, #trigger

Constructor Details

#initialize(text: "", flags: 0, max_length: 255, filter: nil, enabled: true) ⇒ EditString

Returns a new instance of EditString.



6
7
8
9
10
11
12
13
# File 'lib/nuklear/ui/edit_string.rb', line 6

def initialize(text: "", flags: 0, max_length: 255, filter: nil, enabled: true)
  super enabled: enabled
  @text         = text
  @flags        = Nuklear.parse_flags :edit, flags
  @max_length   = max_length
  @filter       = filter
  @demand_focus = false
end

Instance Attribute Details

#filterObject

Returns the value of attribute filter.



4
5
6
# File 'lib/nuklear/ui/edit_string.rb', line 4

def filter
  @filter
end

#flagsObject

Returns the value of attribute flags.



4
5
6
# File 'lib/nuklear/ui/edit_string.rb', line 4

def flags
  @flags
end

#max_lengthObject

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

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/nuklear/ui/edit_string.rb', line 4

def text
  @text
end

Instance Method Details

#demand_focus?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/nuklear/ui/edit_string.rb', line 15

def demand_focus?
  @demand_focus
end

#focusObject



19
20
21
# File 'lib/nuklear/ui/edit_string.rb', line 19

def focus
  @demand_focus = true
end

#result(result, context) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/nuklear/ui/edit_string.rb', line 39

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
end

#to_commandObject



35
36
37
# File 'lib/nuklear/ui/edit_string.rb', line 35

def to_command
  [:ui_edit_string, flags, text, max_length, filter]
end

#to_commandsObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nuklear/ui/edit_string.rb', line 23

def to_commands
  if demand_focus?
    @demand_focus = false
    [
      [:ui_edit_focus, flags],
      self,
    ]
  else
    [self]
  end
end