Class: CyberarmEngine::Element::ListBox
- Inherits:
-
Button
- Object
- CyberarmEngine::Element
- Label
- Button
- CyberarmEngine::Element::ListBox
- Defined in:
- lib/cyberarm_engine/ui/elements/list_box.rb
Constant Summary
Constants included from Theme
Instance Attribute Summary collapse
-
#choose ⇒ Object
Returns the value of attribute choose.
-
#items ⇒ Object
Returns the value of attribute items.
Attributes inherited from CyberarmEngine::Element
#background_canvas, #border_canvas, #enabled, #event_handler, #options, #parent, #style, #tip, #x, #y, #z
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options = {}, block = nil) ⇒ ListBox
constructor
A new instance of ListBox.
- #recalculate ⇒ Object
- #released_left_mouse_button(_sender, _x, _y) ⇒ Object
- #show_menu ⇒ Object
Methods inherited from Button
#blur, #clicked_left_mouse_button, #draw_image, #draw_text, #enter, #leave, #left_mouse_button, #render, #value, #value=
Methods inherited from Label
#clicked_left_mouse_button, #handle_text_wrapping, #line_width, #render, #value, #value=
Methods inherited from CyberarmEngine::Element
#background=, #button_down, #button_up, #content_height, #content_width, #default_events, #dimensional_size, #draggable?, #draw, #enabled?, #height, #hide, #hit?, #inner_height, #inner_width, #is_root?, #noncontent_height, #noncontent_width, #outer_height, #outer_width, #render, #reposition, #root, #set_background, #set_border_color, #set_border_thickness, #set_margin, #set_padding, #set_static_position, #show, #stylize, #to_s, #toggle, #update, #update_background, #value, #value=, #visible?, #width
Methods included from Common
#current_state, #darken, #draw_rect, #fill, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #show_cursor, #show_cursor=, #window
Methods included from CyberarmEngine::Event
#event, #publish, #subscribe, #unsubscribe
Methods included from Theme
#deep_merge, #default, #theme_defaults
Constructor Details
#initialize(options = {}, block = nil) ⇒ ListBox
Returns a new instance of ListBox.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cyberarm_engine/ui/elements/list_box.rb', line 7 def initialize( = {}, block = nil) @items = [:items] || [] @choose = [:choose] || @items.first super(@choose, , block) @style.background_canvas.background = default(:background) # TODO: "Clean Up" into own class? @menu = Stack.new(parent: parent, width: @options[:width], theme: @options[:theme]) @menu.define_singleton_method(:recalculate_menu) do @x = @__list_box.x @y = @__list_box.y + @__list_box.height end @menu.instance_variable_set(:"@__list_box", self) def @menu.recalculate super end end |
Instance Attribute Details
#choose ⇒ Object
Returns the value of attribute choose.
5 6 7 |
# File 'lib/cyberarm_engine/ui/elements/list_box.rb', line 5 def choose @choose end |
#items ⇒ Object
Returns the value of attribute items.
4 5 6 |
# File 'lib/cyberarm_engine/ui/elements/list_box.rb', line 4 def items @items end |
Class Method Details
.recalculate ⇒ Object
23 24 25 26 |
# File 'lib/cyberarm_engine/ui/elements/list_box.rb', line 23 def @menu.recalculate super end |
Instance Method Details
#recalculate ⇒ Object
61 62 63 64 65 |
# File 'lib/cyberarm_engine/ui/elements/list_box.rb', line 61 def recalculate super @menu.recalculate end |
#released_left_mouse_button(_sender, _x, _y) ⇒ Object
40 41 42 43 44 |
# File 'lib/cyberarm_engine/ui/elements/list_box.rb', line 40 def (_sender, _x, _y) :handled end |
#show_menu ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cyberarm_engine/ui/elements/list_box.rb', line 46 def @menu.clear @items.each do |item| [@block] block = proc { self.choose = item; @block.call(item) if @block } b = Button.new(item, { parent: @menu, width: 1.0, theme: @options[:theme], margin: 0, border_color: 0x00ffffff }, block) @menu.add(b) end recalculate root.gui_state.(@menu) end |