31.1.09

Ten Steps in Shoes: step 2, Stack & Flow

Woow, I've been getting quite a lot of feedback on my last post. Thanks for the messages, I really appreciate it! It gets me even more enthusiastic about blogging and Shoes, I hope in my turn I get some other people to be Shoes enthusiasts. If I do, or you are already, consider blogging about it. For me it helps a lot in keeping focussed and to explore a bit further. I always love to read small articles and blogs on Ruby and Shoes, so if you happen to have one let me know!

If you read my previous post, you might have noticed a lack of layout structure in one of the examples. Some of the text was right behind the other, or even overlapped, and it all just looked like a big unsorted pile. This might be fine for dirty clothes or dishes, but our app aint dirty! But no worries, you can create order in this chaos by making neat columns and rows, by using stacks and flows!

To help a bit in explaining, I'll introduce you to something else first. Meet background, background is quite a cool, colourful fellow. You can use background within stacks and flows. One famous flow is the Shoesapp itself. So try this:

Shoes.app do
background black
para "Look ma, a black background!", :size => 30, :align => "center", :stroke => crimson
end

Let's drift a bit farther from our main objective and try a gradient with an angle:

background "#FF0".."#0FF", :angle => 60

Or an image!

background "justsomelocal.jpg", :border => "FF0".."0FF", :strokewidth => 10

You can even use an online picture and a border like so

background "http://poignantguide.net/ruby/i/the.foxes-4c.png"

Sometimes, using online images seem to cause some problems. Don't know why exactly, let's move on for now.

The Stack
A stack is something that allows you to put one thing above the other, simple as that. Stacks can make your shoes look sexy!

Let's create a stack containing four para's:

Shoes.app do
stack do
para "heya"
para "we are stacked"
para "stacked you see?"
para "different lines"
end
end

Let's create put all the para's in their own stacks. One is blue, so he needs a friend:

Shoes.app do
stack do
background fuchsia
para "hi again"
end

stack do
background cornflowerblue
para "we are in stacks"
para "we are blue together"
end

stack do
background peru
para "each our own"
end

stack do
background gold
para "with our colours"
end
end

Remember some of the style options in the previous post? Well, you can use many of them exactly in the same way.

Shoes.app do
background black
stack :width => 100 do
background fuchsia
para "we are not wide"
end

stack :width => 200, :height => 150, :scroll => true do
background cornflowerblue
para "we are in stacks"
para "the stack is high"
para "content exeeds height"
para "bla"
para "blabla"
para "but we have a scrollbar"
end

stack :top => 250, :left => 150 do
background gold
para "some margin for errors"
end
end

The Flow
A flow is like a stack, but horizontal. But, unlike a stack, a flow has a limit. Why? Because there are no horizontal scrollbars, those suck anyway! So try to imagine your flow like a typewriter, going back and down when you have reached the end.

Now wait a minute, just think about it. Remember those para's from step 1? Remember how the para text was placed behind the others until it wrapped around? It's a flow! The shoes.app is a flow! So you already know the basic flow behaviour a bit. So lets just skip the talk and try a combination of stack and flow!

Shoes.app :width => 400, :height => 140 do
flow do
stack :width => '50%' do
background khaki
para "first stack"
para "stacks rock"
para "khakis are only cool in shoes"
end

stack :width => '40%' do
background peru
para "second stack"
end

para "i'm no stack but just in a flow, but did not fit", :stroke => blue
end
end

See, Shoes.app is a flow, so we can use the same style options for it, like setting the height! This example should demonstrate how stacks and flows differ from each other, but can work together. If only the people of the world were like stacks and flows!

27.1.09

10 Steps in Shoes, step 1: Para's

Phew, this has been one of those weeks in which you need to put everyone and everything on hold. But now is not a time to stand still, instead we are going to start the Shoes travel by taking the first step in Shoes. It's going to be a short walk though, just 10 steps to be exact. There are 10 basic concepts in Shoes and we will take a look at the basic possibilities of each one as we talk the talk and learn to walk the walk. We will keep it short, so you have no excuses not to walk with us, let's go!

Wear your Shoes
To start taking steps, you first need to have Shoes. So make sure you have Ruby and Shoes installed.

