Ruby

ruby slippers


August 24, 2008 17:15 by joel

I've been spending some time lately digging into Ruby. It's a great language, and although my knowledge is still very young, I really enjoy working with it.

The other day I discovered a little cross-platform GUI framework called Shoes, which was created by why the lucky stiff. The API is really simple, making it easy for somebody new to the language to use it, but still focus on learning Ruby. Much of Shoes will seem very familiar to anyone who has coded for the web. Since it's used for creating desktop apps, and not confined to a browser, there are also some things that are borrowed from that realm. I won't dig too much into the "how's", since as i said, it's not very difficult, and the basics are well documented in a number of places (which I'll link at the bottom of the post).  

I took a bit of time today and hacked out a little paint application. A word of warning: my graphical design skills are basically non-existent, and I wasn't all that interested in digging too deep into that aspect of the framework, anyway, as my goal at the moment is to learn Ruby, not Shoes. Also, the paint program only has a few features at the moment, but it will hopefully grow and improve as my knowledge of Ruby grows.

Here's a quick screenshot, with a few things drawn: 

Basic App Screenshot

This screenshot shoes the options pane opened, with some stuff drawn in the background:

App Screenshot - Highlight Toolbar

If you want to take a look, it's hosted in The Shoebox, which is a collection of user-created Shoes applications. My paint app can be found here, and the shoes framework itself can be downloaded from here.

Finally, a bit of code, just so you can get a taste of what this stuff is like. This is the layout code for the options panel, seen above:

@options = stack :width => "100%" do
# Horizontal options menu  
background "#eeeeee"
flow do 
button("Fill Color", :margin => 5,:width => 100) do
fill ask_color("Pick a Color")
end
button("Stroke Color", :margin => 5,:width => 100) do
stroke ask_color("Pick a Color")
end
stroke_width = edit_line :width => 50,:margin => 5
button("<-- Set Line Width", :width => 150, :margin => 5) do
strokewidth stroke_width.text.to_i
end
end          
end

The stack and flow methods define layout areas, similar to divs and spans. Buttons are... buttons. Actually, I'm not going to go through the code. .. there's not much to it, and the actual application, although it's only 100 lines long, is probably already in dire need of refactoring. That's where the fun is, though! It's a big adventure, and I'm just getting started. I'll keep you posted. Maybe.

Stuff to check out:

Shoes

The ShoeBox - Collection of Shoes apps.

Nobody Knows Shoes (the official manual)