From 64308c9e520dbd8e72b675d0ba064ecdaf9bd494 Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Tue, 4 Feb 2025 23:39:24 +0100 Subject: add error handling to ui --- lib/nes/app/ui/screen-error.cc | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/nes/app/ui/screen-error.cc (limited to 'lib/nes/app/ui/screen-error.cc') diff --git a/lib/nes/app/ui/screen-error.cc b/lib/nes/app/ui/screen-error.cc new file mode 100644 index 0000000..67a3244 --- /dev/null +++ b/lib/nes/app/ui/screen-error.cc @@ -0,0 +1,38 @@ +#include "nes/app/ui/screen-error.hh" +#include "nes/app/graphics/renderer.hh" +#include "nes/app/graphics/color.hh" +#include "nes/app/input/input-device-keyboard.hh" + +namespace nes::app +{ + screen_error::screen_error(input_device_keyboard& keyboard) + : keyboard_{ keyboard } + { + } + + auto screen_error::render(renderer& renderer) -> void + { + // TODO: Nicer box + renderer.render_rect(2, 9, 28, 5, color::background_secondary); + + auto const attrs = text_attributes{} + .set_alignment(text_alignment::center) + .set_ellipsize_mode(ellipsize_mode::end) + .set_max_width(26); + renderer.render_text_format(16, 10, color::foreground_primary, attrs, "{}:", message_); + renderer.render_text(16, 12, to_string(error_), color::foreground_primary, attrs); + } + + auto screen_error::process_events() -> action + { + while (auto const event = keyboard_.poll_event()) + { + if (event == input_event::key_down(key::enter)) + { + return action::close_popup(); + } + } + + return action{}; + } +} // namespace nes::app \ No newline at end of file -- cgit v1.3.1