Class: Conquer::Dzen::Interaction::TooltipListener

Inherits:
Object
  • Object
show all
Includes:
Celluloid, Celluloid::Notifications, Positioning
Defined in:
lib/conquer/dzen/interaction/tooltip_listener.rb

Constant Summary collapse

MARGIN =
5

Instance Method Summary collapse

Methods included from Positioning

#ignore_bg, #lock_x, #shift, #unlock_x

Constructor Details

#initializeTooltipListener

Returns a new instance of TooltipListener.



14
15
16
17
# File 'lib/conquer/dzen/interaction/tooltip_listener.rb', line 14

def initialize
  @current_tooltip = nil
  subscribe('tooltip', :show_tooltip)
end

Instance Method Details

#show_tooltip(_, title, text, width = 150) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/conquer/dzen/interaction/tooltip_listener.rb', line 19

def show_tooltip(_, title, text, width = 150)
  Process.kill('TERM', @current_tooltip.pid) if @current_tooltip
  lines = text.lines.map { |line| shift(MARGIN) { line } }
  mouse = mouse_location
  dzen_command = dzen_command(mouse, lines.size, width + 2 * MARGIN)
  async.run_dzen(dzen_command, title, lines.join)
end