The way in which the tree and list widgets handle cell formatting is to emphasize data groups in the context a columns, and their background colouration. Specific cells are usually formatted based upon their contents, principally as foreground attributes although cell value contents can also be formatted using pango markup.
Row formatting in comparison is principally used for assisting visibility such as changing alternating row colour hinting and treeline. Selected rows are temporarily highlighted. Unlike the column configuration options Gtk+ offers no equivalent for setting rows attributes. To achieve this, each cell value needs to be reset and specific attributes assigned. The following example shows how to set the foreground colour for cells in the same row.
#!/bin/sh
#\
exec tclsh "$0" "$@"
package require Gnocl
#---------------
# create UI
#---------------
proc main {} {
set box [gnocl::box -orientation vertical]
set ::list [gnocl::list \
-titles {"string" "string" "string" "string"} \
-types {string string string string} ]
$box add $::list -fill {1 1} -expand 1
gnocl::window -child $box -setSize 0.25
$::list add {0 "list widget" -104 1.45} -singleRow 1
$::list add {1 "window box" 3350 9.58} -singleRow 1
$::list add {AAA BBB CCC DDD} -singleRow 1
$::list columnConfigure 1 -editable 1
}
main
proc colorRowInit {wid {from 0} {to end}} {
global _activeRow
if { $to == "end" } { set to [$wid columns] }
for { set i $from } { $i < $to } { incr i } { $wid columnConfigure $i -onCellData {setColor2 %w %p %v} }
set _activeRow ""
#---------------
# change entry colour
#---------------
proc setColor2 { wid row val } {
global _activeRow
if { $row == $_activeRow } {
return "-foreground red "
} else {
return "-foreground [list [$wid cget -textColor]] "
}
}
gnocl::update
}
proc colorRow {wid row} {
global _activeRow
set _activeRow $row
for {set i 0} {$i < [$wid columns] } { incr i } {
$wid cellConfigure $row $i -value [$wid get $row $i]
}
$wid draw
gnocl::update
}
colorRowInit $list
set _activeRow 0
while 1 {
after 1000
colorRow $list $_activeRow
if { [incr _activeRow] == [$list rows] } { set _activeRow 0 }
}
Comments