From 99658f63f65e475b4c2a575c3747d8e95b6e9265 Mon Sep 17 00:00:00 2001 From: Ivan Gagis Date: Wed, 17 Apr 2024 10:49:24 +0300 Subject: [PATCH] exit by esc key --- src/gauge.cpp | 3 ++- src/gui.cpp | 6 ++---- src/gui.hpp | 4 ++-- src/main.cpp | 12 +++++++++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/gauge.cpp b/src/gauge.cpp index 68fe50c..ed1ad4d 100644 --- a/src/gauge.cpp +++ b/src/gauge.cpp @@ -69,7 +69,8 @@ void gauge::render(const matrix4& matrix) const matrix4 mmm; mmm.set_identity(); mmm.rotate( - -(this->params.start_angle_rad + (this->params.end_angle_rad - this->params.start_angle_rad) * this->get_fraction()) + -(this->params.start_angle_rad + + (this->params.end_angle_rad - this->params.start_angle_rad) * this->get_fraction()) ); { auto div = this->arrow_tex->dims.x() * this->params.arm_fraction; diff --git a/src/gui.cpp b/src/gui.cpp index 60148ce..a7fff50 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -39,13 +39,12 @@ using namespace ruis::make; using namespace carcockpit::make; } // namespace m -utki::shared_ref carcockpit::make_root_widgets(utki::shared_ref c) +utki::shared_ref carcockpit::make_root_widgets(utki::shared_ref c) { using ruis::lp; // clang-format off - auto w = m::container( - c, + auto w = m::key_proxy(c, { .container_params = { .layout = ruis::layout::column @@ -139,7 +138,6 @@ utki::shared_ref carcockpit::make_root_widgets(utki::shared_ref. #pragma once -#include +#include namespace carcockpit { -utki::shared_ref make_root_widgets(utki::shared_ref c); +utki::shared_ref make_root_widgets(utki::shared_ref c); } // namespace carcockpit diff --git a/src/main.cpp b/src/main.cpp index 2c45360..6a86ad5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,7 +52,17 @@ class application : public ruisapp::application this->gui.context.get().loader.mount_res_pack(*this->get_res_file(papki::as_dir(res_path))); - this->gui.set_root(make_root_widgets(this->gui.context)); + auto kp = make_root_widgets(this->gui.context); + kp.get().key_handler = [this](ruis::key_proxy&, const ruis::key_event& e) { + if (e.is_down) { + if (e.combo.key == ruis::key::escape) { + this->quit(); + } + } + return false; + }; + + this->gui.set_root(std::move(kp)); } };