Package: gtk

Function gtk:tree-view-insert-column-with-data-func

Lambda List

gtk:tree-view-insert-column-with-data-func (view pos title renderer func)

Arguments

view -- a gtk:tree-view widget
pos -- an integer with the position to insert the new column in
title -- an string with the title to set the header to
renderer -- a gtk:cell-renderer object
func -- a gtk:tree-cell-data-func callback function to set the attributes of renderer

Return Value

The integer with the number of columns in view after insertion.

Details

Convenience function that inserts a new column into the tree view with the given cell renderer and a gtk:tree-cell-data-func callback function to set cell renderer attributes (normally using data from the model). See also the gtk:tree-view-column-set-cell-data-func and gtk:tree-view-column-pack-start functions. If the tree view has the fixed-height-mode property enabled, then the new column will have its sizing property set to be the :fixed value.

Examples

In this example, the cell data function takes the year of birth from the model, calculates the age and formats a suitable text that is displayed in the tree view.
(defun age-cell-data-sortable (column renderer model iter)
  (declare (ignore column))
  (let ((year (sixth (multiple-value-list (get-decoded-time))))
        (text nil)
        (value (gtk:tree-model-value model iter colyearborn)))
    (if (and (< value year) (> value 0))
        (progn
          (setf text (format nil "~a  years old" (- year value)))
          (setf (gtk:cell-renderer-text-foreground-set renderer) nil))
        (progn
          (setf text "age unknown")
          (setf (gtk:cell-renderer-text-foreground renderer) "Red")))
    (setf (gtk:cell-renderer-text-text renderer) text)))

;; Insert a column with the cell data function (let* ((renderer (gtk:cell-renderer-text-new))) (gtk:tree-view-insert-column-with-data-func view -1 "Age" renderer #'age-cell-data-sortable) ... )
 

See also

2024-3-12