Debugging sizer usage and gui layout

In other gui packages I have seen special ‘debug modes’ on panels or
frames which highlighted the specific placement and size of each window
and subwindow (as determined by sizers) to help you visualize why things
aren’t working as expected. Is there such a thing in wxRuby (or Wx in
general?)

Pito S.

Hello Pito,

There isn’t one specifically built into wxRuby, however, doing this
shouldn’t be to hard, simply do the following in a Module, and include
it
into your class:

module Wx
module DebugWindow
def debug_on_size(event)
@debugSize = event.size
event.skip
end

def debug_on_paint(event)
  self.paint do |dc|
    dc.set_text_foregound(Wx::RED)
    dc.set_text_background(Wx::GREEN)
    dc.draw_text("Size of Window is:

#{@debugSize.width}x#{@debugSize.height}")
end unless @debugSize.nil?
event.skip
end

def included(base)
  base.eval("evt_size(:debug_on_size)")
  base.eval("evt_paint(:debug_on_paint)")
end

end

class MyWindow < Wx::Window
include Wx::DebugWindow

… do your code here …
end

This is a small sample, and is not garunteed to run exactly as
advertised,
and may take some tweaking in order to fix it properly.

Hi Pito

Pito S. wrote:

In other gui packages I have seen special ‘debug modes’ on panels or
frames which highlighted the specific placement and size of each window
and subwindow (as determined by sizers) to help you visualize why things
aren’t working as expected. Is there such a thing in wxRuby (or Wx in
general?)

Yes -
http://thread.gmane.org/gmane.comp.lib.wxwidgets.general/53232/focus=53233

I haven’t ever tried this myself. Also note that the distributed wxRuby
builds are based on RELEASE rather than DEBUG builds of Wx - so unless
you compile yourself this won’t be available.

It’s not a solution for everything, but trying things out in a GUI
designer can often help with the trickier bits of nesting, even if you
don’t use XRC for the final code.

cheers
a