Sha256: 46f67f4a55ff5d9b7515546883733e3922ad3708c15a2a6a1759223c87e39a27

Contents?: true

Size: 932 Bytes

Versions: 1

Compression:

Stored size: 932 Bytes

Contents

module Vedeu

  module Borders

    # When a {Vedeu::Borders::Border} has a caption, truncate it if
    # the caption is longer than the interface is wide, and pad with a
    # space either side.
    #
    # @api private
    #
    class Caption < Title

      # Overwrite the border from {#build_horizontal} on the bottom
      # border to include the caption if given.
      #
      # @param [Array<Vedeu::Views::Char>]
      # @return [Array<Vedeu::Views::Char>]
      def render
        return chars if empty?

        caption_index = 0
        chars.each_with_index do |char, index|
          next if index <= start_index || index > (width - 4)

          char.border   = nil
          char.value    = characters[caption_index]
          caption_index += 1
        end
      end

      private

      # @return [Fixnum]
      def start_index
        (width - size) - 4
      end

    end # Caption

  end # Borders

end # Vedeu

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.6.63 lib/vedeu/borders/caption.rb