Class: Fidgit::VerticalScrollBar

Inherits:
ScrollBar show all
Defined in:
lib/fidgit/elements/scroll_bar.rb

Constant Summary

Constants inherited from Composite

Composite::DEBUG_BORDER_COLOR

Constants inherited from Element

Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V

Instance Attribute Summary

Attributes inherited from Packer

#spacing_h, #spacing_v

Attributes inherited from Element

#align_h, #align_v, #background_color, #border_thickness, #font, #padding_bottom, #padding_left, #padding_right, #padding_top, #parent, #tip, #z

Instance Method Summary collapse

Methods inherited from Container

#add, #button, #clear, #color_picker, #color_well, #combo_box, #file_browser, #grid, #group, #hit_element, #horizontal, #image_frame, #insert, #label, #list, #radio_button, #remove, #scroll_area, #scroll_window, #slider, #text_area, #to_s, #toggle_button, #vertical, #write_tree, #x=, #y=

Methods inherited from Element

#default, #drag?, #draw, #draw_frame, #draw_rect, #enabled=, #enabled?, #height, #height=, #hit?, #max_height, #max_width, #min_height, #min_width, new, original_new, #outer_height, #outer_width, #recalc, schema, #to_s, #width, #width=, #with, #x, #x=, #y, #y=

Methods included from Event

#events, included, new_event_handlers, #publish, #subscribe, #unsubscribe

Constructor Details

#initialize(options = {}) ⇒ VerticalScrollBar

Returns a new instance of VerticalScrollBar.



96
97
98
99
100
101
102
103
104
105
# File 'lib/fidgit/elements/scroll_bar.rb', line 96

def initialize(options = {})
  super options

  @handle.width = width

  @handle_container.subscribe :left_mouse_button do |sender, x, y|
    distance = @owner.view_height
    @owner.offset_y += (y > @handle.y)? +distance : -distance
  end
end

Instance Method Details

#clicked_to_move(x, y) ⇒ Object



123
124
125
126
# File 'lib/fidgit/elements/scroll_bar.rb', line 123

def clicked_to_move(x, y)
  new_y = y < @handle.y ? @handle.y - @handle.height : @handle.y + @handle.height
  handle_dragged_to @handle.x, new_y
end

#draw_foregroundObject



114
115
116
117
# File 'lib/fidgit/elements/scroll_bar.rb', line 114

def draw_foreground
  draw_rect x + (width - @rail_thickness) / 2, y + padding_top, @rail_thickness, height, z, @rail_color
  super
end

#handle_dragged_to(x, y) ⇒ Object



119
120
121
# File 'lib/fidgit/elements/scroll_bar.rb', line 119

def handle_dragged_to(x, y)
  @owner.offset_y = @owner.content_height * ((y - self.y) / height.to_f)
end

#updateObject



107
108
109
110
111
112
# File 'lib/fidgit/elements/scroll_bar.rb', line 107

def update
  window = parent.parent
  content_height = window.content_height.to_f
  @handle.height = (window.view_height * height) / content_height
  @handle.y = y + (window.offset_y * height) / content_height
end