2012-06-28 42 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 

ķ