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 { ... }
}
Provided Methods§
sourcefn bounding_box(&self) -> Option<Rectangle>
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.
sourcefn bounding_box_center(&self) -> Option<(f64, f64)>
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
sourcefn device(&self) -> Option<Device>
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
sourcefn last_event(&self, sequence: Option<&EventSequence>) -> Option<Event>
fn last_event(&self, sequence: Option<&EventSequence>) -> Option<Event>
sourcefn last_updated_sequence(&self) -> Option<EventSequence>
fn last_updated_sequence(&self) -> Option<EventSequence>
sourcefn point(&self, sequence: Option<&EventSequence>) -> Option<(f64, f64)>
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
sourcefn sequence_state(&self, sequence: &EventSequence) -> EventSequenceState
fn sequence_state(&self, sequence: &EventSequence) -> EventSequenceState
sourcefn sequences(&self) -> Vec<EventSequence>
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()
sourcefn group_with(&self, gesture: &impl IsA<Gesture>)
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
sourcefn handles_sequence(&self, sequence: Option<&EventSequence>) -> bool
fn handles_sequence(&self, sequence: Option<&EventSequence>) -> bool
sourcefn is_grouped_with(&self, other: &impl IsA<Gesture>) -> bool
fn is_grouped_with(&self, other: &impl IsA<Gesture>) -> bool
sourcefn is_recognized(&self) -> bool
fn is_recognized(&self) -> bool
sourcefn set_sequence_state(
&self,
sequence: &EventSequence,
state: EventSequenceState
) -> bool
👎Deprecated: Since 4.10
fn set_sequence_state( &self, sequence: &EventSequence, state: EventSequenceState ) -> bool
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
§state
the sequence state
§Returns
true
if @sequence is handled by @self,
and the state is changed successfully
sourcefn set_state(&self, state: EventSequenceState) -> bool
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
sourcefn connect_begin<F: Fn(&Self, Option<&EventSequence>) + 'static>(
&self,
f: F
) -> SignalHandlerId
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
sourcefn connect_cancel<F: Fn(&Self, Option<&EventSequence>) + 'static>(
&self,
f: F
) -> SignalHandlerId
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
sourcefn connect_end<F: Fn(&Self, Option<&EventSequence>) + 'static>(
&self,
f: F
) -> SignalHandlerId
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
sourcefn connect_sequence_state_changed<F: Fn(&Self, Option<&EventSequence>, EventSequenceState) + 'static>(
&self,
f: F
) -> SignalHandlerId
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
sourcefn connect_update<F: Fn(&Self, Option<&EventSequence>) + 'static>(
&self,
f: F
) -> SignalHandlerId
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