-
Notifications
You must be signed in to change notification settings - Fork 1
22 #30
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
base: master
Are you sure you want to change the base?
22 #30
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| <div id="header"> | ||
| <h1>gibraltar</h1> | ||
| <h1>gibraltar</h1> | ||
| <h2>demo</h2> | ||
| </div> | ||
| <router-outlet></router-outlet> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Component } from '@angular/core'; | ||
|
|
||
| @Component({ | ||
| selector: 'vapp-demo', | ||
| template: ` | ||
| <div id="vapp-page"> | ||
| <vapp-static-demo></vapp-static-demo> | ||
| </div> | ||
| ` | ||
| }) | ||
| export class VappPageComponent { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { AfterViewInit, Component, ViewChild } from '@angular/core'; | ||
| import * as paper from 'paper'; | ||
| import { DemoComponent } from '../demo-component/demo.component'; | ||
| import { VappData, VappComponent } from '../../../../../src/components/vapp'; | ||
| import { placeholderArrayOfVappData } from '../../constants/vapp-basic-placeholder-data'; | ||
| import { ScrollbarComponent } from '../../../../../src/components/scrollbar'; | ||
| import { CANVAS_BACKGROUND_COLOR } from '../../../../../src/constants/colors'; | ||
| import { CONNECTOR_RADIUS, DEFAULT_SCROLLBAR_THICKNESS } from '../../../../../src/constants/dimensions'; | ||
|
|
||
| @Component({ | ||
| selector: 'vapp-static-demo', | ||
| template: ` | ||
| <demo label="Static Design" height="730" | ||
| description="Demonstrates the static layout design of the vApp visual component for different cases."></demo> | ||
| ` }) | ||
| export class VappStaticDemoComponent implements AfterViewInit { | ||
|
|
||
| @ViewChild(DemoComponent) | ||
| demo: DemoComponent; | ||
|
|
||
| ngAfterViewInit() { | ||
| // sets up Paper Project | ||
| const proj = this.demo.getProject(); | ||
| proj.activate(); | ||
| const view = paper.view; | ||
| const canvas = paper.view.element; | ||
| this.demo.backgroundColor = CANVAS_BACKGROUND_COLOR; | ||
|
|
||
| const VIEW_PADDING = 30; | ||
| const DEMO_VAPP_TOP_ALIGNMENT = 59; | ||
| const VERTICAL_POSITION = VIEW_PADDING + DEMO_VAPP_TOP_ALIGNMENT + CONNECTOR_RADIUS; | ||
| const vapps: Array<VappData> = placeholderArrayOfVappData; | ||
|
|
||
| const content = new paper.Group({ applyMatrix: false }); | ||
| // create origin paper Item for vapps to base position from | ||
| const origin = new paper.Path.Circle({ | ||
|
||
| position: new paper.Point(VIEW_PADDING, VERTICAL_POSITION), | ||
| radius: 0, | ||
| parent: content | ||
| }); | ||
|
|
||
| // create vapps | ||
| vapps.forEach(vappData => { | ||
| const position = new paper.Point(content.lastChild.bounds.right, VERTICAL_POSITION); | ||
| content.addChild(new VappComponent(vappData, position)); | ||
| }); | ||
| (content.lastChild as VappComponent).margin.right = 0; | ||
|
|
||
| // create view horizontal scrollbar | ||
| const horizontalScrollbar = new ScrollbarComponent({ | ||
| content: content, | ||
| containerBounds: view.bounds, | ||
| contentOffsetEnd: VIEW_PADDING | ||
| }, | ||
| new paper.Point(VIEW_PADDING, view.size.height - DEFAULT_SCROLLBAR_THICKNESS - 10), | ||
| view.bounds.width - VIEW_PADDING * 2, | ||
| 'horizontal' | ||
| ); | ||
| if (horizontalScrollbar.isEnabled) { | ||
| canvas.onmouseenter = horizontalScrollbar.containerMouseEnter; | ||
| canvas.onmouseleave = horizontalScrollbar.containerMouseLeave; | ||
| } | ||
|
|
||
| // add scroll listening. paper doesn't have a wheel event handler | ||
| canvas.onwheel = (event: WheelEvent) => { | ||
| // horizontal scrolling sent to horizontal scrollbar | ||
| if (Math.abs(event.deltaX) > Math.abs(event.deltaY)) { | ||
| horizontalScrollbar.onScroll(event); | ||
| } else { | ||
| // vertical scrolling sent to any scrollable vapp that's active/hovered | ||
| content.children.forEach(item => { | ||
| if (item instanceof VappComponent && item.isScrollable) { | ||
| item.setScrollListening(event); | ||
| } | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| // TODO: keydown 'left' and 'right' should always go to horizontalScrollbar. keydown 'up' and 'down' to should go to | ||
| // any scrollable vapp that's active/hovered. can try handling with a paper tools service and/or tool stack | ||
|
|
||
| // TODO: make sure 'Roboto' font loading finishes before canvas elements are rendered | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this pattern where you're requiring the parent component to bind the event handlers. That should be internal to the scrollbar at the time it is created. I suggest creating a wrapper for the canvas that you're rendering to which exposes Observables that are bound to those event handlers so that any component can easily subscribe to them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
event handlers are internal to the scrollbar now