[baobab/wip/cdavis/use-event-controllers: 1/3] chart: Use EventControllerScroll
- From: Christopher Davis <christopherdavis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/cdavis/use-event-controllers: 1/3] chart: Use EventControllerScroll
- Date: Wed, 22 Sep 2021 07:50:32 +0000 (UTC)
commit a23dab0f5d0ed3e5ab941017ec3f874137ccbc8e
Author: Christopher Davis <christopherdavis gnome org>
Date: Tue Sep 21 17:49:58 2021 -0700
chart: Use EventControllerScroll
GTK4 doesn't have the `scroll_event` vfunc and uses
EventControllers. To ease migration, we want to use
event controllers where possible.
src/baobab-chart.vala | 27 +++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)
---
diff --git a/src/baobab-chart.vala b/src/baobab-chart.vala
index 8af189f..9702023 100644
--- a/src/baobab-chart.vala
+++ b/src/baobab-chart.vala
@@ -61,6 +61,8 @@ namespace Baobab {
Gtk.Menu context_menu = null;
+ Gtk.EventControllerScroll scroll_controller;
+
List<ChartItem> items;
Location location_;
@@ -200,7 +202,10 @@ namespace Baobab {
};
construct {
- add_events (Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.ENTER_NOTIFY_MASK |
Gdk.EventMask.LEAVE_NOTIFY_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK |
Gdk.EventMask.SCROLL_MASK);
+ add_events (Gdk.EventMask.EXPOSURE_MASK | Gdk.EventMask.ENTER_NOTIFY_MASK |
Gdk.EventMask.LEAVE_NOTIFY_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK);
+
+ scroll_controller = new Gtk.EventControllerScroll (this,
Gtk.EventControllerScrollFlags.BOTH_AXES);
+ scroll_controller.scroll.connect (scroll_cb);
action_group = new SimpleActionGroup ();
action_group.add_action_entries (action_entries, this);
@@ -498,24 +503,14 @@ namespace Baobab {
return false;
}
- protected override bool scroll_event (Gdk.EventScroll event) {
- Gdk.EventMotion e = (Gdk.EventMotion) event;
- switch (event.direction) {
- case Gdk.ScrollDirection.LEFT:
- case Gdk.ScrollDirection.UP:
+ void scroll_cb (double dx, double dy) {
+ // Up or to the left
+ if (dx > 0.0 || dy < 0.0) {
zoom_out ();
- motion_notify_event (e);
- break;
- case Gdk.ScrollDirection.RIGHT:
- case Gdk.ScrollDirection.DOWN:
+ // Down or to the right
+ } else if (dx < 0.0 || dy > 0.0) {
zoom_in ();
- motion_notify_event (e);
- break;
- case Gdk.ScrollDirection.SMOOTH:
- break;
}
-
- return false;
}
public void open_file () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]