rubyshoes

Populate app with buttons on Ruby Shoes


I'd like to know how to populate an application interface with many buttons. For example, I'd like to make 100 buttons. I saw an example with simple-calc.rb, but there would be a way of doing this without typing a list of 100 numbers. Here is the code:

# Simple buttons
Shoes.app(title: "Alabord 0.0", width:560, height: 300, resizable: false) do

    flow :width => 600, :margin => 4 do
      %w(1 2 3 4 100).each do |btn|
      button btn
     end
    end
    stack :margin => 4 do
        button "Quit" do
            exit()
        end
    end
end

App window


Solution

  • Shoes.app(title: "Alabord 0.0", width:560, height: 300, resizable: false) do
    
    flow :width => 600, :margin => 4 do
      (1..100).each do |btn|
        button btn
      end
    end
    
    stack :margin => 4 do
      button "Quit" do
        exit
      end
    end