Class: Hokusai::Blocks::Dynamic

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

Instance Attribute Summary

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, #initialize, inject, inject!, #method_missing, mount, #on_resize, provide, provides, style, styles_get, template, template_from_file, template_get, #update, use, uses

Constructor Details

This class inherits a constructor from Hokusai::Block

Dynamic Method Handling

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

Instance Method Details

#before_updatedObject



9
10
11
12
13
# File 'ui/src/hokusai/blocks/dynamic.rb', line 9

def before_updated
  width, height = compute_size

  emit("size_updated", width, height)
end

#compute_sizeObject



19
20
21
22
23
24
25
26
27
28
29
# File 'ui/src/hokusai/blocks/dynamic.rb', line 19

def compute_size
  h = 0.0
  w = 0.0

  children.each do |block|
    h += block.node.meta.get_prop?(:height)&.to_f || 0.0
    w += block.node.meta.get_prop?(:width)&.to_f || 0.0
  end

  [w, h]
end

#on_mountedObject



15
16
17
# File 'ui/src/hokusai/blocks/dynamic.rb', line 15

def on_mounted
  compute_size
end

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

Yields:

  • (canvas)


31
32
33
34
35
36
# File 'ui/src/hokusai/blocks/dynamic.rb', line 31

def render(canvas)
  canvas.vertical = true
  canvas.reverse = (reverse == true || reverse == "true")

  yield canvas
end