@@ -2,7 +2,7 @@ import { AfterViewInit, Component, ViewChild } from '@angular/core';
22import * as paper from 'paper' ;
33import { DemoComponent } from '../demo-component/demo.component' ;
44import { VappData , VappComponent } from '../../../../../src/components/vapp' ;
5- import { placeholderArrayOfVappData } from '../../constants/vapp-basic -placeholder-data' ;
5+ import { placeholderArrayOfVappData } from '../../constants/vapp-static -placeholder-data' ;
66import { ScrollbarComponent } from '../../../../../src/components/scrollbar' ;
77import { CANVAS_BACKGROUND_COLOR } from '../../../../../src/constants/colors' ;
88import { CONNECTOR_RADIUS , DEFAULT_SCROLLBAR_THICKNESS } from '../../../../../src/constants/dimensions' ;
@@ -22,63 +22,36 @@ export class VappStaticDemoComponent implements AfterViewInit {
2222 // sets up Paper Project
2323 const proj = this . demo . getProject ( ) ;
2424 proj . activate ( ) ;
25- const view = paper . view ;
26- const canvas = paper . view . element ;
25+ const view = proj . view ;
2726 this . demo . backgroundColor = CANVAS_BACKGROUND_COLOR ;
2827
2928 const VIEW_PADDING = 30 ;
3029 const DEMO_VAPP_TOP_ALIGNMENT = 59 ;
3130 const VERTICAL_POSITION = VIEW_PADDING + DEMO_VAPP_TOP_ALIGNMENT + CONNECTOR_RADIUS ;
3231 const vapps : Array < VappData > = placeholderArrayOfVappData ;
3332
34- const content = new paper . Group ( { applyMatrix : false } ) ;
35- // create origin paper Item for vapps to base position from
36- const origin = new paper . Path . Circle ( {
37- position : new paper . Point ( VIEW_PADDING , VERTICAL_POSITION ) ,
38- radius : 0 ,
39- parent : content
40- } ) ;
33+ const content = new paper . Group ( ) ;
4134
4235 // create vapps
4336 vapps . forEach ( vappData => {
44- const position = new paper . Point ( content . lastChild . bounds . right , VERTICAL_POSITION ) ;
37+ const position = new paper . Point (
38+ content . lastChild ? content . lastChild . bounds . right : VIEW_PADDING , VERTICAL_POSITION ) ;
4539 content . addChild ( new VappComponent ( vappData , position ) ) ;
4640 } ) ;
4741 ( content . lastChild as VappComponent ) . margin . right = 0 ;
4842
4943 // create view horizontal scrollbar
5044 const horizontalScrollbar = new ScrollbarComponent ( {
5145 content : content ,
46+ container : view . element ,
5247 containerBounds : view . bounds ,
5348 contentOffsetEnd : VIEW_PADDING
5449 } ,
5550 new paper . Point ( VIEW_PADDING , view . size . height - DEFAULT_SCROLLBAR_THICKNESS - 10 ) ,
5651 view . bounds . width - VIEW_PADDING * 2 ,
5752 'horizontal'
5853 ) ;
59- if ( horizontalScrollbar . isEnabled ) {
60- canvas . onmouseenter = horizontalScrollbar . containerMouseEnter ;
61- canvas . onmouseleave = horizontalScrollbar . containerMouseLeave ;
62- }
63-
64- // add scroll listening. paper doesn't have a wheel event handler
65- canvas . onwheel = ( event : WheelEvent ) => {
66- // horizontal scrolling sent to horizontal scrollbar
67- if ( Math . abs ( event . deltaX ) > Math . abs ( event . deltaY ) ) {
68- horizontalScrollbar . onScroll ( event ) ;
69- } else {
70- // vertical scrolling sent to any scrollable vapp that's active/hovered
71- content . children . forEach ( item => {
72- if ( item instanceof VappComponent && item . isScrollable ) {
73- item . setScrollListening ( event ) ;
74- }
75- } ) ;
76- }
77- } ;
78-
79- // TODO: keydown 'left' and 'right' should always go to horizontalScrollbar. keydown 'up' and 'down' to should go to
80- // any scrollable vapp that's active/hovered. can try handling with a paper tools service and/or tool stack
54+ ScrollbarComponent . defaultScrollbar = horizontalScrollbar ;
8155
82- // TODO: make sure 'Roboto' font loading finishes before canvas elements are rendered
8356 }
8457}
0 commit comments