Class: Fidgit::Slider::Handle

Inherits:
Element show all
Defined in:
lib/fidgit/elements/slider.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, #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 = {}, &block) ⇒ Handle


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fidgit/elements/slider.rb', line 16

def initialize(options = {}, &block)
  options = {
    background_color: default(:background_color),
    border_color: default(:border_color),
  }.merge! 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|
    if parent.enabled?
      parent.handle_dragged_to x - @drag_start_pos[0], y - @drag_start_pos[1]
    else
      publish :end_drag
    end
  end

  subscribe :end_drag do
    @drag_start_pos = nil
  end
end

Instance Method Details

#drag?(button) ⇒ Boolean


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

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

#tipObject


42
# File 'lib/fidgit/elements/slider.rb', line 42

def tip; parent.tip; end