Skip to content

Commit

Permalink
Closes ilanddev#22: add vapp static designs
Browse files Browse the repository at this point in the history
  • Loading branch information
cho committed Sep 25, 2019
1 parent 5486857 commit 4034463
Show file tree
Hide file tree
Showing 46 changed files with 4,379 additions and 102 deletions.
2 changes: 1 addition & 1 deletion demo/src/app/app.component.html
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>
2 changes: 1 addition & 1 deletion demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: require('./app.component.html'),
styles: [require('./app.component.less')]
styles: [require('../styles.less'), require('./app.component.less')]
})
export class AppComponent {
title = 'demo';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link" routerLink="vm" routerLinkActive="active">Virtual Machine</a>
<a class="nav-link" routerLink="vapp" routerLinkActive="active">Virtual Application</a>
<a class="nav-link" routerLink="misc" routerLinkActive="active">Miscellaneous</a>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
background-color: #E3E8E8
}
.nav-link.active {
background-color: lightgray !important;
font-weight: 500 !important;
background-color: lightgray;
font-weight: 500;
}
}
4 changes: 4 additions & 0 deletions demo/src/app/components/components-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { ComponentsPageComponent } from './components-page/components-page.component';
import { VmPageComponent } from './vm-page-component/vm-page.component';
import { VappPageComponent } from './vapp-page-component/vapp-page.component';
import { MiscPageComponent } from './misc-page-component/misc-page.component';

