Class: Dedalus::ApplicationViewComposer
- Inherits:
-
Object
- Object
- Dedalus::ApplicationViewComposer
- Includes:
- Geometer::DimensionHelpers, Geometer::PointHelpers
- Defined in:
- lib/dedalus/app_view_composer.rb
Instance Method Summary collapse
- #click_molecule(structure, window_dims, mouse_position:) ⇒ Object
- #hover_molecule(structure, window_dims, mouse_position:) ⇒ Object
- #render!(structure, dims) ⇒ Object
- #send_molecule(structure, window_dims, mouse_position:, message:) ⇒ Object
- #traverse(structure, origin: [0,0], dimensions:, render: false, &blk) ⇒ Object
Instance Method Details
#click_molecule(structure, window_dims, mouse_position:) ⇒ Object
35 36 37 |
# File 'lib/dedalus/app_view_composer.rb', line 35 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
31 32 33 |
# File 'lib/dedalus/app_view_composer.rb', line 31 def hover_molecule(structure, window_dims, mouse_position:) send_molecule(structure, window_dims, mouse_position: mouse_position, message: :hover) end |
#render!(structure, dims) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/dedalus/app_view_composer.rb', line 39 def render!(structure, dims) traverse(structure, origin: [0,0], dimensions: dims, render: true) do on_atom do |atom, origin:, dimensions:, freeform:, z_index:| if atom.background_color atom.draw_bounding_box( color: atom.background_color, origin: origin, dimensions: dimensions ) end if freeform # then offset by origin x0,y0 = *origin x,y = *atom.position atom.position = [x+x0,y+y0] else atom.position = origin end atom.z_order = z_index atom.render end on_element do |element, origin:, dimensions:, z_index:| 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
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dedalus/app_view_composer.rb', line 12 def send_molecule(structure, window_dims, mouse_position:, message:) mouse_coord = coord(*mouse_position) updated_structure = traverse(structure, origin: [0,0], dimensions: window_dims) do on_molecule do |molecule, origin:, dimensions:, z_index:| 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.position = origin molecule.send() end molecule end end updated_structure end |
#traverse(structure, origin: [0,0], dimensions:, render: false, &blk) ⇒ Object
6 7 8 9 10 |
# File 'lib/dedalus/app_view_composer.rb', line 6 def traverse(structure, origin: [0,0], dimensions:, render: false, &blk) traversal = ViewTraversal.new(&blk) structure = traversal.walk!(structure, origin: origin, dimensions: dimensions, render: render) structure end |