From 4168c645ec1a4194523d6d46e3e92e6ade316d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kav=C3=ADk?= Date: Sat, 8 Jun 2024 01:11:18 +0200 Subject: [PATCH] convert_base --- Cargo.lock | 8 ++++++++ Cargo.toml | 1 + frontend/Cargo.toml | 1 + frontend/typescript/bundles/pixi_canvas.js | 2 +- frontend/typescript/pixi_canvas/pixi_canvas.ts | 3 +-- src-tauri/Cargo.toml | 1 + src-tauri/src/lib.rs | 11 +++++++---- 7 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ccbf6f9..1100ddb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -859,6 +859,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "convert-base" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e56a404f2112d00ba80a516b60ca3744ef6bd776baa14126eb7d7c11b42cac8a" + [[package]] name = "convert_case" version = "0.4.0" @@ -1414,6 +1420,7 @@ checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" name = "fastwave" version = "0.1.0" dependencies = [ + "convert-base", "serde", "serde_json", "shared", @@ -1499,6 +1506,7 @@ dependencies = [ name = "frontend" version = "0.1.0" dependencies = [ + "convert-base", "gloo-file", "shared", "wasm-bindgen-test", diff --git a/Cargo.toml b/Cargo.toml index 5ab2fb1..6ca9a5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ readme = "../README.md" publish = false [workspace.dependencies] +convert-base = "1.1.2" # wellen = { version = "0.9.9", features = ["serde1"] } # wellen = { path = "../wellen/wellen", features = ["serde1"] } wellen = { git = "https://github.com/MartinKavik/wellen", features = ["serde1"], branch = "new_pub_types" } diff --git a/frontend/Cargo.toml b/frontend/Cargo.toml index 930650e..7ba178a 100644 --- a/frontend/Cargo.toml +++ b/frontend/Cargo.toml @@ -13,6 +13,7 @@ wasm-bindgen-test = "0.3.19" [dependencies] zoon.workspace = true wellen.workspace = true +convert-base.workspace = true shared = { path = "../shared", features = ["frontend"] } web-sys = { version = "*", features = ["FileSystemFileHandle"] } gloo-file = { version = "0.3.0", features = ["futures"] } diff --git a/frontend/typescript/bundles/pixi_canvas.js b/frontend/typescript/bundles/pixi_canvas.js index c3da669..435ea5f 100644 --- a/frontend/typescript/bundles/pixi_canvas.js +++ b/frontend/typescript/bundles/pixi_canvas.js @@ -35152,12 +35152,12 @@ var PixiController = class { // Default automatic Pixi resizing according to the parent is not reliable // and the `app.renderer`'s `resize` event is fired on every browser window size change async resize(width, height) { + this.app.resize(); const width_changed = width !== this.previous_parent_width; this.previous_parent_width = width; if (width_changed) { await this.redraw_rows(); } - this.app.resize(); } destroy() { const rendererDestroyOptions = { diff --git a/frontend/typescript/pixi_canvas/pixi_canvas.ts b/frontend/typescript/pixi_canvas/pixi_canvas.ts index 05cc623..0bbf883 100644 --- a/frontend/typescript/pixi_canvas/pixi_canvas.ts +++ b/frontend/typescript/pixi_canvas/pixi_canvas.ts @@ -46,14 +46,13 @@ export class PixiController { // Default automatic Pixi resizing according to the parent is not reliable // and the `app.renderer`'s `resize` event is fired on every browser window size change async resize(width: number, height: number) { + this.app.resize(); // -- FastWave-specific -- const width_changed = width !== this.previous_parent_width; this.previous_parent_width = width; if (width_changed) { await this.redraw_rows(); } - // -- // -- - this.app.resize(); } destroy() { diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 490242c..66394d0 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -17,6 +17,7 @@ tauri-build = { version = "=2.0.0-beta.17", features = [] } [dependencies] wellen.workspace = true +convert-base.workspace = true shared = { path = "../shared", features = ["backend"] } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index db2b806..7ea748d 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -116,8 +116,8 @@ fn signal_to_timeline( }) .peekable(); + // @TODO parallelize? let mut blocks = Vec::new(); - while let Some((block_x, value)) = x_value_pairs.next() { let next_block_x = if let Some((next_block_x, _)) = x_value_pairs.peek() { *next_block_x @@ -130,10 +130,13 @@ fn signal_to_timeline( continue; } - let value = value.to_string(); // @TODO dynamic formatter - let value = u128::from_str_radix(&value, 2).unwrap(); - let value = format!("{value:x}"); + // @TODO optimize it by not using `.to_string` if possible + let value = value.to_string(); + let ones_and_zeros = value.chars().rev().map(|char| char.to_digit(2).unwrap()).collect::>(); + let mut base = convert_base::Convert::new(2, 16); + let output = base.convert::(&ones_and_zeros); + let value: String = output.into_iter().map(|number| char::from_digit(number, 16).unwrap()).collect(); let value_width = value.chars().count() as u32 * LETTER_WIDTH; let label = if (value_width + (2 * LABEL_X_PADDING)) <= block_width {