0

I can't align middle a list_box in ruby shoes. I have test a few things, including :right => "50" or :left => "50", but it still not work.

Shoes.app do 
  stack :width => "100%", :height => "45%" do
    a = list_box :items => ["lol","b"], :width => 50, :align => "center"
  end
end
sidney
  • 2,704
  • 3
  • 28
  • 44

1 Answers1

2

I did not find a direct way but you can use this hack

module Shoes::Types
def centr
 left=(self.parent.width-self.style[:width])/2
 self.move(left,self.top)
end

def middle
 top=(self.parent.height-self.style[:height])/2
 self.move(self.left,top) 
end
end

Shoes.app do 
 @c=stack :width=>50, :height=>30 do
  a=list_box :items => ["lol","b"], :width => 50, :height=>30
 end
 @c.centr.middle
end

What is done is actually first to extend the functionality of slots so that you can place them in the center or middle of the containing slot. Then you wrap your listbox in a tiny slot, which you center.

kwicher
  • 2,092
  • 1
  • 19
  • 28
  • sorry it doesn't work, we got the illusion this work because there is no border. Write "border black" right between the stack and the a list_box, you will understand :s Then, we have to make the stack bigger in order to see that it doesn't work. – sidney Nov 02 '12 at 17:42
  • Nevermind, I just understood that it wasn't the list_box which was centered inside the new stack, but the new stack that was centered with his parents. Thanks – sidney Nov 02 '12 at 18:13