Skip to content

Commit

Permalink
ui improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchUsr64 committed Jan 10, 2024
1 parent 1406e0b commit d3e1f6b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 53 deletions.
76 changes: 41 additions & 35 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,33 @@ impl App {
ctx.set_pixels_per_point(self.ui_scale);
};
});
if ui
.add(egui::Button::new(if !self.paused {
"Pause Execution"
} else {
"Resume Execution"
}))
.clicked()
{
self.paused = !self.paused;
};
if ui.add(egui::Button::new("Reset")).clicked() {
self.reset = true
};
if self.paused {
if ui.add(egui::Button::new("Step")).clicked() {
self.step = true
ui.horizontal(|ui| {
ui.label("Simulation Speed: ");
ui.add(egui::Slider::new(
&mut self.instructions_per_frame,
1u32..=500,
))
});
ui.horizontal(|ui| {
if ui
.add(egui::Button::new(if !self.paused {
"Pause Execution"
} else {
"Resume Execution"
}))
.clicked()
{
self.paused = !self.paused;
};
}
});
egui::Window::new("Simulation Speed").show(ctx, |ui| {
ui.add(egui::Slider::new(
&mut self.instructions_per_frame,
1u32..=500,
))
if ui.add(egui::Button::new("Reset")).clicked() {
self.reset = true
};
if self.paused {
if ui.add(egui::Button::new("Step")).clicked() {
self.step = true
};
}
});
});
if self.paused {
let cpu_state = cpu.state();
Expand Down Expand Up @@ -153,11 +156,13 @@ impl App {
egui::Window::new("Breakpoints").show(ctx, |ui| {
ui.horizontal(|ui| {
ui.label("Line number:");
ui.add(
egui::TextEdit::singleline(&mut self.breakpoints_user_entry).desired_width(40.),
);

if ui.button("Add").clicked() {
if ui
.add(
egui::TextEdit::singleline(&mut self.breakpoints_user_entry)
.desired_width(40.),
)
.lost_focus() || ui.button("Add").clicked()
{
if let Ok(line_number) = self.breakpoints_user_entry.parse() {
if !self.breakpoints.contains(&line_number) {
self.breakpoints.push(line_number);
Expand All @@ -182,13 +187,14 @@ impl App {
egui::Window::new("Watchpoints").show(ctx, |ui| {
ui.horizontal(|ui| {
ui.label("Address:");
ui.add(
egui::TextEdit::singleline(&mut self.watchpoints_user_entry)
.desired_width(40.)
.hint_text("in hex"),
);

if ui.button("Add").clicked() {
if ui
.add(
egui::TextEdit::singleline(&mut self.watchpoints_user_entry)
.desired_width(40.)
.hint_text("in hex"),
)
.lost_focus() || ui.button("Add").clicked()
{
if let Ok(line_number) = u16::from_str_radix(&self.watchpoints_user_entry, 16) {
if !self.watchpoints.contains(&line_number) {
self.watchpoints.push(line_number);
Expand Down
21 changes: 3 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use log::{info, LevelFilter};
use simplelog::{ColorChoice, Config, TermLogger, TerminalMode};

use macroquad::prelude::{
clear_background, draw_rectangle, draw_rectangle_lines, draw_text, is_key_down, next_frame,
rand, screen_height, screen_width, Color, KeyCode, BLACK, WHITE,
clear_background, draw_rectangle, draw_rectangle_lines, is_key_down, next_frame, rand,
screen_height, screen_width, Color, KeyCode, BLACK, WHITE,
};
const SCREEN_MEMORY_START: usize = 0xfb00;
const INPUT_MEMORY_LOCATION: usize = 0xfb;
Expand Down Expand Up @@ -119,6 +119,7 @@ async fn main() {
(0..app.instructions_per_frame).for_each(|_| execute_one_cycle());
} else if app.step {
execute_one_cycle();
app.step = false;
}
// Window Decorations
clear_background(BLACK);
Expand Down Expand Up @@ -156,22 +157,6 @@ async fn main() {
);
})
});
draw_text(
format!("FPS: {:.0}", macroquad::time::get_fps(),).as_str(),
0.,
0.5 * min_screen_dimension * 0.1,
min_screen_dimension * 0.1,
WHITE,
);
if app.paused {
draw_text(
format!("PAUSED",).as_str(),
0.,
1.5 * min_screen_dimension * 0.1,
min_screen_dimension * 0.1,
WHITE,
);
}

egui_macroquad::ui(|egui_ctx| {
app.render_ui(egui_ctx, &cpu, &mem);
Expand Down

0 comments on commit d3e1f6b

Please sign in to comment.