Module: Sumi::Graphics::Mixtures::Tile
- Defined in:
- graphics/lib/sumi/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) { ... } ⇒ Sumi::Graphics::Element
Builds a two-dimensional tile grid.
-
#TileX(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil) { ... } ⇒ Sumi::Graphics::Element
Builds a one-dimensional horizontal tile row.
-
#TileY(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil) { ... } ⇒ Sumi::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) { ... } ⇒ Sumi::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 'graphics/lib/sumi/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) { ... } ⇒ Sumi::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 |
# File 'graphics/lib/sumi/graphics/mixtures/tile.rb', line 91 def TileX(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block) Helper.axis(self, axis: :x, role: "col", id:, n:, d:, o:, callback: proc, &block) end |
#TileY(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil) { ... } ⇒ Sumi::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.
109 110 111 |
# File 'graphics/lib/sumi/graphics/mixtures/tile.rb', line 109 def TileY(id = Undefined, n: Undefined, d: Undefined, o: 0, proc: nil, &block) Helper.axis(self, axis: :y, role: "row", id:, n:, d:, o:, callback: proc, &block) end |