Simple Tooltips

This example shows how to add help tooltips to the Object Editor in the previous example. The tooltip text is extracted automatically from the :documentation field of the CLOS object definition.

Complete listing


To add tooltip help to the Capacity text field in the previous example we simply add a :documentation definition to the object:

(defclass classic-car ()
  ((name :initarg :name :accessor name)
   (year :initarg :year :type integer)
   (cylinders :initarg :cylinders :type integer)
   (capacity :initarg :capacity :type integer :documentation "Engine displacement in cc")))

This displays the following tooltip:


The implementation

To add tooltips we just need to make the following changes to the Object Editor definitions.

First we add a :help-callback initarg to the definition of the edit-window class: 

(defclass edit-window (capi:interface)
  ((thing :initarg :thing :accessor thing))
   :help-callback #'do-tooltip-help))

Then we define the routine do-tooltip-help that will supply the help text:

(defun do-tooltip-help (interface pane type key)
  (declare (ignorable interface pane))
   (when (eq type :tooltip)
      (find key (clos:class-slots (class-of (thing interface)))
            :key 'clos:slot-definition-name)

This extracts the documentation for the slot and class of the object being displayed in the edit window.

Finally, to specify the text to be displayed in each tooltip we simply define the text to be displayed in the :documentation field of the slot definition:

(defclass classic-car ()
  ((name :initarg :name :accessor name)
   (year :initarg :year :type integer :documentation "Year first introduced")
   (cylinders :initarg :cylinders :type integer :documentation "Number of cylinders")
   (capacity :initarg :capacity :type integer :documentation "Engine displacement in cc")))

blog comments powered by Disqus