Compare commits

..

No commits in common. "d592c746549d7436e20fe53a7f1be5f6d745565c" and "d641610fbfec5b35fcf6b508b09aae61805590d8" have entirely different histories.

7 changed files with 92 additions and 91 deletions

51
Cargo.lock generated
View File

@ -136,12 +136,6 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6"
[[package]]
name = "bincode"
version = "1.3.3"
@ -1220,9 +1214,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.81"
version = "0.3.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305"
checksum = "464a3709c7f55f1f721e5389aa6ea4e3bc6aba669353300af094b29ffbdde1d8"
dependencies = [
"once_cell",
"wasm-bindgen",
@ -2916,9 +2910,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen"
version = "0.2.104"
version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d"
checksum = "0d759f433fa64a2d763d1340820e46e111a7a5ab75f993d1852d70b03dbb80fd"
dependencies = [
"cfg-if",
"once_cell",
@ -2927,25 +2921,11 @@ dependencies = [
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19"
dependencies = [
"bumpalo",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-futures"
version = "0.4.54"
version = "0.4.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e038d41e478cc73bae0ff9b36c60cff1c98b8f38f8d7e8061e79ee63608ac5c"
checksum = "836d9622d604feee9e5de25ac10e3ea5f2d65b41eac0d9ce72eb5deae707ce7c"
dependencies = [
"cfg-if",
"js-sys",
@ -2956,9 +2936,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.104"
version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119"
checksum = "48cb0d2638f8baedbc542ed444afc0644a29166f1595371af4fecf8ce1e7eeb3"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@ -2966,22 +2946,22 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.104"
version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7"
checksum = "cefb59d5cd5f92d9dcf80e4683949f15ca4b511f4ac0a6e14d4e1ac60c6ecd40"
dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.104"
version = "0.2.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1"
checksum = "cbc538057e648b67f72a982e708d485b2efa771e1ac05fec311f9f63e5800db4"
dependencies = [
"unicode-ident",
]
@ -3110,9 +3090,9 @@ dependencies = [
[[package]]
name = "web-sys"
version = "0.3.81"
version = "0.3.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9367c417a924a74cae129e6a2ae3b47fabb1f8995595ab474029da749a8be120"
checksum = "9b32828d774c412041098d182a8b38b16ea816958e07cf40eec2bc080ae137ac"
dependencies = [
"js-sys",
"wasm-bindgen",
@ -3700,7 +3680,6 @@ dependencies = [
name = "ytbn_graphing_software"
version = "0.1.0"
dependencies = [
"base64",
"bincode",
"cfg-if",
"const_format",

View File

@ -57,7 +57,6 @@ static_assertions = "1.1"
bincode = "1.3"
serde = "1"
log = "0.4"
base64 = "0.22"
# Note: benchmarks are in a separate crate - run with:
# cd benchmarks && cargo bench
@ -90,8 +89,7 @@ wasm-bindgen = { version = "0.2", default-features = false, features = ["std"] }
web-sys = "0.3"
tracing-wasm = "0.2"
getrandom = { version = "0.3", features = ["wasm_js"] }
# pinned to 0.4.54 because nix provides up to 0.2.104 wasm-bindgen-cli
wasm-bindgen-futures = "=0.4.54"
wasm-bindgen-futures = "0.4"
[package.metadata.cargo-all-features]
skip_optional_dependencies = true #don't test optional dependencies, only features

8
flake.lock generated
View File

@ -65,17 +65,17 @@
"simon-egui": {
"flake": false,
"locked": {
"lastModified": 1764740756,
"narHash": "sha256-CX0v82hDmLSEx5uFViWvfJaeADFJKR0G+MJYFFQcxng=",
"lastModified": 1764730109,
"narHash": "sha256-vNETC0oq6tKJKF8KOGQKKIWRom38m0RwGgi3MPBrRx8=",
"owner": "Titaniumtown",
"repo": "egui",
"rev": "217d3f250c499ae88c02930b26cacb945c4a2369",
"rev": "b63c21d70150f1b414370f0f9a8af56e886662f4",
"type": "github"
},
"original": {
"owner": "Titaniumtown",
"repo": "egui",
"rev": "217d3f250c499ae88c02930b26cacb945c4a2369",
"rev": "b63c21d70150f1b414370f0f9a8af56e886662f4",
"type": "github"
}
},

View File

@ -9,21 +9,13 @@
inputs.nixpkgs.follows = "nixpkgs";
};
simon-egui = {
url = "github:Titaniumtown/egui/217d3f250c499ae88c02930b26cacb945c4a2369";
url = "github:Titaniumtown/egui/b63c21d70150f1b414370f0f9a8af56e886662f4";
flake = false;
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
simon-egui,
}:
flake-utils.lib.eachDefaultSystem (
system:
outputs = { self, nixpkgs, flake-utils, rust-overlay, simon-egui }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
@ -31,7 +23,7 @@
};
# Use nightly rust with wasm32 target
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
rustToolchain = pkgs.rust-bin.nightly."2025-05-01".default.override {
targets = [ "wasm32-unknown-unknown" ];
};
@ -40,6 +32,28 @@
rustc = rustToolchain;
};
# Build wasm-bindgen-cli matching the version in Cargo.lock (0.2.106)
wasm-bindgen-cli = rustPlatform.buildRustPackage rec {
pname = "wasm-bindgen-cli";
version = "0.2.106";
src = pkgs.fetchCrate {
inherit pname version;
hash = "sha256-M6WuGl7EruNopHZbqBpucu4RWz44/MSdv6f0zkYw+44=";
};
cargoHash = "sha256-ElDatyOwdKwHg3bNH/1pcxKI7LXkhsotlDPQjiLHBwA=";
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = [ pkgs.openssl ] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin [
pkgs.curl
pkgs.darwin.apple_sdk.frameworks.Security
];
# Tests require network access
doCheck = false;
};
# Create a combined source with the main project and dependencies
combinedSrc = pkgs.stdenv.mkDerivation {
name = "ytbn-combined-src";
@ -111,9 +125,9 @@
src = ./.;
nativeBuildInputs = with pkgs; [
nativeBuildInputs = [
wasm-bindgen-cli
binaryen
pkgs.binaryen
];
buildPhase = ''
@ -197,17 +211,14 @@
zstd
];
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (
with pkgs;
[
libxkbcommon
libGL
wayland
xorg.libX11
xorg.libXcursor
xorg.libXi
]
);
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath (with pkgs; [
libxkbcommon
libGL
wayland
xorg.libX11
xorg.libXcursor
xorg.libXi
]);
};
}
);

View File

@ -1,5 +1,8 @@
use crate::{
consts::COLORS, function_entry::FunctionEntry, misc::random_u64, widgets::widgets_ontop,
consts::COLORS,
function_entry::FunctionEntry,
misc::{create_id, get_u64_id, random_u64},
widgets::widgets_ontop,
};
use egui::{Button, Id, Key, Modifiers, Popup, TextEdit, WidgetText};
use emath::vec2;
@ -19,7 +22,7 @@ impl Default for FunctionManager {
fn default() -> Self {
let mut vec: Functions = Vec::with_capacity(COLORS.len());
vec.push((
Id::NULL.with(11414819524356497634_u64), // Random number here to avoid call to crate::misc::random_u64()
create_id(11414819524356497634), // Random number here to avoid call to crate::misc::random_u64()
FunctionEntry::default(),
));
Self { functions: vec }
@ -37,8 +40,8 @@ impl Serialize for FunctionManager {
&self
.functions
.iter()
.map(|(id, func)| (*id, func.clone()))
.collect::<Vec<(Id, FunctionEntry)>>(),
.map(|(id, func)| (get_u64_id(*id), func.clone()))
.collect::<Vec<(u64, FunctionEntry)>>(),
)?;
s.end()
}
@ -50,12 +53,17 @@ impl<'de> Deserialize<'de> for FunctionManager {
D: Deserializer<'de>,
{
#[derive(Deserialize)]
struct Helper(Vec<(Id, FunctionEntry)>);
struct Helper(Vec<(u64, FunctionEntry)>);
let helper = Helper::deserialize(deserializer)?;
Ok(FunctionManager {
functions: helper.0.to_vec(),
functions: helper
.0
.iter()
.cloned()
.map(|(id, func)| (create_id(id), func))
.collect::<Vec<(Id, FunctionEntry)>>(),
})
}
}
@ -196,7 +204,7 @@ impl FunctionManager {
const BUTTONS_Y_OFFSET: f32 = 1.32;
const Y_OFFSET: f32 = crate::consts::FONT_SIZE * BUTTONS_Y_OFFSET;
widgets_ontop(ui, Id::NULL.with(i), &re, Y_OFFSET, |ui| {
widgets_ontop(ui, create_id(i as u64), &re, Y_OFFSET, |ui| {
ui.horizontal(|ui| {
// There's more than 1 function! Functions can now be deleted
if ui
@ -319,7 +327,7 @@ impl FunctionManager {
/// Create and push new empty function entry
pub fn push_empty(&mut self) {
self.functions.push((
Id::NULL.with(random_u64().expect("unable to generate random id")),
create_id(random_u64().expect("unable to generate random id")),
FunctionEntry::default(),
));
}
@ -329,7 +337,7 @@ impl FunctionManager {
// Reset settings_opened so the cloned function doesn't have settings open
entry.settings_opened = false;
self.functions.push((
Id::NULL.with(random_u64().expect("unable to generate random id")),
create_id(random_u64().expect("unable to generate random id")),
entry,
));
}

View File

@ -176,7 +176,6 @@ impl MathApp {
// TODO: stabilize FunctionManager serialize so it can persist across builds
let (commit, func_data) = crate::misc::hashed_storage_read(&data)?;
let func_data: &[u8] = &func_data;
if commit == unsafe { std::mem::transmute::<&str, &[u8]>(build::SHORT_COMMIT) } {

View File

@ -1,3 +1,4 @@
use egui::Id;
use egui_plot::{Line, PlotPoint, PlotPoints, Points};
use emath::Pos2;
use itertools::Itertools;
@ -61,6 +62,14 @@ impl Offset for Pos2 {
}
}
pub const fn create_id(x: u64) -> Id {
unsafe { std::mem::transmute::<u64, Id>(x) }
}
pub const fn get_u64_id(id: Id) -> u64 {
unsafe { std::mem::transmute::<Id, u64>(id) }
}
/*
/// Rounds f64 to `n` decimal places
pub fn decimal_round(x: f64, n: usize) -> f64 {
@ -170,27 +179,24 @@ pub type HashBytes = [u8; HASH_LENGTH];
#[allow(dead_code)]
pub fn hashed_storage_create(hashbytes: HashBytes, data: &[u8]) -> String {
// Use base64 encoding to safely store binary data in localStorage
let combined: Vec<u8> = [hashbytes.to_vec(), data.to_vec()].concat();
base64::encode(combined)
unsafe { std::mem::transmute::<Vec<u8>, String>([hashbytes.to_vec(), data.to_vec()].concat()) }
}
#[allow(dead_code)]
pub fn hashed_storage_read(data: &str) -> Option<(HashBytes, Vec<u8>)> {
// Decode base64 data
let decoded = base64::decode(data).ok()?;
pub fn hashed_storage_read(data: &str) -> Option<(HashBytes, &[u8])> {
// Make sure data is long enough to decode
if HASH_LENGTH >= decoded.len() {
if HASH_LENGTH >= data.len() {
return None;
}
// Extract hash and data
let mut hash: HashBytes = [0u8; HASH_LENGTH];
hash.copy_from_slice(&decoded[..HASH_LENGTH]);
let data_part = decoded[HASH_LENGTH..].to_vec();
// Transmute data into slice
let decoded_1: &[u8] = unsafe { std::mem::transmute::<&str, &[u8]>(data) };
Some((hash, data_part))
// Return hash and decoded data
Some((
unsafe { *(decoded_1[..HASH_LENGTH].as_ptr() as *const HashBytes) },
&decoded_1[HASH_LENGTH..],
))
}
/// Creates and returns random u64