Saturday, 15 November 2008

Table in Shoes

I recently needed to display some data as a table using Shoes.

To this end, I created the class which creates the table: - Table.new(top, left, height, headers, items, blk), where:
- top, left - position of the top and left corner of the table
- height - number of rows to show without the vertical scrolling bar
- headers - array of arrays containing headers and widths of the columns) in the form of ["title", width]
- items - array of arrays containing data to be displayed
- blk - optional Proc object with a block to be called when the row is clicked.

As mentioned, rows are clickable and can invoke a block of code specified during initialization.

The table can be modified after creation. One can update the list of items to be displayed, make the table unresponsive to clicks, hide it and then show it again using provided methods, as well
as directly select a row or retrieve the info which row is selected.

The code of the class with a test application is available from The Shoebox repository.

MTPBWY

K.

No comments: