class Core::GUI::Container
scrollable
Attributes
ch[R]
Public Class Methods
new(x, y, w, h, ch)
click to toggle source
ch = content element height
Calls superclass method
Core::GUI::Element::new
# File lib/gui/base.rb, line 160 def initialize(x, y, w, h, ch) super(x, y, w, h) @bg = Core.sprite("gui/container_background") @scrollbar = Scrollbar.new(x+w-24, y, 24, h) @ch = ch @items = [] @item = nil @changed = false end
Public Instance Methods
add(element)
click to toggle source
# File lib/gui/base.rb, line 170 def add(element) element.x = @x element.y = @y + @yoff + ((@items.size+1)*@ch) @items.push(element) end
changed?()
click to toggle source
# File lib/gui/base.rb, line 217 def changed? if @changed @changed = false return true else return false end end
draw()
click to toggle source
# File lib/gui/base.rb, line 202 def draw @scrollbar.draw @bg.draw(@x+@xoff, @y+@yoff, Core::GUI_Z, (@w-24)/@bg.width.to_f, @h/@bg.height.to_f) @items.each { |item| if item.y + item.yoff + item.h < @scrollbar.y + @scrollbar.yoff next end item.draw } end
hovered()
click to toggle source
# File lib/gui/base.rb, line 176 def hovered i = 0 @items.each { |it| if it.hovered? return i end i += 1 } return -1 end
selected()
click to toggle source
# File lib/gui/base.rb, line 213 def selected return @item end
update()
click to toggle source
# File lib/gui/base.rb, line 187 def update # TODO scrollbar probably doesnt work @scrollbar.update @scrollbar.xoff, @scrollbar.yoff, @scrollbar.zoff = @xoff, @yoff, @zoff offset = @scrollbar.offset * -@ch @items.each { |item| item.xoff, item.zoff = @xoff, @zoff item.yoff = @yoff# + (offset/@ch) - @ch if item.y + item.yoff + item.h < @scrollbar.y + @scrollbar.yoff next end item.update } end
Private Instance Methods
clicked(item)
click to toggle source
# File lib/gui/base.rb, line 228 def clicked(item) @changed = true @item = item end