Chauk-Mean. :
Your code runs ok in a separate file.
If i call MyPanel from my menu to put the panel in my main frame, the
code
does not work.
This code :
begin
require ‘rubygems’
rescue LoadError
end
require ‘wx’;
class TarefasNova < Wx::Panel
def initialize(parent)
super(parent)
box = Wx::BoxSizer.new (Wx::VERTICAL)
box.add_item(Wx::StaticText.new(self, :label => "Centered Title"),
:flag => Wx::ALIGN_CENTER)
box.add_item(Wx::StaticText.new(self, :label => "Leftside Text"),
:flag => Wx::ALIGN_LEFT)
box.add_item(Wx::StaticText.new(self, :label => "Rightside Text"),
:flag => Wx::ALIGN_RIGHT)
self.sizer = box
end
end
The panel only shows “Righ”.
Does not size to fill frame.
When i put :
rect = parent.get_client_rect();
super( parent, 1011, Wx::Point.new( 0, 0 ), rect.get_size(),
SIMPLE_BORDER, “NovaTarefa” );
This makes the panel fill frame.
The frame has menu bar and statusbar.
De: [email protected]
[mailto:[email protected]] Em nome de Chauk-Mean P.
Enviada em: sexta-feira, 20 de março de 2009 10:39
Para: General discussion of wxRuby
Assunto: Re: [wxruby-users] RES: Problem centering a label
Hi Alejandro,
I’m not sure to understand why you need 2 sizers but your main problem
is that you haven’t told the panel to use the sizer !
Here is a sample code where there are 3 texts :
- at the top, the text is centered
- at the middle, the text is left aligned
- at the bottom, the text is right aligned
The important line is the one with self.sizer = box.
You should also use wx constants to make your code clearer.
#!/usr/bin/env ruby
wxRuby2 Sample Code. Copyright (c) 2004-2008 wxRuby development team
Freely reusable code: see SAMPLES-LICENSE.TXT for details
begin
require ‘rubygems’
rescue LoadError
end
require ‘wx’
class MyPanel < Wx::Panel
def initialize(parent)
super(parent)
box = Wx::BoxSizer.new (Wx::VERTICAL)
box.add_item(Wx::StaticText.new(self, :label => “Centered Title”),
:flag => Wx::ALIGN_CENTER)
box.add_item(Wx::StaticText.new(self, :label => “Leftside Text”),
:flag => Wx::ALIGN_LEFT)
box.add_item(Wx::StaticText.new(self, :label => “Rightside Text”),
:flag => Wx::ALIGN_RIGHT)
self.sizer = box
end
end
This is the minimum code to start a WxRuby app - create a Frame, and
show it.
Wx::App.run do
frame = Wx::Frame.new(nil, :title => “Minimal wxRuby App”)
panel = MyPanel.new(frame)
frame.show
end
Cheers.
Chauk-Mean.
wxruby-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wxruby-users
avast! Antivirus http://www.avast.com : Inbound message clean.
Virus Database (VPS): 090319-0, 19/03/2009
Tested on: 20/03/2009 13:13:39
avast! - copyright (c) 1988-2009 ALWIL Software.
avast! Antivirus http://www.avast.com : Outbound message clean.
Virus Database (VPS): 090319-0, 19/03/2009
Tested on: 20/03/2009 13:56:02
avast! - copyright (c) 1988-2009 ALWIL Software.