Class: Fidgit::ScrollBar::Handle

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

Constant Summary

Constants inherited from Element

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

Instance Attribute Summary

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 Element

#default, #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, #update, #width, #width=, #with, #x, #x=, #y, #y=

Methods included from Event

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

Constructor Details

#initialize(options = {}) ⇒ Handle

Returns a new instance of Handle.


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fidgit/elements/scroll_bar.rb', line 13

def initialize(options = {})
  super options

  subscribe :begin_drag do |sender, x, y|
    # Store position of the handle when it starts to drag.
    @drag_start_pos = [x - self.x, y - self.y]
  end

  subscribe :update_drag do |sender, x, y|
    parent.parent.handle_dragged_to x - @drag_start_pos[0], y - @drag_start_pos[1]
  end

  subscribe :end_drag do
    @drag_start_pos = nil
  end
end

Instance Method Details

#drag?(button) ⇒ Boolean

Returns:

  • (Boolean)

11
# File 'lib/fidgit/elements/scroll_bar.rb', line 11

def drag?(button); button == :left; end