Class: Shoes::Link

Inherits:
Span show all
Includes:
Common::Fill, Common::Hover, Common::SafelyEvaluate, Common::Stroke, Common::Style
Defined in:
shoes-core/lib/shoes/link.rb

Constant Summary collapse

STYLES =
{ underline: true, stroke: ::Shoes::COLORS[:blue], fill: nil }.freeze

Constants included from Common::Style

Common::Style::DEFAULT_STYLES, Common::Style::STYLE_GROUPS

Instance Attribute Summary collapse

Attributes included from Common::Hover

#hover_blk, #leave_blk

Attributes inherited from Text

#color, #parent, #text_block, #texts, #to_s

Instance Method Summary collapse

Methods included from Common::Style

#applicable_app_styles, #create_style_hash, included, #style, #style_init

Methods included from Common::Stroke

#update_stroke

Methods included from Common::SafelyEvaluate

#safely_evaluate

Methods included from Common::Hover

#add_mouse_hover_control, #apply_style_from_hover_class, #apply_style_from_pre_hover, create_hover_class, #eval_hover_block, #hover, #hover_class, #hovered?, #leave, #mouse_hovered, #mouse_left

Methods included from Common::Fill

#update_fill

Methods inherited from Span

#style

Methods included from Common::LinkFinder

#find_links

Methods included from Common::Inspect

#inspect, #to_s

Constructor Details

#initialize(my_app, texts, styles = {}, blk = nil) ⇒ Link

Returns a new instance of Link.



15
16
17
18
19
20
21
22
# File 'shoes-core/lib/shoes/link.rb', line 15

def initialize(my_app, texts, styles = {}, blk = nil)
  @app = my_app
  style_init styles
  @gui = Shoes.backend_for self

  register_click blk
  super texts, @style
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



11
12
13
# File 'shoes-core/lib/shoes/link.rb', line 11

def app
  @app
end

#blkObject (readonly)

Returns the value of attribute blk.



11
12
13
# File 'shoes-core/lib/shoes/link.rb', line 11

def blk
  @blk
end

#guiObject (readonly)

Returns the value of attribute gui.



11
12
13
# File 'shoes-core/lib/shoes/link.rb', line 11

def gui
  @gui
end

Instance Method Details

#click(&blk) ⇒ Object



38
39
40
41
42
# File 'shoes-core/lib/shoes/link.rb', line 38

def click(&blk)
  @gui.click blk if blk
  @blk = blk
  self
end

#hidden?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'shoes-core/lib/shoes/link.rb', line 61

def hidden?
  text_block_guard && @text_block.hidden?
end

#in_bounds?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'shoes-core/lib/shoes/link.rb', line 53

def in_bounds?(x, y)
  @gui.in_bounds?(x, y)
end


69
70
71
# File 'shoes-core/lib/shoes/link.rb', line 69

def links
  [self]
end

#pass_coordinates?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'shoes-core/lib/shoes/link.rb', line 49

def pass_coordinates?
  false
end

#register_click(blk) ⇒ Object

Doesn’t use Common::Clickable because of URL flavor option clicks



25
26
27
28
29
30
31
32
33
34
35
36
# File 'shoes-core/lib/shoes/link.rb', line 25

def register_click(blk)
  if blk.nil?
    blk = if @style[:click].respond_to? :call
            @style[:click]
          else
            # Slightly awkward, but we need App, not InternalApp, to call visit
            proc { app.app.visit @style[:click] }
          end
  end

  click(&blk)
end

#release(&blk) ⇒ Object



44
45
46
47
# File 'shoes-core/lib/shoes/link.rb', line 44

def release(&blk)
  @gui.release blk if blk
  self
end

#removeObject



57
58
59
# File 'shoes-core/lib/shoes/link.rb', line 57

def remove
  @gui.remove
end

#visible?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'shoes-core/lib/shoes/link.rb', line 65

def visible?
  text_block_guard && @text_block.visible?
end