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.



338
339
340
341
342
343
344
345
# File 'lib/luit.rb', line 338

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.



337
338
339
# File 'lib/luit.rb', line 337

def contents
  @contents
end

Instance Method Details

#<<(item) ⇒ Object



347
348
349
350
351
# File 'lib/luit.rb', line 347

def <<(item)
	@contents << item
	@totalh += item.h + @spaceing
	@w = @contents.max_by{|x| x.w}.w
end

#draw(x = 0, y = 0) ⇒ Object



353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/luit.rb', line 353

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



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/luit.rb', line 366

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