Class: Nuklear::UI::Checkbox

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

Direct Known Subclasses

Option, Selectable

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, checked: false, enabled: true, &block) ⇒ Checkbox

Returns a new instance of Checkbox.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/nuklear/ui/checkbox.rb', line 6

def initialize(text, checked: false, enabled: true, &block)
  super enabled: enabled
  @text = text
  @checked = checked
  on(true) { @checked = true }
  on(false) { @checked = false }
  if block_given?
    on true,  &block
    on false, &block
  end
end

Instance Attribute Details

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#checked=(checked) ⇒ Object Also known as: selected=



22
23
24
25
# File 'lib/nuklear/ui/checkbox.rb', line 22

def checked=(checked)
  @checked = checked
  @last_event = checked
end

#checked?Boolean Also known as: selected?

Returns:

  • (Boolean)


18
19
20
# File 'lib/nuklear/ui/checkbox.rb', line 18

def checked?
  @checked
end

#result(event, context) ⇒ Object



34
35
36
# File 'lib/nuklear/ui/checkbox.rb', line 34

def result(event, context)
  trigger event
end

#to_commandObject



30
31
32
# File 'lib/nuklear/ui/checkbox.rb', line 30

def to_command
  [ :ui_checkbox, text, checked? ]
end