Aplicando callbacks para las acciones del ui

This commit is contained in:
2025-06-26 21:44:16 -04:00
parent 5ebc235cae
commit 8b20f4499d
6 changed files with 204 additions and 16 deletions

View File

@@ -18,6 +18,8 @@ ControlPanel::ControlPanel(
void ControlPanel::render()
{
int starting_speed = this->ips;
constexpr auto full_width = ImVec2(-FLT_MIN, 0.0f);
if (ImGui::Begin("Chip-8 - Controls"))
@@ -30,14 +32,31 @@ void ControlPanel::render()
if (ImGui::Button(run ? "Pause" : "Run", full_width))
{
this->run = !run;
if (this->run)
{
this->callback_manager->trigger_resume();
}
else
{
this->callback_manager->trigger_stop();
}
}
ImGui::Text("Status: %s", "Stopped");
ImGui::SeparatorText("Debug");
ImGui::Button("Step One", full_width);
ImGui::Button(std::format("Step +{}", steps).data(), full_width);
if (ImGui::Button("Step One", full_width))
{
this->callback_manager->trigger_step(1);
}
if (ImGui::Button(std::format("Step +{}", steps).data(), full_width))
{
this->callback_manager->trigger_step(steps);
}
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::InputInt("##steps", &steps);
ImGui::PopItemWidth();
@@ -46,7 +65,7 @@ void ControlPanel::render()
ImGui::SeparatorText("Emulation speed (IPS)");
ImGui::PushItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::InputInt("##speed", &speed);
ImGui::InputInt("##speed", &ips);
ImGui::PopItemWidth();
ImGui::SeparatorText("");
@@ -55,7 +74,15 @@ void ControlPanel::render()
{
this->callback_manager->trigger_reset();
}
ImGui::Button("Reload ROM", full_width);
if (ImGui::Button("Reload ROM", full_width))
{
this->callback_manager->trigger_reload();
}
}
if (starting_speed != this->ips)
{
this->callback_manager->trigger_ips(this->ips);
}
ImGui::End();
@@ -89,4 +116,4 @@ void ControlPanel::on_callback_load_rom(void* self, const char* const* filelist,
}
control_panel->callback_manager->trigger_rom_load(filelist[0]);
}
}