From 3f9215e28cbe4f1784d0901b23dbb92891e9f595 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 8 Jan 2020 21:03:38 +0100 Subject: [PATCH] Can show an alert popup --- ui_utils.cpp | 27 +++++++++++++++++++++++++-- ui_utils.h | 16 ++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 ui_utils.h diff --git a/ui_utils.cpp b/ui_utils.cpp index 4f2345d..c487620 100644 --- a/ui_utils.cpp +++ b/ui_utils.cpp @@ -15,9 +15,32 @@ void ui_utils::print_base_screen(WINDOW *w) const string msg = "Light client"; mvprintw(0, (col-static_cast(msg.length())), msg.c_str()); +} + +void ui_utils::alert(WINDOW *win, const string &msg) +{ + erase(); + print_base_screen(win); + + int rows, cols; + getmaxyx(win, rows, cols); + + int start = (rows/2) - 3; + + mvwprintw(win, start, (cols-static_cast(msg.length()))/2, msg.c_str()); + + wattron(stdscr, A_REVERSE); + mvwprintw(win, start+3, (cols-4)/2, " OK "); + wattroff(stdscr, A_REVERSE); + + + + curs_set(0); refresh(); + while(getch() != 10); - - + curs_set(1); + erase(); + refresh(); } diff --git a/ui_utils.h b/ui_utils.h new file mode 100644 index 0000000..fa9ace0 --- /dev/null +++ b/ui_utils.h @@ -0,0 +1,16 @@ +/** + * UI utilities + * + * @author Pierre HUBERT + */ + +#include + +#include + +#pragma once + +namespace ui_utils { + void alert(WINDOW *win, const std::string &msg); + void print_base_screen(WINDOW *w); +}