lib/fidgit/elements/combo_box.rb in fidgit-0.0.5alpha vs lib/fidgit/elements/combo_box.rb in fidgit-0.0.6alpha

- old
+ new

@@ -1,9 +1,13 @@ # encoding: utf-8 module Fidgit class ComboBox < Button + extend Forwardable + + def_delegators :@menu, :each + event :changed def index; @menu.index(@value) end def value; @value; end @@ -44,10 +48,12 @@ subscribe :selected do |widget, value| self.value = value end end + @@arrow ||= Gosu::Image["combo_arrow.png"] + super('', options) rect.height = [height, font_size + padding_top + padding_bottom].max rect.width = [width, font_size * 4 + padding_left + padding_right].max end @@ -55,33 +61,48 @@ def item(text, value, options = {}, &block) item = @menu.item(text, value, options, &block) # Force text to be updated if the item added has the same value. if item.value == @value - @text = item.text + self.text = item.text + self.icon = item.icon end item end + def draw + super + size = height / @@arrow.width.to_f + @@arrow.draw x + width - height, y, z, size, size + end + def clicked_left_mouse_button(sender, x, y) @menu.x = self.x @menu.y = self.y + height + border_thickness $window.game_state_manager.current_game_state.show_menu @menu nil end + def clear + self.text = "" + self.icon = nil + @menu.clear + end + protected + def layout + super + rect.width + height # Allow size for the arrow. + + nil + end + + + protected # Any combo-box passed a block will allow you access to its methods. def post_init_block(&block) - case block.arity - when 1 - yield self - when 0 - instance_methods_eval &block - else - raise "block arity must be 0 or 1" - end + with(&block) end end end \ No newline at end of file