Philippe Lang
2007-Oct-12 09:44 UTC
[fxruby-users] Scrolling to the newly appended row in an FXTable
Hi, After appending a row in an FXTable, I''d like to scroll the FXTable to the last line of the FXTable, to make sure the new row is visible. I''m using this kind of code: def onInsertRow(sender, sel, ptr) @table.appendRows(1, true) @table.setPosition(0, -1000) # I never have more that 1000 lines in the table! end The problem is that I''m unable to scroll until the last line, only the line *** before the last line ***. Apparently, it''s a "timing" problem: when position is set, the line append is not completely "committed" to the GUI. Called separately, @table.setPosition(0, -1000) works just fine, as you can see in this test: ------------------ #!/usr/bin/env ruby require ''fox16'' require ''date'' include Fox class TableWindow < FXMainWindow def initialize(app) # Call the base class initializer first super(app, "Table Widget Test", :opts => DECOR_ALL) # Tooltip tooltip = FXToolTip.new(getApp()) # Menubar menubar = FXMenuBar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X) # Separator FXHorizontalSeparator.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X|SEPARATOR_GROOVE) # Contents contents = FXVerticalFrame.new(self, LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y) frame = FXVerticalFrame.new(contents, FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y, :padding => 0) # Table @table = FXTable.new(frame, :opts => TABLE_COL_SIZABLE|TABLE_ROW_SIZABLE|LAYOUT_FILL_X|LAYOUT_FILL_Y, :padding => 2) @table.visibleRows = 10 @table.visibleColumns = 4 @table.setTableSize(20, 14) # Initialize column headers (0...12).each { |c| @table.setColumnText(c, Date::MONTHNAMES[c+1]) } # Initialize row headers (0...20).each { |r| @table.setRowText(r, "Row#{r}") } # File Menu filemenu = FXMenuPane.new(self) FXMenuCommand.new(filemenu, "&Quit\tCtl-Q", nil, getApp(), FXApp::ID_QUIT) FXMenuTitle.new(menubar, "&File", nil, filemenu) # Manipulations Menu manipmenu = FXMenuPane.new(self) FXMenuCommand.new(manipmenu, "Insert Row").connect(SEL_COMMAND, method(:onInsertRow)) FXMenuCommand.new(manipmenu, "Go to last row").connect(SEL_COMMAND, method(:onCmdGoToLastRow)) FXMenuTitle.new(menubar, "&Manipulations", nil, manipmenu) end def onCmdGoToLastRow(sender, sel, ptr) @table.setPosition(0, -1000) end def onInsertRow(sender, sel, ptr) @table.appendRows(1, true) @table.setPosition(0, -1000) end # Create and show this window def create super show(PLACEMENT_SCREEN) end end # Start the whole thing if __FILE__ == $0 # Make application application = FXApp.new("TableApp", "FoxTest") # Make window TableWindow.new(application) # Create app application.create # Run application.run end ------------------ Any idea how I can do that? Thanks! Philippe Lang
Lyle Johnson
2007-Oct-18 20:24 UTC
[fxruby-users] Scrolling to the newly appended row in an FXTable
On Oct 12, 2007, at 4:44 AM, Philippe Lang wrote:> After appending a row in an FXTable, I''d like to scroll the FXTable to > the last line of the FXTable, to make sure the new row is visible. > > I''m using this kind of code: > > def onInsertRow(sender, sel, ptr) > @table.appendRows(1, true) > @table.setPosition(0, -1000) # I never have more that 1000 lines > in the table! > endPhilippe, You just need to add a call to @table.layout() immediately after the call to appendRows(). The call to appendRows() marks the layout as dirty, but the layout won''t actually be recalculated until you return to the event loop. Calling layout() explicitly forces the layout to be reconciled right away, so that setPosition() has the correct metrics to work with. Hope this helps, Lyle
Philippe Lang
2007-Oct-19 05:46 UTC
[fxruby-users] Scrolling to the newly appended row in an FXTable
fxruby-users-bounces at rubyforge.org wrote:> On Oct 12, 2007, at 4:44 AM, Philippe Lang wrote: > >> After appending a row in an FXTable, I''d like to scroll the FXTable >> to the last line of the FXTable, to make sure the new row is visible. >> >> I''m using this kind of code: >> >> def onInsertRow(sender, sel, ptr) >> @table.appendRows(1, true) >> @table.setPosition(0, -1000) # I never have more that 1000 lines >> in the table! end > > Philippe, > > You just need to add a call to @table.layout() immediately after the > call to appendRows(). > > The call to appendRows() marks the layout as dirty, but the layout > won''t actually be recalculated until you return to the event loop. > Calling layout() explicitly forces the layout to be reconciled right > away, so that setPosition() has the correct metrics to work with.Thanks a lot Lyle, it works just fine. Regards, Philippe