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



38
39
40
# File 'lib/dedalus/elements/image_grid.rb', line 38

def self.description
  "a grid of images"
end

.example_dataObject



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dedalus/elements/image_grid.rb', line 42

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



22
23
24
25
26
27
28
# File 'lib/dedalus/elements/image_grid.rb', line 22

def height
  if grid
    grid.length * tile_height
  else
    0
  end
end

#no_imageObject



34
35
36
# File 'lib/dedalus/elements/image_grid.rb', line 34

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

#showObject



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

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

#sprite_for(frame) ⇒ Object



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

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