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

Feat/pointer position and drag #1052

Merged
merged 7 commits into from
Jan 27, 2025
Merged
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
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"packages/@dcl/inspector/hot-reload.js": false
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
"editor.defaultFormatter": "vscode.typescript-language-features"
}
}
60 changes: 31 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bugs": "https://github.com/decentraland/js-sdk-toolchain/issues",
"dependencies": {
"@actions/core": "^1.10.0",
"@dcl/protocol": "1.0.0-12415236132.commit-53e881e",
"@dcl/protocol": "https://sdk-team-cdn.decentraland.org/@dcl/protocol/branch//dcl-protocol-1.0.0-12791995584.commit-4338852.tgz",
"@dcl/quickjs-emscripten": "^0.21.0-3680274614.commit-1808aa1",
"@dcl/ts-proto": "1.153.0",
"@types/fs-extra": "^9.0.12",
Expand Down
109 changes: 106 additions & 3 deletions packages/@dcl/ecs/src/systems/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,27 @@
*/
removeOnPointerHoverLeave(entity: Entity): void

/**
* @public
* Remove the callback for onPointerDrag event
* @param entity - Entity where the callback was attached
*/
removeOnPointerDrag(entity: Entity): void

/**
* @public
* Remove the callback for onPointerDragLocked event
* @param entity - Entity where the callback was attached
*/
removeOnPointerDragLocked(entity: Entity): void

/**
* @public
* Remove the callback for onPointerDragEnd event
* @param entity - Entity where the callback was attached
*/
removeOnPointerDragEnd(entity: Entity): void

/**
* @internal
* Execute callback when the user clicks the entity.
Expand Down Expand Up @@ -124,6 +145,34 @@
pointerData: { entity: Entity; opts?: Partial<EventSystemOptions> },
cb: EventSystemCallback
): void

/**
* @public
* Execute callback when the user clicks and drags the pointer from inside the entity
* @param pointerData - Entity to attach the callback - Opts to trigger Feedback and Button
* @param cb - Function to execute when click fires
*/
onPointerDrag(pointerData: { entity: Entity; opts?: Partial<EventSystemOptions> }, cb: EventSystemCallback): void

/**
* @public
* Execute callback when the user clicks and drags the pointer from inside the entity,
* locking the cursor in place
* @param pointerData - Entity to attach the callback - Opts to trigger Feedback and Button
* @param cb - Function to execute when click fires
*/
onPointerDragLocked(
pointerData: { entity: Entity; opts?: Partial<EventSystemOptions> },
cb: EventSystemCallback
): void

/**
* @public
* Execute callback when the user releases the button after a drag
* @param pointerData - Entity to attach the callback - Opts to trigger Feedback and Button
* @param cb - Function to execute when click fires
*/
onPointerDragEnd(pointerData: { entity: Entity; opts?: Partial<EventSystemOptions> }, cb: EventSystemCallback): void
}

