Method: Fidgit::Label#initialize

Defined in:
lib/fidgit/elements/label.rb

#initialize(text, options = {}) ⇒ Label

Returns a new instance of Label.

Parameters:

  • text (String)

    The string to display in the label.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :icon (Gosu::Image, nil) — default: nil
  • :justify (:left, :right, :center) — default: :left

    Text justification.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fidgit/elements/label.rb', line 57

def initialize(text, options = {})
  options = {
    color: default(:color),
    justify: default(:justify),
    background_color: default(:background_color),
    border_color: default(:border_color),
    icon_options: {},
    font_name: default(:font_name),
    font_height: default(:font_height),
    icon_position: default(:icon_position),
  }.merge! options

  super(options)

  # Bit of a fudge since font info is managed circularly here!
  # By using a grid, we'll be able to turn it around easily (in theory).
  @contents = grid num_rows: 1, padding: 0, spacing_h: spacing_h, spacing_v: spacing_v, width: options[:width], height: options[:height], z: z do |contents|
    @text = TextLine.new(text, parent: contents, justify: options[:justify], color: options[:color], padding: 0, z: z,
                           font_name: options[:font_name], font_height: options[:font_height], align_h: :fill, align_v: :center)
  end

  # Create an image frame, but don't show it unless there is an image in it.
  @icon = ImageFrame.new(nil, options[:icon_options].merge(z: z, align: :center))
  @icon.image = options[:icon]

  self.icon_position = options[:icon_position]
end