import { invoke } from '@tauri-apps/api'; import { Component, createEffect, createMemo, createRoot, createSignal, For, JSX, splitProps, useContext, } from 'solid-js'; import { useTippy } from 'solid-tippy'; import { followCursor } from 'tippy.js'; import { LedStripConfig } from '../../models/led-strip-config'; import { LedStripConfigurationContext } from '../../contexts/led-strip-configuration.context'; import { ledStripStore } from '../../stores/led-strip.store'; type LedStripPartProps = { config?: LedStripConfig | null; } & JSX.HTMLAttributes; type PixelProps = { color: string; }; export const Pixel: Component = (props) => { const style = createMemo(() => ({ background: props.color, })); return (
); }; export const LedStripPart: Component = (props) => { const [localProps, rootProps] = splitProps(props, ['config']); const [stripConfiguration] = useContext(LedStripConfigurationContext); const [colors, setColors] = createSignal([]); // update led strip colors from global store createEffect(() => { if (!localProps.config) { return; } const index = ledStripStore.strips.findIndex( (s) => s.display_id === localProps.config!.display_id && s.border === localProps.config!.border, ); if (index === -1) { return; } const mapper = ledStripStore.mappers[index]; if (!mapper) { return; } const offset = mapper.pos * 3; const colors = new Array(localProps.config.len).fill(null).map((_, i) => { const index = offset + i * 3; return `rgb(${ledStripStore.colors[index]}, ${ledStripStore.colors[index + 1]}, ${ ledStripStore.colors[index + 2] })`; }); setColors(colors); }); const [anchor, setAnchor] = createSignal(); useTippy(anchor, { hidden: true, props: { trigger: 'mouseenter focus', followCursor: true, plugins: [followCursor], content: () => createRoot(() => { return ( Count: {localProps.config?.len ?? '--'} ); }) as Element, }, }); const onWheel = (e: WheelEvent) => { if (localProps.config) { invoke('patch_led_strip_len', { displayId: localProps.config.display_id, border: localProps.config.border, deltaLen: e.deltaY > 0 ? 1 : -1, }) .then(() => {}) .catch((e) => { console.error(e); }); } }; return (
{(item) => }
); };