diff --git a/Cargo.lock b/Cargo.lock index 66b4588..595b533 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -659,7 +659,7 @@ checksum = "453440c271cf5577fd2a40e4942540cb7d0d2f85e27c8d07dd0023c925a67541" [[package]] name = "eframe" version = "0.18.0" -source = "git+https://github.com/Titaniumtown/egui.git#df1e7b36af0f3d951501e168c85b2f340b56e42c" +source = "git+https://github.com/Titaniumtown/egui.git#756fd7ef87bb128f944d676531405b128d9bbfe3" dependencies = [ "bytemuck", "egui", @@ -679,18 +679,19 @@ dependencies = [ [[package]] name = "egui" version = "0.18.1" -source = "git+https://github.com/Titaniumtown/egui.git#df1e7b36af0f3d951501e168c85b2f340b56e42c" +source = "git+https://github.com/Titaniumtown/egui.git#756fd7ef87bb128f944d676531405b128d9bbfe3" dependencies = [ "ahash", "epaint", "nohash-hasher", + "serde", "tracing", ] [[package]] name = "egui-winit" version = "0.18.0" -source = "git+https://github.com/Titaniumtown/egui.git#df1e7b36af0f3d951501e168c85b2f340b56e42c" +source = "git+https://github.com/Titaniumtown/egui.git#756fd7ef87bb128f944d676531405b128d9bbfe3" dependencies = [ "arboard", "egui", @@ -704,7 +705,7 @@ dependencies = [ [[package]] name = "egui_glow" version = "0.18.1" -source = "git+https://github.com/Titaniumtown/egui.git#df1e7b36af0f3d951501e168c85b2f340b56e42c" +source = "git+https://github.com/Titaniumtown/egui.git#756fd7ef87bb128f944d676531405b128d9bbfe3" dependencies = [ "bytemuck", "egui", @@ -724,7 +725,7 @@ checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" [[package]] name = "emath" version = "0.18.0" -source = "git+https://github.com/Titaniumtown/egui.git#df1e7b36af0f3d951501e168c85b2f340b56e42c" +source = "git+https://github.com/Titaniumtown/egui.git#756fd7ef87bb128f944d676531405b128d9bbfe3" dependencies = [ "bytemuck", "serde", @@ -733,7 +734,7 @@ dependencies = [ [[package]] name = "epaint" version = "0.18.1" -source = "git+https://github.com/Titaniumtown/egui.git#df1e7b36af0f3d951501e168c85b2f340b56e42c" +source = "git+https://github.com/Titaniumtown/egui.git#756fd7ef87bb128f944d676531405b128d9bbfe3" dependencies = [ "ab_glyph", "ahash", diff --git a/Cargo.toml b/Cargo.toml index 71539a2..fa86135 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,9 @@ parsing = { path = "./parsing" } eframe = { git = "https://github.com/Titaniumtown/egui.git", default-features = false, features = [ "glow", ] } -egui = { git = "https://github.com/Titaniumtown/egui.git", default-features = false } +egui = { git = "https://github.com/Titaniumtown/egui.git", default-features = false, features = [ + "serde", +] } epaint = { git = "https://github.com/Titaniumtown/egui.git", default-features = false, features = [ "serde", ] } @@ -66,6 +68,9 @@ shadow-rs = "0.11" epaint = { git = "https://github.com/Titaniumtown/egui.git", default-features = false, features = [ "serde", ] } +egui = { git = "https://github.com/Titaniumtown/egui.git", default-features = false, features = [ + "serde", +] } bincode = "1.3" serde = "1" serde_json = "1" diff --git a/build.rs b/build.rs index 5c3449c..6b03305 100644 --- a/build.rs +++ b/build.rs @@ -126,11 +126,11 @@ fn main() { } } - let text_data: TextData = serde_json::from_value(serde_json::Value::Object(json_file_array)) - .expect("Failed to convert data to TextData"); + let text_data: TextDataRaw = serde_json::from_value(serde_json::Value::Object(json_file_array)) + .expect("Failed to convert data to TextDataRaw"); let data = bincode::serialize(&TotalData { - text: text_data, + text: text_data.into_rich(), fonts, }) .unwrap(); diff --git a/src/data.rs b/src/data.rs index 9b15d5b..73e12e4 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,5 +1,16 @@ -#[derive(PartialEq, Debug, serde::Serialize, serde::Deserialize)] +#[derive(PartialEq, serde::Serialize, serde::Deserialize)] pub struct TextData { + pub help_expr: egui::RichText, + pub help_vars: egui::RichText, + pub help_panel: egui::RichText, + pub help_function: egui::RichText, + pub help_other: egui::RichText, + pub license_info: egui::RichText, + pub welcome: egui::RichText, +} + +#[derive(PartialEq, serde::Serialize, serde::Deserialize)] +pub struct TextDataRaw { pub help_expr: String, pub help_vars: String, pub help_panel: String, @@ -9,7 +20,23 @@ pub struct TextData { pub welcome: String, } -#[derive(serde::Serialize, serde::Deserialize, PartialEq, Debug)] +impl TextDataRaw { + #[allow(dead_code)] + fn into_rich(self) -> TextData { + use egui::RichText; + TextData { + help_expr: RichText::from(self.help_expr), + help_vars: RichText::from(self.help_vars), + help_panel: RichText::from(self.help_panel), + help_function: RichText::from(self.help_function), + help_other: RichText::from(self.help_other), + license_info: RichText::from(self.license_info), + welcome: RichText::from(self.welcome).size(16.0), + } + } +} + +#[derive(serde::Serialize, serde::Deserialize, PartialEq)] pub struct TotalData { pub text: TextData, pub fonts: epaint::text::FontDefinitions, diff --git a/src/math_app.rs b/src/math_app.rs index afb5ba6..5e2df6f 100644 --- a/src/math_app.rs +++ b/src/math_app.rs @@ -5,8 +5,8 @@ use crate::function_manager::FunctionManager; use crate::misc::{dyn_mut_iter, option_vec_printer}; use eframe::App; use egui::{ - plot::Plot, style::Margin, vec2, Button, CentralPanel, Color32, ComboBox, Context, Frame, Key, - Label, Layout, RichText, SidePanel, Slider, TopBottomPanel, Vec2, Visuals, Window, + plot::Plot, style::Margin, Button, CentralPanel, Color32, ComboBox, Context, Frame, Key, Label, + Layout, RichText, SidePanel, Slider, TopBottomPanel, Vec2, Visuals, Window, }; use emath::{Align, Align2}; use epaint::Rounding; @@ -367,7 +367,7 @@ impl MathApp { ui.add(Label::new( RichText::new("(and licensed under AGPLv3)").color(Color32::LIGHT_GRAY), )) - .on_hover_text(&self.text.license_info); + .on_hover_text(self.text.license_info.clone()); // Hyperlink to project's github ui.hyperlink_to( @@ -477,34 +477,34 @@ impl App for MathApp { .collapsible(false) .show(ctx, |ui| { ui.collapsing("Supported Expressions", |ui| { - ui.label(&self.text.help_expr); + ui.label(self.text.help_expr.clone()); }); ui.collapsing("Supported Constants", |ui| { - ui.label(&self.text.help_vars); + ui.label(self.text.help_vars.clone()); }); ui.collapsing("Panel", |ui| { - ui.label(&self.text.help_panel); + ui.label(self.text.help_panel.clone()); }); ui.collapsing("Functions", |ui| { - ui.label(&self.text.help_function); + ui.label(self.text.help_function.clone()); }); ui.collapsing("Other", |ui| { - ui.label(&self.text.help_other); + ui.label(self.text.help_other.clone()); }); }); // Welcome window Window::new("Welcome!") .open(&mut self.opened.welcome) - .anchor(Align2::CENTER_CENTER, vec2(0.0, 0.0)) + .anchor(Align2::CENTER_CENTER, Vec2::ZERO) .resizable(false) .collapsible(false) .show(ctx, |ui| { - ui.label(&self.text.welcome); + ui.label(self.text.welcome.clone()); }); // Window with information about the build and current commit