From c87d4b8dda2b34cc5864833d5d7ec8cacdd5a934 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Mon, 22 Apr 2024 22:27:21 +0200 Subject: [PATCH] feat: style checkboxes better --- .../lib/graph-interface/graph/Graph.svelte | 4 +- app/src/lib/node-store/BreadCrumbs.svelte | 3 +- app/src/lib/runtime-executor.ts | 2 +- app/src/lib/settings/NestedSettings.svelte | 8 +- app/src/lib/settings/app-settings.ts | 10 ++- app/src/routes/+page.svelte | 4 +- packages/ui/src/lib/elements/Checkbox.svelte | 83 +++++++++++++++++++ packages/utils/src/flatTree.test.ts | 26 +++--- packages/utils/src/tree.rs | 19 +---- 9 files changed, 119 insertions(+), 40 deletions(-) diff --git a/app/src/lib/graph-interface/graph/Graph.svelte b/app/src/lib/graph-interface/graph/Graph.svelte index c107d06..25537e0 100644 --- a/app/src/lib/graph-interface/graph/Graph.svelte +++ b/app/src/lib/graph-interface/graph/Graph.svelte @@ -60,8 +60,8 @@ edges: [number, number, number, string][]; } = null; - let width = globalThis?.innerWidth ?? 100; - let height = globalThis?.innerHeight ?? 100; + let width = rect?.width ?? 100; + let height = rect?.height ?? 100; let cameraBounds = [-1000, 1000, -1000, 1000]; $: cameraBounds = [ diff --git a/app/src/lib/node-store/BreadCrumbs.svelte b/app/src/lib/node-store/BreadCrumbs.svelte index 87270c3..1881013 100644 --- a/app/src/lib/node-store/BreadCrumbs.svelte +++ b/app/src/lib/node-store/BreadCrumbs.svelte @@ -44,7 +44,8 @@ align-items: center; padding: 0.4em; gap: 0.8em; - height: 1em; + height: 35px; + box-sizing: border-box; border-bottom: solid thin var(--outline); } .breadcrumbs > button { diff --git a/app/src/lib/runtime-executor.ts b/app/src/lib/runtime-executor.ts index 13032ca..6470a1a 100644 --- a/app/src/lib/runtime-executor.ts +++ b/app/src/lib/runtime-executor.ts @@ -204,7 +204,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor { // console.log(`${a2 - a1}ms TRANSFORMED_INPUTS`); - const encoded_inputs = concatEncodedArrays(transformed_inputs); + const encoded_inputs = encodeNestedArray(transformed_inputs); const a3 = performance.now(); console.groupCollapsed(`executing ${node_type.id || node.id}`); console.log(`Inputs:`, transformed_inputs); diff --git a/app/src/lib/settings/NestedSettings.svelte b/app/src/lib/settings/NestedSettings.svelte index dc88dc0..3026784 100644 --- a/app/src/lib/settings/NestedSettings.svelte +++ b/app/src/lib/settings/NestedSettings.svelte @@ -1,6 +1,6 @@ + + + diff --git a/packages/utils/src/flatTree.test.ts b/packages/utils/src/flatTree.test.ts index c6d020a..a64e28e 100644 --- a/packages/utils/src/flatTree.test.ts +++ b/packages/utils/src/flatTree.test.ts @@ -1,15 +1,15 @@ import { expect, test } from 'vitest' -import { decode, encode, concat_encoded } from './flatTree' +import { decodeNestedArray, encodeNestedArray, concatEncodedArrays } from './flatTree' 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_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]); @@ -19,49 +19,49 @@ test("it correctly concats nested arrays", () => { // Original test case test('it correctly decodes/encodes complex nested arrays', () => { 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); }); // Test with empty array test('it correctly handles an empty array', () => { const input: number[] = []; - const decoded = decode(encode(input)); + const decoded = decodeNestedArray(encodeNestedArray(input)); expect(decoded).toEqual(input); }); // Test with nested empty arrays test('it correctly handles nested empty arrays', () => { const input = [5, [], [6, []], []]; - const decoded = decode(encode(input)); + const decoded = decodeNestedArray(encodeNestedArray(input)); expect(decoded).toEqual(input); }); // Test with single-element array test('it correctly handles a single-element array', () => { const input = [42]; - const decoded = decode(encode(input)); + const decoded = decodeNestedArray(encodeNestedArray(input)); expect(decoded).toEqual(input); }); // Test with deeply nested array test('it correctly handles deeply nested arrays', () => { const input = [[[[[1]]]]]; - const decoded = decode(encode(input)); + const decoded = decodeNestedArray(encodeNestedArray(input)); expect(decoded).toEqual(input); }); // Test with large numbers test('it correctly handles large numbers', () => { const input = [2147483647, [-2147483648, 1234567890]]; - const decoded = decode(encode(input)); + const decoded = decodeNestedArray(encodeNestedArray(input)); expect(decoded).toEqual(input); }); // Test with sequential nesting test('it correctly handles sequential nesting', () => { const input = [1, [2, [3, [4, [5]]]]]; - const decoded = decode(encode(input)); + const decoded = decodeNestedArray(encodeNestedArray(input)); expect(decoded).toEqual(input); }); @@ -71,6 +71,6 @@ test('it correctly handles sequential nesting', () => { test('it correctly handles arrays with mixed data types', () => { const input = [1, 'text', [true, [null, ['another text']]]]; //@ts-ignore - const decoded = decode(encode(input)); + const decoded = decodeNestedArray(encodeNestedArray(input)); expect(decoded).toEqual(input); }); diff --git a/packages/utils/src/tree.rs b/packages/utils/src/tree.rs index 7dd368c..600acb2 100644 --- a/packages/utils/src/tree.rs +++ b/packages/utils/src/tree.rs @@ -39,9 +39,6 @@ pub fn get_args(args: &[i32]) -> Vec<&[i32]> { // skip over the bracket encoding idx += 2; } else { - if depth == 1 { - arg_start_index = idx + 2; - } // skip to the next bracket if we are at depth > 0 idx = next_bracket_index; } @@ -60,12 +57,6 @@ pub fn get_args(args: &[i32]) -> Vec<&[i32]> { 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 } @@ -111,8 +102,6 @@ pub fn wrap_arg(arg: &[i32]) -> Vec { pub fn evaluate_node(input_args: &[i32]) -> i32 { let node_type = input_args[0]; - println!("node_type: {} -> {:?}", node_type, input_args); - match node_type { 0 => crate::nodes::math_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); - println!("args: {:?}", args); - let mut resolved: Vec = Vec::new(); for arg in args { @@ -194,7 +181,7 @@ mod tests { // 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, 1053609165, 54 @@ -204,7 +191,7 @@ mod tests { let args = get_args(&input); println!("{:?}", args[0]); - assert_eq!(args[0].len(), 27); + assert_eq!(args[0].len(), 29); assert_eq!(args[1][0], 1086324736); assert_eq!(args[2][0], 1053609165); } @@ -230,6 +217,8 @@ mod tests { let args = get_args(&input_a); + println!("{:?}", args); + assert_eq!(args.len(), 4); assert_eq!(args[0], [1]); assert_eq!(args[1], [2]);