悬停、菜单和按钮

发布于 2024-07-18 06:42:10 字数 159 浏览 7 评论 0原文

我想设置一个矩形/槽,当悬停在其上时,会创建一个悬停在矩形/槽侧面的小窗口(有点重叠)。

我还想在小菜单中添加一些按钮。 我希望小菜单比原始的矩形/插槽更长(宽度方向),以便容纳许多按钮,这意味着我不能使用 slot.hover,因为如果我从直接到按钮上的按钮...有什么帮助吗?

I want to setup a rect/slot, that when hovered over, creates a little window hovering off the side of the rect/slot (a little overlapping).

I'd also like to fit some buttons in the little menu. I'd like the little menu to be longer (width-wise) than the original rect/slot, in order to fit many buttons, which means I can't use slot.hover, because the menu goes away if I move from the rect to the button thats off the rect... Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乙白 2024-07-25 06:42:10

这是一个示例,应该向您展示完成此操作所需的逻辑。 如果你有一堆这样的菜单,它显然会失控:

Shoes.app :title => "Test", :width => 1000, :height => 600 do
  @menu_hover = false
  @zone_hover = false
  @menu = nil
  @zone = stack :width => 200, :height => 100 do
    background '#DFA'
  end
  @zone.hover do
    @zone_hover = true
    app.append do
      break if not @menu.nil?
      @menu = stack :width => 230, :height => 35, :top => 50, :left => 150 do
        background '#F00'
        flow :margin => 5 do 
          button 'OK'
          button 'Cancel'
          button 'Ponies!'
        end
      end
      @menu.hover {@menu_hover = true}
      @menu.leave do
            @menu_hover = false
            break if @menu.nil? or @menu_hover or @zone_hover
            @menu.remove
            @menu = nil
      end
    end
  end

  @zone.leave do
    @zone_hover = false
    break if @menu.nil? or @menu_hover or @zone_hover
    @menu.remove
    @menu = nil
  end
end

这是对上述解决方案的即兴发挥,它扩展了 Shoes::Stack 和 Shoes::App 类以添加 hover? 方法到堆栈(我认为他们应该默认支持)。 对于您的情况,我会考虑创建一个自定义小部件,但这显示了您可能能够使用的结构类型。

class Shoes::Stack
  def hover?
    @hover ||= false
  end

  alias_method :default_hover, :hover
  alias_method :default_leave, :leave

  def hover(*args, &block)
    new_block = lambda { @hover = true; block.call }
    default_hover(*args, &new_block)
  end

  def leave(*args, &block)
    new_block = lambda { @hover = false; block.call }
    default_leave(*args, &new_block)
  end
end

class Shoes::App
  alias_method :default_stack, :stack
  def stack(*args, &block)
    s = default_stack(*args, &block)
    s.hover {}
    s.leave {}
    s
  end
end

Shoes.app :title => "Test", :width => 1000, :height => 600 do
  @menu = nil
  @zone = stack :width => 200, :height => 100 do
    background '#DFA'
  end
  @zone.hover do
    app.append do
      break if not @menu.nil?
      @menu = stack :width => 230, :height => 35, :top => 50, :left => 150 do
        background '#F00'
        flow :margin => 5 do 
          button 'OK'
          button 'Cancel'
          button 'Ponies!'
        end
      end
      @menu.leave do
            break if @menu.nil? or @menu.hover? or @zone.hover?
            @menu.remove
            @menu = nil
      end
    end
  end

  @zone.leave do
    break if @menu.nil? or @menu.hover? or @zone.hover?
    @menu.remove
    @menu = nil
  end
end

Here is an example that should show you the logic you need in order to accomplish this. It would obviously get out of hand if you had a bunch of these menus:

Shoes.app :title => "Test", :width => 1000, :height => 600 do
  @menu_hover = false
  @zone_hover = false
  @menu = nil
  @zone = stack :width => 200, :height => 100 do
    background '#DFA'
  end
  @zone.hover do
    @zone_hover = true
    app.append do
      break if not @menu.nil?
      @menu = stack :width => 230, :height => 35, :top => 50, :left => 150 do
        background '#F00'
        flow :margin => 5 do 
          button 'OK'
          button 'Cancel'
          button 'Ponies!'
        end
      end
      @menu.hover {@menu_hover = true}
      @menu.leave do
            @menu_hover = false
            break if @menu.nil? or @menu_hover or @zone_hover
            @menu.remove
            @menu = nil
      end
    end
  end

  @zone.leave do
    @zone_hover = false
    break if @menu.nil? or @menu_hover or @zone_hover
    @menu.remove
    @menu = nil
  end
end

Here is a riff on the above solution which extends the Shoes::Stack and Shoes::App classes to add a hover? method to stacks (which I think they ought to support by default). In your case, I'd consider creating a custom Widget instead, but this shows the sort of structure you might be able to use.

class Shoes::Stack
  def hover?
    @hover ||= false
  end

  alias_method :default_hover, :hover
  alias_method :default_leave, :leave

  def hover(*args, &block)
    new_block = lambda { @hover = true; block.call }
    default_hover(*args, &new_block)
  end

  def leave(*args, &block)
    new_block = lambda { @hover = false; block.call }
    default_leave(*args, &new_block)
  end
end

class Shoes::App
  alias_method :default_stack, :stack
  def stack(*args, &block)
    s = default_stack(*args, &block)
    s.hover {}
    s.leave {}
    s
  end
end

Shoes.app :title => "Test", :width => 1000, :height => 600 do
  @menu = nil
  @zone = stack :width => 200, :height => 100 do
    background '#DFA'
  end
  @zone.hover do
    app.append do
      break if not @menu.nil?
      @menu = stack :width => 230, :height => 35, :top => 50, :left => 150 do
        background '#F00'
        flow :margin => 5 do 
          button 'OK'
          button 'Cancel'
          button 'Ponies!'
        end
      end
      @menu.leave do
            break if @menu.nil? or @menu.hover? or @zone.hover?
            @menu.remove
            @menu = nil
      end
    end
  end

  @zone.leave do
    break if @menu.nil? or @menu.hover? or @zone.hover?
    @menu.remove
    @menu = nil
  end
end
勿忘初心 2024-07-25 06:42:10

听起来您需要使用一些额外的东西来保持该矩形在按钮上以及在插槽上时保持打开和可见。

这样就可以在任何事情发生时都将菜单保留在那里。

Sounds like you need to use some extra stuff to keep that rect open and visible while on a button as well as while over the slot.

That should keep the menu there while over anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文