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 |
| F2 | Dump the current data to a csv and graph it with gnuplot |
| 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)
.await
.expect("Cannot load ttf {selection}");
println!("Loaded \"{:?}\"", ttfs[0]);
println!("Loaded {:?}", ttfs[0]);
return Some(ttf);
} else {
eprintln!(
@@ -306,13 +306,19 @@ async fn main() {
let mut graph = Graph::new(Axis::One, font.as_ref());
// Tooling
let mut show_debug = true;
let mut show_debug = false;
let mut plot_delta_time = 0.;
let mut pause = false;
// Serial
let (rx, _handle) = get_serial_port_or_demo();
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);
graph.recalculate_origin();
@@ -391,14 +397,8 @@ async fn main() {
show_debug = !show_debug;
}
let (_, my) = mouse_wheel();
graph.px_per_s += 10. * my;
let mut debug = DebugWindow::new(font.as_ref());
let params = debug.get_params();
if !pause {
// Cursor information
let (mouse_x, mouse_y) = mouse_position();
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(
@@ -408,9 +408,30 @@ async fn main() {
-(size.height),
DARKGRAY,
);
draw_text_ex(text, mouse_x, mouse_y, params.clone());
}
if pause {
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);
let text = &format!("x{}, y{}", i.x, i.y);
let size = measure_text(text, params.font, params.font_size, params.font_scale);
draw_rectangle(
i.x,
i.y + (size.offset_y / 4.),
size.width,
-(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 {
// Debug textbox
debug.add_line(format!(
@@ -431,6 +452,7 @@ async fn main() {
debug.draw();
}
next_frame().await;
}
}