Sha256: f721e81d07d0ca9391af3d39c4461547a62b9cb59a27f2dd09dbe28f6aaa30ec

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require "subtle/subtlext"
module Dominikh
  # @abstract Subclass and override {#render} to implement a dynamic
  # icon, e.g. a graph.
  # @see http://rdoc.subforge.org/subtle/classes/Subtlext/Icon.html
  class DynamicIcon < Subtlext::Icon
    attr_reader :color

    def initialize(width, height)
      super(width, height)
      @color               = nil
    end

    def color=(val)
      case val
      when Subtlext::Color
        @color = val
      when NilClass
        @color = nil
      else
        @color = Subtlext::Color.new(val.to_s)
      end
    end

    # return [String]
    def to_str
      s = super
      if color
        p " -->"
        p Subtlext::Subtle.colors[:fg_sublets]
        return color + s + Subtlext::Subtle.colors[:fg_sublets].to_s
      else
        return s
      end
    end
    alias_method :to_s, :to_str

    def +(other)
      self.to_s + other
    end

    # Draws the icon. Redefine this in subclasses to define custom
    # drawing routines.
    #
    # @return [void]
    def render
      clear
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
subtle-dynamic_icon-0.0.2 lib/subtle/dominikh/dynamic_icon.rb