Sha256: ef4953cd6186bad702eaf6a836cd22d92585f57f00840a15ac666ab30522b8a0

Contents?: true

Size: 1.29 KB

Versions: 10

Compression:

Stored size: 1.29 KB

Contents

module Vedeu
  class Geometry
    def initialize(values = {})
      @values = values || {}
    end

    def origin(index = 0)
      Position.set(vy(index), vx)
    end

    def z
      values[:z]
    end
    alias_method :layer, :z

    def y
      values[:y]
    end
    alias_method :row,  :y
    alias_method :line, :y

    def x
      values[:x]
    end
    alias_method :column, :x
    alias_method :col,    :x

    def width
      values[:width]
    end

    def height
      values[:height]
    end

    def dy
      clip_y? ? defaults[:height] : (y + height)
    end

    def dx
      clip_x? ? defaults[:width] : (x + width)
    end

    def vx(index = 0) # virtual x position
      ((x..dx).to_a)[index]
    end

    def vy(index = 0) # virtual y position
      ((y..dy).to_a)[index]
    end

    private

    def clip_y?
      ((y + height) > defaults[:height])
    end

    def clip_x?
      ((x + width) > defaults[:width])
    end

    def values
      defaults.merge!(auto)
    end

    def auto
      @values.delete_if { |k, v| k == :width  && v == :auto }
      @values.delete_if { |k, v| k == :height && v == :auto }
    end

    def defaults
      {
        width:  Terminal.width,
        height: Terminal.height,
        z:      0,
        y:      1,
        x:      1
      }
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
vedeu-0.0.21 lib/vedeu/output/geometry.rb
vedeu-0.0.20 lib/vedeu/output/geometry.rb
vedeu-0.0.19 lib/vedeu/output/geometry.rb
vedeu-0.0.18 lib/vedeu/output/geometry.rb
vedeu-0.0.17 lib/vedeu/output/geometry.rb
vedeu-0.0.16 lib/vedeu/output/geometry.rb
vedeu-0.0.15 lib/vedeu/output/geometry.rb
vedeu-0.0.14 lib/vedeu/output/geometry.rb
vedeu-0.0.13 lib/vedeu/output/geometry.rb
vedeu-0.0.12 lib/vedeu/output/geometry.rb