src/swipl-devel/packages/xpce/man/refmanual/md/connect_gesture.md

class connect_gesture {#class-connect_gesture}

A connect_gesture is used to create a connection object between two graphical objects by dragging from the first to the second graphical object. The gesture is connected to a graphical that can serve as an origin (starting) point for a connection. Note that the graphical should have handle objects that can connect to the link object associated with the gesture. Thus, if the link is created from the term link(in, out), the graphical from which the connection is started should have at least one handle of handle<-kind in and the graphical at the other end should have at least one handle of handle<-kind out.

This class provides a high-level user-interface for creating connections. The following program illustrates the use of PCE's graphical connection facilities:

connect_demo :-
    send(new(P, picture('Connect Demo')), open),
    send(P, recogniser,
         click_gesture(left, '', single,
                       message(@prolog,
                               display_box, P,
                               @event?position))).

:- pce_global(@east,  new(handle(0, h/2, any, east))).
:- pce_global(@north, new(handle(w/2, 0, any, north))).
:- pce_global(@west,  new(handle(w, h/2, any, west))).
:- pce_global(@south, new(handle(w/2, h, any, south))).

:- pce_global(@connect_recogniser,
              new(handler_group(connect_gesture(left, '',
                                                link(any)),
                                new(move_gesture)))).


display_box(P, Pos) :-
    send(P, display, new(B, box(30,30)), Pos),
    send_list(B, handle,
              [ @east, @north, @west, @south
              ]),
    send(B, recogniser, @connect_recogniser).

Unfortunately possible links often rely on semantics too complicated to deal with by the handle and link naming mechanism. For this reason this class defines a large number of methods that may be redefined. The most commonly redefined are:

| ->verify   | Additional tests, assign <-device |
| <-pointed  | Determine graphical to link too   |
| ->indicate | Find possible connection-points   |
| ->connect  | Creates the actual connection     |

The default methods allow for connecting objects displayed on the same device. In principle, connect-gestures may be used to connect any two objects displayed on the same window object, arbitrary nested in device objects. To use this feature, the ->verify method should be redefined and should set ->device to the common device displaying both the origin and target objects (this can be the window). The <-pointed method should be redefined to find graphicals under the pointer that can be used to connect to. The methods device <-find and `device <-pointed' are often useful to implement the <-pointed.

See also class handle, class connection, class link, `graphical ->connect'. The PceDraw demo illustrates the use of connections.

User interface {#class-connect_gesture-user-interface}

On a down event (of the appropriate button with the appropriate modifiers), the gesture will indicate the possible connection-points of the graphical with the from-side of the link using small markers. If the down occurs close to one specific handle, the gesture assumes this is the only handle the user wants to connect to. On termination, the from-side of the connection will be fixed to this handle. Otherwise all handles of the appropriate kind are indicated. In this case the connection will not be fixed and moving or resizing one of the objects may reconnect the connection to a visually more attractive handle.

On each subsequent drag event, the gesture will indicate valid to-handles if they exist.

When the gesture is terminated after an up event, the appropriate connection is created.

@see class connection

Class variables {#class-connect_gesture-classvars}

Instance variables {#class-connect_gesture-instvars}

Send methods {#class-connect_gesture-send}

Get methods {#class-connect_gesture-get}



Try the rswipl package in your browser

Any scripts or data that you put into this service are public.

rswipl documentation built on June 16, 2026, 5:07 p.m.