From 32d3a8c83d46cfb69cb9c8654be76c2e92d23913 Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Fri, 21 Feb 2020 19:43:50 -0500 Subject: [PATCH 01/12] Initial add libscroll --- package.json | 6 ++++-- src/UI/dune | 2 +- src/UI_Components/ScrollView.re | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 291f76aeb..012427171 100644 --- a/package.json +++ b/package.json @@ -55,14 +55,16 @@ "reason-sdl2": "^2.10.3016", "reason-skia": "github:revery-ui/reason-skia#69743dc", "revery-text-wrap": "github:revery-ui/revery-text-wrap#005385c", - "timber": "*" + "timber": "*", + "libscroll": "*" }, "resolutions": { "@esy-ocaml/libffi": "esy-ocaml/libffi#c61127d", "@opam/cmdliner": "1.0.2", "esy-cmake": "prometheansacrifice/esy-cmake#2a47392def755", "timber": "glennsl/timber#ae065bb", - "reason-harfbuzz": "revery-ui/reason-harfbuzz#0848520" + "reason-harfbuzz": "revery-ui/reason-harfbuzz#0848520", + "libscroll": "link:../libscroll-re" }, "devDependencies": { "ocaml": "~4.8", diff --git a/src/UI/dune b/src/UI/dune index fea1cf8b5..77f2b80c5 100644 --- a/src/UI/dune +++ b/src/UI/dune @@ -2,4 +2,4 @@ (name Revery_UI) (public_name Revery.UI) (preprocess (pps lwt_ppx ppx_deriving.show)) - (libraries brisk-reconciler lwt lwt.unix sdl2 skia flex rebez.lib Revery_Core Revery_Draw Revery_Math)) + (libraries brisk-reconciler lwt lwt.unix sdl2 skia flex rebez.lib Revery_Core Revery_Draw Revery_Math Libscroll)) diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index 01e3ccef2..35ce76d55 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -57,6 +57,9 @@ let%component make = let%hook (actualScrollLeft, setScrollLeft) = Hooks.state(scrollLeft); let%hook (bouncingState, setBouncingState) = Hooks.state(Idle); + let%hook (scrollview, setScrollview) = Hooks.state(() => Libscroll.scrollview_new()); + //setScrollview(_ => scrollview); + let%hook (actualScrollTop, _bounceAnimationState, resetBouncingAnimation) = switch (bouncingState) { | Idle => From fef827360d5803ef54e610c5cc253dd31b8aab6a Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Wed, 26 Feb 2020 16:33:15 -0500 Subject: [PATCH 02/12] Push temp changes for input --- package.json | 5 +++-- src/UI/NodeEvents.re | 7 +++++++ src/UI_Components/ScrollView.re | 26 +++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 61bb75dff..d6054a613 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "reason-harfbuzz": "^1.91.5004", "rench": "^1.9.1", "rebez": "github:jchavarri/rebez#03fa3b7", - "reason-sdl2": "^2.10.3016", + "reason-sdl2": "*", "reason-skia": "github:revery-ui/reason-skia#69743dc", "revery-text-wrap": "github:revery-ui/revery-text-wrap#005385c", "timber": "*", @@ -64,7 +64,8 @@ "esy-cmake": "prometheansacrifice/esy-cmake#2a47392def755", "@opam/cmdliner": "1.0.2", "timber": "glennsl/timber#ae065bb", - "libscroll": "link:../libscroll-re" + "libscroll": "link:../libscroll-re", + "reason-sdl2": "link:../../revery-bryphe/reason-sdl2" }, "devDependencies": { "ocaml": "~4.8", diff --git a/src/UI/NodeEvents.re b/src/UI/NodeEvents.re index de8e14ffa..2621d0fb2 100644 --- a/src/UI/NodeEvents.re +++ b/src/UI/NodeEvents.re @@ -21,6 +21,12 @@ type mouseButtonEventParams = { type mouseWheelEventParams = { deltaX: float, deltaY: float, + containsX: bool, + containsY: bool, + isFling: bool, + isInterrupt: bool, + source: Sdl2.WheelType.t, + timestamp: int, }; [@deriving show({with_path: false})] @@ -83,6 +89,7 @@ type mouseMoveHandler = mouseMoveEventParams => unit; type mouseOverHandler = mouseMoveEventParams => unit; type mouseOutHandler = mouseMoveEventParams => unit; type mouseWheelHandler = mouseWheelEventParams => unit; +type panHandler = panEventParams => unit; type mouseWindowHandler = Window.t => unit; type focusHandler = focusEventParams => unit; type keyDownHandler = keyEventParams => unit; diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index 35ce76d55..854b93013 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -57,8 +57,18 @@ let%component make = let%hook (actualScrollLeft, setScrollLeft) = Hooks.state(scrollLeft); let%hook (bouncingState, setBouncingState) = Hooks.state(Idle); - let%hook (scrollview, setScrollview) = Hooks.state(() => Libscroll.scrollview_new()); + //let%hook (scrollview, setScrollview) = Hooks.state(() => Libscroll.scrollview_new()); //setScrollview(_ => scrollview); + let%hook (scrollViewRef) = Hooks.ref(None); + let%hook () = Hooks.effect(OnMount, () => { + let scrollView = Libscroll.scrollview_new(); + scrollViewRef := Some(scrollView); + + let dispose = () => { + scrollViewRef := None; + }; + Some(dispose); + }); let%hook (actualScrollTop, _bounceAnimationState, resetBouncingAnimation) = switch (bouncingState) { @@ -157,8 +167,22 @@ let%component make = thumbColor=scrollThumbColor /> : empty; + + /*let pan = (panEvent: NodeEvents.panEventParams) => { + switch (scrollViewRef^) { + | None => () + | Some(scrollview) => { + let timestamp = wheelEvent.timestamp; + let delta = wheelEvent.delta; + let axis = wheelEvent.axis; + } + }*/ let scroll = (wheelEvent: NodeEvents.mouseWheelEventParams) => { + switch (scrollViewRef^) { + | Some(scrollview) => Libscroll.push_pan(scrollview, Libscroll.Vertical, 10.0) + | None => () + } let delta = int_of_float(wheelEvent.deltaY *. 25.); let newScrollTop = actualScrollTop - delta; From 81223fe6729d8cb95d647dcb650a986c087c6954 Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Wed, 26 Feb 2020 16:58:54 -0500 Subject: [PATCH 03/12] More changes to figure out why build fails --- package.json | 5 +++-- src/UI/dune | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index d6054a613..25d973d22 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "build": [ "dune build -p Revery -j4" ], + "buildsInSource": "_build", "install": [ "esy-installer Revery.install", "bash -c \"#{os == 'windows' ? 'cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/*.dll \\'$cur__bin\\'': ':'}\"" @@ -53,7 +54,7 @@ "reason-harfbuzz": "^1.91.5004", "rench": "^1.9.1", "rebez": "github:jchavarri/rebez#03fa3b7", - "reason-sdl2": "*", + "reason-sdl2": "github:revery-ui/reason-sdl2", "reason-skia": "github:revery-ui/reason-skia#69743dc", "revery-text-wrap": "github:revery-ui/revery-text-wrap#005385c", "timber": "*", @@ -65,7 +66,7 @@ "@opam/cmdliner": "1.0.2", "timber": "glennsl/timber#ae065bb", "libscroll": "link:../libscroll-re", - "reason-sdl2": "link:../../revery-bryphe/reason-sdl2" + "reason-sdl2": "revery-ui/reason-sdl2#a52eee7" }, "devDependencies": { "ocaml": "~4.8", diff --git a/src/UI/dune b/src/UI/dune index 77f2b80c5..fea1cf8b5 100644 --- a/src/UI/dune +++ b/src/UI/dune @@ -2,4 +2,4 @@ (name Revery_UI) (public_name Revery.UI) (preprocess (pps lwt_ppx ppx_deriving.show)) - (libraries brisk-reconciler lwt lwt.unix sdl2 skia flex rebez.lib Revery_Core Revery_Draw Revery_Math Libscroll)) + (libraries brisk-reconciler lwt lwt.unix sdl2 skia flex rebez.lib Revery_Core Revery_Draw Revery_Math)) From d538a8915fe8ee82b665e46d58b2e756a55fc5c2 Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Thu, 27 Feb 2020 20:23:05 -0500 Subject: [PATCH 04/12] Get building with new fields --- src/Core/Events.re | 6 ++++++ src/Core/Window.re | 6 ++++++ src/Core/dune | 2 +- src/UI/Mouse.re | 11 ++++++++++- src/UI/NodeEvents.re | 3 +-- src/UI/dune | 2 +- src/UI_Components/ScrollView.re | 4 +++- 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/Core/Events.re b/src/Core/Events.re index 611b009c2..3c287cc1a 100644 --- a/src/Core/Events.re +++ b/src/Core/Events.re @@ -25,6 +25,12 @@ type mouseMoveEvent = { type mouseWheelEvent = { deltaX: float, deltaY: float, + containsX: bool, + containsY: bool, + isFling: bool, + isInterrupt: bool, + source: Libscroll.Source.t, + timestamp: int, }; type mouseButtonEvent = {button: MouseButton.t}; diff --git a/src/Core/Window.re b/src/Core/Window.re index 9dd2f8062..ae36db552 100644 --- a/src/Core/Window.re +++ b/src/Core/Window.re @@ -303,6 +303,12 @@ let handleEvent = (sdlEvent: Sdl2.Event.t, v: t) => { let wheelEvent: Events.mouseWheelEvent = { deltaX: float_of_int(deltaX), deltaY: float_of_int(deltaY), + containsX: true, + containsY: true, + source: Libscroll.Source.Mousewheel, + timestamp: 0, // TODO: add timestamps to mousewheel events in sdl OR completely switch to pan + isFling: false, + isInterrupt: false, }; Event.dispatch(v.onMouseWheel, wheelEvent); | Sdl2.Event.MouseMotion({x, y, _}) => diff --git a/src/Core/dune b/src/Core/dune index 67f205386..92d2fd852 100644 --- a/src/Core/dune +++ b/src/Core/dune @@ -5,4 +5,4 @@ (c_names file) (c_flags :standard -Wall -Wextra -Werror) (preprocess (pps ppx_deriving.show)) - (libraries threads console.lib str lwt sdl2 skia flex Rench re Revery_Native revery-text-wrap timber)) + (libraries threads console.lib str lwt sdl2 skia flex Rench re Revery_Native revery-text-wrap timber Libscroll)) diff --git a/src/UI/Mouse.re b/src/UI/Mouse.re index dfbf18b28..7873e80fe 100644 --- a/src/UI/Mouse.re +++ b/src/UI/Mouse.re @@ -287,7 +287,16 @@ let internalToExternalEvent = (c: Cursor.t, evt: Events.internalMouseEvents) => | InternalMouseMove(evt) => MouseMove({mouseX: evt.mouseX, mouseY: evt.mouseY}) | InternalMouseWheel(evt) => - MouseWheel({deltaX: evt.deltaX, deltaY: evt.deltaY}) + MouseWheel({ + deltaX: evt.deltaX, + deltaY: evt.deltaY, + containsX: evt.containsX, + containsY: evt.containsY, + isFling: evt.isFling, + isInterrupt: evt.isInterrupt, + source: evt.source, + timestamp: evt.timestamp + }) | InternalMouseEnter(evt) => MouseEnter({mouseX: evt.mouseX, mouseY: evt.mouseY}) | InternalMouseLeave(evt) => diff --git a/src/UI/NodeEvents.re b/src/UI/NodeEvents.re index 2621d0fb2..d4bc7f1a3 100644 --- a/src/UI/NodeEvents.re +++ b/src/UI/NodeEvents.re @@ -25,7 +25,7 @@ type mouseWheelEventParams = { containsY: bool, isFling: bool, isInterrupt: bool, - source: Sdl2.WheelType.t, + source: Libscroll.Source.t, timestamp: int, }; @@ -89,7 +89,6 @@ type mouseMoveHandler = mouseMoveEventParams => unit; type mouseOverHandler = mouseMoveEventParams => unit; type mouseOutHandler = mouseMoveEventParams => unit; type mouseWheelHandler = mouseWheelEventParams => unit; -type panHandler = panEventParams => unit; type mouseWindowHandler = Window.t => unit; type focusHandler = focusEventParams => unit; type keyDownHandler = keyEventParams => unit; diff --git a/src/UI/dune b/src/UI/dune index fea1cf8b5..77f2b80c5 100644 --- a/src/UI/dune +++ b/src/UI/dune @@ -2,4 +2,4 @@ (name Revery_UI) (public_name Revery.UI) (preprocess (pps lwt_ppx ppx_deriving.show)) - (libraries brisk-reconciler lwt lwt.unix sdl2 skia flex rebez.lib Revery_Core Revery_Draw Revery_Math)) + (libraries brisk-reconciler lwt lwt.unix sdl2 skia flex rebez.lib Revery_Core Revery_Draw Revery_Math Libscroll)) diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index 854b93013..fe0fe32c8 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -180,7 +180,9 @@ let%component make = let scroll = (wheelEvent: NodeEvents.mouseWheelEventParams) => { switch (scrollViewRef^) { - | Some(scrollview) => Libscroll.push_pan(scrollview, Libscroll.Vertical, 10.0) + | Some(scrollview) => {//Libscroll.push_pan(scrollview, Libscroll.Axis.Vertical, 10.0, 0) + () + } | None => () } let delta = int_of_float(wheelEvent.deltaY *. 25.); From 110bd8f498356db92edd93d5fa3b815c33eb2c75 Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Thu, 27 Feb 2020 21:03:55 -0500 Subject: [PATCH 05/12] Precise scroll now (sort of) works --- package.json | 3 ++- src/Core/App.re | 1 + src/Core/Window.re | 28 ++++++++++++++++++++++++++++ src/UI_Components/ScrollView.re | 3 +++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 25d973d22..f9c0a72ba 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,8 @@ "@opam/cmdliner": "1.0.2", "timber": "glennsl/timber#ae065bb", "libscroll": "link:../libscroll-re", - "reason-sdl2": "revery-ui/reason-sdl2#a52eee7" + "reason-sdl2": "revery-ui/reason-sdl2#a52eee7", + "esy-sdl2": "revery-ui/esy-sdl2#13ac578" }, "devDependencies": { "ocaml": "~4.8", diff --git a/src/Core/App.re b/src/Core/App.re index 270a25b4a..cb1ff0f91 100644 --- a/src/Core/App.re +++ b/src/Core/App.re @@ -160,6 +160,7 @@ let start = (~onIdle=noop, initFunc: appInitFunc) => { | Sdl2.Event.MouseButtonDown({windowID, _}) => handleEvent(windowID) | Sdl2.Event.MouseMotion({windowID, _}) => handleEvent(windowID) | Sdl2.Event.MouseWheel({windowID, _}) => handleEvent(windowID) + | Sdl2.Event.MousePan({windowID, _}) => handleEvent(windowID) | Sdl2.Event.KeyDown({windowID, _}) => handleEvent(windowID) | Sdl2.Event.KeyUp({windowID, _}) => handleEvent(windowID) | Sdl2.Event.TextInput({windowID, _}) => handleEvent(windowID) diff --git a/src/Core/Window.re b/src/Core/Window.re index ae36db552..f3e3381ef 100644 --- a/src/Core/Window.re +++ b/src/Core/Window.re @@ -297,6 +297,21 @@ let render = (w: t) => { w.isRendering = false; }; +let convertWheelType = (intype: Sdl2.WheelType.t) => { + open Libscroll; + open Sdl2; + switch (intype) { + | WheelType.Last => Source.Previous + | WheelType.Undefined => Source.Undefined + | WheelType.Touchscreen => Source.Touchscreen + | WheelType.Touchpad => Source.Touchpad + | WheelType.Wheel => Source.Mousewheel + | WheelType.WheelPrecise => Source.PreciseMousewheel + | WheelType.OtherNonKinetic => KineticPassthrough + | WheelType.OtherKinetic => KineticPassthrough + } +} + let handleEvent = (sdlEvent: Sdl2.Event.t, v: t) => { switch (sdlEvent) { | Sdl2.Event.MouseWheel({deltaX, deltaY, _}) => @@ -311,6 +326,19 @@ let handleEvent = (sdlEvent: Sdl2.Event.t, v: t) => { isInterrupt: false, }; Event.dispatch(v.onMouseWheel, wheelEvent); + | Sdl2.Event.MousePan({deltaX, deltaY, containsX, containsY, isFling, isInterrupt, source, timestamp}) => + Log.info("Got pan event"); + let wheelEvent: Events.mouseWheelEvent = { + deltaX: float_of_int(deltaX), + deltaY: float_of_int(deltaY), + containsX: containsX, + containsY: containsY, + isFling: isFling, + isInterrupt: isInterrupt, + source: convertWheelType(source), + timestamp: timestamp, + } + Event.dispatch(v.onMouseWheel, wheelEvent); | Sdl2.Event.MouseMotion({x, y, _}) => let mouseEvent: Events.mouseMoveEvent = { mouseX: float_of_int(x), diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index fe0fe32c8..b4da4ef38 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -5,6 +5,8 @@ open Revery_UI_Primitives; module Hooks = Revery_UI_Hooks; +module Log = (val Log.withNamespace("Revery.ScrollView")); + type bouncingState = | Bouncing(int) | Idle; @@ -181,6 +183,7 @@ let%component make = let scroll = (wheelEvent: NodeEvents.mouseWheelEventParams) => { switch (scrollViewRef^) { | Some(scrollview) => {//Libscroll.push_pan(scrollview, Libscroll.Axis.Vertical, 10.0, 0) + Log.info("Scrollview existed"); () } | None => () From d349008b9501c68bc4a82bc7874db83c8a2b19dc Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Fri, 28 Feb 2020 09:29:15 -0500 Subject: [PATCH 06/12] Change event makeup to be more ideomatic --- src/Core/Events.re | 6 ++---- src/Core/Window.re | 12 ++++-------- src/UI/Mouse.re | 2 -- src/UI/NodeEvents.re | 6 ++---- src/UI_Components/ScrollView.re | 25 ++++++++++++++++--------- 5 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/Core/Events.re b/src/Core/Events.re index 3c287cc1a..0397ff109 100644 --- a/src/Core/Events.re +++ b/src/Core/Events.re @@ -23,10 +23,8 @@ type mouseMoveEvent = { }; type mouseWheelEvent = { - deltaX: float, - deltaY: float, - containsX: bool, - containsY: bool, + deltaX: option(float), + deltaY: option(float), isFling: bool, isInterrupt: bool, source: Libscroll.Source.t, diff --git a/src/Core/Window.re b/src/Core/Window.re index f3e3381ef..0a6d98ee6 100644 --- a/src/Core/Window.re +++ b/src/Core/Window.re @@ -316,10 +316,8 @@ let handleEvent = (sdlEvent: Sdl2.Event.t, v: t) => { switch (sdlEvent) { | Sdl2.Event.MouseWheel({deltaX, deltaY, _}) => let wheelEvent: Events.mouseWheelEvent = { - deltaX: float_of_int(deltaX), - deltaY: float_of_int(deltaY), - containsX: true, - containsY: true, + deltaX: Some(float_of_int(deltaX)), + deltaY: Some(float_of_int(deltaY)), source: Libscroll.Source.Mousewheel, timestamp: 0, // TODO: add timestamps to mousewheel events in sdl OR completely switch to pan isFling: false, @@ -329,10 +327,8 @@ let handleEvent = (sdlEvent: Sdl2.Event.t, v: t) => { | Sdl2.Event.MousePan({deltaX, deltaY, containsX, containsY, isFling, isInterrupt, source, timestamp}) => Log.info("Got pan event"); let wheelEvent: Events.mouseWheelEvent = { - deltaX: float_of_int(deltaX), - deltaY: float_of_int(deltaY), - containsX: containsX, - containsY: containsY, + deltaX: containsX ? Some(float_of_int(deltaX)) : None, + deltaY: containsY ? Some(float_of_int(deltaY)) : None, isFling: isFling, isInterrupt: isInterrupt, source: convertWheelType(source), diff --git a/src/UI/Mouse.re b/src/UI/Mouse.re index 7873e80fe..b72e4cece 100644 --- a/src/UI/Mouse.re +++ b/src/UI/Mouse.re @@ -290,8 +290,6 @@ let internalToExternalEvent = (c: Cursor.t, evt: Events.internalMouseEvents) => MouseWheel({ deltaX: evt.deltaX, deltaY: evt.deltaY, - containsX: evt.containsX, - containsY: evt.containsY, isFling: evt.isFling, isInterrupt: evt.isInterrupt, source: evt.source, diff --git a/src/UI/NodeEvents.re b/src/UI/NodeEvents.re index d4bc7f1a3..0daf64ad4 100644 --- a/src/UI/NodeEvents.re +++ b/src/UI/NodeEvents.re @@ -19,10 +19,8 @@ type mouseButtonEventParams = { [@deriving show({with_path: false})] type mouseWheelEventParams = { - deltaX: float, - deltaY: float, - containsX: bool, - containsY: bool, + deltaX: option(float), + deltaY: option(float), isFling: bool, isInterrupt: bool, source: Libscroll.Source.t, diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index b4da4ef38..e1539b4de 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -184,27 +184,34 @@ let%component make = switch (scrollViewRef^) { | Some(scrollview) => {//Libscroll.push_pan(scrollview, Libscroll.Axis.Vertical, 10.0, 0) Log.info("Scrollview existed"); - () + } + | None => Log.error("Scrollview not present on event dispatch"); } - | None => () - } - let delta = int_of_float(wheelEvent.deltaY *. 25.); + let delta = switch(wheelEvent.deltaY) { + | Some(value) => value *. 25. + | None => 0.0 + }; + //let delta = int_of_float(wheelEvent.deltaY *. 25.); + let delta_s = delta; + let delta = int_of_float(delta /. -400.0); let newScrollTop = actualScrollTop - delta; let isAtTop = newScrollTop < 0; let isAtBottom = newScrollTop > maxHeight; switch (bouncingState) { - | Bouncing(force) when force < 0 && wheelEvent.deltaY < 0. => + | Bouncing(force) when force < 0 && delta_s < 0. => setBouncingState(_ => Idle) - | Bouncing(force) when force > 0 && wheelEvent.deltaY > 0. => + | Bouncing(force) when force > 0 && delta_s > 0. => setBouncingState(_ => Idle) | Bouncing(_) => () | Idle when !bounce && (isAtTop || isAtBottom) => - let clampedScrollTop = isAtTop ? 0 : maxHeight; - dispatch(ScrollUpdated(clampedScrollTop)); + dispatch(ScrollUpdated(newScrollTop)); + //let clampedScrollTop = isAtTop ? 0 : maxHeight; + //dispatch(ScrollUpdated(clampedScrollTop)); + () | Idle when bounce && (isAtTop || isAtBottom) => - setBouncingState(_ => Bouncing(- delta * 2)); + //setBouncingState(_ => Bouncing(- delta * 2)); dispatch(ScrollUpdated(isAtTop ? 0 : maxHeight)); | Idle => dispatch(ScrollUpdated(newScrollTop)) }; From 52c120ebaf12fbdd7817b31d4b7d088fe2c911f2 Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Sat, 7 Mar 2020 18:54:22 -0500 Subject: [PATCH 07/12] Add changes before pulling in latest master --- package.json | 3 ++- src/UI_Components/ScrollView.re | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index f9c0a72ba..ac661a8ec 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,8 @@ "timber": "glennsl/timber#ae065bb", "libscroll": "link:../libscroll-re", "reason-sdl2": "revery-ui/reason-sdl2#a52eee7", - "esy-sdl2": "revery-ui/esy-sdl2#13ac578" + "esy-sdl2": "link:../esy-sdl2", + "reason-sdl2": "link:../reason-sdl2" }, "devDependencies": { "ocaml": "~4.8", diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index e1539b4de..d8d162190 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -180,10 +180,41 @@ let%component make = } }*/ + let scrollForFrameFlip = (timestamp: int) => { + // call into libscroll to sample new position + } + let scroll = (wheelEvent: NodeEvents.mouseWheelEventParams) => { switch (scrollViewRef^) { | Some(scrollview) => {//Libscroll.push_pan(scrollview, Libscroll.Axis.Vertical, 10.0, 0) Log.info("Scrollview existed"); + + Libscroll.set_source(scrollview, wheelEvent.source); + + switch(wheelEvent.deltaX) { + | Some(delta) => { + Libscroll.push_pan(scrollview, Libscroll.Axis.Horizontal, delta, wheelEvent.timestamp); + } + | None => () + }; + + switch(wheelEvent.deltaY) { + | Some(delta) => { + Libscroll.push_pan(scrollview, Libscroll.Axis.Vertical, delta, wheelEvent.timestamp); + } + | None => () + }; + + switch(wheelEvent.isFling) { + | true => Libscroll.push_fling(scrollview, wheelEvent.timestamp); + | false => () + }; + + switch(wheelEvent.isInterrupt) { + | true => Libscroll.push_interrupt(scrollview, wheelEvent.timestamp); + | false => () + }; + } | None => Log.error("Scrollview not present on event dispatch"); } From a1bbd2e0f00d480d7576c29459562fe54dde26d1 Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Tue, 21 Apr 2020 19:35:10 -0400 Subject: [PATCH 08/12] Mostly working --- src/Core/App.re | 2 +- src/Core/Events.re | 19 +++++-- src/Core/Window.re | 41 +++++++++----- src/UI/Mouse.re | 6 +-- src/UI/NodeEvents.re | 6 +-- src/UI_Components/ScrollView.re | 94 ++++++++++++++++++++++----------- 6 files changed, 111 insertions(+), 57 deletions(-) diff --git a/src/Core/App.re b/src/Core/App.re index 35b18f45e..f127b07c4 100644 --- a/src/Core/App.re +++ b/src/Core/App.re @@ -183,7 +183,7 @@ let start = init => { | Sdl2.Event.MouseButtonDown({windowID, _}) => handleEvent(windowID) | Sdl2.Event.MouseMotion({windowID, _}) => handleEvent(windowID) | Sdl2.Event.MouseWheel({windowID, _}) => handleEvent(windowID) - | Sdl2.Event.MousePan({windowID, _}) => handleEvent(windowID) + | Sdl2.Event.Pan({windowID, _}) => handleEvent(windowID) | Sdl2.Event.KeyDown({windowID, _}) => handleEvent(windowID) | Sdl2.Event.KeyUp({windowID, _}) => handleEvent(windowID) | Sdl2.Event.TextInput({windowID, _}) => handleEvent(windowID) diff --git a/src/Core/Events.re b/src/Core/Events.re index 0397ff109..3a68fa860 100644 --- a/src/Core/Events.re +++ b/src/Core/Events.re @@ -22,12 +22,23 @@ type mouseMoveEvent = { mouseY: float, }; +module MousePanAction = { + type t = + | Interrupt + | Fling + | Pan(float); + + let pp : Format.formatter => t => unit = (_: Format.formatter) => (_: t) => () +} + type mouseWheelEvent = { - deltaX: option(float), - deltaY: option(float), - isFling: bool, - isInterrupt: bool, + //deltaX: option(float), + //deltaY: option(float), + //isFling: bool, + //isInterrupt: bool, source: Libscroll.Source.t, + axis: Libscroll.Axis.t, + action: MousePanAction.t, timestamp: int, }; diff --git a/src/Core/Window.re b/src/Core/Window.re index fc579a189..fe564bc66 100644 --- a/src/Core/Window.re +++ b/src/Core/Window.re @@ -313,27 +313,42 @@ let convertWheelType = (intype: Sdl2.WheelType.t) => { } } +let mapAxis = (sdlAxis: Sdl2.Axis.t) => switch (sdlAxis) { + | Sdl2.Axis.Vertical => Libscroll.Axis.Vertical + | Sdl2.Axis.Horizontal => Libscroll.Axis.Horizontal +} + +let mapPanAction = (sdlAction: Sdl2.Event.PanElements.t) => switch (sdlAction) { + | Sdl2.Event.PanElements.Fling => Events.MousePanAction.Fling + | Sdl2.Event.PanElements.Interrupt => Events.MousePanAction.Interrupt + | Sdl2.Event.PanElements.Pan(amount) => Events.MousePanAction.Pan(amount) +} + let handleEvent = (sdlEvent: Sdl2.Event.t, v: t) => { switch (sdlEvent) { | Sdl2.Event.MouseWheel({deltaX, deltaY, _}) => - let wheelEvent: Events.mouseWheelEvent = { - deltaX: Some(float_of_int(deltaX)), - deltaY: Some(float_of_int(deltaY)), + let xEvent: Events.mouseWheelEvent = { source: Libscroll.Source.Mousewheel, - timestamp: 0, // TODO: add timestamps to mousewheel events in sdl OR completely switch to pan - isFling: false, - isInterrupt: false, + timestamp: 0, // TODO: add timestamps to mosuewheel events in sdl OR completely switch to pan + action: Events.MousePanAction.Pan(float_of_int(deltaX)), + axis: Libscroll.Axis.Horizontal, }; - Event.dispatch(v.onMouseWheel, wheelEvent); - | Sdl2.Event.MousePan({deltaX, deltaY, containsX, containsY, isFling, isInterrupt, source, timestamp}) => - Log.info("Got pan event"); + Event.dispatch(v.onMouseWheel, xEvent); + + let yEvent: Events.mouseWheelEvent = { + source: Libscroll.Source.Mousewheel, + timestamp: 0, // TODO: add timestamps to mosuewheel events in sdl OR completely switch to pan + action: Events.MousePanAction.Pan(float_of_int(deltaY)), + axis: Libscroll.Axis.Vertical, + }; + Event.dispatch(v.onMouseWheel, yEvent); + | Sdl2.Event.Pan({timestamp, source, axis, action}) => + Log.info("Got a pan event"); let wheelEvent: Events.mouseWheelEvent = { - deltaX: containsX ? Some(float_of_int(deltaX)) : None, - deltaY: containsY ? Some(float_of_int(deltaY)) : None, - isFling: isFling, - isInterrupt: isInterrupt, source: convertWheelType(source), timestamp: timestamp, + action: mapPanAction(action), + axis: mapAxis(axis), } Event.dispatch(v.onMouseWheel, wheelEvent); | Sdl2.Event.MouseMotion({x, y, _}) => diff --git a/src/UI/Mouse.re b/src/UI/Mouse.re index b72e4cece..b5ed53c67 100644 --- a/src/UI/Mouse.re +++ b/src/UI/Mouse.re @@ -288,11 +288,9 @@ let internalToExternalEvent = (c: Cursor.t, evt: Events.internalMouseEvents) => MouseMove({mouseX: evt.mouseX, mouseY: evt.mouseY}) | InternalMouseWheel(evt) => MouseWheel({ - deltaX: evt.deltaX, - deltaY: evt.deltaY, - isFling: evt.isFling, - isInterrupt: evt.isInterrupt, source: evt.source, + axis: evt.axis, + action: evt.action, timestamp: evt.timestamp }) | InternalMouseEnter(evt) => diff --git a/src/UI/NodeEvents.re b/src/UI/NodeEvents.re index 40689a502..80aafbab1 100644 --- a/src/UI/NodeEvents.re +++ b/src/UI/NodeEvents.re @@ -20,11 +20,9 @@ type mouseButtonEventParams = { [@deriving show({with_path: false})] type mouseWheelEventParams = { - deltaX: option(float), - deltaY: option(float), - isFling: bool, - isInterrupt: bool, source: Libscroll.Source.t, + axis: Libscroll.Axis.t, + action: Events.MousePanAction.t, timestamp: int, }; diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index d8d162190..77a1d7402 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -59,9 +59,37 @@ let%component make = let%hook (actualScrollLeft, setScrollLeft) = Hooks.state(scrollLeft); let%hook (bouncingState, setBouncingState) = Hooks.state(Idle); + //Time.timer; + //let%hook (time, _) = Revery_Core.Timer.timer(~active=true, ()); + //let%hook (scrollview, setScrollview) = Hooks.state(() => Libscroll.scrollview_new()); //setScrollview(_ => scrollview); let%hook (scrollViewRef) = Hooks.ref(None); + + let scrollviewActive = () => { + let r = switch (scrollViewRef^) { + | None => { + Log.info("Scrollview was none"); + false + } + | Some(scrollview) => { + Log.info("Scrollview was some"); + let v = Libscroll.animating(scrollview) + if (v) { + Log.info("animating is true"); + } else { + Log.info("animating is false"); + } + + v + } + } + + r + } + + let%hook (_dt, _reset) = Hooks.timer(~active=scrollviewActive(), ()); + let%hook () = Hooks.effect(OnMount, () => { let scrollView = Libscroll.scrollview_new(); scrollViewRef := Some(scrollView); @@ -70,7 +98,7 @@ let%component make = scrollViewRef := None; }; Some(dispose); - }); + }); let%hook (actualScrollTop, _bounceAnimationState, resetBouncingAnimation) = switch (bouncingState) { @@ -96,6 +124,19 @@ let%component make = TranslateY((-1.) *. float_of_int(actualScrollTop)), ]; + let (scrollX, scrollY) = switch (scrollViewRef^) { + | None => { + Log.info("Can't sample, sv null"); + (0.0, 0.0) + } + | Some(scrollview) => { + Log.info("Scrollview was some, sampling..."); + Libscroll.sample(scrollview, Sdl2.Timekeeping.getTicks()) + } + } + dispatch(ScrollUpdated(int_of_float(scrollY))); + + let (horizontalScrollBar, verticalScrollBar, scroll) = switch (outerRef) { | Some(outer) => @@ -179,9 +220,16 @@ let%component make = let axis = wheelEvent.axis; } }*/ + Log.info("renders the scrollview"); + + let pageflip = (~initialState=?, ~restThreshold=0.0) => { - let scrollForFrameFlip = (timestamp: int) => { - // call into libscroll to sample new position + let isActive = switch (scrollViewRef^) { + | Some(scrollview) => Libscroll.animating(scrollview) + | None => false + }; + + //let%hook (time, _) = Timer.timer(~active=isActive } let scroll = (wheelEvent: NodeEvents.mouseWheelEventParams) => { @@ -191,46 +239,30 @@ let%component make = Libscroll.set_source(scrollview, wheelEvent.source); - switch(wheelEvent.deltaX) { - | Some(delta) => { - Libscroll.push_pan(scrollview, Libscroll.Axis.Horizontal, delta, wheelEvent.timestamp); - } - | None => () - }; - - switch(wheelEvent.deltaY) { - | Some(delta) => { - Libscroll.push_pan(scrollview, Libscroll.Axis.Vertical, delta, wheelEvent.timestamp); - } - | None => () - }; - - switch(wheelEvent.isFling) { - | true => Libscroll.push_fling(scrollview, wheelEvent.timestamp); - | false => () - }; - - switch(wheelEvent.isInterrupt) { - | true => Libscroll.push_interrupt(scrollview, wheelEvent.timestamp); - | false => () - }; + switch (wheelEvent.action) { + | Events.MousePanAction.Fling => Libscroll.push_fling(scrollview, wheelEvent.axis, wheelEvent.timestamp) + | Events.MousePanAction.Interrupt => Libscroll.push_interrupt(scrollview, wheelEvent.axis, wheelEvent.timestamp) + | Events.MousePanAction.Pan(delta) => Libscroll.push_pan(scrollview, wheelEvent.axis, delta, wheelEvent.timestamp) + } } | None => Log.error("Scrollview not present on event dispatch"); } - let delta = switch(wheelEvent.deltaY) { + /*let delta = switch(wheelEvent.deltaY) { | Some(value) => value *. 25. | None => 0.0 - }; + };*/ + /*let delta = 0.0; // just to test //let delta = int_of_float(wheelEvent.deltaY *. 25.); let delta_s = delta; let delta = int_of_float(delta /. -400.0); let newScrollTop = actualScrollTop - delta; let isAtTop = newScrollTop < 0; - let isAtBottom = newScrollTop > maxHeight; + let isAtBottom = newScrollTop > maxHeight;*/ - switch (bouncingState) { + + /*switch (bouncingState) { | Bouncing(force) when force < 0 && delta_s < 0. => setBouncingState(_ => Idle) | Bouncing(force) when force > 0 && delta_s > 0. => @@ -245,7 +277,7 @@ let%component make = //setBouncingState(_ => Bouncing(- delta * 2)); dispatch(ScrollUpdated(isAtTop ? 0 : maxHeight)); | Idle => dispatch(ScrollUpdated(newScrollTop)) - }; + };*/ }; (horizontalScrollbar, verticalScrollBar, scroll); | _ => (empty, empty, (_ => ())) From 2a12b5886b41b9467dcde579c590ad2f304d2f0c Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Thu, 23 Apr 2020 15:43:37 -0400 Subject: [PATCH 09/12] Idle+animating+sampling+bounds/geometry --- src/Core/Window.re | 1 - src/UI_Components/ScrollView.re | 38 ++++++++++++++++----------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/Core/Window.re b/src/Core/Window.re index fe564bc66..ea046b016 100644 --- a/src/Core/Window.re +++ b/src/Core/Window.re @@ -343,7 +343,6 @@ let handleEvent = (sdlEvent: Sdl2.Event.t, v: t) => { }; Event.dispatch(v.onMouseWheel, yEvent); | Sdl2.Event.Pan({timestamp, source, axis, action}) => - Log.info("Got a pan event"); let wheelEvent: Events.mouseWheelEvent = { source: convertWheelType(source), timestamp: timestamp, diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index 77a1d7402..5cc1b377b 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -66,6 +66,8 @@ let%component make = //setScrollview(_ => scrollview); let%hook (scrollViewRef) = Hooks.ref(None); + let%hook (kickAnimating, setKickAnimating) = Hooks.state(0); + let scrollviewActive = () => { let r = switch (scrollViewRef^) { | None => { @@ -73,12 +75,12 @@ let%component make = false } | Some(scrollview) => { - Log.info("Scrollview was some"); let v = Libscroll.animating(scrollview) if (v) { - Log.info("animating is true"); + //Log.info("animating is true"); + setKickAnimating(_ => kickAnimating + 1); } else { - Log.info("animating is false"); + setKickAnimating(_ => kickAnimating); } v @@ -88,7 +90,8 @@ let%component make = r } - let%hook (_dt, _reset) = Hooks.timer(~active=scrollviewActive(), ()); + let%hook (animationTimerTime, resetAnimationTimer) = Hooks.timer(~active=scrollviewActive(), ()); + let%hook () = Hooks.effect(OnMount, () => { let scrollView = Libscroll.scrollview_new(); @@ -130,8 +133,10 @@ let%component make = (0.0, 0.0) } | Some(scrollview) => { - Log.info("Scrollview was some, sampling..."); - Libscroll.sample(scrollview, Sdl2.Timekeeping.getTicks()) + let (x, y) = Libscroll.sample(scrollview, Sdl2.Timekeeping.getTicks()); + Log.infof(m => m("Sample gives %f, %f", x, y)); + + (x, y) } } dispatch(ScrollUpdated(int_of_float(scrollY))); @@ -210,17 +215,6 @@ let%component make = thumbColor=scrollThumbColor /> : empty; - - /*let pan = (panEvent: NodeEvents.panEventParams) => { - switch (scrollViewRef^) { - | None => () - | Some(scrollview) => { - let timestamp = wheelEvent.timestamp; - let delta = wheelEvent.delta; - let axis = wheelEvent.axis; - } - }*/ - Log.info("renders the scrollview"); let pageflip = (~initialState=?, ~restThreshold=0.0) => { @@ -234,8 +228,9 @@ let%component make = let scroll = (wheelEvent: NodeEvents.mouseWheelEventParams) => { switch (scrollViewRef^) { - | Some(scrollview) => {//Libscroll.push_pan(scrollview, Libscroll.Axis.Vertical, 10.0, 0) - Log.info("Scrollview existed"); + | Some(scrollview) => { + //Log.info("Scrollview existed"); + Libscroll.set_geometry(scrollview, float_of_int(maxHeight), 0.0, 0.0, 0.0); Libscroll.set_source(scrollview, wheelEvent.source); @@ -244,10 +239,15 @@ let%component make = | Events.MousePanAction.Interrupt => Libscroll.push_interrupt(scrollview, wheelEvent.axis, wheelEvent.timestamp) | Events.MousePanAction.Pan(delta) => Libscroll.push_pan(scrollview, wheelEvent.axis, delta, wheelEvent.timestamp) } + Log.infof(m => m("newScrollTop is %d, maxHeight is %d", scrollTop, maxHeight)); + + setKickAnimating(_ => kickAnimating + 1); + resetAnimationTimer(); } | None => Log.error("Scrollview not present on event dispatch"); } + /*let delta = switch(wheelEvent.deltaY) { | Some(value) => value *. 25. | None => 0.0 From 7acd3f1e96eb2c399a9717da1d9dea47a47190bf Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Thu, 23 Apr 2020 15:48:05 -0400 Subject: [PATCH 10/12] cleanup --- src/UI_Components/ScrollView.re | 54 ++------------------------------- 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index 5cc1b377b..8a2a0b30d 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -71,13 +71,12 @@ let%component make = let scrollviewActive = () => { let r = switch (scrollViewRef^) { | None => { - Log.info("Scrollview was none"); + Log.error("Scrollview was none"); false } | Some(scrollview) => { let v = Libscroll.animating(scrollview) if (v) { - //Log.info("animating is true"); setKickAnimating(_ => kickAnimating + 1); } else { setKickAnimating(_ => kickAnimating); @@ -115,10 +114,6 @@ let%component make = setBouncingState(_ => Idle) ) }; - let setBouncingState = state => { - resetBouncingAnimation(); - setBouncingState(state); - }; let scrollBarThickness = 10; @@ -129,12 +124,12 @@ let%component make = let (scrollX, scrollY) = switch (scrollViewRef^) { | None => { - Log.info("Can't sample, sv null"); + Log.error("Can't sample, sv null"); + (0.0, 0.0) } | Some(scrollview) => { let (x, y) = Libscroll.sample(scrollview, Sdl2.Timekeeping.getTicks()); - Log.infof(m => m("Sample gives %f, %f", x, y)); (x, y) } @@ -216,20 +211,9 @@ let%component make = /> : empty; - let pageflip = (~initialState=?, ~restThreshold=0.0) => { - - let isActive = switch (scrollViewRef^) { - | Some(scrollview) => Libscroll.animating(scrollview) - | None => false - }; - - //let%hook (time, _) = Timer.timer(~active=isActive - } - let scroll = (wheelEvent: NodeEvents.mouseWheelEventParams) => { switch (scrollViewRef^) { | Some(scrollview) => { - //Log.info("Scrollview existed"); Libscroll.set_geometry(scrollview, float_of_int(maxHeight), 0.0, 0.0, 0.0); Libscroll.set_source(scrollview, wheelEvent.source); @@ -239,7 +223,6 @@ let%component make = | Events.MousePanAction.Interrupt => Libscroll.push_interrupt(scrollview, wheelEvent.axis, wheelEvent.timestamp) | Events.MousePanAction.Pan(delta) => Libscroll.push_pan(scrollview, wheelEvent.axis, delta, wheelEvent.timestamp) } - Log.infof(m => m("newScrollTop is %d, maxHeight is %d", scrollTop, maxHeight)); setKickAnimating(_ => kickAnimating + 1); resetAnimationTimer(); @@ -247,37 +230,6 @@ let%component make = } | None => Log.error("Scrollview not present on event dispatch"); } - - /*let delta = switch(wheelEvent.deltaY) { - | Some(value) => value *. 25. - | None => 0.0 - };*/ - /*let delta = 0.0; // just to test - //let delta = int_of_float(wheelEvent.deltaY *. 25.); - let delta_s = delta; - let delta = int_of_float(delta /. -400.0); - let newScrollTop = actualScrollTop - delta; - - let isAtTop = newScrollTop < 0; - let isAtBottom = newScrollTop > maxHeight;*/ - - - /*switch (bouncingState) { - | Bouncing(force) when force < 0 && delta_s < 0. => - setBouncingState(_ => Idle) - | Bouncing(force) when force > 0 && delta_s > 0. => - setBouncingState(_ => Idle) - | Bouncing(_) => () - | Idle when !bounce && (isAtTop || isAtBottom) => - dispatch(ScrollUpdated(newScrollTop)); - //let clampedScrollTop = isAtTop ? 0 : maxHeight; - //dispatch(ScrollUpdated(clampedScrollTop)); - () - | Idle when bounce && (isAtTop || isAtBottom) => - //setBouncingState(_ => Bouncing(- delta * 2)); - dispatch(ScrollUpdated(isAtTop ? 0 : maxHeight)); - | Idle => dispatch(ScrollUpdated(newScrollTop)) - };*/ }; (horizontalScrollbar, verticalScrollBar, scroll); | _ => (empty, empty, (_ => ())) From 8863d536ca7d09429daab8cabc298c891c48e5de Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Mon, 27 Apr 2020 11:37:04 -0400 Subject: [PATCH 11/12] Cleanup --- src/Core/Events.re | 4 ---- src/UI_Components/ScrollView.re | 37 +-------------------------------- 2 files changed, 1 insertion(+), 40 deletions(-) diff --git a/src/Core/Events.re b/src/Core/Events.re index 3a68fa860..5aa7d0241 100644 --- a/src/Core/Events.re +++ b/src/Core/Events.re @@ -32,10 +32,6 @@ module MousePanAction = { } type mouseWheelEvent = { - //deltaX: option(float), - //deltaY: option(float), - //isFling: bool, - //isInterrupt: bool, source: Libscroll.Source.t, axis: Libscroll.Axis.t, action: MousePanAction.t, diff --git a/src/UI_Components/ScrollView.re b/src/UI_Components/ScrollView.re index 8a2a0b30d..76063ffd6 100644 --- a/src/UI_Components/ScrollView.re +++ b/src/UI_Components/ScrollView.re @@ -26,29 +26,12 @@ let reducer = (action, _state) => { }; }; -let bounceAnimation = (~origin, ~force) => - Animation.( - { - let bounceAway = - animate(Time.ms(100)) - |> ease(Easing.cubicBezier(0.23, 1., 0.32, 1.)) - |> tween(float(origin), float(origin + force)); - - let bounceBack = - Animation.animate(Time.ms(800)) - |> ease(Easing.cubicBezier(0.23, 1., 0.32, 1.)) - |> tween(float(origin + force), float(origin)); - - bounceAway |> andThen(~next=bounceBack) |> map(int_of_float); - } - ); - let%component make = ( ~style, ~scrollLeft=0, ~scrollTop=0, - ~bounce=defaultBounce, + ~bounce=defaultBounce, // TODO: pass bounce hint to libscroll ~children=React.empty, (), ) => { @@ -59,11 +42,6 @@ let%component make = let%hook (actualScrollLeft, setScrollLeft) = Hooks.state(scrollLeft); let%hook (bouncingState, setBouncingState) = Hooks.state(Idle); - //Time.timer; - //let%hook (time, _) = Revery_Core.Timer.timer(~active=true, ()); - - //let%hook (scrollview, setScrollview) = Hooks.state(() => Libscroll.scrollview_new()); - //setScrollview(_ => scrollview); let%hook (scrollViewRef) = Hooks.ref(None); let%hook (kickAnimating, setKickAnimating) = Hooks.state(0); @@ -102,19 +80,6 @@ let%component make = Some(dispose); }); - let%hook (actualScrollTop, _bounceAnimationState, resetBouncingAnimation) = - switch (bouncingState) { - | Idle => - // TODO: Why isn't Animation.const always sufficient to stop the timer? - Hooks.animation(~active=false, Animation.const(actualScrollTop)) - - | Bouncing(force) => - Hooks.animation( - bounceAnimation(~origin=actualScrollTop, ~force), ~onComplete=() => - setBouncingState(_ => Idle) - ) - }; - let scrollBarThickness = 10; let innerViewTransform = [ From b03b8a360a692711ce8d96d7298698aee2c9efcf Mon Sep 17 00:00:00 2001 From: Sawyer Bergeron Date: Tue, 28 Apr 2020 14:42:40 -0400 Subject: [PATCH 12/12] Avoid libscroll panicking on non-pan-supporting platforms --- src/Core/Window.re | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/Window.re b/src/Core/Window.re index ea046b016..7c0067004 100644 --- a/src/Core/Window.re +++ b/src/Core/Window.re @@ -329,7 +329,7 @@ let handleEvent = (sdlEvent: Sdl2.Event.t, v: t) => { | Sdl2.Event.MouseWheel({deltaX, deltaY, _}) => let xEvent: Events.mouseWheelEvent = { source: Libscroll.Source.Mousewheel, - timestamp: 0, // TODO: add timestamps to mosuewheel events in sdl OR completely switch to pan + timestamp: Sdl2.Timekeeping.getTicks(), // TODO: try to migrate completely to pan events for more precise timestamps action: Events.MousePanAction.Pan(float_of_int(deltaX)), axis: Libscroll.Axis.Horizontal, }; @@ -337,7 +337,7 @@ let handleEvent = (sdlEvent: Sdl2.Event.t, v: t) => { let yEvent: Events.mouseWheelEvent = { source: Libscroll.Source.Mousewheel, - timestamp: 0, // TODO: add timestamps to mosuewheel events in sdl OR completely switch to pan + timestamp: Sdl2.Timekeeping.getTicks(), // TODO: try to migrate completely to pan events for more precise timestamps action: Events.MousePanAction.Pan(float_of_int(deltaY)), axis: Libscroll.Axis.Vertical, };