The Shoes toolkit has a nice rich text format support. At first sight it might seem that Shoes text support borrows a lot from HTML, for example the most commonly used text block is para. In addition to the paragraph text block, you can use banner, title, subtitle, tagline, caption, and inscription.

[source:ruby]Shoes.app dostack dobanner “banner”title “title”subtitle “subtitle”tagline “tagline”caption “caption”para “paragraph”inscription “inscritpion”endend[/source]

As you can see banner is the largest text block, followed by tittle, etc. The default size for banner, title, subtitle, tagline, caption, para, and inscription is 48, 34, 26, 18, 14, 12, 10 pixels respectively. You can also change the default size of a text block by using the optional size parameter.

[source:ruby]Shoes.app dostack dobanner “banner”, :size => 20endend[/source]

Most often you will use the paragraph text block. If you have to display a great amount of text on a paragraph you pass in variable number of strings parameters.

[source:ruby]Shoes.app dostack dopara “Lorem ipsum dolor sit amet, “,“consectetur adipisicing elit”endend[/source]

In addition to text blocks, Shoes supports text formats such as strong, em, code, ins, span, sub, and sup. Here is an example of using a paragraph block with all of the text formats.

[source:ruby]Shoes.app dostack dopara “Normal. “,strong(“Bold. “),em(“Italics. “),code(“Code. “),ins(“Inscription. “),span(“Span. “),sub(“Sub. “),sup(“Sup. “)endend[/source]

In addition to simple text blocks and text formatting methods, you can create hyper links. Just like the hyper web, links can execute some event or code.

[source:ruby]Shoes.app dohyper_link = link “hyper link” doputs “link pressed”endstack dopara hyper_linkendend[/source]

The above code creates a link and assigns it to the hyper_link variable. The link is later passed on to the paragraph block for display. If you click on the link ‘link pressed’ will be printed on the terminal console.

In addition to executing custom code when a link is pressed, you can also launch the default browser if you use the click parameter. The code below displays a link and when pressed it will launch the Firefox or your default browser to the given URL.

[source:ruby]Shoes.app dostack dopara(link “Juixe TechKnow”, :click => “http://www.juixe.com/techknow”)endend[/source]

All the text formatting methods also accept an option stroke parameter to sent the color. Here is a simple example of using color with your text.

[source:ruby]Shoes.app dostack dopara em(“Hello, “, :stroke => green),strong(“World!”, :stroke => blue)endend[/source]

Here is a recap of the available methods for working with text with the Shoes toolkit.

Text Blocks:

para, banner, title, subtitle, tagline, caption, inscription

text formats:

strong, em, del, ins, link, span, sub, sup

There are more Shoes GUI tutorials and code samples here.

Technorati Tags: ruby, shoes, gui, ui, toolkit, text block, text format