Class: Shoes::TextBlock

Inherits:
Common::UIElement show all
Includes:
Common::Clickable, Common::Hover, Common::LinkFinder, Common::Translate, TextBlockDimensionsDelegations
Defined in:
shoes-core/lib/shoes/text_block.rb

Constant Summary collapse

STYLES =

used in TextBlock specs only

{ font: DEFAULT_TEXTBLOCK_FONT }.freeze

Constants included from TextBlockDimensionsDelegations

Shoes::TextBlockDimensionsDelegations::DELEGATED_METHODS

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 included from Common::Clickable

#pass_coordinates

Attributes inherited from Common::UIElement

#app, #dimensions, #gui, #parent

Instance Method Summary collapse

Methods included from Common::Translate

#clear_translate, #translate_left, #translate_top

Methods included from Common::LinkFinder

#find_links

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::Clickable

#click, #pass_coordinates?, #register_click, #release

Methods inherited from Common::UIElement

#after_initialize, #before_initialize, #create_backend, #handle_block, #initialize, #needs_rotate?, #painted?, #redraw_height, #redraw_left, #redraw_top, #redraw_width, #update_fill, #update_stroke

Methods included from Common::Style

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

Methods included from Common::SafelyEvaluate

#safely_evaluate

Methods included from Common::Positioning

#_position, #displace, #move

Methods included from Common::Visibility

#hidden?, #hidden_from_view?, #hide, #outside_parent_view?, #show, #toggle, #visible?

Methods included from Common::Inspect

#inspect

Methods included from Common::Attachable

#attached_to

Constructor Details

This class inherits a constructor from Shoes::Common::UIElement

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



19
20
21
# File 'shoes-core/lib/shoes/text_block.rb', line 19

def contents
  @contents
end

#cursorObject

Returns the value of attribute cursor.



21
22
23
# File 'shoes-core/lib/shoes/text_block.rb', line 21

def cursor
  @cursor
end

#textObject

Returns the value of attribute text.



19
20
21
# File 'shoes-core/lib/shoes/text_block.rb', line 19

def text
  @text
end

#text_stylesObject (readonly)

Returns the value of attribute text_styles.



19
20
21
# File 'shoes-core/lib/shoes/text_block.rb', line 19

def text_styles
  @text_styles
end

#textcursor(line_height = 0) ⇒ Object



89
90
91
# File 'shoes-core/lib/shoes/text_block.rb', line 89

def textcursor(line_height = 0)
  @textcursor ||= app.textcursor(line_height)
end

Instance Method Details

#add_to_parent(text) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'shoes-core/lib/shoes/text_block.rb', line 30

def add_to_parent(text)
  handle_styles @style

  # Important to use accessor and do this after the backend exists, but
  # before we place ourselves in the parent container!
  self.text = Array(text)

  super
end

#adjust_current_position(current_position) ⇒ Object



85
86
87
# File 'shoes-core/lib/shoes/text_block.rb', line 85

def adjust_current_position(current_position)
  @gui.adjust_current_position(current_position)
end

#centered?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'shoes-core/lib/shoes/text_block.rb', line 97

def centered?
  style[:align] == CENTER
end

#contents_alignment(current_position = nil) ⇒ Object



81
82
83
# File 'shoes-core/lib/shoes/text_block.rb', line 81

def contents_alignment(current_position = nil)
  @gui.contents_alignment(current_position)
end

#create_dimensions(*_) ⇒ Object



26
27
28
# File 'shoes-core/lib/shoes/text_block.rb', line 26

def create_dimensions(*_)
  @dimensions = TextBlockDimensions.new @parent, @style
end

#in_bounds?(*args) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'shoes-core/lib/shoes/text_block.rb', line 40

def in_bounds?(*args)
  @gui.in_bounds?(*args)
end


101
102
103
# File 'shoes-core/lib/shoes/text_block.rb', line 101

def links
  find_links(contents)
end

#removeObject



48
49
50
51
52
53
# File 'shoes-core/lib/shoes/text_block.rb', line 48

def remove
  super
  links.each do |link|
    @app.remove_mouse_hover_control(link)
  end
end

#replace(*texts) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'shoes-core/lib/shoes/text_block.rb', line 59

def replace(*texts)
  opts = texts.pop if texts.last.is_a?(Hash)
  if opts
    style(opts)
    handle_styles(opts)
  end

  # Order here matters as well--backend#replace shouldn't rely on DSL state
  # but the texts that it's passed if it needs information at this point.
  @gui.replace(*texts)

  @text        = texts.map(&:to_s).join
  @contents    = texts
  @text_styles = gather_text_styles(self, texts)

  self
end

#takes_up_space?Boolean

Returns:

  • (Boolean)


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

def takes_up_space?
  @style[:align] != "right"
end

#textcursor?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'shoes-core/lib/shoes/text_block.rb', line 93

def textcursor?
  @textcursor
end

#to_sObject



77
78
79
# File 'shoes-core/lib/shoes/text_block.rb', line 77

def to_s
  text
end