Class: Fidgit::ComboBox
- Extended by:
- Forwardable
- Defined in:
- lib/fidgit/elements/combo_box.rb
Constant Summary collapse
- ARROW_IMAGE =
"combo_arrow.png"
Constants inherited from Label
Constants inherited from Composite
Fidgit::Composite::DEBUG_BORDER_COLOR
Constants inherited from Element
Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V
Instance Attribute Summary
Attributes inherited from Label
#background_color, #border_color, #icon_position
Attributes inherited from Packer
Attributes inherited from Element
#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z
Instance Method Summary collapse
- #clear ⇒ Object
- #clicked_left_mouse_button(sender, x, y) ⇒ Object
- #draw ⇒ Object
- #index ⇒ Object
- #index=(index) ⇒ Object
-
#initialize(options = {}, &block) ⇒ ComboBox
constructor
A new instance of ComboBox.
- #item(text, value, options = {}, &block) ⇒ Object
- #value ⇒ Object
- #value=(value) ⇒ Object
Methods inherited from Button
#activate, #enabled=, #enter, #leave, #parent=, #text=
Methods inherited from Label
Methods inherited from Container
#add, #button, #color_picker, #color_well, #combo_box, #file_browser, #grid, #group, #hit_element, #horizontal, #image_frame, #insert, #label, #list, #radio_button, #remove, #scroll_area, #scroll_window, #slider, #text_area, #to_s, #toggle_button, #update, #vertical, #write_tree, #x=, #y=
Methods inherited from Element
#default, #drag?, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #to_s, #update, #width, #width=, #with, #x, #x=, #y, #y=
Methods included from Event
#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe
Constructor Details
#initialize(options = {}, &block) ⇒ ComboBox
Returns a new instance of ComboBox.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fidgit/elements/combo_box.rb', line 40 def initialize( = {}, &block) = { background_color: default(:background_color), border_color: default(:border_color), }.merge! @value = [:value] @hover_index = 0 @menu = MenuPane.new(show: false) do subscribe :selected do |, value| self.value = value end end @@arrow ||= Gosu::Image[ARROW_IMAGE] super('', ) rect.height = [height, font.height + padding_top + padding_bottom].max rect.width = [width, font.height * 4 + padding_left + padding_right].max end |
Instance Method Details
#clear ⇒ Object
92 93 94 95 96 |
# File 'lib/fidgit/elements/combo_box.rb', line 92 def clear self.text = "" self.icon = nil @menu.clear end |
#clicked_left_mouse_button(sender, x, y) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/fidgit/elements/combo_box.rb', line 84 def (sender, x, y) @menu.x = self.x @menu.y = self.y + height + border_thickness $window.game_state_manager.current_game_state. @menu nil end |
#draw ⇒ Object
78 79 80 81 82 |
# File 'lib/fidgit/elements/combo_box.rb', line 78 def draw super size = height / @@arrow.width.to_f @@arrow.draw x + width - height, y, z, size, size end |
#index ⇒ Object
14 |
# File 'lib/fidgit/elements/combo_box.rb', line 14 def index; @menu.index(@value) end |
#index=(index) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/fidgit/elements/combo_box.rb', line 29 def index=(index) if index.between?(0, @menu.size - 1) self.value = @menu[index].value end index end |
#item(text, value, options = {}, &block) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fidgit/elements/combo_box.rb', line 64 def item(text, value, = {}, &block) item = @menu.item(text, value, , &block) # Force text to be updated if the item added has the same value. if item.value == @value self.text = item.text self.icon = item.icon end recalc item end |
#value ⇒ Object
15 |
# File 'lib/fidgit/elements/combo_box.rb', line 15 def value; @value; end |
#value=(value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fidgit/elements/combo_box.rb', line 17 def value=(value) if @value != value @value = value item = @menu.find(@value) self.text = item.text self.icon = item.icon publish :changed, @value end value end |