Robert Anderson wrote:>
> What I''d like to be able to do is use a wxTreeCtrl to manage a
tree
> layout of not only text, but several buttons which would line up
> adjacent to the text in the tree items. I''ve googled around a bit
on
> this and it doesn''t seem straightforward, if it is possible at
all.
>
> Can anyone provide any pointers for attempting this?
This comes up frequently in C++ wxWidgets. There''s no core class in
wxWidgets which does this, and hence nothing in wxRuby. But there are
numerous user-contributed classes on eg wxCode which have multi-column
TreeCtrls.
But at present these are only in C++, and I have no experience of trying
to wrap third-party C++ extensions in Ruby. For some classes this should
not be too hard using SWIG - but TreeCtrl is one of the most complex
wrappings in wxRuby.> I am starting to think that I will have to synthesize the entire thing
> using sizers. Would it even be possible in the wx model to
> dynamically add/remove items and spacers to create a tree-like
> behavior? Thoughts?
One possibility might be to have two sibling controls, a TreeCtrl on the
left, and a Panel on the right where the buttons are drawn. Use
TreeCtrl#get_bounding_rect to find the position of each of the visible
tree items, and place Wx::Buttons at an appropriate height on the right.
Or you can draw directly control-like things upon the panel with a
DeviceContext (DC), possibly using RendererNative to get the right look
and feel for your platform. Either way, update the Panel''s contents as
tree items are collapsed and expanded (with event handlers).
This would mean that there would be a gap between the text labels and
the associated buttons. Closer to what you want would be to try drawing
directly on top of the TreeCtrl, again using get_bounding_rect to find
where the label is positioned. But I am not sure how well drawing
directly on top of a native control will work - be sure to test on any
platform you want to use.
hth
alex