Module: Sevgi::Graphics::Mixtures::Tile
- Defined in:
- lib/sevgi/graphics/mixtures/tile.rb
Overview
DSL helpers for defining one SVG template and repeating it through use elements.
Use Sundries::Tile instead when Ruby code needs inspectable repeated geometry or row/column bounds rather than SVG references.
Constant Summary collapse
- PREFIX =
Stable prefix used for generated tile CSS classes.
"tile"
Instance Method Summary collapse
-
#Tile(id = Undefined, nx: Undefined, dx: Undefined, ox: 0, ny: Undefined, dy: Undefined, oy: 0, proc: nil) { ... } ⇒ Sevgi::Graphics::Element
Builds a two-dimensional tile grid.
-
#TileX(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil) { ... } ⇒ Sevgi::Graphics::Element
Builds a one-dimensional horizontal tile row.
-
#TileY(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil) { ... } ⇒ Sevgi::Graphics::Element
Builds a one-dimensional vertical tile column.
Instance Method Details
#Tile(id = Undefined, nx: Undefined, dx: Undefined, ox: 0, ny: Undefined, dy: Undefined, oy: 0, proc: nil) { ... } ⇒ Sevgi::Graphics::Element
Builds a two-dimensional tile grid.
Each use id has the form id-row-column, with one-based row and column numbers. Generated classes identify
the one-based row and column and mark their first and last positions. A block defines the referenced template
as a group under defs before the uses are added.
38 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/sevgi/graphics/mixtures/tile.rb', line 38 def Tile( id = Undefined, nx: Undefined, dx: Undefined, ox: 0, ny: Undefined, dy: Undefined, oy: 0, proc: nil, &block ) id, nx, dx, ox, ny, dy, oy, callback = Helper .normalize(id:, nx:, dx:, ox:, ny:, dy:, oy:, proc:) .values_at(:id, :nx, :dx, :ox, :ny, :dy, :oy, :proc) 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: [id, y + 1, x + 1].join("-"), href: "##{id}", class: [*rs, *cs].join(" "), **Helper.coordinates( x: Scalar.number((x * dx) + ox, context: "tile", field: :x), y: Scalar.number((y * dy) + oy, context: "tile", field: :y) ) ) callback&.call(element, x:, y:, nx:, ny:) end end end end |
#TileX(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil) { ... } ⇒ Sevgi::Graphics::Element
Builds a one-dimensional horizontal tile row.
Each use id has the form id-column, with a one-based column number. Generated classes identify the column and
mark its first and last positions. A block defines the referenced template as a group under defs before the
uses are added.
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 91 def TileX(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block) id, n, d, o, callback = Helper.normalize(id:, n:, d:, o:, proc:).values_at(:id, :n, :d, :o, :proc) defs { g(id:, &block) } if block Within do n.times do |x| cs = Helper.classify(as: "col", index: x, upper: n) element = use( id: [id, x + 1].join("-"), href: "##{id}", class: cs.join(" "), **Helper.coordinates(x: Scalar.number((x * d) + o, context: "tile", field: :x)) ) callback&.call(element, x:, n:) end end end |
#TileY(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil) { ... } ⇒ Sevgi::Graphics::Element
Builds a one-dimensional vertical tile column.
Each use id has the form id-row, with a one-based row number. Generated classes identify the row and mark its
first and last positions. A block defines the referenced template as a group under defs before the uses are
added.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/sevgi/graphics/mixtures/tile.rb', line 125 def TileY(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block) id, n, d, o, callback = Helper.normalize(id:, n:, d:, o:, proc:).values_at(:id, :n, :d, :o, :proc) defs { g(id:, &block) } if block Within do n.times do |y| rs = Helper.classify(as: "row", index: y, upper: n) element = use( id: [id, y + 1].join("-"), href: "##{id}", class: rs.join(" "), **Helper.coordinates(y: Scalar.number((y * d) + o, context: "tile", field: :y)) ) callback&.call(element, y:, n:) end end end |