Class: LUIT::List

Inherits:
LUITElement show all
Defined in:
lib/luit.rb

Instance Attribute Summary collapse

Attributes inherited from LUITElement

#h, #hover, #id, #w, #x, #y

Instance Method Summary collapse

Methods inherited from LUITElement

#button_down, #draw_rel, #updateHover, #update_rel

Constructor Details

#initialize(holder, id, x, y, h, s = 10) ⇒ List

Returns a new instance of List.



331
332
333
334
335
336
337
338
# 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

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



330
331
332
# File 'lib/luit.rb', line 330

def contents
  @contents
end

Instance Method Details

#<<(item) ⇒ Object



340
341
342
343
344
# 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) ⇒ Object



346
347
348
349
350
351
352
353
354
355
356
357
# 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) ⇒ Object



359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# 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