5.4 Constraints

XPCE allows the user to specify constraints between pairs of objects. In the example above we would like the text to be centered relative to the bitmap. This may be achieved using:

10 ?- get(@ic, member, bitmap, Bitmap),
      get(@ic, member, text, Text),
      new(_, constraint(Bitmap, Text, identity(center_x))).

Each time either the bitmap or the text changes this constraint will invoke <-center_x on the changed object and ->center_x with the return value on the other object. Class spatial defines more general geometrical constraints between graphicals.

Constraints are high-level, but potentially expensive means to specify graphical relations. An alternative is the redefinition of the ->geometry method of (compound) graphical objects. See chapter 7.