Class: Fidgit::HorizontalScrollBar

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 collapse

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 = {}) ⇒ HorizontalScrollBar

Returns a new instance of HorizontalScrollBar.



60
61
62
63
64
65
66
67
68
69
# File 'lib/fidgit/elements/scroll_bar.rb', line 60

def initialize(options = {})
  super options

  @handle.height = height

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

Instance Attribute Details

#ownerObject (readonly)

Returns the value of attribute owner.



58
59
60
# File 'lib/fidgit/elements/scroll_bar.rb', line 58

def owner
  @owner
end

Instance Method Details

#clicked_to_move(x, y) ⇒ Object



89
90
91
92
# File 'lib/fidgit/elements/scroll_bar.rb', line 89

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

#draw_foregroundObject



80
81
82
83
# File 'lib/fidgit/elements/scroll_bar.rb', line 80

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

#handle_dragged_to(x, y) ⇒ Object



85
86
87
# File 'lib/fidgit/elements/scroll_bar.rb', line 85

def handle_dragged_to(x, y)
  @owner.offset_x = @owner.content_width * ((x - self.x) / width.to_f)
end

#updateObject



71
72
73
74
75
76
77
78
# File 'lib/fidgit/elements/scroll_bar.rb', line 71

def update
  window = parent.parent

  # Resize and re-locate the handles based on changes to the scroll-window.
  content_width = window.content_width.to_f
  @handle.width = (window.view_width * width) / content_width
  @handle.x = x + (window.offset_x * width) / content_width
end