diff --git a/lib/cyberarm_engine/ui/container.rb b/lib/cyberarm_engine/ui/container.rb index 86d6228..f0ad32d 100644 --- a/lib/cyberarm_engine/ui/container.rb +++ b/lib/cyberarm_engine/ui/container.rb @@ -36,11 +36,11 @@ module CyberarmEngine end def draw - Gosu.clip_to(@x, @y, @width, @height) do + # Gosu.clip_to(@x, @y, @width, @height) do background @children.each(&:draw) - end + # end end def update @@ -79,12 +79,23 @@ module CyberarmEngine end def recalculate - @current_position = Vector.new(@margin_left + @x, @margin_top + @y) + @current_position = Vector.new(@margin_left, @margin_top) layout @width = @max_width ? @max_width : (@children.map {|c| c.x + c.width }.max + @margin_right || 0) @height = @max_height ? @max_height : (@children.map {|c| c.y + c.height}.max + @margin_bottom || 0) + + # Move child to parent after positioning + @children.each do |child| + child.x += @x + child.y += @y + + # Fix child being displaced + child.recalculate + end + # puts unless @parent + # puts "<#{self.class} X: #{@x}, Y: #{@y}, width: #{@width}, height: #{@height} (children: #{@children.count}) [#{children.first.class}]" end def layout @@ -92,7 +103,7 @@ module CyberarmEngine end def max_width - @max_width ? @max_width : window.width + @max_width ? @max_width : window.width - (@parent ? @parent.margin_right + @margin_right : @margin_right) end def fits_on_line?(element) @@ -103,6 +114,8 @@ module CyberarmEngine element.x = @current_position.x element.y = @current_position.y + element.recalculate + @current_position.x += element.width + element.margin_right @current_position.x = @margin_left + @x if @current_position.x >= max_width end @@ -111,7 +124,23 @@ module CyberarmEngine element.x = @current_position.x element.y = @current_position.y + element.recalculate + @current_position.y += element.height + element.margin_bottom end + + # def mouse_wheel_up(sender, x, y) + # @children.each {|c| c.y -= @scroll_speed} + # @children.each {|c| c.recalculate} + # end + + # def mouse_wheel_down(sender, x, y) + # @children.each {|c| c.y += @scroll_speed} + # @children.each {|c| c.recalculate} + # end + + def value + @children.map {|c| c.class}.join(", ") + end end end \ No newline at end of file diff --git a/lib/cyberarm_engine/ui/flow.rb b/lib/cyberarm_engine/ui/flow.rb index 4492674..5e6033c 100644 --- a/lib/cyberarm_engine/ui/flow.rb +++ b/lib/cyberarm_engine/ui/flow.rb @@ -4,14 +4,18 @@ module CyberarmEngine def layout @children.each do |child| - child.recalculate - if fits_on_line?(child) position_on_current_line(child) else @current_position.x = @margin_left + @x + @current_position.y += child.height + child.margin_bottom - move_to_next_line(child) + child.x = @current_position.x + child.y = @current_position.y + + child.recalculate + + @current_position.x += child.width + child.margin_right end end end diff --git a/lib/cyberarm_engine/ui/gui_state.rb b/lib/cyberarm_engine/ui/gui_state.rb index c4c6b4a..19a54c4 100644 --- a/lib/cyberarm_engine/ui/gui_state.rb +++ b/lib/cyberarm_engine/ui/gui_state.rb @@ -33,6 +33,7 @@ module CyberarmEngine if new_mouse_over new_mouse_over.publish(:enter) if new_mouse_over != @mouse_over new_mouse_over.publish(:hover) + # puts "#{new_mouse_over.class}[#{new_mouse_over.value}]: #{new_mouse_over.x}:#{new_mouse_over.y} #{new_mouse_over.width}:#{new_mouse_over.height}" if new_mouse_over != @mouse_over end @mouse_over.publish(:leave) if @mouse_over && new_mouse_over != @mouse_over @mouse_over = new_mouse_over diff --git a/lib/cyberarm_engine/ui/image.rb b/lib/cyberarm_engine/ui/image.rb index cc2998f..ef21085 100644 --- a/lib/cyberarm_engine/ui/image.rb +++ b/lib/cyberarm_engine/ui/image.rb @@ -2,6 +2,7 @@ module CyberarmEngine class Image < Element def initialize(path, options = {}, block = nil) super(options, block) + @path = path @image = Gosu::Image.new(path, retro: @options[:image_retro]) if @options[:width].nonzero? && @options[:height].nonzero? @@ -35,5 +36,9 @@ module CyberarmEngine @width = @image.width * @scale_x @height = @image.height * @scale_y end + + def value + @path + end end end \ No newline at end of file diff --git a/lib/cyberarm_engine/ui/stack.rb b/lib/cyberarm_engine/ui/stack.rb index 202909f..0d0b9f7 100644 --- a/lib/cyberarm_engine/ui/stack.rb +++ b/lib/cyberarm_engine/ui/stack.rb @@ -4,8 +4,6 @@ module CyberarmEngine def layout @children.each do |child| - child.recalculate - move_to_next_line(child) end end