The Shoes Manual

Button

Buttons are, you know, push buttons. You click them and they do something. Buttons are known to say "OK" or "Are you sure?" And, then, if you're sure, you click the button.

 Shoes.app do
   button "OK!"
   button "Are you sure?"
 end

The buttons in the example above don't do anything when you click them. In order to get them to work, you've got to hook up a block to each button.

 Shoes.app do
   button "OK!" do
     append { para "Well okay then." }
   end
   button "Are you sure?" do
     append { para "Your confidence is inspiring." }
   end
 end

So now we've got blocks for the buttons. Each block appends a new paragraph to the page. The more you click, the more paragraphs get added.

It doesn't go much deeper than that. A button is just a clickable phrase.

Just to be pedantic, though, here's another way to write that last example.

 Shoes.app do
   @b1 = button "OK!"
   @b1.click { para "Well okay then." }
   @b2 = button "Are you sure?"
   @b2.click { para "Your confidence is inspiring." }
 end

This looks dramatically different, but it does the same thing. The first difference: rather than attaching the block directly to the button, the block is attached later, through the click method.

The second change isn't related to buttons at all. The append block was dropped since Shoes allows you to add new elements directly to the slot. So we can just call para directly. (This isn't the case with the prepend, before or after methods.)

Beside the methods below, buttons also inherit all of the methods that are Common.

When a button is clicked, its click block is called. The block is handed self. Meaning: the button which was clicked.

focus() » self

Moves focus to the button. The button will be highlighted and, if the user hits Enter, the button will be clicked.

Next: Check