make pause menu better

This commit is contained in:
2026-01-29 16:20:48 -07:00
parent 82230299a4
commit 31c6eb0821
2 changed files with 42 additions and 19 deletions

View File

@@ -9,3 +9,4 @@ Finally, an easy way to do graphics with rust.
| F1 | Pause/Play the graph | | F1 | Pause/Play the graph |
| F2 | Dump the current data to a csv and graph it with gnuplot | | F2 | Dump the current data to a csv and graph it with gnuplot |
| F3 | Show/Hide Debug info | | F3 | Show/Hide Debug info |
| F4 | Show/Hide Cursor Location |

View File

@@ -282,7 +282,7 @@ async fn get_font() -> Option<Font> {
let ttf = load_ttf_font(selection) let ttf = load_ttf_font(selection)
.await .await
.expect("Cannot load ttf {selection}"); .expect("Cannot load ttf {selection}");
println!("Loaded \"{:?}\"", ttfs[0]); println!("Loaded {:?}", ttfs[0]);
return Some(ttf); return Some(ttf);
} else { } else {
eprintln!( eprintln!(
@@ -306,13 +306,19 @@ async fn main() {
let mut graph = Graph::new(Axis::One, font.as_ref()); let mut graph = Graph::new(Axis::One, font.as_ref());
// Tooling // Tooling
let mut show_debug = true; let mut show_debug = false;
let mut plot_delta_time = 0.; let mut plot_delta_time = 0.;
let mut pause = false; let mut pause = false;
// Serial // Serial
let (rx, _handle) = get_serial_port_or_demo(); let (rx, _handle) = get_serial_port_or_demo();
loop { loop {
let mut debug = DebugWindow::new(font.as_ref());
let params = debug.get_params();
let (mouse_x, mouse_y) = mouse_position();
let (_, my) = mouse_wheel();
graph.px_per_s += 10. * my;
clear_background(BLACK); clear_background(BLACK);
graph.recalculate_origin(); graph.recalculate_origin();
@@ -391,26 +397,41 @@ async fn main() {
show_debug = !show_debug; show_debug = !show_debug;
} }
let (_, my) = mouse_wheel(); if !pause {
graph.px_per_s += 10. * my; // Cursor information
let text = &format!("x{mouse_x}, y{}", -(mouse_y - graph.y_origin));
let size = measure_text(text, params.font, params.font_size, params.font_scale);
draw_rectangle(
mouse_x,
mouse_y + (size.offset_y / 4.),
size.width,
-(size.height),
DARKGRAY,
);
draw_text_ex(text, mouse_x, mouse_y, params.clone());
}
let mut debug = DebugWindow::new(font.as_ref()); if pause {
let params = debug.get_params(); for i in graph.points {
let distance = 15.;
if (i.x - mouse_x).abs() < distance && (i.y - mouse_y).abs() < distance {
let size = 10.;
draw_rectangle(i.x - size / 2., i.y - size / 2., size, size, YELLOW);
// Cursor information let text = &format!("x{}, y{}", i.x, i.y);
let (mouse_x, mouse_y) = mouse_position(); let size = measure_text(text, params.font, params.font_size, params.font_scale);
let text = &format!("x{mouse_x}, y{}", -(mouse_y - graph.y_origin)); draw_rectangle(
let size = measure_text(text, params.font, params.font_size, params.font_scale); i.x,
draw_rectangle( i.y + (size.offset_y / 4.),
mouse_x, size.width,
mouse_y + (size.offset_y / 4.), -(size.height),
size.width, DARKGRAY,
-(size.height), );
DARKGRAY, draw_text_ex(text, i.x, i.y, params.clone());
); }
}
}
draw_text_ex(text, mouse_x, mouse_y, params);
// toggle debug box
if show_debug { if show_debug {
// Debug textbox // Debug textbox
debug.add_line(format!( debug.add_line(format!(
@@ -431,6 +452,7 @@ async fn main() {
debug.draw(); debug.draw();
} }
next_frame().await; next_frame().await;
} }
} }