wxRuby: How to add a scrollbar to a Wx::Notebook tab

S

Stephan Kämper

Hi all,

having just started to work with wxRuby, I would like to
- display a Wx::Notebook
- with several widgets in each row
- where the text field in the row horizontally fills the frame/window.
- and with a scrollbar in case the list gets too long to fit into
the available space

Now I condensed the code I started with into this example (with faked
data to fill the tabs):

--- code begin ---

require 'wxruby'

class TabScroller < Wx::App

def on_init
frame = Wx::Frame.new( nil, -1, 'Matices in tabs' )
frame.set_client_size( Wx::Size.new( 400, 120 ) )
sizer = Wx::BoxSizer.new( Wx::VERTICAL )

notebook = Wx::Notebook.new( frame, -1 )

fill_tabbook( notebook )

frame.show
end

def fill_tabbook( notebook )
@sl = [ { :header => "Header 1",
:list =>[ ["CB1", "Additional text1 "],
["CB2", "ding"],
["text2", "dong"] ]
},
{ :header => "Third" ,
:list => [ ["3rd check 1", "..." ],
["3rd check 2", "..." ],
["3rd check 3", "..." ],
["3rd check 4", "..." ] ]
}
]

@sl.each_with_index{ | line, idx |
panel = Wx::panel.new( notebook, -1 )
sizer = Wx::FlexGridSizer.new( 2, 0, 2 )
panel.set_sizer sizer

header = Wx::StaticText.new( panel, -1, line[:header] )
sizer.add( header, 0, Wx::ALIGN_LEFT )
sizer.add( Wx::StaticText.new( panel, -1, '' ), 0,
Wx::ALIGN_LEFT )

line[:list].each { | item |
checker = Wx::CheckBox.new( panel, -1, item[0] )
sizer.add( checker, 0, Wx::ALIGN_LEFT )

notes = Wx::TextCtrl.new( panel, -1, item[1] )
sizer.add( notes, 1)

sizer.add( Wx::StaticText.new( panel, -1, '' ), 0,
Wx::ALIGN_LEFT )
sizer.add( Wx::StaticText.new( panel, -1, '' ), 0,
Wx::ALIGN_LEFT )
}
notebook.add_page( panel, "Tab No #{idx + 1}" )
}
end

end

if __FILE__ == $0
TabScroller.new.main_loop()
end

--- code end ---

These are my questions:
How would I introduce a Wx::ScrolledWindow (if that's what is needed)
into this to add a scrollbar to each tab (so the user can use the scroll
bar to reach all the widgets)?

How can I make the Wx::TextCrtl fill the available space to the right?

Any help would be greatly appreciated.

Happy rubying

Stephan
 
C

Curt Hibbs

I'm going to cross-post this to the wxRuby ML because I know of at least one
wxRuby expert who does not subscribe to ruby-talk.

Curt

Stephan Kämper [mailto:[email protected]]
 
S

Stephan Kämper

Curt said:
I'm going to cross-post this to the wxRuby ML because I know of at least one
wxRuby expert who does not subscribe to ruby-talk.

Curt

Thanks! (I'm going to subscribe to the wxRuby ML, too.)

Happy rubying

Stephan
 
Z

Zach Dennis

The only thing that appears to be in the wxRuby arsenal to handle
something Scrollable is Wx::ScrolledWindow, but whenever it is attempted
to be implemented it complains that there is no on_draw method. I
haven't done any digging to see if it's got any subclasses successfully
implemented in wxRuby.

Kevin, Nick, any thoughts?

Zach



Curt said:
I'm going to cross-post this to the wxRuby ML because I know of at least one
wxRuby expert who does not subscribe to ruby-talk.

Curt

Stephan Kämper [mailto:[email protected]]

Hi all,

having just started to work with wxRuby, I would like to
- display a Wx::Notebook
- with several widgets in each row
- where the text field in the row horizontally fills the frame/window.
- and with a scrollbar in case the list gets too long to fit into
the available space

Now I condensed the code I started with into this example (with faked
data to fill the tabs):

--- code begin ---

require 'wxruby'

class TabScroller < Wx::App

def on_init
frame = Wx::Frame.new( nil, -1, 'Matices in tabs' )
frame.set_client_size( Wx::Size.new( 400, 120 ) )
sizer = Wx::BoxSizer.new( Wx::VERTICAL )

notebook = Wx::Notebook.new( frame, -1 )

fill_tabbook( notebook )

frame.show
end

def fill_tabbook( notebook )
@sl = [ { :header => "Header 1",
:list =>[ ["CB1", "Additional text1 "],
["CB2", "ding"],
["text2", "dong"] ]
},
{ :header => "Third" ,
:list => [ ["3rd check 1", "..." ],
["3rd check 2", "..." ],
["3rd check 3", "..." ],
["3rd check 4", "..." ] ]
}
]

@sl.each_with_index{ | line, idx |
panel = Wx::panel.new( notebook, -1 )
sizer = Wx::FlexGridSizer.new( 2, 0, 2 )
panel.set_sizer sizer

header = Wx::StaticText.new( panel, -1, line[:header] )
sizer.add( header, 0, Wx::ALIGN_LEFT )
sizer.add( Wx::StaticText.new( panel, -1, '' ), 0,
Wx::ALIGN_LEFT )

line[:list].each { | item |
checker = Wx::CheckBox.new( panel, -1, item[0] )
sizer.add( checker, 0, Wx::ALIGN_LEFT )

notes = Wx::TextCtrl.new( panel, -1, item[1] )
sizer.add( notes, 1)

sizer.add( Wx::StaticText.new( panel, -1, '' ), 0,
Wx::ALIGN_LEFT )
sizer.add( Wx::StaticText.new( panel, -1, '' ), 0,
Wx::ALIGN_LEFT )
}
notebook.add_page( panel, "Tab No #{idx + 1}" )
}
end

end

if __FILE__ == $0
TabScroller.new.main_loop()
end

--- code end ---

These are my questions:
How would I introduce a Wx::ScrolledWindow (if that's what is needed)
into this to add a scrollbar to each tab (so the user can use the scroll
bar to reach all the widgets)?

How can I make the Wx::TextCrtl fill the available space to the right?

Any help would be greatly appreciated.

Happy rubying

Stephan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top