Pas pour le moment. Les boutons sont encore peu fiables dans les chaussures, en particulier sur Windows. Vous pouvez contourner le problème en mettant le bouton dans une fente et masquant ou en affichant la fente, mais vous découvrirez peut-être que le bouton ne cache encore une fois qu'il a été cliqué une fois:
Shoes.app do
para 'This is some text.'
@flow = flow :width => 50, :hidden => true do
button 'a' do |btn|
alert 'Hello, World!'
end
end
button 'toggle' do
@flow.toggle
end
para 'Blah blah blah'
end
Heureusement, il y a un moyen de sortir: les fentes. Les emplacements peuvent recevoir un événement click, ce qui les fait se comporter comme un bouton. En fait, vous pouvez faire des boutons assez décents hors des fentes.
Voici quelque chose que j'ai bricolé ensemble. Il vous permet d'utiliser la méthode pesto_button
pour générer des boutons construits sur des flux. Vous pouvez le modifier pour répondre à vos besoins, notamment en utilisant une image comme arrière-plan, texte modifiable (avec largeur d'expansion automatique?), Possibilité de changer de style à la volée, etc.:
class PestoButton < Widget
def initialize (text, opts = {})
@border_color = opts[:border_color] || gray
@border_width = opts[:border_width] || 3
@color = opts[:up_color] || gainsboro
@click_color = opts[:down_color] || @border_color
@width = opts[:width] || 80
@click = block_given? ? Proc.new { yield } : nil
@text = text
@visible = true
@flow = flow :width => @width do
background @color
border @border_color, :strokewidth => @border_width
para @text, :align => 'center'
end
@flow.click do
@flow.clear
@flow.append do
background @click_color
border @border_color, :strokewidth => @border_width
para @text, :align => 'center'
end
end
@flow.release do
@flow.clear
@flow.append do
background @color
border @border_color, :strokewidth => @border_width
para @text, :align => 'center'
@click.call if @click
end
end
end
def click
@click = block_given? ? Proc.new { yield } : nil
end
def show
@flow.show
end
def toggle
@flow.toggle
end
def hide
@flow.hide
end
end
Shoes.app do
para 'This is some text.'
@btn = pesto_button 'Click me!' do
alert 'Hello, World!'
end
button 'toggle' do
@btn.toggle
end
button 'new block' do
@btn.click do
alert 'Goodbye, World!'
end
end
button 'no block' do
@btn.click #Clears the click method
end
para 'Blah blah blah'
end