class LUIT::List

Attributes

contents[R]

Public Class Methods

new(holder, id, x, y, h, s = 10) click to toggle source
Calls superclass method LUIT::LUITElement::new
# File lib/luit.rb, line 331
def initialize(holder, id, x, y, h, s = 10)
        super(holder, id, x, y, 50, h)
        @spaceing = s
        @contents = []
        @totalh = 0
        @focus = 0
        @scrollbar = VerticalSlider.new(self, "scroll", 0, 0, @h - 10)
end

Public Instance Methods

<<(item) click to toggle source
# File lib/luit.rb, line 340
def <<(item)
        @contents << item
        @totalh += item.h + @spaceing
        @w = @contents.max_by{|x| x.w}.w
end
draw(x = 0, y = 0) click to toggle source
# File lib/luit.rb, line 346
def draw(x = 0, y = 0)
        x += @x
        y += @y
        prevh = 0
        @contents.each do |item|
                if !((prevh - @focus + item.h) <= 0 || (prevh - @focus) >= @h)
                        item.draw(x + 30, y + prevh - @focus)
                end
                prevh += item.h + @spaceing
        end
        @scrollbar.draw(x, y)
end
update(x = 0, y = 0) click to toggle source
# File lib/luit.rb, line 359
def update(x = 0, y = 0)
        x += @x
        y += @y
        prevh = 0
        @contents.each do |item|
                if !((prevh - @focus + item.h) < 0 || (prevh - @focus) > @h)
                        item.update(x + 30, y + prevh - @focus)
                end
                prevh += item.h + @spaceing
        end
        @scrollbar.update(x, y)
        if @totalh > @h
                v = @scrollbar.value / (@h - 10)
                @focus = (@totalh - @h) * v
        else
                @focus = 0
        end
end