lib/cyberarm_engine/ui/elements/container.rb in cyberarm_engine-0.17.1 vs lib/cyberarm_engine/ui/elements/container.rb in cyberarm_engine-0.18.0
- old
+ new
@@ -58,34 +58,17 @@
def render
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
def update
@children.each(&:update)
@@ -203,11 +186,10 @@
@current_position.y += element.outer_height
end
def mouse_wheel_up(sender, x, y)
return unless @style.scroll
- return if height < max_scroll_height
if @scroll_position.y < 0
@scroll_position.y += @scroll_speed
@scroll_position.y = 0 if @scroll_position.y > 0
recalculate
@@ -216,17 +198,33 @@
end
end
def mouse_wheel_down(sender, x, y)
return unless @style.scroll
- return if height < max_scroll_height
+ return unless height < scroll_height
+
if @scroll_position.y.abs < max_scroll_height
@scroll_position.y -= @scroll_speed
@scroll_position.y = -max_scroll_height if @scroll_position.y.abs > max_scroll_height
recalculate
return :handled
+ end
+ end
+
+ def scroll_top
+ @scroll_position.y
+ end
+
+ 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
@children.map { |c| c.class }.join(", ")