The Purple Shoes Manual 0.7.166

TextBlock

The TextBlock object represents a group of text organized as a single element. A paragraph containing bolded text, for example. A caption containing links and bolded text. (So, a caption is a TextBlock type. However, link and strong are Text types.)

All of the various types of TextBlock are found on the Element Creation page.

contents() » an array of elements

Lists all of the strings and styled text objects inside this block.

cursor() » an index

Return a text cursor position. That is an index of the text which is a string of all of the characters in this text box.

Shows or hides the text cursor. Using cursor = 3, for instance, shows the text cursor at index 3 from the front. Using cursor = -1 shows the text cursor at the end of the text. Using cursor = nil hides the text cursor.

 Shoes.app do
  msg = para 'hello ' * 20
  msg.cursor = -1
  keypress do |k|
    n = case k
      when 'ARROW_LEFT'; -1
      when 'ARROW_RIGHT'; 1
      else
        next
    end
    n += msg.cursor
    len = msg.text.length
    n = len unless n > -1
    msg.cursor = n % (len+1)
    flush
  end
 end
highlight() » an array

Return an array which includes a text marker start position and highlighted length.

hit(left, top) » an index or nil

Return an index of the text at which the mouse cursor points on. The left and top are the mouse coordinates.

 Shoes.app do
   para 'index: ', width: 50
   index = para '', width: 20
   msg = title 'hello ' * 5
   click do |b, x, y|
     index.text = msg.hit(x, y).to_s
   end
 end
marker() » an index

Return a text marker start position.

Note: Purple Shoes doesn't support marker method.

Highlight a part of text from marker start position to cursor position.

 # Not yet available
 Shoes.app do
   background gainsboro
   extend HH::Markup
   code = 'alert "Hello Purple Shoes! " * 5'
   msg = para highlight code, nil
   button 'marker' do
     msg.cursor = 17
     msg.marker = 14
     msg.text = highlight msg.markup, nil
     para msg.highlight
     flush
   end
 end

Note: Purple Shoes doesn't support marker= method.

markup() » a string

Return a string as same as text().

Replaces the text of the entire block with the characters of a string.

text() » a string

Return a string of all of the characters in this text box. This will strip off any style or text classes and just return the actual characters, as if seen on the screen.

Replaces the text of the entire block with the characters of a string.

to_s() » a string

An alias for text. Returns a flattened string of all of this TextBlock's contents.

Note: Purple Shoes doesn't support to_s method.

Next: Timers