class Fidgit::MenuPane
Public Class Methods
new(options = {}, &block)
click to toggle source
@option (see Composite#initialize) @option options [Float] :x (cursor x, if in a GuiState
) @option options [Float] :y (cursor y, if in a GuiState
) @option options [Boolean] :show (true) Whether to show immediately (show later with show
).
Calls superclass method
Fidgit::Composite::new
# File lib/fidgit/elements/menu_pane.rb, line 77 def initialize(options = {}, &block) options = { background_color: default(:color), z: Float::INFINITY, show: true, }.merge! options state = $window.current_game_state if state.is_a? GuiState cursor = $window.current_game_state.cursor options = { x: cursor.x, y: cursor.y, }.merge! options end @items = nil super(options) @items = vertical spacing: 0, padding: 0 if options[:show] and state.is_a? GuiState show end end
Public Instance Methods
find(value)
click to toggle source
# File lib/fidgit/elements/menu_pane.rb, line 104 def find(value) @items.find {|c| c.value == value } end
index(value)
click to toggle source
# File lib/fidgit/elements/menu_pane.rb, line 69 def index(value); @items.index find(value); end
item(text, value, options = {}, &block)
click to toggle source
# File lib/fidgit/elements/menu_pane.rb, line 114 def item(text, value, options = {}, &block) options = options.merge({ parent: @items, z: z, }) item = Item.new(text, value, options, &block) item.subscribe :left_mouse_button, method(:item_selected) item.subscribe :right_mouse_button, method(:item_selected) item end
item_selected(sender, x, y)
click to toggle source
# File lib/fidgit/elements/menu_pane.rb, line 127 def item_selected(sender, x, y) publish(:selected, sender.value) $window.game_state_manager.current_game_state.hide_menu nil end
separator(options = {})
click to toggle source
# File lib/fidgit/elements/menu_pane.rb, line 108 def separator(options = {}) options[:z] = z Separator.new({ parent: @items }.merge!(options)) end
show()
click to toggle source
# File lib/fidgit/elements/menu_pane.rb, line 135 def show $window.game_state_manager.current_game_state.show_menu self nil end
x=(value)
click to toggle source
Calls superclass method
# File lib/fidgit/elements/menu_pane.rb, line 70 def x=(value); super(value); recalc; end
y=(value)
click to toggle source
Calls superclass method
# File lib/fidgit/elements/menu_pane.rb, line 71 def y=(value); super(value); recalc; end
Protected Instance Methods
layout()
click to toggle source
Calls superclass method
# File lib/fidgit/elements/menu_pane.rb, line 141 def layout super if @items # Ensure the menu can't go over the edge of the screen. If it can't be avoided, align with top-left edge of screen. rect.x = [[x, $window.width - width - padding_right].min, 0].max rect.y = [[y, $window.height - height - padding_bottom].min, 0].max # Move the actual list if the menu has moved to keep on the screen. @items.x = x + padding_left @items.y = y + padding_top # Ensure that all items are of the same width. max_width = @items.map(&:width).max || 0 @items.each {|c| c.rect.width = max_width } @items.recalc # Move all the items inside the packer to correct ones. end nil end