Show different mouse cursor when zoomed in.

This commit is contained in:
Dermot Duffy
2023-05-06 13:14:04 -07:00
parent a0f2ed1bab
commit 2b1f0f5d85
2 changed files with 32 additions and 3 deletions
+29 -2
View File
@@ -1,20 +1,43 @@
import { css, CSSResultGroup, html, LitElement, TemplateResult } from 'lit'; import {
import { customElement } from 'lit/decorators.js'; css,
CSSResultGroup,
html,
LitElement,
PropertyValues,
TemplateResult,
} from 'lit';
import { customElement, state } from 'lit/decorators.js';
import { setOrRemoveAttribute } from '../utils/basic.js';
import { Zoom } from '../utils/zoom/zoom.js'; import { Zoom } from '../utils/zoom/zoom.js';
@customElement('frigate-card-zoomer') @customElement('frigate-card-zoomer')
export class FrigateCardZoomer extends LitElement { export class FrigateCardZoomer extends LitElement {
protected _zoom = new Zoom(this); protected _zoom = new Zoom(this);
@state()
protected _zoomed = false;
protected _zoomHandler = () => (this._zoomed = true);
protected _unzoomHandler = () => (this._zoomed = false);
connectedCallback(): void { connectedCallback(): void {
super.connectedCallback(); super.connectedCallback();
this.addEventListener('frigate-card:zoom:zoomed', this._zoomHandler);
this.addEventListener('frigate-card:zoom:unzoomed', this._unzoomHandler);
this._zoom.activate(); this._zoom.activate();
} }
disconnectedCallback(): void { disconnectedCallback(): void {
this._zoom.deactivate(); this._zoom.deactivate();
this.removeEventListener('frigate-card:zoom:zoomed', this._zoomHandler);
this.removeEventListener('frigate-card:zoom:unzoomed', this._unzoomHandler);
} }
protected willUpdate(changedProps: PropertyValues): void {
if (changedProps.has('_zoomed')) {
setOrRemoveAttribute(this, this._zoomed, 'zoomed');
}
}
protected render(): TemplateResult | void { protected render(): TemplateResult | void {
return html` <slot></slot> `; return html` <slot></slot> `;
} }
@@ -25,6 +48,10 @@ export class FrigateCardZoomer extends LitElement {
width: 100%; width: 100%;
height: 100%; height: 100%;
display: block; display: block;
cursor: auto;
}
:host([zoomed]) {
cursor: move;
} }
`; `;
} }
+3 -1
View File
@@ -75,7 +75,9 @@ export class Zoom {
maxScale: 10, maxScale: 10,
minScale: 1, minScale: 1,
noBind: true, noBind: true,
cursor: 'auto', // Do not force the cursor style (by default it will always show the
// 'move' type cursor whether or not it is zoomed in).
cursor: undefined,
}); });
const registerListeners = ( const registerListeners = (