2 * Copyright (C) 2024 Mikulas Patocka
4 * This file is part of Ajla.
6 * Ajla is free software: you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation, either version 3 of the License, or (at your option) any later
11 * Ajla is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along with
16 * Ajla. If not, see <https://www.gnu.org/licenses/>.
19 private unit ui.widget.msgbox;
21 uses ui.widget.common;
23 record msgbox_button [
25 click : fn(world, appstate, wid) : (world, appstate);
26 hotkeys : treeset(char);
29 fn msgbox_new(w : world, app : appstate, caption : string, align : widget_align, text : string, color_scheme : bytes, buttons : list(msgbox_button)) : (world, appstate, wid);
34 uses ui.widget.button;
35 uses ui.widget.dialog;
37 fn msgbox_dialog_layout(implicit app : appstate, ids : list(wid), offs_x offs_y min_x pref_x max_x : int) : (appstate, int, int)
40 xs := max(xs, widget_get_width(ids[0], pref_x));
41 xs := max(xs, widgets_get_width(ids[1 .. ], 2, pref_x));
48 yp := widget_place(ids[0], offs_x, xs, yp);
50 yp := widgets_place(ids[1 .. ], widget_align.center, 2, 1, offs_x, xs, yp);
55 fn msgbox_new(implicit w : world, implicit app : appstate, caption : string, align : widget_align, text : string, color_scheme : bytes, buttons : list(msgbox_button)) : (world, appstate, wid)
60 init : text_init(align, text, color_scheme,,,),
63 for i := 0 to len(buttons) do [
64 entries +<= dialog_entry.[
66 init : button_init(buttons[i].label, true, color_scheme, button_no_action, buttons[i].click,,,),
67 hotkeys : buttons[i].hotkeys,
70 var id := widget_new_window(dialog_class, dialog_init(caption, entries, select(len(buttons) > 0, -1, 1), dialog_no_event, msgbox_dialog_layout, color_scheme,,,), false);