Class: Shoes::TextBlock

Inherits:
Basic show all
Defined in:
lib/shoes/basic.rb,
lib/shoes/style.rb

Direct Known Subclasses

Banner, Caption, Inscription, Para, Subtitle, Tagline, Title

Instance Attribute Summary

Attributes inherited from Basic

#args, #cleared, #hided, #initials, #parent, #shows

Attributes included from Mod

#click_proc, #hover_proc, #hovered, #leave_proc, #margin_bottom, #margin_left, #margin_right, #margin_top, #release_proc

Instance Method Summary collapse

Methods inherited from Basic

#clear, #fix_size, #hide, #move, #move3, #show, #toggle

Methods included from Mod

#click, #hover, #leave, #release, #set_margin

Constructor Details

#initialize(args) ⇒ TextBlock

Returns a new instance of TextBlock.



210
211
212
213
214
# File 'lib/shoes/basic.rb', line 210

def initialize args
  super
  @app.mlcs << self  if !@real or @add_mlcs
  @add_mlcs = false
end

Instance Method Details

#cursorObject



251
252
253
# File 'lib/shoes/basic.rb', line 251

def cursor
  @app.textcursors[self] ? @app.textcursors[self][0] : nil
end

#cursor=(n) ⇒ Object



242
243
244
245
246
247
248
249
# File 'lib/shoes/basic.rb', line 242

def cursor=(n)
  if !n
    @app.textcursors[self][1].clear if @app.textcursors[self][1]
    @app.textcursors.delete self
  else
    @app.textcursors[self] ? (@app.textcursors[self][0] = n) : (@app.textcursors[self] = [n, nil])
  end
end

#highlightObject



273
274
275
276
277
278
279
280
281
# File 'lib/shoes/basic.rb', line 273

def highlight
  unless cursor
    return nil, 0
  else
    cindex = cursor == -1 ? text.length : cursor
    mindex = marker ? marker : cindex
    return marker, cindex - mindex
  end
end

#hit(x, y) ⇒ Object



255
256
257
258
# File 'lib/shoes/basic.rb', line 255

def hit x, y
  a, b, c = @app.make_textcursor_index(self, x - left, y - top + @app.scroll_top)
  a ? b : nil
end

#markerObject



269
270
271
# File 'lib/shoes/basic.rb', line 269

def marker
  @app.textmarkers[self]
end

#marker=(n) ⇒ Object



260
261
262
263
264
265
266
267
# File 'lib/shoes/basic.rb', line 260

def marker=(n)
  if cursor
    cindex = cursor == -1 ? text.length : cursor
    len = cindex - n
    self.text = text[0...n] + @app.bg(text[n, len], @app.yellow) + text[n+len..-1] if len > 1
  end
  @app.textmarkers[self] = n
end

#move2(x, y) ⇒ Object



232
233
234
235
# File 'lib/shoes/basic.rb', line 232

def move2 x, y
  self.text = @args[:markup]
  super
end

#positioning(x, y, max) ⇒ Object



227
228
229
230
# File 'lib/shoes/basic.rb', line 227

def positioning x, y, max
  self.text = @args[:markup]
  super
end

#removeObject



237
238
239
240
# File 'lib/shoes/basic.rb', line 237

def remove
  flag = @args[:hidden] ? @shows : @hided
  @app.canvas.remove @real unless flag
end

#style(args) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/shoes/style.rb', line 45

def style args
  args[:markup] ||= @args[:markup]
  args[:size] ||= @args[:size]
  args[:font] ||= @args[:font]
  args[:align] ||= @args[:align]
  
  clear false if @real
  @width = (@left + parent.width <= @app.width) ? parent.width : @app.width - @left
  @width = initials[:width] unless initials[:width].zero?
  @height = 20 if @height.zero?
  m = self.class.to_s.downcase[7..-1]
  args = [args[:markup], @args.merge({left: @left, top: @top, width: @width, height: @height, 
    create_real: true, nocontrol: true, size: args[:size], font: args[:font], align: args[:align]})]
  tb = @app.send(m, *args)
  @real, @height = tb.real, tb.height
  @args[:markup], @args[:size], @args[:font], @args[:align] = tb.markup, tb.size, tb.font, tb.align
  @markup, @size, @font, @align = @args[:markup], @args[:size], @args[:font], @args[:align]
end

#textObject



216
217
218
# File 'lib/shoes/basic.rb', line 216

def text
  @args[:markup].gsub(/\<.*?>/, '').gsub('&amp;', '&').gsub('&lt;', '<')
end

#text=(s) ⇒ Object Also known as: replace



220
221
222
223
# File 'lib/shoes/basic.rb', line 220

def text= s
  @args[:add_mlcs] = false
  style markup: s  if !@hided or @args[:hidden]
end