How to create a hidden button in Shoes?

In Shoes, I would like to create a button that is initially hidden. I tried passing: hidden => true as part of the button's style, and also calling @ button.hide () after creating it, but it remains stubbornly visible.

I managed to get around this without creating a button until I want it to be shown, but for this I need to check if it already exists, and not just use it.

+3
source share
1 answer

Not now. Buttons are still pretty unreliable in shoes, especially on Windows. You can work around the problem by placing the button in the slot, hiding or showing the slot, but you may find that the button will not hide again once it has been pressed once:

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

, : . , , . .

-, . pesto_button , . , , , ( ?), ..:

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
+3

Source: https://habr.com/ru/post/1714749/


All Articles