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: :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

#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

#text_wasObject (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

Returns:

  • (Boolean)


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

def demand_focus?
  @demand_focus
end

#focusObject



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_commandObject



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_commandsObject



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