Class: Dedalus::ApplicationViewComposer

Inherits:
Object
  • Object
show all
Includes:
Geometer::DimensionHelpers, Geometer::PointHelpers
Defined in:
lib/dedalus/app_view_composer.rb

Instance Method Summary collapse

Instance Method Details

#click_molecule(structure, window_dims, mouse_position:) ⇒ Object



30
31
32
# File 'lib/dedalus/app_view_composer.rb', line 30

def click_molecule(structure, window_dims, mouse_position:)
  send_molecule(structure, window_dims, mouse_position: mouse_position, message: :click)
end

#hover_molecule(structure, window_dims, mouse_position:) ⇒ Object



26
27
28
# File 'lib/dedalus/app_view_composer.rb', line 26

def hover_molecule(structure, window_dims, mouse_position:)
  send_molecule(structure, window_dims, mouse_position: mouse_position, message: :hover)
end

#render!(structure, dims) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dedalus/app_view_composer.rb', line 34

def render!(structure, dims)
  traverse(structure, origin: [0,0], dimensions: dims) do
    on_atom do |atom, origin:, dimensions:, freeform:|
      if atom.background_color
        atom.draw_bounding_box(
          color: atom.background_color,
          origin: origin,
          dimensions: dimensions
        )
      end

      atom.position = origin unless freeform
      atom.render
    end

    on_element do |element, origin:, dimensions:|
      if element.background_color
        element.draw_bounding_box(
          color: element.background_color,
          origin: origin,
          dimensions: dimensions
        )
      end
      element.position = origin # ...
    end
  end
end

#send_molecule(structure, window_dims, mouse_position:, message:) ⇒ Object

, origin: [0,0], dimensions:, mouse_position:)



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dedalus/app_view_composer.rb', line 12

def send_molecule(structure, window_dims, mouse_position:, message:) #, origin: [0,0], dimensions:, mouse_position:)
  mouse_coord = coord(*mouse_position)

  traverse(structure, origin: [0,0], dimensions: window_dims) do
    on_molecule do |molecule, origin:, dimensions:|
      element_bounding_box = Geometer::Rectangle.new(coord(*origin), dim(*dimensions))
      mouse_overlap = element_bounding_box.contains?(mouse_coord) rescue false # could get bad coords...
      if mouse_overlap
        molecule.send(message)
      end
    end
  end
end

#traverse(structure, origin: [0,0], dimensions:, &blk) ⇒ Object



6
7
8
9
10
# File 'lib/dedalus/app_view_composer.rb', line 6

def traverse(structure, origin: [0,0], dimensions:, &blk)
  traversal = ViewTraversal.new(&blk)
  traversal.walk!(structure, origin: origin, dimensions: dimensions)
  structure
end