Sha256: f7a3111a89fc8b1810573b4735c7ce0a5add0e2ef6250ada4e58b8c2b7af11c5

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

class MenuPanel < Shoes::Widget
  @@boxes = []

  # Handling width against internal stack until widget widths are fixed
  # https://github.com/shoes/shoes4/issues/641
  def width
    @stack.width
  end

  def width=(value)
    @stack.width = value
  end

  def initialize(color, args)
    @@boxes << self
    @stack = stack(args) do
      background color
      para link("Box #{@@boxes.length}", fg: white, fill: nil, click: "/"),
        margin: 18, align: "center", size: 20
      hover { expand }
    end
  end

  def expand
    if self.width < 170
      a = animate 30 do
        @@boxes.each do |b|
          b.width -= 5 if b != self and b.width > 140
        end
        self.width += 5
        a.stop if self.width >= 170
      end
    end
  end
end

Shoes.app width: 600, height: 130 do
  style(Shoes::Link, underline: nil)

  # hover styling currently a no-op https://github.com/shoes/shoes4/issues/638
  style(Shoes::LinkHover, fill: nil, underline: nil)

  menu_panel green,  width: 170, height: 120, margin: 4
  menu_panel blue,   width: 140, height: 120, margin: 4
  menu_panel red,    width: 140, height: 120, margin: 4
  menu_panel purple, width: 140, height: 120, margin: 4
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shoes-4.0.0.pre2 samples/simple-menu.rb
shoes-4.0.0.pre1 samples/simple-menu.rb