Module: GlimR::Scrollable

Included in:
HScrollBar, VScrollBar
Defined in:
lib/glimr/widgets/scrollbar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_scroll_horizObject

Default horizontal scroll amount (=0.1).



19
20
21
# File 'lib/glimr/widgets/scrollbar.rb', line 19

def default_scroll_horiz
  @default_scroll_horiz
end

#default_scroll_vertObject

Default horizontal scroll amount (=0.1).



22
23
24
# File 'lib/glimr/widgets/scrollbar.rb', line 22

def default_scroll_vert
  @default_scroll_vert
end

#scroll_xObject

Accessors for scroll positions



25
26
27
# File 'lib/glimr/widgets/scrollbar.rb', line 25

def scroll_x
  @scroll_x
end

#scroll_yObject

Accessors for scroll positions



25
26
27
# File 'lib/glimr/widgets/scrollbar.rb', line 25

def scroll_y
  @scroll_y
end

Instance Method Details

#default_configObject



9
10
11
12
13
14
15
16
# File 'lib/glimr/widgets/scrollbar.rb', line 9

def default_config
  super.merge(
    :default_scroll_horiz => 0.1,
    :default_scroll_vert => 0.1,
    :scroll_x => 0.0,
    :scroll_y => 0.0
  )
end

#scroll(x, y) ⇒ Object

Increases both x and y scroll position by given amounts.



66
67
68
# File 'lib/glimr/widgets/scrollbar.rb', line 66

def scroll(x, y)
  scroll_to(@scroll_position.x + x, @scroll_position.y + y)
end

#scroll_down(amount = default_scroll_vert) ⇒ Object

Scrolls down (increases scroll_y) by given amount, default is #default_scroll_vert.



51
52
53
# File 'lib/glimr/widgets/scrollbar.rb', line 51

def scroll_down(amount = default_scroll_vert)
  self.scroll_y += amount
end

#scroll_left(amount = default_scroll_horiz) ⇒ Object

Scrolls to left (decreases scroll_x) by given amount, default is #default_scroll_horiz.



30
31
32
# File 'lib/glimr/widgets/scrollbar.rb', line 30

def scroll_left(amount = default_scroll_horiz)
  self.scroll_x -= amount
end

#scroll_right(amount = default_scroll_horiz) ⇒ Object

Scrolls to right (increases scroll_x) by given amount, default is #default_scroll_horiz.



37
38
39
# File 'lib/glimr/widgets/scrollbar.rb', line 37

def scroll_right(amount = default_scroll_horiz)
  self.scroll_x += amount
end

#scroll_to(x, y) ⇒ Object

Scrolls to given coordinates, clamped between 0.0 and 1.0, and fires a scroll event.



80
81
82
83
84
85
# File 'lib/glimr/widgets/scrollbar.rb', line 80

def scroll_to(x,y)
  @scroll_x = [[x, 0.0].max, 1.0].min
  @scroll_y = [[y, 0.0].max, 1.0].min
  @container.scroll = [@scroll_x, @scroll_y] if @container
  dispatch_event(Event.new(:scroll, :x => scroll_x, :y => scroll_y, :source => self))
end

#scroll_up(amount = default_scroll_vert) ⇒ Object

Scrolls up (decreases scroll_y) by given amount, default is #default_scroll_vert.



44
45
46
# File 'lib/glimr/widgets/scrollbar.rb', line 44

def scroll_up(amount = default_scroll_vert)
  self.scroll_y -= amount
end