Improvements

This commit is contained in:
2022-05-02 19:09:50 -05:00
parent ed2c1929e7
commit ef477cfdd5
16 changed files with 333 additions and 31 deletions

52
lib/gui_state_ext.rb Normal file
View File

@@ -0,0 +1,52 @@
module CyberarmEngine
class GuiState < CyberarmEngine::GameState
def menu(host_element, items:, width: 200)
container = CyberarmEngine::Element::Stack.new(
parent: host_element.parent,
width: width,
theme: W3DHub::THEME,
border_color: 0xff_000000,
border_thickness: 1
)
container.instance_variable_set(:"@__menu", host_element)
container.define_singleton_method(:recalculate_menu) do
@x = @__menu.x
@y = @__menu.y + @__menu.height
@y = @__menu.y - height if @y + height > window.height
end
def container.recalculate
super
recalculate_menu
end
items.each do |item|
btn = CyberarmEngine::Element::Button.new(
item[:label],
{
parent: container,
width: 1.0,
text_align: :left,
theme: W3DHub::THEME,
border_thickness: 0,
margin: 0
},
proc do
item[:block]&.call
end
)
container.add(btn)
end
container.recalculate
container.recalculate
container.recalculate
show_menu(container)
end
end
end