More adjustments to scrolling and scroll_top, added debug_draw to elements that draws a box around the element that is atop all rendered things

This commit is contained in:
2021-02-13 22:57:18 -06:00
parent 92dd63dc1d
commit 1e0d2004b5
4 changed files with 48 additions and 25 deletions

View File

@@ -18,6 +18,8 @@ module CyberarmEngine
@visible = @options[:visible].nil? ? true : @options[:visible] @visible = @options[:visible].nil? ? true : @options[:visible]
@tip = @options[:tip] || "" @tip = @options[:tip] || ""
@debug_color = @options[:debug_color].nil? ? Gosu::Color::RED : @options[:debug_color]
@style = Style.new(options) @style = Style.new(options)
@root ||= nil @root ||= nil
@@ -160,6 +162,31 @@ module CyberarmEngine
end end
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 def update
end end

View File

@@ -60,30 +60,13 @@ module CyberarmEngine
Gosu.clip_to(@x, @y, width, height) do Gosu.clip_to(@x, @y, width, height) do
@children.each(&:draw) @children.each(&:draw)
end end
end
if false # DEBUG def debug_draw
Gosu.flush super
Gosu.draw_line( @children.each do |child|
x, y, Gosu::Color::RED, child.debug_draw
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
)
end end
end end
@@ -206,8 +189,6 @@ module CyberarmEngine
def mouse_wheel_up(sender, x, y) def mouse_wheel_up(sender, x, y)
return unless @style.scroll return unless @style.scroll
return unless height < scroll_height
if @scroll_position.y < 0 if @scroll_position.y < 0
@scroll_position.y += @scroll_speed @scroll_position.y += @scroll_speed
@scroll_position.y = 0 if @scroll_position.y > 0 @scroll_position.y = 0 if @scroll_position.y > 0
@@ -238,7 +219,12 @@ module CyberarmEngine
def scroll_top=(n) def scroll_top=(n)
n = 0 if n <= 0 n = 0 if n <= 0
@scroll_position.y = -n @scroll_position.y = -n
if max_scroll_height.positive?
@scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height @scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
else
@scroll_position.y = 0
end
end end
def value def value

View File

@@ -55,6 +55,12 @@ module CyberarmEngine
Gosu.flush Gosu.flush
@tip.draw @tip.draw
end end
if defined?(GUI_DEBUG)
Gosu.flush
@root_container.debug_draw
end
end end
def update def update

View File

@@ -64,6 +64,10 @@ module CyberarmEngine
border_radius: 0 border_radius: 0
}, },
Container: { # < Element (Base class for Stack and Flow)
debug_color: Gosu::Color::YELLOW
},
Button: { # < Label Button: { # < Label
margin: 1, margin: 1,
padding: 4, padding: 4,