major cleanups

This commit is contained in:
Simon Gardling 2023-03-23 22:52:01 -04:00
parent f8a1297857
commit cce932400a
8 changed files with 37 additions and 43 deletions

22
Cargo.lock generated
View File

@ -242,13 +242,13 @@ dependencies = [
[[package]] [[package]]
name = "bytemuck_derive" name = "bytemuck_derive"
version = "1.4.0" version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aca418a974d83d40a0c1f0c5cba6ff4bc28d8df099109ca459a2118d40b6322" checksum = "fdde5c9cd29ebd706ce1b35600920a33550e402fc998a2e53ad3b42c3c47a192"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.109", "syn 2.0.8",
] ]
[[package]] [[package]]
@ -697,7 +697,7 @@ checksum = "0bd4b30a6560bbd9b4620f4de34c3f14f60848e58a9b7216801afcb4c7b31c3c"
[[package]] [[package]]
name = "ecolor" name = "ecolor"
version = "0.21.0" version = "0.21.0"
source = "git+https://github.com/titaniumtown/egui.git#638dd4c2a0da939d67d32bc87ae5bf9f32b4c947" source = "git+https://github.com/titaniumtown/egui.git#b1372da7e9343c12c8b1648c8c2b649ca9b3c96a"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"serde", "serde",
@ -706,7 +706,7 @@ dependencies = [
[[package]] [[package]]
name = "eframe" name = "eframe"
version = "0.21.3" version = "0.21.3"
source = "git+https://github.com/titaniumtown/egui.git#638dd4c2a0da939d67d32bc87ae5bf9f32b4c947" source = "git+https://github.com/titaniumtown/egui.git#b1372da7e9343c12c8b1648c8c2b649ca9b3c96a"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"egui", "egui",
@ -729,7 +729,7 @@ dependencies = [
[[package]] [[package]]
name = "egui" name = "egui"
version = "0.21.0" version = "0.21.0"
source = "git+https://github.com/titaniumtown/egui.git#638dd4c2a0da939d67d32bc87ae5bf9f32b4c947" source = "git+https://github.com/titaniumtown/egui.git#b1372da7e9343c12c8b1648c8c2b649ca9b3c96a"
dependencies = [ dependencies = [
"accesskit", "accesskit",
"ahash", "ahash",
@ -742,7 +742,7 @@ dependencies = [
[[package]] [[package]]
name = "egui-winit" name = "egui-winit"
version = "0.21.1" version = "0.21.1"
source = "git+https://github.com/titaniumtown/egui.git#638dd4c2a0da939d67d32bc87ae5bf9f32b4c947" source = "git+https://github.com/titaniumtown/egui.git#b1372da7e9343c12c8b1648c8c2b649ca9b3c96a"
dependencies = [ dependencies = [
"android-activity", "android-activity",
"arboard", "arboard",
@ -757,7 +757,7 @@ dependencies = [
[[package]] [[package]]
name = "egui_glow" name = "egui_glow"
version = "0.21.0" version = "0.21.0"
source = "git+https://github.com/titaniumtown/egui.git#638dd4c2a0da939d67d32bc87ae5bf9f32b4c947" source = "git+https://github.com/titaniumtown/egui.git#b1372da7e9343c12c8b1648c8c2b649ca9b3c96a"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"egui", "egui",
@ -777,7 +777,7 @@ checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91"
[[package]] [[package]]
name = "emath" name = "emath"
version = "0.21.0" version = "0.21.0"
source = "git+https://github.com/titaniumtown/egui.git#638dd4c2a0da939d67d32bc87ae5bf9f32b4c947" source = "git+https://github.com/titaniumtown/egui.git#b1372da7e9343c12c8b1648c8c2b649ca9b3c96a"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"serde", "serde",
@ -797,7 +797,7 @@ dependencies = [
[[package]] [[package]]
name = "epaint" name = "epaint"
version = "0.21.0" version = "0.21.0"
source = "git+https://github.com/titaniumtown/egui.git#638dd4c2a0da939d67d32bc87ae5bf9f32b4c947" source = "git+https://github.com/titaniumtown/egui.git#b1372da7e9343c12c8b1648c8c2b649ca9b3c96a"
dependencies = [ dependencies = [
"ab_glyph", "ab_glyph",
"ahash", "ahash",
@ -844,7 +844,7 @@ dependencies = [
[[package]] [[package]]
name = "exmex" name = "exmex"
version = "0.17.0" version = "0.17.0"
source = "git+https://github.com/bertiqwerty/exmex.git?branch=main#cc02696cae7cae4688b918b51426540eb643b585" source = "git+https://github.com/bertiqwerty/exmex.git?branch=main#d30aec8c0f2d15a87f7ea2ba8a25ece1991e893f"
dependencies = [ dependencies = [
"lazy_static", "lazy_static",
"num", "num",

View File

@ -13,8 +13,6 @@ use epaint::{
use run_script::ScriptOptions; use run_script::ScriptOptions;
include!(concat!(env!("CARGO_MANIFEST_DIR"), "/src/data.rs"));
include!(concat!( include!(concat!(
env!("CARGO_MANIFEST_DIR"), env!("CARGO_MANIFEST_DIR"),
"/src/unicode_helper.rs" "/src/unicode_helper.rs"
@ -146,7 +144,7 @@ fn main() {
]), ]),
}; };
let data = bincode::serialize(&TotalData { fonts }).unwrap(); let data = bincode::serialize(&fonts).unwrap();
let zstd_levels = zstd::compression_level_range(); let zstd_levels = zstd::compression_level_range();
let data_compressed = let data_compressed =

View File

@ -14,6 +14,8 @@ pub const BUILD_INFO: &str = formatc!(
&build::RUST_VERSION[6..], &build::RUST_VERSION[6..],
); );
pub const FONT_SIZE: f32 = 14.0;
// Default values // Default values
/// Default minimum X value to display /// Default minimum X value to display
pub const DEFAULT_MIN_X: f64 = -10.0; pub const DEFAULT_MIN_X: f64 = -10.0;

View File

@ -1,6 +0,0 @@
pub const FONT_SIZE: f32 = 14.0;
#[derive(serde::Serialize, serde::Deserialize, PartialEq)]
pub struct TotalData {
pub fonts: epaint::text::FontDefinitions,
}

View File

@ -87,7 +87,7 @@ impl FunctionManager {
let available_width = ui.available_width(); let available_width = ui.available_width();
let mut remove_i: Option<usize> = None; let mut remove_i: Option<usize> = None;
let target_size = vec2(available_width, crate::data::FONT_SIZE); let target_size = vec2(available_width, crate::consts::FONT_SIZE);
for (i, (te_id, function)) in self.functions.iter_mut().map(|(a, b)| (*a, b)).enumerate() { for (i, (te_id, function)) in self.functions.iter_mut().map(|(a, b)| (*a, b)).enumerate() {
let mut new_string = function.autocomplete.string.clone(); let mut new_string = function.autocomplete.string.clone();
function.update_string(&new_string); function.update_string(&new_string);
@ -190,7 +190,7 @@ impl FunctionManager {
/// The y offset multiplier of the `buttons_area` area /// The y offset multiplier of the `buttons_area` area
const BUTTONS_Y_OFFSET: f32 = 1.32; const BUTTONS_Y_OFFSET: f32 = 1.32;
const Y_OFFSET: f32 = crate::data::FONT_SIZE * BUTTONS_Y_OFFSET; const Y_OFFSET: f32 = crate::consts::FONT_SIZE * BUTTONS_Y_OFFSET;
widgets_ontop(ui, create_id(i as u64), &re, Y_OFFSET, |ui| { widgets_ontop(ui, create_id(i as u64), &re, Y_OFFSET, |ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {

View File

@ -15,7 +15,6 @@
extern crate static_assertions; extern crate static_assertions;
mod consts; mod consts;
mod data;
mod function_entry; mod function_entry;
mod function_manager; mod function_manager;
mod math_app; mod math_app;

View File

@ -15,7 +15,6 @@
extern crate static_assertions; extern crate static_assertions;
mod consts; mod consts;
mod data;
mod function_entry; mod function_entry;
mod function_manager; mod function_manager;
mod math_app; mod math_app;

View File

@ -191,7 +191,7 @@ impl MathApp {
} }
} }
fn decompress_data() -> crate::data::TotalData { fn decompress_fonts() -> epaint::text::FontDefinitions {
let mut data = Vec::new(); let mut data = Vec::new();
let _ = ruzstd::StreamingDecoder::new( let _ = ruzstd::StreamingDecoder::new(
&mut const { include_bytes!(concat!(env!("OUT_DIR"), "/compressed_data")).as_slice() }, &mut const { include_bytes!(concat!(env!("OUT_DIR"), "/compressed_data")).as_slice() },
@ -224,23 +224,23 @@ impl MathApp {
bincode::deserialize(data.as_slice()).expect("unable to deserialize bincode") bincode::deserialize(data.as_slice()).expect("unable to deserialize bincode")
} }
#[cfg(target = "wasm32")] tracing::info!("Reading fonts...");
let data: crate::data::TotalData = if let Some(Ok(data)) =
get_storage_decompressed().map(|data| bincode::deserialize(data.as_slice()))
{
data
} else {
decompress_data()
};
#[cfg(not(target = "wasm32"))]
let data: crate::data::TotalData = decompress_data();
tracing::info!("Reading assets...");
// Initialize fonts // Initialize fonts
// This used to be in the `update` method, but (after a ton of digging) this actually caused OOMs. that was a pain to debug // This used to be in the `update` method, but (after a ton of digging) this actually caused OOMs. that was a pain to debug
cc.egui_ctx.set_fonts(data.fonts); cc.egui_ctx.set_fonts({
#[cfg(target = "wasm32")]
if let Some(Ok(data)) =
get_storage_decompressed().map(|data| bincode::deserialize(data.as_slice()))
{
data
} else {
decompress_fonts()
}
#[cfg(not(target = "wasm32"))]
decompress_fonts()
});
// Set dark mode by default // Set dark mode by default
// cc.egui_ctx.set_visuals(crate::style::style()); // cc.egui_ctx.set_visuals(crate::style::style());
@ -395,7 +395,7 @@ impl MathApp {
} }
// Only render if there's enough space // Only render if there's enough space
if ui.available_height() > crate::data::FONT_SIZE { if ui.available_height() > crate::consts::FONT_SIZE {
ui.with_layout(Layout::bottom_up(Align::Min), |ui| { ui.with_layout(Layout::bottom_up(Align::Min), |ui| {
// Contents put in reverse order from bottom to top due to the 'buttom_up' layout // Contents put in reverse order from bottom to top due to the 'buttom_up' layout
@ -591,9 +591,11 @@ impl App for MathApp {
.data_aspect(1.0) .data_aspect(1.0)
.include_y(0) .include_y(0)
.show(ui, |plot_ui| { .show(ui, |plot_ui| {
let bounds = plot_ui.plot_bounds(); let (min_x, max_x): (f64, f64) = {
let min_x: f64 = bounds.min()[0]; let bounds = plot_ui.plot_bounds();
let max_x: f64 = bounds.max()[0]; (bounds.min()[0], bounds.max()[0])
};
let min_max_changed = let min_max_changed =
(min_x != self.settings.min_x) | (max_x != self.settings.max_x); (min_x != self.settings.min_x) | (max_x != self.settings.max_x);
let did_zoom = (max_x - min_x).abs() let did_zoom = (max_x - min_x).abs()