feat: style checkboxes better

This commit is contained in:
max_richter 2024-04-22 22:27:21 +02:00
parent 1de0094c85
commit c87d4b8dda
9 changed files with 119 additions and 40 deletions

View File

@ -60,8 +60,8 @@
edges: [number, number, number, string][]; edges: [number, number, number, string][];
} = null; } = null;
let width = globalThis?.innerWidth ?? 100; let width = rect?.width ?? 100;
let height = globalThis?.innerHeight ?? 100; let height = rect?.height ?? 100;
let cameraBounds = [-1000, 1000, -1000, 1000]; let cameraBounds = [-1000, 1000, -1000, 1000];
$: cameraBounds = [ $: cameraBounds = [

View File

@ -44,7 +44,8 @@
align-items: center; align-items: center;
padding: 0.4em; padding: 0.4em;
gap: 0.8em; gap: 0.8em;
height: 1em; height: 35px;
box-sizing: border-box;
border-bottom: solid thin var(--outline); border-bottom: solid thin var(--outline);
} }
.breadcrumbs > button { .breadcrumbs > button {

View File

@ -204,7 +204,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
// console.log(`${a2 - a1}ms TRANSFORMED_INPUTS`); // console.log(`${a2 - a1}ms TRANSFORMED_INPUTS`);
const encoded_inputs = concatEncodedArrays(transformed_inputs); const encoded_inputs = encodeNestedArray(transformed_inputs);
const a3 = performance.now(); const a3 = performance.now();
console.groupCollapsed(`executing ${node_type.id || node.id}`); console.groupCollapsed(`executing ${node_type.id || node.id}`);
console.log(`Inputs:`, transformed_inputs); console.log(`Inputs:`, transformed_inputs);

View File

@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import type { NodeInput } from "@nodes/types"; import type { NodeInput } from "@nodes/types";
import Input, { Details } from "@nodes/ui"; import Input from "@nodes/ui";
import type { Writable } from "svelte/store"; import type { Writable } from "svelte/store";
interface Nested { interface Nested {
@ -11,7 +11,7 @@
export let store: Writable<Record<string, any>>; export let store: Writable<Record<string, any>>;
export let depth = 0; export let depth = 0;
const keys = Object.keys(settings); const keys = Object.keys(settings).filter((key) => key !== "__title");
function isNodeInput(v: NodeInput | Nested): v is NodeInput { function isNodeInput(v: NodeInput | Nested): v is NodeInput {
return "type" in v; return "type" in v;
} }
@ -24,7 +24,7 @@
<div class="input input-{settings[key].type}"> <div class="input input-{settings[key].type}">
{#if settings[key].type === "button"} {#if settings[key].type === "button"}
<button on:click={() => settings[key]?.callback?.()} <button on:click={() => settings[key]?.callback?.()}
>{key || settings[key].label}</button >{settings[key].label || key}</button
> >
{:else} {:else}
<label for={key}>{settings[key].label || key}</label> <label for={key}>{settings[key].label || key}</label>
@ -37,7 +37,7 @@
</div> </div>
{:else} {:else}
<details> <details>
<summary>{key}</summary> <summary>{settings[key]?.__title || key}</summary>
<div class="content"> <div class="content">
<svelte:self settings={settings[key]} {store} depth={depth + 1} /> <svelte:self settings={settings[key]} {store} depth={depth + 1} />
</div> </div>

View File

@ -35,26 +35,32 @@ export const AppSettingTypes = {
value: true, value: true,
}, },
nodeInterface: { nodeInterface: {
__title: "Node Interface",
showNodeGrid: { showNodeGrid: {
type: "boolean", type: "boolean",
label: "Show Grid",
value: true value: true
}, },
snapToGrid: { snapToGrid: {
type: "boolean", type: "boolean",
label: "Snap to Grid",
value: true value: true
} }
}, },
stressTest: { stressTest: {
__title: "Stress Test",
amount: { amount: {
type: "integer", type: "integer",
min: 2, min: 2,
max: 15 max: 15
}, },
loadGrid: { loadGrid: {
type: "button" type: "button",
label: "Load Grid"
}, },
loadTree: { loadTree: {
type: "button" type: "button",
label: "Load Tree"
}, },
}, },
debug: { debug: {

View File

@ -138,7 +138,7 @@
<style> <style>
header { header {
border-bottom: solid thin var(--outline); /* border-bottom: solid thin var(--outline); */
background-color: var(--layer-1); background-color: var(--layer-1);
} }
@ -147,7 +147,7 @@
width: 100vw; width: 100vw;
color: white; color: white;
display: grid; display: grid;
grid-template-rows: 50px 1fr; grid-template-rows: 0px 1fr;
} }
.wrapper :global(canvas) { .wrapper :global(canvas) {

View File

@ -11,3 +11,86 @@
</script> </script>
<input {id} type="checkbox" bind:checked={value} /> <input {id} type="checkbox" bind:checked={value} />
<label for={id}>
<svg viewBox="0 0 19 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M2 7L7 12L17 2"
stroke="currentColor"
stroke-width="3"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
</label>
<style>
input[type="checkbox"] {
position: absolute;
overflow: hidden;
clip: rect(0 0 0 0);
height: 1px;
width: 1px;
margin: -1px;
padding: 0;
border: 0;
}
#inputPreview {
display: flex;
gap: 20px;
justify-content: center;
}
input + label {
position: relative;
font-size: 14px;
cursor: pointer;
display: inline-flex;
align-items: center;
height: 22px;
color: rgb(0, 0, 0);
}
input + label::before {
content: " ";
display: inline;
vertical-align: middle;
margin-right: 3px;
width: 22px;
height: 22px;
background-color: var(--layer-2);
border-radius: 5px;
border: none;
box-shadow: none;
}
input:checked + label::after {
content: " ";
background-repeat: no-repeat;
background-size: 12px 12px;
background-position: center center;
position: absolute;
display: flex;
justify-content: center;
align-items: center;
margin-left: 0px;
left: 0px;
top: 0px;
text-align: center;
background-color: transparent;
color: red;
font-size: 10px;
height: 22px;
width: 22px;
}
input + label > svg {
position: absolute;
display: none;
width: 12px;
height: 10px;
left: 5px;
color: var(--text-color);
top: 5.9px;
}
input:checked + label > svg {
display: block;
}
</style>

View File

@ -1,15 +1,15 @@
import { expect, test } from 'vitest' import { expect, test } from 'vitest'
import { decode, encode, concat_encoded } from './flatTree' import { decodeNestedArray, encodeNestedArray, concatEncodedArrays } from './flatTree'
test("it correctly concats nested arrays", () => { test("it correctly concats nested arrays", () => {
const input_a = encode([1, 2, 3]); const input_a = encodeNestedArray([1, 2, 3]);
const input_b = 2; const input_b = 2;
const input_c = encode([4, 5, 6]); const input_c = encodeNestedArray([4, 5, 6]);
const output = concat_encoded([input_a, input_b, input_c]); const output = concatEncodedArrays([input_a, input_b, input_c]);
const decoded = decode(output); const decoded = decodeNestedArray(output);
expect(decoded[0]).toEqual([1, 2, 3]); expect(decoded[0]).toEqual([1, 2, 3]);
@ -19,49 +19,49 @@ test("it correctly concats nested arrays", () => {
// Original test case // Original test case
test('it correctly decodes/encodes complex nested arrays', () => { test('it correctly decodes/encodes complex nested arrays', () => {
const input = [5, [6, 1], 1, 5, [5], [7, 2, [5, 1]]]; const input = [5, [6, 1], 1, 5, [5], [7, 2, [5, 1]]];
const decoded = decode(encode(input)); const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input); expect(decoded).toEqual(input);
}); });
// Test with empty array // Test with empty array
test('it correctly handles an empty array', () => { test('it correctly handles an empty array', () => {
const input: number[] = []; const input: number[] = [];
const decoded = decode(encode(input)); const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input); expect(decoded).toEqual(input);
}); });
// Test with nested empty arrays // Test with nested empty arrays
test('it correctly handles nested empty arrays', () => { test('it correctly handles nested empty arrays', () => {
const input = [5, [], [6, []], []]; const input = [5, [], [6, []], []];
const decoded = decode(encode(input)); const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input); expect(decoded).toEqual(input);
}); });
// Test with single-element array // Test with single-element array
test('it correctly handles a single-element array', () => { test('it correctly handles a single-element array', () => {
const input = [42]; const input = [42];
const decoded = decode(encode(input)); const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input); expect(decoded).toEqual(input);
}); });
// Test with deeply nested array // Test with deeply nested array
test('it correctly handles deeply nested arrays', () => { test('it correctly handles deeply nested arrays', () => {
const input = [[[[[1]]]]]; const input = [[[[[1]]]]];
const decoded = decode(encode(input)); const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input); expect(decoded).toEqual(input);
}); });
// Test with large numbers // Test with large numbers
test('it correctly handles large numbers', () => { test('it correctly handles large numbers', () => {
const input = [2147483647, [-2147483648, 1234567890]]; const input = [2147483647, [-2147483648, 1234567890]];
const decoded = decode(encode(input)); const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input); expect(decoded).toEqual(input);
}); });
// Test with sequential nesting // Test with sequential nesting
test('it correctly handles sequential nesting', () => { test('it correctly handles sequential nesting', () => {
const input = [1, [2, [3, [4, [5]]]]]; const input = [1, [2, [3, [4, [5]]]]];
const decoded = decode(encode(input)); const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input); expect(decoded).toEqual(input);
}); });
@ -71,6 +71,6 @@ test('it correctly handles sequential nesting', () => {
test('it correctly handles arrays with mixed data types', () => { test('it correctly handles arrays with mixed data types', () => {
const input = [1, 'text', [true, [null, ['another text']]]]; const input = [1, 'text', [true, [null, ['another text']]]];
//@ts-ignore //@ts-ignore
const decoded = decode(encode(input)); const decoded = decodeNestedArray(encodeNestedArray(input));
expect(decoded).toEqual(input); expect(decoded).toEqual(input);
}); });

View File

@ -39,9 +39,6 @@ pub fn get_args(args: &[i32]) -> Vec<&[i32]> {
// skip over the bracket encoding // skip over the bracket encoding
idx += 2; idx += 2;
} else { } else {
if depth == 1 {
arg_start_index = idx + 2;
}
// skip to the next bracket if we are at depth > 0 // skip to the next bracket if we are at depth > 0
idx = next_bracket_index; idx = next_bracket_index;
} }
@ -60,12 +57,6 @@ pub fn get_args(args: &[i32]) -> Vec<&[i32]> {
idx += 1; idx += 1;
} }
println!("idx: {}, length: {}, asi: {}", idx, length, arg_start_index);
if arg_start_index < length {
out_args.push(&args[arg_start_index..]);
}
out_args out_args
} }
@ -111,8 +102,6 @@ pub fn wrap_arg(arg: &[i32]) -> Vec<i32> {
pub fn evaluate_node(input_args: &[i32]) -> i32 { pub fn evaluate_node(input_args: &[i32]) -> i32 {
let node_type = input_args[0]; let node_type = input_args[0];
println!("node_type: {} -> {:?}", node_type, input_args);
match node_type { match node_type {
0 => crate::nodes::math_node(&input_args[1..]), 0 => crate::nodes::math_node(&input_args[1..]),
1 => crate::nodes::random_node(&input_args[1..]), 1 => crate::nodes::random_node(&input_args[1..]),
@ -156,8 +145,6 @@ pub fn evaluate_int(input_args: &[i32]) -> i32 {
let args = get_args(input_args); let args = get_args(input_args);
println!("args: {:?}", args);
let mut resolved: Vec<i32> = Vec::new(); let mut resolved: Vec<i32> = Vec::new();
for arg in args { for arg in args {
@ -194,7 +181,7 @@ mod tests {
// this should be the output // this should be the output
/* [ /* [
[ 0, 2, 1048576000, 0, 20, 0, 4, 0, 0, 1073741824, 0, 9, 0, 5, 0, 0, 1073741824, 1073741824, 1, 1, 1, 0, 1, 1, 1, 4, 1041865114 ], [ 0, 28, 0, 2, 1048576000, 0, 20, 0, 4, 0, 0, 1073741824, 0, 9, 0, 5, 0, 0, 1073741824, 1073741824, 1, 1, 1, 0, 1, 1, 1, 4, 1041865114 ],
1086324736, 1086324736,
1053609165, 1053609165,
54 54
@ -204,7 +191,7 @@ mod tests {
let args = get_args(&input); let args = get_args(&input);
println!("{:?}", args[0]); println!("{:?}", args[0]);
assert_eq!(args[0].len(), 27); assert_eq!(args[0].len(), 29);
assert_eq!(args[1][0], 1086324736); assert_eq!(args[1][0], 1086324736);
assert_eq!(args[2][0], 1053609165); assert_eq!(args[2][0], 1053609165);
} }
@ -230,6 +217,8 @@ mod tests {
let args = get_args(&input_a); let args = get_args(&input_a);
println!("{:?}", args);
assert_eq!(args.len(), 4); assert_eq!(args.len(), 4);
assert_eq!(args[0], [1]); assert_eq!(args[0], [1]);
assert_eq!(args[1], [2]); assert_eq!(args[1], [2]);