Tie your Shoes
Before we can start using anything in Shoes, we need to create a Shoes app.
Open a file in your favorite editor, mine being vi and call it step1.rb. Notice the .rb extension, that's for Ruby, not Shoes. But how does Ruby know we want to run a Shoes app? Well just write "Shoes.app do" in the first line of your Shoes code. See, Shoes is easy! How to end a Shoes app? Any guesses? Yes you are right, write "end"!

Here's what your Shoes app looks like:
Shoes.app do

end
Para's
Now that you know how to start coding a Shoes app, let's take the first step in Shoes! Any programming starts with a first program to salute the world, so you need to know how to write some text, or a paragraph if you have much to say. Lets write a short paragraph, in fact lets not say paragraph but say para instead.
Shoes.app do
para "Hello World!"
end
Save your file and open it with Shoes by running "shoes step1.rb" or just opening an app from the Shoes GUI. You will get something like this:

Your shoes application screen just gets filled with the characters you provided to para. Para works quite like writing on a piece of paper, you can write in diferent sizes, in different styles, on different locations and in different colors and when you have reached the end, you start again at the following line. Let's try it. Reopen your file in your editor and add the following line:
para "Hello World, are you there?", :size => 48
Save, run and take a look.
What we did here is use the size style option. Note the comma and the semicolon. Style options are key-value pairs of a hash, hence we use => to say that key size has value 48. This is just like the way we use hashes in Ruby. First I thought the biggest size of text in shoes is 48 and it could not grow beyond 48. This is not true however. You can have really huge letter sizes, I'm not sure if there is a maximum. There is some weird behaviour if you use really, really large values though.

Instead of using a para with a certain size value, you can use any of the following:

title (same as para with size of 34)
subtitle (same as para with size of 26)
tagline (same as para with size of 18)
caption (same as para with size of 14)
para (default size is 12)
inscription (same as para with size of 10)

Colour your shoes!
Even though the eighties have long gone and nobody knows what happend to King, we still want to colour our shoes! Don't click that link if you keep some youth sentiment about that moment you saw your first ever music clip on tv, you have been warned! Better humn that song and use the Shoes equivalent to spraycans to be cool like so:
Shoes.app do
para "Hello World!", :size => 48, :stroke => dodgerblue
subtitle "Why are you not answering?", :stroke => red
tagline "Hmm wait, what to say in case it does answer?", :fill => "#FF0000"
inscription "...yes quite some responsibility to be the one who talks to the world", :fill => darkkhaki
end
What do you think this app will look like? Save and run it! As you might have noticed you can use style options for colors too. Colors can be specified by their name or their hexadecimal Red-Green-Blue value. Here's a list for color names and values. We also used some alternatives to para's.

The Fonts is cool
Heeeyy, use cool Fonts and the girls will be kissing with a snap of the fingers! But that was in a time of innocence and the coolest technology around was a motorcycle. For people who have grown up and want more then just kissing, there is Shoes. The happy days are over, but Shoes has many Fonts.

Shoes.app do
para "heeeeyyyy":font => "Helvetica, Arial"
end

These Shoes are made for walking
I guess you get it by now. There is much more you can do with para and it's siblings. Almost everything is related to style.
You should be able to work it out for yourself, just look at the shoes help on styles. Not all styles work for everything, so note what it says after "For".
Here's a small example of various possibilities.

Shoes.app do
para "Centered text!", :size => 14, :align => "center", :stroke => firebrick
subtitle "justify", :justify => true, :stroke => hotpink, :fill => black
para "top and left", :top => 150, :left => 222, :stroke => mediumspringgreen
tagline "oblique", :emphasis => "oblique", :stroke => peru
inscription "displace", :displace_left => 20, :top => 180
para "more left less top", :top => 250, :left => 280, :stroke => olive
title "strikethrough and strikecolor", :strikethrough => "single", :strikecolor => crimson
caption "leading", :leading => 10
para "undercolor", :underline => "single", :undercolor => darkorchid, :top => 210
tagline "Variant Weight", :variant => "smallcaps", :weight => "heavy", :stroke => gold
end

A few last tips: use alt + ? for help and alt + . to reload your Shoes app in the Shoes GUI. Use alt + / for the Shoes console to see debug messages. Use alt + p to package your app.
I suggest you play with the various options for a bit, and get ready for Step 2!