Module: Sevgi::Graphics::Mixtures::Tile

Defined in:
lib/sevgi/graphics/mixtures/tile.rb

Overview

rubocop:disable Metrics/MethodLength

Constant Summary collapse

PREFIX =
"tile"

Instance Method Summary collapse

Instance Method Details

#Tile(id = Undefined, nx: Undefined, dx: Undefined, ox: 0, ny: Undefined, dy: Undefined, oy: 0, proc: nil, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 10

def Tile(
  id = Undefined,
  nx: Undefined,
  dx: Undefined,
  ox: 0,
  ny: Undefined,
  dy: Undefined,
  oy: 0,
  proc: nil,
  &block
)
  Helper.assert(id:, nx:, dx:, ox:, ny:, dy:, oy:, proc:)

  href, coords = id, proc do |x, y|
    # rubocop:disable Style/NestedTernaryOperator
    # for pretty kwargs handling
    x.zero? ? (y.zero? ? {} : {y:}) : (y.zero? ? {x:} : {x:, y:})
    # rubocop:enable Style/NestedTernaryOperator
  end

  defs { g(id:, &block) } if block

  Within do
    ny.times do |y|
      rs = Helper.classify(as: "row", index: y, upper: ny)

      nx.times do |x|
        cs = Helper.classify(as: "col", index: x, upper: nx)

        element = use(
          id: [href, y + 1, x + 1].join("-"),
          href: "##{href}",
          class: [*rs, *cs].join(" "),
          **coords.((x * dx) + ox, (y * dy) + oy)
        )
        proc&.call(element, x:, y:, nx:, ny:)
      end
    end
  end
end

#Tile!(id, klass = PREFIX) ⇒ Object



51
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 51

def Tile!(id, klass = PREFIX, ...) = g(id:, class: klass) { Tile(id, ...) }

#TileX(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 53

def TileX(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block)
  Helper.assert(id:, n:, d:, o:, proc:)

  href, coords = id, proc do |x|
    # for pretty kwargs handling
    x.zero? ? {} : {x:}
  end

  defs { g(id:, &block) } if block

  Within do
    n.times do |x|
      cs = Helper.classify(as: "col", index: x, upper: n)

      element = use(
        id: [href, x + 1].join("-"),
        href: "##{href}",
        class: cs.join(" "),
        **coords.((x * d) + o)
      )
      proc&.call(element, x:, n:)
    end
  end
end

#TileX!(id, klass = PREFIX) ⇒ Object



78
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 78

def TileX!(id, klass = PREFIX, ...) = g(id:, class: klass) { TileX(id, ...) }

#TileY(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 80

def TileY(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block)
  Helper.assert(id:, n:, d:, o:, proc:)

  href, coords = id, proc do |y|
    # for pretty kwargs handling
    y.zero? ? {} : {y:}
  end

  defs { g(id:, &block) } if block

  Within do
    n.times do |y|
      rs = Helper.classify(as: "row", index: y, upper: n)

      element = use(
        id: [href, y + 1].join("-"),
        href: "##{href}",
        class: rs.join(" "),
        **coords.((y * d) + o)
      )
      proc&.call(element, y:, n:)
    end
  end
end

#TileY!(id, klass = PREFIX) ⇒ Object



105
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 105

def TileY!(id, klass = PREFIX, ...) = g(id:, class: klass) { TileY(id, ...) }