Refactored plan-display a bit..

merge-notes
isark 2 years ago
parent bd8cfb573c
commit af09d88360

@ -1,14 +1,11 @@
<div class="target" [style.background-color]="backgroundColor ? backgroundColor.rgbaString : 'rgba(0, 0, 0, 0.1)'" #targetRef> <ng-container *ngIf="rect">
<div class="target" [style.background-color]="backgroundColor ? backgroundColor.rgbaString : 'rgba(0, 0, 0, 0.1)'"
[style.transform]="transform()" [style.width]="rect.width + 'px'" [style.height]="rect.height + 'px'" #targetRef>
<ng-container *ngIf="plan"> <ng-container *ngIf="plan">
Has Plan! Has Plan!
</ng-container> </ng-container>
</div> </div>
<ngx-moveable
[target]="targetRef" <ngx-moveable [target]="targetRef" [draggable]="draggable" [resizable]="true" (drag)="onDrag($event)"
[draggable]="draggable" (resize)="onResize($event)" (dragEnd)="onDragEnd($event)" (resizeEnd)="onResizeEnd($event)"></ngx-moveable>
[resizable]="true" </ng-container>
(drag)="onDrag($event)"
(resize)="onResize($event)"
(dragEnd)="onDragEnd($event)"
(resizeEnd)="onResizeEnd($event)"
#moveableRef></ngx-moveable>

@ -1,87 +1,61 @@
import { AfterViewInit, Component, Input, OnInit, ViewChild } from '@angular/core'; import { AfterViewInit, ChangeDetectorRef, Component, Input, OnInit, ViewChild } from '@angular/core';
import { NgxMoveableComponent, OnDragEnd, OnResize, OnResizeEnd } from 'ngx-moveable'; import { NgxMoveableComponent, OnDragEnd, OnResize, OnResizeEnd } from 'ngx-moveable';
import { OnDrag } from 'ngx-moveable'; import { OnDrag } from 'ngx-moveable';
import { ConfigService } from '../services/config.service'; import { ConfigService } from '../services/config.service';
import { Rect } from '../models/generated/Rect'; import { Rect } from '../models/generated/Rect';
import { Plan } from '../models/plan'; import { Plan } from '../models/plan';
import { Color } from '../color-picker/color-picker.component'; import { Color } from '../color-picker/color-picker.component';
import { Subject } from 'rxjs';
@Component({ @Component({
selector: 'plan-display', selector: 'plan-display',
templateUrl: './plan-display.component.html', templateUrl: './plan-display.component.html',
styleUrls: ['./plan-display.component.scss'] styleUrls: ['./plan-display.component.scss']
}) })
export class PlanDisplayComponent implements OnInit, AfterViewInit { export class PlanDisplayComponent implements AfterViewInit {
@ViewChild('targetRef') targetRef: any;
@Input() plan: boolean = false;
@Input() backgroundColor?: Color;
draggable: boolean = true; draggable: boolean = true;
initialized: boolean = false; rect?: Rect;
@Input() constructor(private configService: ConfigService, private cdr: ChangeDetectorRef) { }
plan: boolean = false;
@Input()
backgroundColor?: Color;
@ViewChild("moveableRef")
moveableRef!: NgxMoveableComponent;
constructor(private configService: ConfigService) {}
ngOnInit(): void {
transform() {
return `translate(${this.rect!.x}px, ${this.rect!.y}px)`;
} }
ngAfterViewInit(): void { width() {
let init = this.configService.config.initialPlanWindowPosition; return `${this.rect!.width}px`;
this.setPosition(init.x, init.y);
this.setArea(init.width, init.height);
this.initialized = true;
console.log("init: ", init);
console.log("cfg at init: ", this.configService.config);
} }
setPosition(x: number, y: number) { height() {
this.moveableRef.request("draggable", { return `${this.rect!.height}px`;
x,
y,
}, true);
} }
setArea(width: number, height: number) { ngAfterViewInit(): void {
this.moveableRef.request("resizable", { this.rect = this.configService.config.initialPlanWindowPosition;
offsetWidth: width, this.cdr.detectChanges();
offsetHeight: height,
}, true);
}
toRect(): Rect {
let rectInfo = this.moveableRef.getRect();
return {
x: rectInfo.left,
y: rectInfo.top,
width: rectInfo.width,
height: rectInfo.height
};
} }
onDrag(e: OnDrag) { onDrag(e: OnDrag) {
e.target.style.transform = e.transform; this.rect!.x = e.translate[0];
this.rect!.y = e.translate[1];
} }
onDragEnd(e: OnDragEnd) { onDragEnd(e: OnDragEnd) {
if (this.initialized) { this.configService.config.initialPlanWindowPosition = this.rect!;
this.configService.config.initialPlanWindowPosition = this.toRect();
}
} }
onResize(e: OnResize) { onResize(e: OnResize) {
e.target.style.width = `${e.width}px`; this.rect!.width = e.width;
e.target.style.height = `${e.height}px`; this.rect!.height = e.height;
e.target.style.transform = e.drag.transform; this.onDrag(e.drag);
console.log(e.style);
} }
onResizeEnd(e: OnResizeEnd) { onResizeEnd(e: OnResizeEnd) {
if (this.initialized) { this.configService.config.initialPlanWindowPosition = this.rect!;
this.configService.config.initialPlanWindowPosition = this.toRect();
}
} }
} }

@ -19,8 +19,6 @@ export class ConfigService {
init() { init() {
return invoke<Config>('load_config').then(cfg => { return invoke<Config>('load_config').then(cfg => {
const _this = this; const _this = this;
// Mostly to wrap setters so we can run the (debounced) sync function on any config changes! // Mostly to wrap setters so we can run the (debounced) sync function on any config changes!
this.config = new Proxy(cfg, { this.config = new Proxy(cfg, {
get(target: any, property) { get(target: any, property) {
@ -34,9 +32,6 @@ export class ConfigService {
} }
}); });
console.log("Loaded cfg:", this.config);
console.log("Loaded x:", this.config.initialPlanWindowPosition.x);
}); });
} }
@ -45,7 +40,6 @@ export class ConfigService {
} }
private underlyingSync() { private underlyingSync() {
console.log("saving config");
invoke('set_config', { config: this.config }); invoke('set_config', { config: this.config });
} }
} }

@ -20,7 +20,6 @@ export class OverlayService {
constructor(private shortcuts: ShortcutService, private events: EventsService, private configService: ConfigService) { constructor(private shortcuts: ShortcutService, private events: EventsService, private configService: ConfigService) {
console.log("cfg", configService);
this.shortcuts.register(this.configService.config.toggleOverlay, this.onToggleOverlay); this.shortcuts.register(this.configService.config.toggleOverlay, this.onToggleOverlay);
this.events.listen<StateEvent>("OverlayStateChange").subscribe(this.onOverlayStateChange); this.events.listen<StateEvent>("OverlayStateChange").subscribe(this.onOverlayStateChange);
} }
@ -46,7 +45,6 @@ export class OverlayService {
return acc.concat('+').concat(curr); return acc.concat('+').concat(curr);
}, ''); }, '');
console.log(chord);
this.shortcuts.rebind(chord, this.onToggleOverlay); this.shortcuts.rebind(chord, this.onToggleOverlay);
} }

Loading…
Cancel
Save