【问题标题】:Aligning a Stack when using Shoes使用鞋子时对齐堆栈
【发布时间】:2012-06-28 16:00:22
【问题描述】:

我使用 Shoes 作为 Ruby 的 GUI 工具包。

我的问题是如何对齐整个堆栈?我设法将一个 para 对齐到中心,但是 :align 在堆栈上不起作用......请有任何想法

【问题讨论】:

    标签: ruby shoes


    【解决方案1】:

    我认为没有直接的方法,但你可以这样做(它实际上是水平和垂直居中):

    Shoes.app do
     @s=stack :width=>300, :height=>100,  do 
      background red
     end
     @top=(@s.parent.height-@s.style[:height])/2
     @left=(@s.parent.width-@s.style[:width])/2
     @s.move(@left,@top)
    end
    

    您可以将其包装在一个函数中以便于使用。:

    def center(elem)
      top=(elem.parent.height-elem.style[:height])/2
      left=(elem.parent.width-elem.style[:width])/2
      elem.move(left,top)
    end
    

    然后像这样使用它:

     ...
     @s=stack :width=>300, :height=>100,  do 
      background red
     end
     center(@s)
     ...
    

    .. 或者你可以像这样扩展 Stack 类:

    class Shoes::Types::Stack
     def center
      top=(self.parent.height-self.style[:height])/2
      left=(self.parent.width-self.style[:width])/2
      self.move(left,top)
     end
    end
    

    而不是像那样使用它:

    @s=stack :width=>300, :height=>100,  do 
      background red
    end
    @s.center
    

    K

    【讨论】:

      猜你喜欢
      • 2012-03-08
      • 1970-01-01
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      • 2015-01-08
      • 2017-01-04
      • 2016-05-04
      • 2014-03-11
      相关资源
      最近更新 更多