/**
Expand All @@ -138,7 +187,10 @@
Down,
Up,
HoverEnter,
HoverLeave
HoverLeave,
Drag,
DragLocked,
DragEnd
}
type EventMapType = Map<EventType, { cb: EventSystemCallback; opts: EventSystemOptions }>

Expand Down Expand Up @@ -177,6 +229,12 @@
return PointerEventType.PET_HOVER_LEAVE
} else if (eventType === EventType.HoverEnter) {
return PointerEventType.PET_HOVER_ENTER
} else if (eventType === EventType.Drag) {
return PointerEventType.PET_DRAG

Check warning on line 233 in packages/@dcl/ecs/src/systems/events.ts

View check run for this annotation

Codecov / codecov/patch

packages/@dcl/ecs/src/systems/events.ts#L233

Added line #L233 was not covered by tests
} else if (eventType === EventType.DragLocked) {
return PointerEventType.PET_DRAG_LOCKED

Check warning on line 235 in packages/@dcl/ecs/src/systems/events.ts

View check run for this annotation

Codecov / codecov/patch

packages/@dcl/ecs/src/systems/events.ts#L235

Added line #L235 was not covered by tests
} else if (eventType === EventType.DragEnd) {
return PointerEventType.PET_DRAG_END

Check warning on line 237 in packages/@dcl/ecs/src/systems/events.ts

View check run for this annotation

Codecov / codecov/patch

packages/@dcl/ecs/src/systems/events.ts#L237

Added line #L237 was not covered by tests
}
return PointerEventType.PET_DOWN
}
Expand Down Expand Up @@ -210,7 +268,10 @@
eventType === EventType.Down ||
eventType === EventType.Up ||
eventType === EventType.HoverEnter ||
eventType === EventType.HoverLeave
eventType === EventType.HoverLeave ||
eventType === EventType.Drag ||
eventType === EventType.DragLocked ||
eventType === EventType.DragEnd
) {
const command = inputSystem.getInputCommand(opts.button, getPointerEvent(eventType), entity)
if (command) {
Expand Down Expand Up @@ -263,6 +324,33 @@
setPointerEvent(entity, PointerEventType.PET_HOVER_LEAVE, options)
}

const onPointerDrag: PointerEventsSystem['onPointerDrag'] = (...args) => {
const [data, cb] = args
const { entity, opts } = data
const options = getDefaultOpts(opts)
removeEvent(entity, EventType.Drag)
getEvent(entity).set(EventType.Drag, { cb, opts: options })
setPointerEvent(entity, PointerEventType.PET_DRAG, options)

Check warning on line 333 in packages/@dcl/ecs/src/systems/events.ts

View check run for this annotation

Codecov / codecov/patch

packages/@dcl/ecs/src/systems/events.ts#L328-L333

Added lines #L328 - L333 were not covered by tests
}

const onPointerDragLocked: PointerEventsSystem['onPointerDragLocked'] = (...args) => {
const [data, cb] = args
const { entity, opts } = data
const options = getDefaultOpts(opts)
removeEvent(entity, EventType.DragLocked)
getEvent(entity).set(EventType.DragLocked, { cb, opts: options })
setPointerEvent(entity, PointerEventType.PET_DRAG_LOCKED, options)

Check warning on line 342 in packages/@dcl/ecs/src/systems/events.ts

View check run for this annotation

Codecov / codecov/patch

packages/@dcl/ecs/src/systems/events.ts#L337-L342

Added lines #L337 - L342 were not covered by tests
}

const onPointerDragEnd: PointerEventsSystem['onPointerDragEnd'] = (...args) => {
const [data, cb] = args
const { entity, opts } = data
const options = getDefaultOpts(opts)
removeEvent(entity, EventType.DragEnd)
getEvent(entity).set(EventType.DragEnd, { cb, opts: options })
setPointerEvent(entity, PointerEventType.PET_DRAG_END, options)

Check warning on line 351 in packages/@dcl/ecs/src/systems/events.ts

View check run for this annotation

Codecov / codecov/patch

packages/@dcl/ecs/src/systems/events.ts#L346-L351

Added lines #L346 - L351 were not covered by tests
}

return {
removeOnClick(entity: Entity) {
removeEvent(entity, EventType.Click)
Expand All @@ -284,6 +372,18 @@
removeEvent(entity, EventType.HoverLeave)
},

removeOnPointerDrag(entity: Entity) {
removeEvent(entity, EventType.Drag)
},

removeOnPointerDragLocked(entity: Entity) {
removeEvent(entity, EventType.DragLocked)
},

removeOnPointerDragEnd(entity: Entity) {
removeEvent(entity, EventType.DragEnd)
},

onClick(value, cb) {
const { entity } = value
const options = getDefaultOpts(value.opts)
Expand All @@ -298,6 +398,9 @@
onPointerDown,
onPointerUp,
onPointerHoverEnter,
onPointerHoverLeave
onPointerHoverLeave,
onPointerDrag,
onPointerDragLocked,
onPointerDragEnd
}
}
Empty file modified packages/@dcl/inspector/build.js
100755 → 100644
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions packages/@dcl/playground-assets/etc/playground-assets.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,9 @@ export type EntityComponents = {
onMouseUp: Callback;
onMouseEnter: Callback;
onMouseLeave: Callback;
onMouseDrag: Callback;
onMouseDragLocked: Callback;
onMouseDragEnd: Callback;
};

// @public (undocumented)
Expand Down Expand Up @@ -1644,6 +1647,9 @@ export type Listeners = {
onMouseUp?: Callback;
onMouseEnter?: Callback;
onMouseLeave?: Callback;
onMouseDrag?: Callback;
onMouseDragLocked?: Callback;
onMouseDragEnd?: Callback;
};

// @public (undocumented)
Expand Down Expand Up @@ -3596,6 +3602,18 @@ export interface PointerEventsSystem {
}, cb: EventSystemCallback): void;
// @deprecated (undocumented)
onPointerDown(entity: Entity, cb: EventSystemCallback, opts?: Partial<EventSystemOptions>): void;
onPointerDrag(pointerData: {
entity: Entity;
opts?: Partial<EventSystemOptions>;
}, cb: EventSystemCallback): void;
onPointerDragEnd(pointerData: {
entity: Entity;
opts?: Partial<EventSystemOptions>;
}, cb: EventSystemCallback): void;
onPointerDragLocked(pointerData: {
entity: Entity;
opts?: Partial<EventSystemOptions>;
}, cb: EventSystemCallback): void;
onPointerHoverEnter(pointerData: {
entity: Entity;
opts?: Partial<EventSystemOptions>;
Expand All @@ -3611,6 +3629,9 @@ export interface PointerEventsSystem {
// @deprecated (undocumented)
onPointerUp(entity: Entity, cb: EventSystemCallback, opts?: Partial<EventSystemOptions>): void;
removeOnPointerDown(entity: Entity): void;
removeOnPointerDrag(entity: Entity): void;
removeOnPointerDragEnd(entity: Entity): void;
removeOnPointerDragLocked(entity: Entity): void;
removeOnPointerHoverEnter(entity: Entity): void;
removeOnPointerHoverLeave(entity: Entity): void;
removeOnPointerUp(entity: Entity): void;
Expand Down
16 changes: 15 additions & 1 deletion packages/@dcl/react-ecs/src/components/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,18 @@ function getButtonProps(props: UiButtonProps) {
*/
/* @__PURE__ */
export function Button(props: UiButtonProps) {
const { uiTransform, uiBackground, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, ...otherProps } = props
const {
uiTransform,
uiBackground,
onMouseDown,
onMouseUp,
onMouseEnter,
onMouseLeave,
onMouseDrag,
onMouseDragLocked,
onMouseDragEnd,
...otherProps
} = props
const buttonProps = getButtonProps(props)
const uiBackgroundProps = parseUiBackground({
...buttonProps.uiBackground,
Expand Down Expand Up @@ -66,6 +77,9 @@ export function Button(props: UiButtonProps) {
onMouseUp={!!props.disabled ? undefined : onMouseUp}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onMouseDrag={onMouseDrag}
onMouseDragLocked={onMouseDragLocked}
onMouseDragEnd={onMouseDragEnd}
uiTransform={uiTransformProps}
uiText={textProps}
uiBackground={uiBackgroundProps}
Expand Down
Loading
Loading