From 5fcf57739e68a8b5053e03778aaee0eed445babd Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Thu, 11 Mar 2021 22:00:22 -0500 Subject: settings editor, and lots of changes in service of that --- src/user/raleigh/d/dialog.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 src/user/raleigh/d/dialog.cpp (limited to 'src/user/raleigh/d/dialog.cpp') diff --git a/src/user/raleigh/d/dialog.cpp b/src/user/raleigh/d/dialog.cpp new file mode 100644 index 0000000..38ca310 --- /dev/null +++ b/src/user/raleigh/d/dialog.cpp @@ -0,0 +1,74 @@ +#include + +#include +#include +#include +#include + +using namespace raleigh; + +void dialog::show_modal() { + show(); + do { + _wait_for_action(); + _yield_task(); + consume_actions(); + } while (!result); + to_be_deleted.add_back(*this); +} + +static bool on_diag_close(window_tag_t) { + return false; +} + +struct diag_and_result { + dialog *d; + diag_result_t r; + diag_and_result(dialog *d, diag_result_t r) + : d(d), r(r) {} +}; + +static void set_diag_result(button_tag_t tag) { + const diag_and_result *const cast = (const diag_and_result *)tag; + cast->d->result = cast->r; + //TODO: go through all of raleigh and add destructors + //in this case, delete all of these tags when the window is closed +} + +dialog::dialog(widget &top_part, alist> buttons) + : window(*new vbox(), RGB(bf, bf, bf), &on_diag_close), result(0), main_box((vbox *)&root) { + dllist *button_row = new dllist(); + for (duple *i = buttons.buf; i < buttons.buf + buttons.n_entries; ++i) { + label *l = new label(i->a); + padding *p = new padding(*l, 4); + button *b = new button(*p, &set_diag_result, new diag_and_result(this, i->b)); + padding *pb = new padding(*b, 2); + button_row->add_back(*pb); + } + hbox *button_box = new hbox(*button_row); + + padding *ptop = new padding(top_part, 2); + padding *pbot = new padding(*button_box, 2); + + main_box->add_end(*ptop); + main_box->add_end(*pbot); +} + +alist> &mk_yes_no_cancel() { + alist> *list = new alist>(3, 1); + list->add_back(duple("Yes", YES)); + list->add_back(duple("No", NO)); + list->add_back(duple("Cancel", CANCEL)); + return *list; +} + +alist> &mk_yes_no_retry() { + alist> *list = new alist>(3, 1); + list->add_back(duple("Yes", YES)); + list->add_back(duple("No", NO)); + list->add_back(duple("Retry", RETRY)); + return *list; +} + +alist> &raleigh::yes_no_cancel(mk_yes_no_cancel()); +alist> &raleigh::yes_no_retry(mk_yes_no_retry()); \ No newline at end of file -- cgit v1.2.3