Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add onSomethingDown callbacks #910

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/UI_Components/Clickable.re
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ let%component make =
(
~style=[],
~onClick=() => (),
~onDown=() => (),
~onRightClick=() => (),
~onRightDown=() => (),
~onDoubleClick=?,
~onDoubleDown=?,
~onAnyClick=_event => (),
~onAnyDown=_event => (),
~componentRef=?,
~onBlur=?,
~onFocus=?,
Expand Down Expand Up @@ -62,9 +66,24 @@ let%component make =
isMouseCaptured := false;
};

let onMouseDown = _event => {
let onMouseDown = (mouseEvt: NodeEvents.mouseButtonEventParams) => {
capture();
mouseDownTimes := (Time.now(), fst(mouseDownTimes^));

if (isMouseCapturedHere^) {
switch (mouseEvt.button) {
| MouseButton.BUTTON_LEFT =>
if (onDoubleDown != None && isDoubleClick()) {
Option.get(onDoubleDown, ());
} else {
onDown();
}
| MouseButton.BUTTON_RIGHT => onRightDown()
| _ => ()
};

onAnyDown(mouseEvt);
};
};
let onMouseLeave = _event => {
releaseCapture();
Expand Down
4 changes: 4 additions & 0 deletions src/UI_Components/Clickable.rei
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ let make:
~key: Brisk_reconciler.Key.t=?,
~style: list(Revery_UI.Style.viewStyleProps)=?,
~onClick: unit => unit=?,
~onDown: unit => unit=?,
~onRightClick: unit => unit=?,
~onRightDown: unit => unit=?,
~onDoubleClick: unit => unit=?,
~onDoubleDown: unit => unit=?,
~onAnyClick: NodeEvents.mouseButtonEventParams => unit=?,
~onAnyDown: NodeEvents.mouseButtonEventParams => unit=?,
Comment on lines +23 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be onMouseDown, onRightMouseDown etc. to disambiguate it from for example onKeyDown.

~componentRef: Revery_UI.node => unit=?,
~onBlur: Revery_UI.NodeEvents.focusHandler=?,
~onFocus: Revery_UI.NodeEvents.focusHandler=?,
Expand Down