const routes = [
Expand All @@ -17,6 +18,9 @@ const routes = [
{
path: 'vm', component: VmPageComponent
},
{
path: 'vapp', component: VappPageComponent
},
{
path: 'misc', component: MiscPageComponent
}
Expand Down
4 changes: 4 additions & 0 deletions demo/src/app/components/components.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { DemoComponent } from './demo-component/demo.component';
import { VmPageComponent } from './vm-page-component/vm-page.component';
import { VmCreateDemoComponent } from './vm-create-demo-component/vm-create-demo.component';
import { VmDeleteDemoComponent } from './vm-delete-demo-component/vm-delete-demo.component';
import { VappPageComponent } from './vapp-page-component/vapp-page.component';
import { VappStaticDemoComponent } from './vapp-static-demo-component/vapp-static-demo.component';
import { MiscPageComponent } from './misc-page-component/misc-page.component';
import { MiscScrollbarHorizontalDemoComponent } from
'./misc-scrollbar-demo-component/misc-scrollbar-horizontal-demo.component';
Expand All @@ -23,6 +25,8 @@ import { MiscScrollbarVerticalDemoComponent } from
VmBasicDemoComponent,
ComponentsPageComponent,
DemoComponent,
VappPageComponent,
VappStaticDemoComponent,
MiscPageComponent,
MiscScrollbarHorizontalDemoComponent,
MiscScrollbarVerticalDemoComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Component } from '@angular/core';

@Component({
selector: 'other-page',
selector: 'misc-page',
template: `
<div id="other-page">
<div id="misc-page">
<misc-scrollbar-horizontal-demo></misc-scrollbar-horizontal-demo>
<misc-scrollbar-vertical-demo></misc-scrollbar-vertical-demo>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { DEFAULT_SCROLLBAR_THICKNESS } from '../../../../../src/constants/dimens

@Component({
selector: 'misc-scrollbar-horizontal-demo',
template: `
<demo label="Horizontal Scrollbar" height="200"
template: `
<demo label="Horizontal Scrollbar" height="162"
description="Scrollbar UI component for horizontal scrolling with the default scrollbar and scroll track."
runnable="true" (run)="run()" (reset)="reset()"></demo>
` })
Expand All @@ -26,7 +26,7 @@ export class MiscScrollbarHorizontalDemoComponent implements AfterViewInit {
proj.activeLayer.applyMatrix = false;
this.demo.backgroundColor = CANVAS_BACKGROUND_COLOR;
const view = paper.view;
const canvas = this.demo.canvas.nativeElement;
const canvas = paper.view.element;
const VIEW_PADDING = 30;

// create content
Expand All @@ -37,13 +37,13 @@ export class MiscScrollbarHorizontalDemoComponent implements AfterViewInit {
: i % 15 === 0 && 'fizzbuzz' || i % 3 === 0 && 'fizz' || i % 5 === 0 && 'buzz' || i;
content.addChildren([
new paper.Path.Circle({
position: new paper.Point((100 + 15) * i + 50, view.center.y - 15),
position: new paper.Point((100 + 15) * i + 50, view.center.y),
radius: 50,
strokeWidth: 1,
strokeColor: LIGHT_GREY
}),
new paper.PointText({
point: new paper.Point((100 + 15) * i + 50, view.center.y + 10 - 15),
point: new paper.Point((100 + 15) * i + 50, view.center.y + 10),
content: textContent,
fillColor: LIGHT_GREY,
fontSize: 25,
Expand All @@ -54,21 +54,24 @@ export class MiscScrollbarHorizontalDemoComponent implements AfterViewInit {
content.translate(new paper.Point(VIEW_PADDING, 0));

// create scrollbar
const scrollbar = new ScrollbarComponent(
{ content: content, containerBounds: view.bounds, contentOffsetEnd: VIEW_PADDING },
new paper.Point(VIEW_PADDING, view.bounds.bottom - VIEW_PADDING - DEFAULT_SCROLLBAR_THICKNESS),
view.bounds.width - VIEW_PADDING * 2,
'horizontal'
const scrollbar = 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
);
if (scrollbar.isEnabled) {
canvas.onmouseenter = scrollbar.containerMouseEnter;
canvas.onmouseleave = scrollbar.containerMouseLeave;

// add scroll listening. paper doesn't have a wheel event handler
canvas.onwheel = (event: WheelEvent) => {
scrollbar.onScroll(event);
};
}

// add scroll listening. paper doesn't have a wheel event handler
canvas.onwheel = (event: WheelEvent) => {
scrollbar.onScroll(event);
};
// paper tools are global, so specific tools need to be activated when a different view is active
view.onMouseEnter = () => {
scrollbar.activateDefaultTool();
};
}

run() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { AfterViewInit, Component, ViewChild } from '@angular/core';
import * as paper from 'paper';
import { DemoComponent } from '../demo-component/demo.component';
import { LIGHT_GREY, CANVAS_BACKGROUND_COLOR, VAPP_BACKGROUND_COLOR } from '../../../../../src/constants/colors';
import { LIGHT_GREY, CANVAS_BACKGROUND_COLOR } from '../../../../../src/constants/colors';
import { ScrollbarComponent } from '../../../../../src/components/scrollbar';
import { DEFAULT_SCROLLBAR_THICKNESS } from '../../../../../src/constants/dimensions';

@Component({
selector: 'misc-scrollbar-vertical-demo',
Expand All @@ -26,7 +25,7 @@ export class MiscScrollbarVerticalDemoComponent implements AfterViewInit {
proj.activeLayer.applyMatrix = false;
this.demo.backgroundColor = CANVAS_BACKGROUND_COLOR;
const view = paper.view;
const canvas = this.demo.canvas.nativeElement;
const canvas = paper.view.element;
const VIEW_PADDING = 30;

// create content
Expand Down Expand Up @@ -54,20 +53,25 @@ export class MiscScrollbarVerticalDemoComponent implements AfterViewInit {
content.translate(new paper.Point(0, VIEW_PADDING));

// create scrollbar
const scrollbar = new ScrollbarComponent(
{ content: content, containerBounds: view.bounds, contentOffsetEnd: VIEW_PADDING },
new paper.Point(view.bounds.right - VIEW_PADDING - DEFAULT_SCROLLBAR_THICKNESS, VIEW_PADDING),
const scrollbar = new ScrollbarComponent({
content: content,
containerBounds: view.bounds,
contentOffsetEnd: VIEW_PADDING
},
new paper.Point(view.bounds.right - VIEW_PADDING, VIEW_PADDING),
view.bounds.height - VIEW_PADDING * 2,
'vertical');
'vertical'
);
if (scrollbar.isEnabled) {
canvas.onmouseenter = scrollbar.containerMouseEnter;
canvas.onmouseleave = scrollbar.containerMouseLeave;

// add scroll listening. paper doesn't have a wheel event handler
canvas.onwheel = (event: WheelEvent) => {
scrollbar.onScroll(event);
};
}

// add scroll listening. paper doesn't have a wheel event handler
canvas.onwheel = (event: WheelEvent) => {
scrollbar.onScroll(event);
};
// paper tools are global, so specific tools need to be activated when a different view is active
view.onMouseEnter = () => {
scrollbar.activateDefaultTool();
};
}

run() {
Expand Down
12 changes: 12 additions & 0 deletions demo/src/app/components/vapp-page-component/vapp-page.component.ts
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
}
}
Loading

0 comments on commit 4034463

Please sign in to comment.