-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #10 Adds crown scroll event handler, on web matched to mouse wheel
- Loading branch information
1 parent
747a0f8
commit 35abc74
Showing
12 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ export enum NodeType { | |
|
||
Remember = 'remember', | ||
Effect = 'effect', | ||
Event = 'event', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { EventType } from '../working_tree/EventNode.js' | ||
|
||
export interface EventHandler { | ||
type: EventType | ||
handler: (...args: any[]) => boolean | ||
} | ||
|
||
export abstract class GlobalEventManager { | ||
private static handlers: EventHandler[] = [] | ||
|
||
public static clearHandlers() { | ||
GlobalEventManager.handlers = [] | ||
} | ||
|
||
public static registerHandler(handler: EventHandler) { | ||
GlobalEventManager.handlers.push(handler) | ||
} | ||
|
||
public static dispatchCrownEvent(delta: number): boolean { | ||
// iterate upwards so the deeper nodes receive the event earlier | ||
for (let i = GlobalEventManager.handlers.length - 1; i >= 0; i--) { | ||
const handler = GlobalEventManager.handlers[i] | ||
if (handler.type === EventType.Crown && handler.handler(delta)) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { WorkingNode } from './WorkingNode.js' | ||
|
||
export enum EventType { | ||
Button, | ||
Crown, | ||
Gesture, | ||
} | ||
|
||
export class EventNode extends WorkingNode { | ||
public handler: (...args: any[]) => boolean | ||
public eventType: EventType | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
@zapp/core/src/working_tree/effects/registerCrownEventHandler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { EventType } from '../EventNode.js' | ||
import { ViewNode } from '../ViewNode.js' | ||
import { WorkingTree } from '../WorkingTree.js' | ||
|
||
export function registerCrownEventHandler(handler: (delta: number) => boolean) { | ||
const current = WorkingTree.current as ViewNode | ||
const context = current.event() | ||
|
||
context.handler = handler | ||
context.eventType = EventType.Crown | ||
|
||
current.children.push(context) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters