[gnome-characters/bilelmoussaoui/gtk4] characters view: add a gesture click controller
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-characters/bilelmoussaoui/gtk4] characters view: add a gesture click controller
- Date: Mon, 22 Nov 2021 13:17:41 +0000 (UTC)
commit dfc773629c2ba00f7bcd9ea1ca2fdc5a17198f5a
Author: Bilal Elmoussaoui <bil elmoussaoui gmail com>
Date: Mon Nov 22 11:19:46 2021 +0100
characters view: add a gesture click controller
to replace the key_press_event vfuncs
src/charactersView.js | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/src/charactersView.js b/src/charactersView.js
index 54b859b..379cc5d 100644
--- a/src/charactersView.js
+++ b/src/charactersView.js
@@ -204,6 +204,11 @@ const CharacterListWidget = GObject.registerClass({
Gdk.DragAction.COPY);
this.drag_source_add_text_targets();
*/
+ const gestureClick = new Gtk.GestureClick();
+ gestureClick.connect('pressed', this.onButtonPress.bind(this));
+ gestureClick.connect('released', this.onButtonRelease.bind(this));
+ this.add_controller(gestureClick);
+
this._character = null;
}
/*
@@ -225,12 +230,12 @@ const CharacterListWidget = GObject.registerClass({
if (this._character !== null)
data.set_text(this._character, -1);
}
+ */
- vfunc_button_press_event(event) {
- let allocation = this.get_allocation();
+ onButtonPress(nPress, x, y) {
let cellSize = getCellSize(this._fontDescription);
- let x = Math.floor(event.x / cellSize);
- let y = Math.floor(event.y / cellSize);
+ x = Math.floor(x / cellSize);
+ y = Math.floor(y / cellSize);
let index = y * this._cellsPerRow + x;
if (index < this._characters.length)
this._character = this._characters[index];
@@ -239,12 +244,12 @@ const CharacterListWidget = GObject.registerClass({
return false;
}
- vfunc_button_release_event(event) {
+ onButtonRelease() {
if (this._character)
this.emit('character-selected', this._character);
+ log(this._character);
return false;
}
- */
vfunc_measure(orientation, _forSize) {
if (orientation === Gtk.Orientation.HORIZONTAL) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]