ruby-****@sourc*****
ruby-****@sourc*****
2012年 10月 5日 (金) 01:21:30 JST
------------------------- REMOTE_ADDR = 184.145.80.187 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-cdf ------------------------- @@ -1,8 +1,13 @@ = The Tree View Widget {{link "tut-gtk2-treev-etr", "tut-gtk2-treev", "tut-gtk", "tut-gtk2-treev-crs"}} == Cell Data Functions +:Note: + Because ((*set_cell_data_func*))is a method defined in Gtk::TreeViewColumn class, and is tigtly related to tree view and its managenent classes as well as to the model clases, we have already intoduced it earlier in this chapter (Using Gtk TreeStore) in the segment [8.2.2] entitled ((<Cell Data Function|tut-gtk2-treev-trees#Cell Data Function>)), where we looked at it in the perspective of tree view and model clases. Here it is presented in the shortest possible way, without bothering too much about its relationships to the tree view and model clases and objects. If you are new to GTK+, or plan to learn it well, you should also read just mentioned sections [8.2.2]. Otherwise this segment may be enough to give you an idea, what((*set_cell_data_func*)) method is about. + + + {{image_right("treev-cdf-01.png")}} If you need to further customize every cell before it is rendered to the screen, you can use cell data function Gtk::TreeViewColumn#set_cell_data_func(cell) {|tvc, cell, model, iter| ... }. This method allows you to tinker with every property for each individual cell. For example, you can set the background colour based on the content of the cell, or format the numeric value to your liking, or perhaps only restricting the number of decimal places for a floating point. It can also be used to set properties that are calculated during the run time. The next example will give you an idea how this can be done: @@ -77,7 +82,12 @@ Gtk.main -In the above example program all the new stuff to learn is in the ((*setup_tree_view*)) method. Focus here is on the Gtk::TreeViewColumn#set_cell_data_func(cell) method. Note that the API designates the argument ((*cell*)) to represent a renderer. It may not be obvious from the code, that you do not need to use this cell data function to simply set a property of a cell. For instance we could set change the font for all cells to ((*bold*)) simply by sending the message ((*weight*)) without ever calling the Gtk::TreeViewColumn#set_cell_data_func method. It only makes sense to call this method if rendering of each cell depends on some run-time value or processing. Our cells, do indeed meet this criteria. First each cell's background is rendered in a different colour, and to make it more interesting we are monitoring the brightness of the background and set accordingly the foreground colour. For your learning convenience we also dynamically alter the font's weight. +In the above example program the focus is on the Gtk::TreeViewColumn#set_cell_data_func(cell) method. Note that the API designates the argument ((*cell*)) to represent a renderer. It may not be obvious from the code, that you do not need to use this cell data function to simply set a property of a cell. For instance we could set change the font for all cells to ((*bold*)) simply by sending the message ((*weight*)) to a Gtk::CellRendererText object without ever calling the Gtk::TreeViewColumn#set_cell_data_func method. It only makes sense to call this method if rendering of each cell depends on some run-time value or processing. The cells in the tree view of our 'celldatafunction.rb' example program, do indeed meet this criteria. First each cell's background is rendered in a different colour, and to make it more interesting we are monitoring the brightness of the background and set accordingly the foreground colour. For your learning convenience we also dynamically alter the font's weight. Also pay attention to: