Trait gtk4::prelude::GestureExt

source ·
pub trait GestureExt: IsA<Gesture> + Sealed + 'static {
Show 23 methods // Provided methods fn bounding_box(&self) -> Option<Rectangle> { ... } fn bounding_box_center(&self) -> Option<(f64, f64)> { ... } fn device(&self) -> Option<Device> { ... } fn group(&self) -> Vec<Gesture> { ... } fn last_event(&self, sequence: Option<&EventSequence>) -> Option<Event> { ... } fn last_updated_sequence(&self) -> Option<EventSequence> { ... } fn point(&self, sequence: Option<&EventSequence>) -> Option<(f64, f64)> { ... } fn sequence_state(&self, sequence: &EventSequence) -> EventSequenceState { ... } fn sequences(&self) -> Vec<EventSequence> { ... } fn group_with(&self, gesture: &impl IsA<Gesture>) { ... } fn handles_sequence(&self, sequence: Option<&EventSequence>) -> bool { ... } fn is_active(&self) -> bool { ... } fn is_grouped_with(&self, other: &impl IsA<Gesture>) -> bool { ... } fn is_recognized(&self) -> bool { ... } fn set_sequence_state( &self, sequence: &EventSequence, state: EventSequenceState ) -> bool { ... } fn set_state(&self, state: EventSequenceState) -> bool { ... } fn ungroup(&self) { ... } fn n_points(&self) -> u32 { ... } fn connect_begin<F: Fn(&Self, Option<&EventSequence>) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_cancel<F: Fn(&Self, Option<&EventSequence>) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_end<F: Fn(&Self, Option<&EventSequence>) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_sequence_state_changed<F: Fn(&Self, Option<&EventSequence>, EventSequenceState) + 'static>( &self, f: F ) -> SignalHandlerId { ... } fn connect_update<F: Fn(&Self, Option<&EventSequence>) + 'static>( &self, f: F ) -> SignalHandlerId { ... }
}
Expand description

Provided Methods§

source

fn bounding_box(&self) -> Option<Rectangle>

If there are touch sequences being currently handled by @self, returns true and fills in @rect with the bounding box containing all active touches.

Otherwise, false will be returned.

Note: This function will yield unexpected results on touchpad gestures. Since there is no correlation between physical and pixel distances, these will look as if constrained in an infinitely small area, @rect width and height will thus be 0 regardless of the number of touchpoints.

Returns

true if there are active touches, false otherwise

rect

bounding box containing all active touches.

source

fn bounding_box_center(&self) -> Option<(f64, f64)>

If there are touch sequences being currently handled by @self, returns true and fills in @x and @y with the center of the bounding box containing all active touches.

Otherwise, false will be returned.

Returns

false if no active touches are present, true otherwise

x

X coordinate for the bounding box center

y

Y coordinate for the bounding box center

source

fn device(&self) -> Option<Device>

Returns the logical gdk::Device that is currently operating on @self.

This returns None if the gesture is not being interacted.

Returns

a gdk::Device

source

fn group(&self) -> Vec<Gesture>

Returns all gestures in the group of @self

Returns

The list of Gestures, free with g_list_free()

source

fn last_event(&self, sequence: Option<&EventSequence>) -> Option<Event>

Returns the last event that was processed for @sequence.

Note that the returned pointer is only valid as long as the @sequence is still interpreted by the @self. If in doubt, you should make a copy of the event.

sequence

a gdk::EventSequence

Returns

The last event from @sequence

source

fn last_updated_sequence(&self) -> Option<EventSequence>

Returns the gdk::EventSequence that was last updated on @self.

Returns

The last updated sequence

source

fn point(&self, sequence: Option<&EventSequence>) -> Option<(f64, f64)>

If @sequence is currently being interpreted by @self, returns true and fills in @x and @y with the last coordinates stored for that event sequence.

The coordinates are always relative to the widget allocation.

sequence

a gdk::EventSequence, or None for pointer events

Returns

true if @sequence is currently interpreted

x

return location for X axis of the sequence coordinates

y

return location for Y axis of the sequence coordinates

source

fn sequence_state(&self, sequence: &EventSequence) -> EventSequenceState

Returns the @sequence state, as seen by @self.

sequence

a gdk::EventSequence

Returns

The sequence state in @self

source

fn sequences(&self) -> Vec<EventSequence>

Returns the list of GdkEventSequences currently being interpreted by @self.

Returns

A list of gdk::EventSequence, the list elements are owned by GTK and must not be freed or modified, the list itself must be deleted through g_list_free()

source

fn group_with(&self, gesture: &impl IsA<Gesture>)

Adds @gesture to the same group than @self.

Gestures are by default isolated in their own groups.

Both gestures must have been added to the same widget before they can be grouped.

When gestures are grouped, the state of GdkEventSequences is kept in sync for all of those, so calling set_sequence_state(), on one will transfer the same value to the others.

Groups also perform an “implicit grabbing” of sequences, if a gdk::EventSequence state is set to EventSequenceState::Claimed on one group, every other gesture group attached to the same Widget will switch the state for that sequence to EventSequenceState::Denied.

gesture

a Gesture

source

fn handles_sequence(&self, sequence: Option<&EventSequence>) -> bool

Returns true if @self is currently handling events corresponding to @sequence.

sequence

a gdk::EventSequence

Returns

true if @self is handling @sequence, false otherwise

source

fn is_active(&self) -> bool

Returns true if the gesture is currently active.

A gesture is active while there are touch sequences interacting with it.

Returns

true if gesture is active

source

fn is_grouped_with(&self, other: &impl IsA<Gesture>) -> bool

Returns true if both gestures pertain to the same group.

other

another Gesture

Returns

whether the gestures are grouped

source

fn is_recognized(&self) -> bool

Returns true if the gesture is currently recognized.

A gesture is recognized if there are as many interacting touch sequences as required by @self.

Returns

true if gesture is recognized

source

fn set_sequence_state( &self, sequence: &EventSequence, state: EventSequenceState ) -> bool

👎Deprecated: Since 4.10

Sets the state of @sequence in @self.

Sequences start in state EventSequenceState::None, and whenever they change state, they can never go back to that state. Likewise, sequences in state EventSequenceState::Denied cannot turn back to a not denied state. With these rules, the lifetime of an event sequence is constrained to the next four:

  • None
  • None → Denied
  • None → Claimed
  • None → Claimed → Denied

Note: Due to event handling ordering, it may be unsafe to set the state on another gesture within a begin signal handler, as the callback might be executed before the other gesture knows about the sequence. A safe way to perform this could be:

⚠️ The following code is in c ⚠️

static void
first_gesture_begin_cb (GtkGesture       *first_gesture,
                        GdkEventSequence *sequence,
                        gpointer          user_data)
{
  gtk_gesture_set_sequence_state (first_gesture, sequence, GTK_EVENT_SEQUENCE_CLAIMED);
  gtk_gesture_set_sequence_state (second_gesture, sequence, GTK_EVENT_SEQUENCE_DENIED);
}

static void
second_gesture_begin_cb (GtkGesture       *second_gesture,
                         GdkEventSequence *sequence,
                         gpointer          user_data)
{
  if (gtk_gesture_get_sequence_state (first_gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED)
    gtk_gesture_set_sequence_state (second_gesture, sequence, GTK_EVENT_SEQUENCE_DENIED);
}

If both gestures are in the same group, just set the state on the gesture emitting the event, the sequence will be already be initialized to the group’s global state when the second gesture processes the event.

Deprecated since 4.10

Use set_state()

sequence

a gdk::EventSequence

state

the sequence state

Returns

true if @sequence is handled by @self, and the state is changed successfully

source

fn set_state(&self, state: EventSequenceState) -> bool

Sets the state of all sequences that @self is currently interacting with.

Sequences start in state EventSequenceState::None, and whenever they change state, they can never go back to that state. Likewise, sequences in state EventSequenceState::Denied cannot turn back to a not denied state. With these rules, the lifetime of an event sequence is constrained to the next four:

  • None
  • None → Denied
  • None → Claimed
  • None → Claimed → Denied

Note: Due to event handling ordering, it may be unsafe to set the state on another gesture within a begin signal handler, as the callback might be executed before the other gesture knows about the sequence. A safe way to perform this could be:

⚠️ The following code is in c ⚠️

static void
first_gesture_begin_cb (GtkGesture       *first_gesture,
                        GdkEventSequence *sequence,
                        gpointer          user_data)
{
  gtk_gesture_set_state (first_gesture, GTK_EVENT_SEQUENCE_CLAIMED);
  gtk_gesture_set_state (second_gesture, GTK_EVENT_SEQUENCE_DENIED);
}

static void
second_gesture_begin_cb (GtkGesture       *second_gesture,
                         GdkEventSequence *sequence,
                         gpointer          user_data)
{
  if (gtk_gesture_get_sequence_state (first_gesture, sequence) == GTK_EVENT_SEQUENCE_CLAIMED)
    gtk_gesture_set_state (second_gesture, GTK_EVENT_SEQUENCE_DENIED);
}

If both gestures are in the same group, just set the state on the gesture emitting the event, the sequence will be already be initialized to the group’s global state when the second gesture processes the event.

state

the sequence state

Returns

true if the state of at least one sequence was changed successfully

source

fn ungroup(&self)

Separates @self into an isolated group.

source

fn n_points(&self) -> u32

The number of touch points that trigger recognition on this gesture.

source

fn connect_begin<F: Fn(&Self, Option<&EventSequence>) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted when the gesture is recognized.

This means the number of touch sequences matches n-points.

Note: These conditions may also happen when an extra touch (eg. a third touch on a 2-touches gesture) is lifted, in that situation @sequence won’t pertain to the current set of active touches, so don’t rely on this being true.

sequence

the gdk::EventSequence that made the gesture to be recognized

source

fn connect_cancel<F: Fn(&Self, Option<&EventSequence>) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted whenever a sequence is cancelled.

This usually happens on active touches when EventControllerExt::reset() is called on @gesture (manually, due to grabs…), or the individual @sequence was claimed by parent widgets’ controllers (see set_sequence_state()).

@gesture must forget everything about @sequence as in response to this signal.

sequence

the gdk::EventSequence that was cancelled

source

fn connect_end<F: Fn(&Self, Option<&EventSequence>) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted when @gesture either stopped recognizing the event sequences as something to be handled, or the number of touch sequences became higher or lower than n-points.

Note: @sequence might not pertain to the group of sequences that were previously triggering recognition on @gesture (ie. a just pressed touch sequence that exceeds n-points). This situation may be detected by checking through handles_sequence().

sequence

the gdk::EventSequence that made gesture recognition to finish

source

fn connect_sequence_state_changed<F: Fn(&Self, Option<&EventSequence>, EventSequenceState) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted whenever a sequence state changes.

See set_sequence_state() to know more about the expectable sequence lifetimes.

sequence

the gdk::EventSequence that was cancelled

state

the new sequence state

source

fn connect_update<F: Fn(&Self, Option<&EventSequence>) + 'static>( &self, f: F ) -> SignalHandlerId

Emitted whenever an event is handled while the gesture is recognized.

@sequence is guaranteed to pertain to the set of active touches.

sequence

the gdk::EventSequence that was updated

Implementors§