diff --git a/lib/cyberarm_engine/ui/element.rb b/lib/cyberarm_engine/ui/element.rb index 3fda6a1..a09ea2d 100644 --- a/lib/cyberarm_engine/ui/element.rb +++ b/lib/cyberarm_engine/ui/element.rb @@ -18,6 +18,8 @@ module CyberarmEngine @visible = @options[:visible].nil? ? true : @options[:visible] @tip = @options[:tip] || "" + @debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color] + @style = Style.new(options) @root ||= nil @@ -160,6 +162,31 @@ module CyberarmEngine end end + def debug_draw + return if defined?(GUI_DEBUG_ONLY_ELEMENT) && self.class == GUI_DEBUG_ONLY_ELEMENT + + Gosu.draw_line( + x, y, @debug_color, + x + outer_width, y, @debug_color, + Float::INFINITY + ) + Gosu.draw_line( + x + outer_width, y, @debug_color, + x + outer_width, y + outer_height, @debug_color, + Float::INFINITY + ) + Gosu.draw_line( + x + outer_width, y + outer_height, @debug_color, + x, y + outer_height, @debug_color, + Float::INFINITY + ) + Gosu.draw_line( + x, outer_height, @debug_color, + x, y, @debug_color, + Float::INFINITY + ) + end + def update end diff --git a/lib/cyberarm_engine/ui/elements/container.rb b/lib/cyberarm_engine/ui/elements/container.rb index 197796c..7a2dd6c 100644 --- a/lib/cyberarm_engine/ui/elements/container.rb +++ b/lib/cyberarm_engine/ui/elements/container.rb @@ -60,30 +60,13 @@ module CyberarmEngine Gosu.clip_to(@x, @y, width, height) do @children.each(&:draw) end + end - if false # DEBUG - Gosu.flush + def debug_draw + super - Gosu.draw_line( - x, y, Gosu::Color::RED, - x + outer_width, y, Gosu::Color::RED, - Float::INFINITY - ) - Gosu.draw_line( - x + outer_width, y, Gosu::Color::RED, - x + outer_width, y + outer_height, Gosu::Color::RED, - Float::INFINITY - ) - Gosu.draw_line( - x + outer_width, y + outer_height, Gosu::Color::RED, - x, y + outer_height, Gosu::Color::RED, - Float::INFINITY - ) - Gosu.draw_line( - x, outer_height, Gosu::Color::RED, - x, y, Gosu::Color::RED, - Float::INFINITY - ) + @children.each do |child| + child.debug_draw end end @@ -206,8 +189,6 @@ module CyberarmEngine def mouse_wheel_up(sender, x, y) return unless @style.scroll - return unless height < scroll_height - if @scroll_position.y < 0 @scroll_position.y += @scroll_speed @scroll_position.y = 0 if @scroll_position.y > 0 @@ -238,7 +219,12 @@ module CyberarmEngine def scroll_top=(n) n = 0 if n <= 0 @scroll_position.y = -n - @scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height + + if max_scroll_height.positive? + @scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height + else + @scroll_position.y = 0 + end end def value diff --git a/lib/cyberarm_engine/ui/gui_state.rb b/lib/cyberarm_engine/ui/gui_state.rb index 9e5bfa6..53004ef 100644 --- a/lib/cyberarm_engine/ui/gui_state.rb +++ b/lib/cyberarm_engine/ui/gui_state.rb @@ -55,6 +55,12 @@ module CyberarmEngine Gosu.flush @tip.draw end + + if defined?(GUI_DEBUG) + Gosu.flush + + @root_container.debug_draw + end end def update diff --git a/lib/cyberarm_engine/ui/theme.rb b/lib/cyberarm_engine/ui/theme.rb index 5f218b1..e6c6746 100644 --- a/lib/cyberarm_engine/ui/theme.rb +++ b/lib/cyberarm_engine/ui/theme.rb @@ -64,6 +64,10 @@ module CyberarmEngine border_radius: 0 }, + Container: { # < Element (Base class for Stack and Flow) + debug_color: Gosu::Color::YELLOW + }, + Button: { # < Label margin: 1, padding: 4,