Method: Fidgit::ComboBox#initialize

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

#initialize(options = {}, &block) ⇒ ComboBox

Returns a new instance of ComboBox.

Parameters:

  • text (String)

    The string to display in the label.

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

    a customizable set of options

Options Hash (options):

  • [] (Object)

    :value

  • :shortcut (Symbol) — default: nil

    Adds a shortcut key for this element, that activates it. :auto takes the first letter of the text.

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

    Text justification.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fidgit/elements/combo_box.rb', line 39

def initialize(options = {}, &block)
  options = {
    background_color: default(:background_color),
    border_color: default(:border_color),
  }.merge! options

  @value = options[:value]
  
  @hover_index = 0

  @menu = MenuPane.new(show: false) do
    subscribe :selected do |widget, value|
      self.value = value
    end
  end

  @@arrow ||= Gosu::Image[ARROW_IMAGE]

  super('', options)

  rect.height = [height, font.height + padding_top + padding_bottom].max
  rect.width = [width, font.height * 4 + padding_left + padding_right].max
end