Class: Fidgit::HorizontalScrollBar
Constant Summary
Constants inherited from Composite
Constants inherited from Element
Element::DEFAULT_SCHEMA_FILE, Element::VALID_ALIGN_H, Element::VALID_ALIGN_V
Instance Attribute Summary collapse
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
Attributes inherited from Packer
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
- #clicked_to_move(x, y) ⇒ Object
- #draw_foreground ⇒ Object
- #handle_dragged_to(x, y) ⇒ Object
-
#initialize(options = {}) ⇒ HorizontalScrollBar
constructor
A new instance of HorizontalScrollBar.
- #update ⇒ Object
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( = {}) super @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
#owner ⇒ Object (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_foreground ⇒ Object
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 |
#update ⇒ Object
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 |