Skip to content
Snippets Groups Projects
Commit 640a9e41 authored by Finn Bear's avatar Finn Bear
Browse files

Fix pseudocode font size.

parent a68eaa55
No related branches found
No related tags found
No related merge requests found
...@@ -641,8 +641,7 @@ dependencies = [ ...@@ -641,8 +641,7 @@ dependencies = [
[[package]] [[package]]
name = "egui_demo_lib" name = "egui_demo_lib"
version = "0.17.0" version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/finnbear/egui?branch=code_theme_font_size_3#559ffe9d90d03969f446da9f34f0a1d0fcf64cfd"
checksum = "43ed5e8c26d1d7f9f56e51f32469b13e9880fceda61199bd0a7cae79b88d5dd5"
dependencies = [ dependencies = [
"chrono", "chrono",
"egui", "egui",
......
...@@ -5,6 +5,6 @@ edition = "2021" ...@@ -5,6 +5,6 @@ edition = "2021"
[dependencies] [dependencies]
eframe = "0.17" eframe = "0.17"
egui_demo_lib = "0.17" egui_demo_lib = {git = "https://github.com/finnbear/egui", branch = "code_theme_font_size_3"}
image = {version = "0.24", default-features = false, features=["png"]} image = {version = "0.24", default-features = false, features=["png"]}
rand = {version = "0.8"} rand = {version = "0.8"}
\ No newline at end of file
...@@ -14,7 +14,7 @@ Transitions are reset when the slideshow wraps around. ...@@ -14,7 +14,7 @@ Transitions are reset when the slideshow wraps around.
## Development ## Development
You'll need the [Rust toolchain](https://rustup.rs/). You'll need the **nightly** [Rust toolchain](https://rustup.rs/).
Use [this demo](https://www.egui.rs/index.html) to better understand the [egui](https://github.com/emilk/egui) library. Use [this demo](https://www.egui.rs/index.html) to better understand the [egui](https://github.com/emilk/egui) library.
......
...@@ -85,13 +85,10 @@ impl epi::App for Cartoon { ...@@ -85,13 +85,10 @@ impl epi::App for Cartoon {
let small_style = style.text_styles.get_mut(&TextStyle::Small).unwrap(); let small_style = style.text_styles.get_mut(&TextStyle::Small).unwrap();
small_style.size = 22.0; small_style.size = 22.0;
} }
// TODO(finnb): This doesn't work. May have to fork syntax coloring code to fix it.
/*
{ {
let monospaced_style = style.text_styles.get_mut(&TextStyle::Monospace).unwrap(); let monospaced_style = style.text_styles.get_mut(&TextStyle::Monospace).unwrap();
monospaced_style.size = 22.0; monospaced_style.size = 22.0;
} }
*/
ctx.set_style(style); ctx.set_style(style);
// Start fading in title slide now. // Start fading in title slide now.
......
use crate::color::{set_alpha_in_place, set_style_alpha}; use crate::color::{set_alpha_in_place, set_style_alpha};
use eframe::egui; use eframe::egui;
use eframe::egui::{Align2, Color32, Context, Frame, Vec2, Widget, Window}; use eframe::egui::{Align2, Color32, Context, Frame, TextStyle, Vec2, Widget, Window};
/// A reusable (pseudo)code-display component. /// A reusable (pseudo)code-display component.
#[derive(Clone)] #[derive(Clone)]
...@@ -47,8 +47,16 @@ impl Code { ...@@ -47,8 +47,16 @@ impl Code {
) )
.fixed_size(Vec2::splat(self.size_pixels)) .fixed_size(Vec2::splat(self.size_pixels))
.show(ctx, |ui| { .show(ctx, |ui| {
// Syntax coloring code adapted from: https://github.com/emilk/egui/blob/master/egui_demo_lib/src/apps/demo/code_editor.rs // Syntax coloring code adapted from: https://github.com/emilk/egui/blob/master/egui_demo_lib/src/demo/code_editor.rs
let theme = egui_demo_lib::syntax_highlighting::CodeTheme::light(); let theme = egui_demo_lib::syntax_highlighting::CodeTheme::light(
ui.ctx()
.style()
.text_styles
.get(&TextStyle::Monospace)
.unwrap()
.size,
);
let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| { let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
let mut layout_job = egui_demo_lib::syntax_highlighting::highlight( let mut layout_job = egui_demo_lib::syntax_highlighting::highlight(
ui.ctx(), ui.ctx(),
...@@ -78,7 +86,8 @@ impl Code { ...@@ -78,7 +86,8 @@ impl Code {
/// ///
/// Note: Must use non-idiomatic `return x;` instead of just `x`. /// Note: Must use non-idiomatic `return x;` instead of just `x`.
pub fn pseudocode(code: &str) -> String { pub fn pseudocode(code: &str) -> String {
code.replace("pub ", "") code.replace("#[rustfmt::skip]\n", "")
.replace("pub ", "")
.replace("fn ", "function ") .replace("fn ", "function ")
.replace("let ", "") .replace("let ", "")
.replace("mut ", "") .replace("mut ", "")
......
#[rustfmt::skip]
pub fn circle(x: f32, y: f32) -> bool { pub fn circle(x: f32, y: f32) -> bool {
return x * x + y * y <= 3.0; return x * x
+ y * y <= 3.0;
} }
#[rustfmt::skip]
pub fn mandelbrot(x: f32, y: f32) -> bool { pub fn mandelbrot(x: f32, y: f32) -> bool {
let max = 512; let max = 512;
let mut x1 = 0.0; let mut x1 = 0.0;
let mut y1 = 0.0; let mut y1 = 0.0;
let mut i = 0; let mut i = 0;
while x1 * x1 + y1 * y1 <= 4.0 && i < max { while x1 * x1 + y1 * y1
let x_tmp = x1 * x1 - y1 * y1 + x; <= 4.0 && i < max {
let x_tmp = x1 * x1
- y1 * y1 + x;
y1 = 2.0 * x1 * y1 + y; y1 = 2.0 * x1 * y1 + y;
x1 = x_tmp; x1 = x_tmp;
i += 1; i += 1;
......
#[rustfmt::skip]
pub fn rectangle(x: f32, y: f32) -> bool { pub fn rectangle(x: f32, y: f32) -> bool {
return -1.5 < x && x < 1.5 && -1.0 < y && y < 1.0; return -1.5 < x && x < 1.5
&& -1.0 < y && y < 1.0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment