Class: Hokusai::Blocks::Checkbox

Inherits:
Hokusai::Block show all
Defined in:
ui/src/hokusai/blocks/checkbox.rb

Constant Summary collapse

DEFAULT_COLOR =
[184,201,219]
DEFAULT_CIRCLE_COLOR =
[44, 113, 183]

Instance Attribute Summary collapse

Attributes inherited from Hokusai::Block

#node, #provides, #publisher

Instance Method Summary collapse

Methods inherited from Hokusai::Block

#children, #children?, compile, computed, computed!, #draw, #draw_with, #dump, #emit, inject, inject!, #method_missing, mount, #on_resize, provide, provides, style, styles_get, template, template_from_file, template_get, #update, use, uses

Constructor Details

#initialize(**args) ⇒ Checkbox

Returns a new instance of Checkbox.



39
40
41
42
43
# File 'ui/src/hokusai/blocks/checkbox.rb', line 39

def initialize(**args)
  @checked = false

  super(**args)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hokusai::Block

Instance Attribute Details

#checkedObject

Returns the value of attribute checked.



27
28
29
# File 'ui/src/hokusai/blocks/checkbox.rb', line 27

def checked
  @checked
end

Instance Method Details

#check(event) ⇒ Object



33
34
35
36
37
# File 'ui/src/hokusai/blocks/checkbox.rb', line 33

def check(event)
  self.checked = !checked

  emit("check", checked)
end

#circle_sizeObject



29
30
31
# File 'ui/src/hokusai/blocks/checkbox.rb', line 29

def circle_size
  (size.to_f * 0.35)
end

#render(canvas) {|canvas| ... } ⇒ Object

Yields:

  • (canvas)


45
46
47
48
49
50
# File 'ui/src/hokusai/blocks/checkbox.rb', line 45

def render(canvas)
  canvas.width = size.to_f
  canvas.height = size.to_f

  yield canvas
end