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_size, #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, #insert, #label, #list, #radio_button, #remove, #scroll_area, #scroll_window, #slider, #text_area, #toggle_button, #vertical, #x=, #y=

Methods inherited from Element

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

Methods included from Event

#events, included, #publish, #subscribe

Constructor Details

#initialize(options = {}) ⇒ HorizontalScrollBar

Returns a new instance of HorizontalScrollBar.



56
57
58
59
60
61
62
63
64
65
# File 'lib/fidgit/elements/scroll_bar.rb', line 56

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.



54
55
56
# File 'lib/fidgit/elements/scroll_bar.rb', line 54

def owner
  @owner
end

Instance Method Details

#draw_foregroundObject



76
77
78
79
# File 'lib/fidgit/elements/scroll_bar.rb', line 76

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



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

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

#updateObject



67
68
69
70
71
72
73
74
# File 'lib/fidgit/elements/scroll_bar.rb', line 67

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