11import { AfterViewInit , Component , ViewChild } from '@angular/core' ;
22import * as paper from 'paper' ;
33import { DemoComponent } from '../demo-component/demo.component' ;
4- import { LIGHT_GREY , CANVAS_BACKGROUND_COLOR , VAPP_BACKGROUND_COLOR } from '../../../../../src/constants/colors' ;
4+ import { LIGHT_GREY , CANVAS_BACKGROUND_COLOR } from '../../../../../src/constants/colors' ;
55import { ScrollbarComponent } from '../../../../../src/components/scrollbar' ;
6- import { DEFAULT_SCROLLBAR_THICKNESS } from '../../../../../src/constants/dimensions' ;
76
87@Component ( {
98 selector : 'misc-scrollbar-vertical-demo' ,
109 template : `
1110 <demo label="Vertical Scrollbar" height="800"
12- description="Scrollbar UI component for vertical scrolling with custom scrollbar, track, and effects ."
11+ description="Scrollbar UI component for vertical scrolling with default scrollbar and track ."
1312 runnable="true" (run)="run()" (reset)="reset()"></demo>
1413 ` } )
1514export class MiscScrollbarVerticalDemoComponent implements AfterViewInit {
@@ -26,7 +25,7 @@ export class MiscScrollbarVerticalDemoComponent implements AfterViewInit {
2625 proj . activeLayer . applyMatrix = false ;
2726 this . demo . backgroundColor = CANVAS_BACKGROUND_COLOR ;
2827 const view = paper . view ;
29- const canvas = this . demo . canvas . nativeElement ;
28+ const canvas = paper . view . element ;
3029 const VIEW_PADDING = 30 ;
3130
3231 // create content
@@ -54,57 +53,25 @@ export class MiscScrollbarVerticalDemoComponent implements AfterViewInit {
5453 content . translate ( new paper . Point ( 0 , VIEW_PADDING ) ) ;
5554
5655 // create scrollbar
57- const scrollbar = new ScrollbarComponent (
58- { content : content , containerBounds : view . bounds , contentOffsetEnd : VIEW_PADDING } ,
59- new paper . Point ( view . bounds . right - VIEW_PADDING - DEFAULT_SCROLLBAR_THICKNESS , VIEW_PADDING ) ,
56+ const scrollbar = new ScrollbarComponent ( {
57+ content : content ,
58+ containerBounds : view . bounds ,
59+ contentOffsetEnd : VIEW_PADDING
60+ } ,
61+ new paper . Point ( view . bounds . right - VIEW_PADDING , VIEW_PADDING ) ,
6062 view . bounds . height - VIEW_PADDING * 2 ,
61- 'vertical' ) ;
63+ 'vertical'
64+ ) ;
65+ if ( scrollbar . isEnabled ) {
66+ canvas . onmouseenter = scrollbar . containerMouseEnter ;
67+ canvas . onmouseleave = scrollbar . containerMouseLeave ;
6268
63- // add scroll listening. paper doesn't have a wheel event handler
64- canvas . onwheel = ( event : WheelEvent ) => {
65- scrollbar . onScroll ( event ) ;
66- } ;
67- // paper tools are global, so specific tools need to be activated when a different view is active
68- view . onMouseEnter = ( ) => {
69- scrollbar . activateDefaultTool ( ) ;
70- } ;
71-
72- scrollbar . getScrollbar ( ) . fillColor = 'red' ;
73- scrollbar . getTrack ( ) . fillColor = 'blue' ;
74-
75- // set up custom scrollbar
76- const customScrollbar = new paper . Path . Rectangle ( {
77- point : new paper . Point ( - 6.5 , 0 ) ,
78- size : new paper . Size ( 15 , 15 ) ,
79- pivot : new paper . Point ( 0 , 0 ) ,
80- radius : 15 / 2 ,
81- fillColor : LIGHT_GREY
82- } ) ;
83- customScrollbar . remove ( ) ;
84- scrollbar . setScrollbar ( customScrollbar ) ;
85-
86- // set up custom track
87- const customTrack = new paper . Path . Rectangle ( {
88- point : new paper . Point ( 0 , 0 ) ,
89- size : new paper . Size ( 2 , view . bounds . height - VIEW_PADDING * 2 ) ,
90- fillColor : VAPP_BACKGROUND_COLOR
91- } ) ;
92- customTrack . remove ( ) ;
93- scrollbar . setTrack ( customTrack ) ;
69+ // add scroll listening. paper doesn't have a wheel event handler
70+ canvas . onwheel = ( event : WheelEvent ) => {
71+ scrollbar . onScroll ( event ) ;
72+ } ;
73+ }
9474
95- // set custom Effects
96- ( scrollbar . getScrollbar ( ) as paper . Path ) . opacity = 1 ;
97- scrollbar . disableDefaultEffects ( ) ;
98- scrollbar . setCustomEffects ( {
99- setActive : ( ) => {
100- ( scrollbar . getScrollbar ( ) as paper . Path ) . fillColor = 'DeepSkyBlue' ;
101- } ,
102- setNormal : ( ) => {
103- ( scrollbar . getScrollbar ( ) as any ) . tweenTo ( {
104- fillColor : LIGHT_GREY
105- } , 250 ) ;
106- }
107- } ) ;
10875 }
10976
11077 run ( ) {
0 commit comments