2023-03-21 23:42:02 +08:00
|
|
|
import {
|
|
|
|
createEffect,
|
|
|
|
createSignal,
|
2023-03-26 22:39:47 +08:00
|
|
|
JSX,
|
2023-03-21 23:42:02 +08:00
|
|
|
onCleanup,
|
|
|
|
onMount,
|
|
|
|
ParentComponent,
|
|
|
|
} from 'solid-js';
|
2023-03-19 11:19:20 +08:00
|
|
|
import { displayStore, setDisplayStore } from '../stores/display.store';
|
2023-03-26 22:39:47 +08:00
|
|
|
import background from '../assets/transparent-grid-background.svg?url';
|
2023-03-19 11:19:20 +08:00
|
|
|
|
|
|
|
export const DisplayListContainer: ParentComponent = (props) => {
|
2023-03-21 23:42:02 +08:00
|
|
|
let root: HTMLElement;
|
2023-03-19 11:19:20 +08:00
|
|
|
const [olStyle, setOlStyle] = createSignal({
|
|
|
|
top: '0px',
|
|
|
|
left: '0px',
|
|
|
|
});
|
2023-03-26 22:39:47 +08:00
|
|
|
const [rootStyle, setRootStyle] = createSignal<JSX.CSSProperties>({
|
2023-03-19 11:19:20 +08:00
|
|
|
height: '100%',
|
|
|
|
});
|
2023-03-21 23:42:02 +08:00
|
|
|
const [bound, setBound] = createSignal({
|
|
|
|
left: 0,
|
|
|
|
top: 0,
|
|
|
|
right: 100,
|
|
|
|
bottom: 100,
|
|
|
|
});
|
|
|
|
|
|
|
|
const resetSize = () => {
|
|
|
|
const _bound = bound();
|
|
|
|
|
|
|
|
setDisplayStore({
|
|
|
|
viewScale: root.clientWidth / (_bound.right - _bound.left),
|
|
|
|
});
|
|
|
|
|
|
|
|
setOlStyle({
|
|
|
|
top: `${-_bound.top * displayStore.viewScale}px`,
|
|
|
|
left: `${-_bound.left * displayStore.viewScale}px`,
|
|
|
|
});
|
|
|
|
|
|
|
|
setRootStyle({
|
|
|
|
height: `${(_bound.bottom - _bound.top) * displayStore.viewScale}px`,
|
2023-03-26 22:39:47 +08:00
|
|
|
background: `url(${background})`,
|
2023-03-21 23:42:02 +08:00
|
|
|
});
|
|
|
|
};
|
2023-03-19 11:19:20 +08:00
|
|
|
|
|
|
|
createEffect(() => {
|
|
|
|
const boundLeft = Math.min(0, ...displayStore.displays.map((display) => display.x));
|
|
|
|
const boundTop = Math.min(0, ...displayStore.displays.map((display) => display.y));
|
|
|
|
const boundRight = Math.max(
|
|
|
|
0,
|
|
|
|
...displayStore.displays.map((display) => display.x + display.width),
|
|
|
|
);
|
|
|
|
const boundBottom = Math.max(
|
|
|
|
0,
|
|
|
|
...displayStore.displays.map((display) => display.y + display.height),
|
|
|
|
);
|
|
|
|
|
2023-03-21 23:42:02 +08:00
|
|
|
setBound({
|
|
|
|
left: boundLeft,
|
|
|
|
top: boundTop,
|
|
|
|
right: boundRight,
|
|
|
|
bottom: boundBottom,
|
2023-03-19 11:19:20 +08:00
|
|
|
});
|
2023-03-21 23:42:02 +08:00
|
|
|
let observer: ResizeObserver;
|
|
|
|
onMount(() => {
|
|
|
|
observer = new ResizeObserver(resetSize);
|
|
|
|
observer.observe(root);
|
2023-03-19 11:19:20 +08:00
|
|
|
});
|
|
|
|
|
2023-03-21 23:42:02 +08:00
|
|
|
onCleanup(() => {
|
|
|
|
observer?.unobserve(root);
|
2023-03-19 11:19:20 +08:00
|
|
|
});
|
|
|
|
});
|
2023-03-21 23:42:02 +08:00
|
|
|
|
|
|
|
createEffect(() => {});
|
|
|
|
|
2023-03-19 11:19:20 +08:00
|
|
|
return (
|
2023-03-21 23:42:02 +08:00
|
|
|
<section ref={root!} class="relative bg-gray-400/30" style={rootStyle()}>
|
2023-03-26 22:39:47 +08:00
|
|
|
<ol class="absolute" style={olStyle()}>
|
2023-03-19 11:19:20 +08:00
|
|
|
{props.children}
|
|
|
|
</ol>
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
};
|