2012-06-28 46 views
2

我使用Shoes作为Ruby的GUI工具箱。使用鞋子时对齐堆栈

我的问题是如何对齐整个堆栈?我设法对准中心,但:对齐不能在堆栈上工作...任何想法请

回答

1

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

Shoes.app do 
@s=stack :width=>300, :height=>100, do 
    background red 
end 
@top=(@[email protected][:height])/2 
@left=(@[email protected][: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 

ķ