Class: Dedalus::Elements::ImageGrid

Inherits:
Molecule show all
Defined in:
lib/dedalus/elements/image_grid.rb

Instance Attribute Summary collapse

Attributes inherited from Dedalus::Element

#background_color, #color, #height_percent, #margin, #padding, #position, #width, #width_percent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Molecule

#click, #hover

Methods inherited from Dedalus::Element

#big_font, #code_font, #draw_bounding_box, #font, #huge_font, #initialize, #tiny_font, #view, #window

Constructor Details

This class inherits a constructor from Dedalus::Element

Instance Attribute Details

#gridObject

Returns the value of attribute grid.



4
5
6
# File 'lib/dedalus/elements/image_grid.rb', line 4

def grid
  @grid
end

#tile_heightObject

Returns the value of attribute tile_height.



4
5
6
# File 'lib/dedalus/elements/image_grid.rb', line 4

def tile_height
  @tile_height
end

#tile_widthObject

Returns the value of attribute tile_width.



4
5
6
# File 'lib/dedalus/elements/image_grid.rb', line 4

def tile_width
  @tile_width
end

#tiles_pathObject

Returns the value of attribute tiles_path.



4
5
6
# File 'lib/dedalus/elements/image_grid.rb', line 4

def tiles_path
  @tiles_path
end

Class Method Details

.descriptionObject



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

def self.description
  "a grid of images"
end

.example_dataObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dedalus/elements/image_grid.rb', line 34

def self.example_data
  {
    tiles_path: "media/images/tiles.png",
    tile_width: 64,
    tile_height: 64,
    grid: [
      [ nil, 0, 2, 0 ],
      [ 0, nil, 1, 0 ],
      [ 0, 0, nil, 0 ],
      [ 0, 1, 2, nil ],
    ]
  }
end

Instance Method Details

#heightObject



18
19
20
# File 'lib/dedalus/elements/image_grid.rb', line 18

def height
  grid.length * tile_height
end

#no_imageObject



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

def no_image
  Void.new(height: tile_height, width: tile_width)
end

#showObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dedalus/elements/image_grid.rb', line 6

def show
  grid.map do |row|
    row.map do |grid_value|
      if grid_value
        sprite_for(grid_value)
      else
        no_image
      end
    end
  end
end

#sprite_for(frame) ⇒ Object



22
23
24
# File 'lib/dedalus/elements/image_grid.rb', line 22

def sprite_for(frame)
  Sprite.new(frame: frame, width: tile_width, height: tile_height, path: tiles_path)
end