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]
@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

View File

@@ -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
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

View File

@@ -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

View File

@@ -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,