fix build on newer egui

This commit is contained in:
Simon Gardling 2025-12-03 16:43:58 -05:00
parent 74813f5f13
commit 8b7e3b3009
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D
6 changed files with 47 additions and 34 deletions

View File

@ -8,8 +8,8 @@ use std::{
}; };
use epaint::{ use epaint::{
text::{FontData, FontDefinitions, FontTweak},
FontFamily, FontFamily,
text::{FontData, FontDefinitions, FontTweak},
}; };
use run_script::ScriptOptions; use run_script::ScriptOptions;

View File

@ -449,7 +449,7 @@ impl FunctionEntry {
Some(integral_data) => { Some(integral_data) => {
if integral_step > step { if integral_step > step {
plot_ui.bar_chart( plot_ui.bar_chart(
BarChart::new(integral_data.0.clone()) BarChart::new("integral bar chart", integral_data.0.clone())
.color(Color32::BLUE) .color(Color32::BLUE)
.width(integral_step), .width(integral_step),
); );

View File

@ -1,7 +1,7 @@
use crate::{ use crate::{
consts::COLORS, function_entry::FunctionEntry, misc::random_u64, widgets::widgets_ontop, consts::COLORS, function_entry::FunctionEntry, misc::random_u64, widgets::widgets_ontop,
}; };
use egui::{Button, Id, Key, Modifiers, TextEdit, WidgetText}; use egui::{Button, Id, Key, Modifiers, PopupCloseBehavior, TextEdit, WidgetText};
use emath::vec2; use emath::vec2;
use parsing::Movement; use parsing::Movement;
use serde::ser::SerializeStruct; use serde::ser::SerializeStruct;
@ -147,7 +147,12 @@ impl FunctionManager {
let autocomplete_popup_id = Id::new("autocomplete popup"); let autocomplete_popup_id = Id::new("autocomplete popup");
egui::popup_below_widget(ui, autocomplete_popup_id, &re, |ui| { egui::popup_below_widget(
ui,
autocomplete_popup_id,
&re,
PopupCloseBehavior::CloseOnClickOutside,
|ui| {
hints.iter().enumerate().for_each(|(i, candidate)| { hints.iter().enumerate().for_each(|(i, candidate)| {
if ui if ui
.selectable_label(i == function.autocomplete.i, *candidate) .selectable_label(i == function.autocomplete.i, *candidate)
@ -157,7 +162,8 @@ impl FunctionManager {
function.autocomplete.i = i; function.autocomplete.i = i;
} }
}); });
}); },
);
if clicked { if clicked {
function function
@ -172,10 +178,14 @@ impl FunctionManager {
// Push cursor to end if needed // Push cursor to end if needed
if movement == Movement::Complete { if movement == Movement::Complete {
// TODO! proper error handling
let mut state = let mut state =
unsafe { TextEdit::load_state(ui.ctx(), te_id).unwrap_unchecked() }; unsafe { TextEdit::load_state(ui.ctx(), te_id).unwrap_unchecked() };
let ccursor = egui::text::CCursor::new(function.autocomplete.string.len()); let ccursor = egui::text::CCursor::new(function.autocomplete.string.len());
state.set_ccursor_range(Some(egui::text::CCursorRange::one(ccursor))); state
.cursor
.set_char_range(Some(egui::text::CCursorRange::one(ccursor)));
TextEdit::store_state(ui.ctx(), te_id, state); TextEdit::store_state(ui.ctx(), te_id, state);
} }
} }

View File

@ -22,6 +22,7 @@ pub use crate::{
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(target_arch = "wasm32")] { if #[cfg(target_arch = "wasm32")] {
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use web_sys::HtmlCanvasElement;
use lol_alloc::{FreeListAllocator, LockedAllocator}; use lol_alloc::{FreeListAllocator, LockedAllocator};
#[global_allocator] #[global_allocator]
@ -51,12 +52,12 @@ cfg_if::cfg_if! {
/// Call this once from JavaScript to start your app. /// Call this once from JavaScript to start your app.
#[wasm_bindgen] #[wasm_bindgen]
pub async fn start(&self, canvas_id: &str) -> Result<(), wasm_bindgen::JsValue> { pub async fn start(&self, canvas_id: HtmlCanvasElement) -> Result<(), wasm_bindgen::JsValue> {
self.runner self.runner
.start( .start(
canvas_id, canvas_id,
eframe::WebOptions::default(), 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 .await
} }
@ -66,9 +67,11 @@ cfg_if::cfg_if! {
pub async fn start() { pub async fn start() {
tracing::info!("Starting..."); tracing::info!("Starting...");
let document = web_sys::window().unwrap().document().unwrap();
let canvas = document.get_element_by_id("canvas").unwrap().dyn_into::<HtmlCanvasElement>().unwrap();
let web_handle = WebHandle::new(); let web_handle = WebHandle::new();
web_handle.start("canvas").await.unwrap() web_handle.start(canvas).await.unwrap()
} }
} }
} }

View File

@ -6,13 +6,13 @@ use crate::{
}; };
use eframe::App; use eframe::App;
use egui::{ use egui::{
Button, CentralPanel, Color32, ComboBox, Context, DragValue, Frame, Key, Layout, SidePanel, Button, CentralPanel, Color32, ComboBox, Context, CornerRadius, DragValue, Frame, Key, Layout,
TopBottomPanel, Ui, Vec2, Window, style::Margin, SidePanel, TopBottomPanel, Ui, Vec2, Window,
}; };
use egui_plot::Plot; use egui_plot::Plot;
use emath::{Align, Align2}; use emath::{Align, Align2};
use epaint::Rounding; use epaint::{Margin, Rounding};
use instant::Instant; use instant::Instant;
use itertools::Itertools; use itertools::Itertools;
use std::{io::Read, ops::BitXorAssign}; use std::{io::Read, ops::BitXorAssign};
@ -535,11 +535,11 @@ impl App for MathApp {
// Central panel which contains the central plot (or an error created when parsing) // Central panel which contains the central plot (or an error created when parsing)
CentralPanel::default() CentralPanel::default()
.frame(Frame { .frame(Frame {
inner_margin: Margin::symmetric(0.0, 0.0), inner_margin: Margin::ZERO,
rounding: Rounding::ZERO, corner_radius: CornerRadius::ZERO,
// fill: crate::style::STYLE.window_fill(), // fill: crate::style::STYLE.window_fill(),
fill: Color32::from_gray(27), fill: Color32::from_gray(27),
..Frame::none() ..Frame::NONE
}) })
.show(ctx, |ui| { .show(ctx, |ui| {
// Display an error if it exists // Display an error if it exists

View File

@ -1,4 +1,4 @@
use base64::{engine::general_purpose, Engine as _}; use base64::{Engine as _, engine::general_purpose};
use egui_plot::{Line, PlotPoint, PlotPoints, Points}; use egui_plot::{Line, PlotPoint, PlotPoints, Points};
use emath::Pos2; use emath::Pos2;
use getrandom::getrandom; use getrandom::getrandom;