update EVERYTHING and rebase egui and depdencies

This commit is contained in:
2025-12-02 22:40:08 -05:00
parent 33847acd53
commit dd377c1659
16 changed files with 1904 additions and 1489 deletions

View File

@@ -118,7 +118,7 @@ impl<'de> Deserialize<'de> for FunctionEntry {
}
}
impl const Default for FunctionEntry {
impl Default for FunctionEntry {
/// Creates default FunctionEntry instance (which is empty)
fn default() -> FunctionEntry {
FunctionEntry {
@@ -379,7 +379,7 @@ impl FunctionEntry {
.cloned()
.collect::<Vec<PlotPoint>>()
.to_line()
.stroke(epaint::Stroke::NONE)
.stroke((0.0, Color32::TRANSPARENT))
.color(Color32::from_rgb(4, 4, 255))
.fill(0.0),
);
@@ -388,7 +388,7 @@ impl FunctionEntry {
self.back_data
.clone()
.to_line()
.stroke(egui::Stroke::new(4.0, main_plot_color)),
.stroke((4.0, main_plot_color)),
);
}
@@ -430,7 +430,7 @@ impl FunctionEntry {
Some(integral_data) => {
if integral_step > step {
plot_ui.bar_chart(
BarChart::new(integral_data.0.clone())
BarChart::new("integral", integral_data.0.clone())
.color(Color32::BLUE)
.width(integral_step),
);

View File

@@ -4,7 +4,7 @@ use crate::{
misc::{create_id, get_u64_id, random_u64},
widgets::widgets_ontop,
};
use egui::{Button, Id, Key, Modifiers, TextEdit, WidgetText};
use egui::{Button, Id, Key, Modifiers, Popup, TextEdit, WidgetText};
use emath::vec2;
use parsing::Movement;
use serde::ser::SerializeStruct;
@@ -151,46 +151,36 @@ impl FunctionManager {
if movement != Movement::Complete
&& let Some(hints) = function.autocomplete.hint.many()
{
// Doesn't need to have a number in id as there should only be 1 autocomplete popup in the entire gui
// hashed "autocomplete_popup"
const POPUP_ID: Id = create_id(7574801616484505465);
let mut clicked = false;
let selected_i = function.autocomplete.i;
egui::popup_below_widget(ui, POPUP_ID, &re, |ui| {
if let Some(popup_response) = Popup::menu(&re).show(|ui| {
hints.iter().enumerate().for_each(|(i, candidate)| {
if ui
.selectable_label(i == function.autocomplete.i, *candidate)
.selectable_label(i == selected_i, *candidate)
.clicked()
{
clicked = true;
function.autocomplete.i = i;
}
});
});
if clicked {
function
.autocomplete
.apply_hint(hints[function.autocomplete.i]);
// Don't need this here as it simply won't be display next frame
// ui.memory_mut().close_popup();
movement = Movement::Complete;
} else {
ui.memory_mut(|x| x.open_popup(POPUP_ID));
}) {
if clicked {
function
.autocomplete
.apply_hint(hints[function.autocomplete.i]);
movement = Movement::Complete;
}
}
}
// Push cursor to end if needed
if movement == Movement::Complete {
let mut state =
unsafe { TextEdit::load_state(ui.ctx(), te_id).unwrap_unchecked() };
let ccursor = egui::text::CCursor::new(function.autocomplete.string.len());
state.set_ccursor_range(Some(egui::text::CCursorRange::one(ccursor)));
TextEdit::store_state(ui.ctx(), te_id, state);
if let Some(mut state) = TextEdit::load_state(ui.ctx(), te_id) {
let ccursor = egui::text::CCursor::new(function.autocomplete.string.len());
state.cursor.set_char_range(Some(egui::text::CCursorRange::one(ccursor)));
TextEdit::store_state(ui.ctx(), te_id, state);
}
}
}

View File

@@ -1,14 +1,3 @@
#![feature(const_mut_refs)]
#![feature(let_chains)]
#![feature(const_trait_impl)]
#![feature(const_fn_floating_point_arithmetic)]
#![feature(const_assume)]
#![feature(const_option_ext)]
#![feature(const_slice_index)]
#![feature(slice_split_at_unchecked)]
#![feature(inline_const)]
#![feature(const_for)]
#[macro_use]
extern crate static_assertions;
@@ -62,12 +51,12 @@ cfg_if::cfg_if! {
/// Call this once from JavaScript to start your app.
#[wasm_bindgen]
pub async fn start(&self, canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> {
pub async fn start(&self, canvas: web_sys::HtmlCanvasElement) -> Result<(), wasm_bindgen::JsValue> {
self.runner
.start(
canvas_id,
canvas,
eframe::WebOptions::default(),
Box::new(|cc| Box::new(math_app::MathApp::new(cc))),
Box::new(|cc| Ok(Box::new(math_app::MathApp::new(cc)))),
)
.await
}
@@ -77,9 +66,16 @@ cfg_if::cfg_if! {
pub async fn start() {
tracing::info!("Starting...");
let window = web_sys::window().expect("no global window exists");
let document = window.document().expect("should have a document on window");
let canvas = document
.get_element_by_id("canvas")
.expect("should have a canvas element with id 'canvas'")
.dyn_into::<web_sys::HtmlCanvasElement>()
.expect("canvas element should be an HtmlCanvasElement");
let web_handle = WebHandle::new();
web_handle.start("canvas").await.unwrap()
web_handle.start(canvas).await.unwrap()
}
}
}

View File

@@ -1,14 +1,3 @@
#![feature(const_mut_refs)]
#![feature(let_chains)]
#![feature(const_trait_impl)]
#![feature(const_fn_floating_point_arithmetic)]
#![feature(const_assume)]
#![feature(const_option_ext)]
#![feature(const_slice_index)]
#![feature(slice_split_at_unchecked)]
#![feature(inline_const)]
#![feature(const_for)]
#[macro_use]
extern crate static_assertions;
@@ -22,7 +11,7 @@ mod widgets;
// For running the program natively! (Because why not?)
#[cfg(not(target_arch = "wasm32"))]
fn main() -> eframe::Result<()> {
fn main() -> eframe::Result {
let subscriber = tracing_subscriber::FmtSubscriber::builder()
.with_max_level(tracing::Level::INFO)
.finish();
@@ -32,6 +21,6 @@ fn main() -> eframe::Result<()> {
eframe::run_native(
"(Yet-to-be-named) Graphing Software",
eframe::NativeOptions::default(),
Box::new(|cc| Box::new(math_app::MathApp::new(cc))),
Box::new(|cc| Ok(Box::new(math_app::MathApp::new(cc)))),
)
}

View File

@@ -6,14 +6,14 @@ use crate::{
};
use eframe::App;
use egui::{
style::Margin, Button, CentralPanel, Color32, ComboBox, Context, DragValue, Frame, Key, Layout,
SidePanel, TopBottomPanel, Ui, Vec2, Window,
Button, CentralPanel, Color32, ComboBox, Context, DragValue, Frame, Key, Layout,
Panel, Ui, Vec2, Window,
};
use egui_plot::Plot;
use emath::{Align, Align2};
use epaint::Rounding;
use instant::Instant;
use epaint::{CornerRadius, Margin};
use web_time::Instant;
use itertools::Itertools;
use std::{io::Read, ops::BitXorAssign};
@@ -51,7 +51,7 @@ pub struct AppSettings {
pub plot_width: usize,
}
impl const Default for AppSettings {
impl Default for AppSettings {
/// Default implementation of `AppSettings`, this is how the application starts up
fn default() -> Self {
Self {
@@ -84,7 +84,7 @@ struct Opened {
pub welcome: bool,
}
impl const Default for Opened {
impl Default for Opened {
fn default() -> Opened {
Self {
help: false,
@@ -183,14 +183,14 @@ impl MathApp {
fn decompress_fonts() -> epaint::text::FontDefinitions {
let mut data = Vec::new();
let _ = ruzstd::StreamingDecoder::new(
&mut const { include_bytes!(concat!(env!("OUT_DIR"), "/compressed_data")).as_slice() },
let _ = ruzstd::decoding::StreamingDecoder::new(
const { include_bytes!(concat!(env!("OUT_DIR"), "/compressed_data")).as_slice() },
)
.expect("unable to decode compressed data")
.read_to_end(&mut data)
.expect("unable to read compressed data");
#[cfg(target = "wasm32")]
#[cfg(target_arch = "wasm32")]
{
tracing::info!("Setting decompression cache");
let commit: crate::misc::HashBytes = const {
@@ -213,7 +213,7 @@ impl MathApp {
// 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
cc.egui_ctx.set_fonts({
#[cfg(target = "wasm32")]
#[cfg(target_arch = "wasm32")]
if let Some(Ok(data)) =
get_storage_decompressed().map(|data| bincode::deserialize(data.as_slice()))
{
@@ -222,7 +222,7 @@ impl MathApp {
decompress_fonts()
}
#[cfg(not(target = "wasm32"))]
#[cfg(not(target_arch = "wasm32"))]
decompress_fonts()
});
@@ -251,7 +251,7 @@ impl MathApp {
fn side_panel(&mut self, ctx: &Context) {
// Side Panel which contains vital options to the operation of the application
// (such as adding functions and other options)
SidePanel::left("side_panel")
Panel::left("side_panel")
.resizable(false)
.show(ctx, |ui| {
let any_using_integral = self.functions.any_using_integral();
@@ -400,7 +400,7 @@ impl App for MathApp {
fn update(&mut self, ctx: &Context, _frame: &mut eframe::Frame) {
// start timer
let start = if self.opened.info {
Some(instant::Instant::now())
Some(Instant::now())
} else {
// if disabled, clear the stored formatted time
self.last_info.1 = None;
@@ -417,7 +417,7 @@ impl App for MathApp {
}
// Creates Top bar that contains some general options
TopBottomPanel::top("top_bar").show(ctx, |ui| {
Panel::top("top_bar").show(ctx, |ui| {
ui.horizontal(|ui| {
// Button in top bar to toggle showing the side panel
self.opened.side_panel.bitxor_assign(
@@ -537,11 +537,11 @@ impl App for MathApp {
// Central panel which contains the central plot (or an error created when parsing)
CentralPanel::default()
.frame(Frame {
inner_margin: Margin::symmetric(0.0, 0.0),
rounding: Rounding::ZERO,
inner_margin: Margin::ZERO,
corner_radius: CornerRadius::ZERO,
// fill: crate::style::STYLE.window_fill(),
fill: Color32::from_gray(27),
..Frame::none()
..Frame::NONE
})
.show(ctx, |ui| {
// Display an error if it exists
@@ -573,7 +573,7 @@ impl App for MathApp {
// Create and setup plot
Plot::new("plot")
.set_margin_fraction(Vec2::ZERO)
.set_margin_fraction(emath::Vec2::ZERO)
.data_aspect(1.0)
.include_y(0)
.show(ui, |plot_ui| {
@@ -620,6 +620,6 @@ impl App for MathApp {
});
// Calculate and store the last time it took to draw the frame
self.last_info.1 = start.map(|a| format!("Took: {}ms", a.elapsed().as_micros()));
self.last_info.1 = start.map(|a| format!("Took: {}us", a.elapsed().as_micros()));
}
}

View File

@@ -1,20 +1,19 @@
use egui::Id;
use egui_plot::{Line, PlotPoint, PlotPoints, Points};
use emath::Pos2;
use getrandom::getrandom;
use itertools::Itertools;
use parsing::FlatExWrapper;
/// Implements traits that are useful when dealing with Vectors of egui's `Value`
pub trait EguiHelper {
/// Converts to `egui::plot::Values`
fn to_values(self) -> PlotPoints;
fn to_values(self) -> PlotPoints<'static>;
/// Converts to `egui::plot::Line`
fn to_line(self) -> Line;
fn to_line(self) -> Line<'static>;
/// Converts to `egui::plot::Points`
fn to_points(self) -> Points;
fn to_points(self) -> Points<'static>;
/// Converts Vector of Values into vector of tuples
fn to_tuple(self) -> Vec<(f64, f64)>;
@@ -22,15 +21,15 @@ pub trait EguiHelper {
impl EguiHelper for Vec<PlotPoint> {
#[inline(always)]
fn to_values(self) -> PlotPoints {
fn to_values(self) -> PlotPoints<'static> {
PlotPoints::from(unsafe { std::mem::transmute::<Vec<PlotPoint>, Vec<[f64; 2]>>(self) })
}
#[inline(always)]
fn to_line(self) -> Line { Line::new(self.to_values()) }
fn to_line(self) -> Line<'static> { Line::new("", self.to_values()) }
#[inline(always)]
fn to_points(self) -> Points { Points::new(self.to_values()) }
fn to_points(self) -> Points<'static> { Points::new("", self.to_values()) }
#[inline(always)]
fn to_tuple(self) -> Vec<(f64, f64)> {
@@ -43,7 +42,7 @@ pub trait Offset {
fn offset_x(self, x_offset: f32) -> Pos2;
}
impl const Offset for Pos2 {
impl Offset for Pos2 {
fn offset_y(self, y_offset: f32) -> Pos2 {
Pos2 {
x: self.x,
@@ -191,7 +190,7 @@ pub fn random_u64() -> Result<u64, getrandom::Error> {
// Buffer of 8 `u8`s that are later merged into one u64
let mut buf = [0u8; 8];
// Populate buffer with random values
getrandom(&mut buf)?;
getrandom::fill(&mut buf)?;
// Merge buffer into u64
Ok(u64::from_be_bytes(buf))
}