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 = [
[[package]]
name = "egui_demo_lib"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43ed5e8c26d1d7f9f56e51f32469b13e9880fceda61199bd0a7cae79b88d5dd5"
source = "git+https://github.com/finnbear/egui?branch=code_theme_font_size_3#559ffe9d90d03969f446da9f34f0a1d0fcf64cfd"
dependencies = [
"chrono",
"egui",
......
......@@ -5,6 +5,6 @@ edition = "2021"
[dependencies]
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"]}
rand = {version = "0.8"}
\ No newline at end of file
......@@ -14,7 +14,7 @@ Transitions are reset when the slideshow wraps around.
## 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.
......
......@@ -85,13 +85,10 @@ impl epi::App for Cartoon {
let small_style = style.text_styles.get_mut(&TextStyle::Small).unwrap();
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();
monospaced_style.size = 22.0;
}
*/
ctx.set_style(style);
// Start fading in title slide now.
......
use crate::color::{set_alpha_in_place, set_style_alpha};
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.
#[derive(Clone)]
......@@ -47,8 +47,16 @@ impl Code {
)
.fixed_size(Vec2::splat(self.size_pixels))
.show(ctx, |ui| {
// Syntax coloring code adapted from: https://github.com/emilk/egui/blob/master/egui_demo_lib/src/apps/demo/code_editor.rs
let theme = egui_demo_lib::syntax_highlighting::CodeTheme::light();
// 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(
ui.ctx()
.style()
.text_styles
.get(&TextStyle::Monospace)
.unwrap()
.size,
);
let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
let mut layout_job = egui_demo_lib::syntax_highlighting::highlight(
ui.ctx(),
......@@ -78,7 +86,8 @@ impl Code {
///
/// Note: Must use non-idiomatic `return x;` instead of just `x`.
pub fn pseudocode(code: &str) -> String {
code.replace("pub ", "")
code.replace("#[rustfmt::skip]\n", "")
.replace("pub ", "")
.replace("fn ", "function ")
.replace("let ", "")
.replace("mut ", "")
......
#[rustfmt::skip]
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 {
let max = 512;
let mut x1 = 0.0;
let mut y1 = 0.0;
let mut i = 0;
while x1 * x1 + y1 * y1 <= 4.0 && i < max {
let x_tmp = x1 * x1 - y1 * y1 + x;
while x1 * x1 + y1 * y1
<= 4.0 && i < max {
let x_tmp = x1 * x1
- y1 * y1 + x;
y1 = 2.0 * x1 * y1 + y;
x1 = x_tmp;
i += 1;
......
#[rustfmt::skip]
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