System/Core/MessageBox: Update API and add Confirm()
This commit is contained in:
parent
39cdf87903
commit
bfa41f334b
1 changed files with 45 additions and 14 deletions
|
@ -16,6 +16,10 @@ Context2D* MESSAGEBOX_WIN_ICON_WARN = Image.FileToContext2D(
|
|||
#define MESSAGEBOX_TYPE_ALERT 0
|
||||
#define MESSAGEBOX_TYPE_ERROR 1
|
||||
#define MESSAGEBOX_TYPE_INFO 2
|
||||
#define MESSAGEBOX_TYPE_CONFIRM 3
|
||||
|
||||
JsonArray* @messagebox_default_info = Json.Parse("[\"OK\"]", Fs);
|
||||
JsonArray* @messagebox_default_confirm = Json.Parse("[\"OK\",\"Cancel\"]", Fs);
|
||||
|
||||
U0 @messagebox_close_window(Window* window)
|
||||
{
|
||||
|
@ -27,7 +31,7 @@ U0 @messagebox_close_widget(Widget* widget)
|
|||
}
|
||||
|
||||
U0 @messagebox_msg(U8* str, I64 type, Context2D* win_icon, Context2D* icon,
|
||||
U8* options = NULL, U64 callback = NULL)
|
||||
U64 callback = NULL, JsonArray* options = NULL)
|
||||
{
|
||||
U64 flags = WIN_FLAGS_MOVABLE | WIN_FLAGS_ICON | WIN_FLAGS_TITLE_BAR | WIN_FLAGS_CLOSE_BUTTON;
|
||||
Window* win = Compositor.CreateWindow(0, 0, 320, 192, flags);
|
||||
|
@ -42,6 +46,9 @@ U0 @messagebox_msg(U8* str, I64 type, Context2D* win_icon, Context2D* icon,
|
|||
case MESSAGEBOX_TYPE_INFO:
|
||||
Gui.Window.SetTitle(win, "Info");
|
||||
break;
|
||||
case MESSAGEBOX_TYPE_CONFIRM:
|
||||
Gui.Window.SetTitle(win, "Confirm");
|
||||
break;
|
||||
}
|
||||
Context2DWidget* ctx_icon = Gui.CreateWidget(win, WIDGET_TYPE_CONTEXT2D, 8, 16, 24, 24);
|
||||
ctx_icon->ctx = icon;
|
||||
|
@ -52,13 +59,17 @@ U0 @messagebox_msg(U8* str, I64 type, Context2D* win_icon, Context2D* icon,
|
|||
Gui.Widget.SetText(lbl_text, str);
|
||||
Gui.Window.SetCallback(win, "close", callback);
|
||||
|
||||
if (options) {
|
||||
if (!callback) {
|
||||
callback = &@messagebox_close_widget;
|
||||
}
|
||||
|
||||
if (options->length > 1) {
|
||||
btn_ok = Gui.CreateWidget(win, WIDGET_TYPE_BUTTON, (win->width / 2) - 80,
|
||||
win->height - 60, 64, 24);
|
||||
btn_cancel = Gui.CreateWidget(win, WIDGET_TYPE_BUTTON, (win->width / 2) + 16,
|
||||
win->height - 60, 64, 24);
|
||||
Gui.Widget.SetText(btn_ok, " OK ");
|
||||
Gui.Widget.SetText(btn_cancel, " Cancel ");
|
||||
Gui.Widget.SetText(btn_ok, options->@(0));
|
||||
Gui.Widget.SetText(btn_cancel, options->@(1));
|
||||
Gui.Widget.SetCallback(btn_ok, "clicked", callback);
|
||||
Gui.Widget.SetCallback(btn_cancel, "clicked", callback);
|
||||
btn_ok->tag = TRUE;
|
||||
|
@ -66,7 +77,7 @@ U0 @messagebox_msg(U8* str, I64 type, Context2D* win_icon, Context2D* icon,
|
|||
} else {
|
||||
btn_ok = Gui.CreateWidget(win, WIDGET_TYPE_BUTTON, (win->width / 2) - 32,
|
||||
win->height - 60, 64, 24);
|
||||
Gui.Widget.SetText(btn_ok, " OK ");
|
||||
Gui.Widget.SetText(btn_ok, options->@(0));
|
||||
Gui.Widget.SetCallback(btn_ok, "clicked", callback);
|
||||
btn_ok->tag = TRUE;
|
||||
}
|
||||
|
@ -75,34 +86,54 @@ U0 @messagebox_msg(U8* str, I64 type, Context2D* win_icon, Context2D* icon,
|
|||
Gui.Window.SetFocus(win);
|
||||
}
|
||||
|
||||
U0 @messagebox_alert(U8* str, U8* options = NULL, U64 callback = NULL)
|
||||
U0 @messagebox_alert(U8* str, U64 callback = NULL, JsonArray* options = NULL)
|
||||
{
|
||||
if (!options || !options->length) {
|
||||
options = @messagebox_default_info;
|
||||
}
|
||||
@messagebox_msg(str, MESSAGEBOX_TYPE_ALERT, MESSAGEBOX_WIN_ICON_WARN,
|
||||
MESSAGEBOX_ICON_WARN, options, callback);
|
||||
MESSAGEBOX_ICON_WARN, callback, options);
|
||||
}
|
||||
|
||||
U0 @messagebox_error(U8* str, U8* options = NULL, U64 callback = NULL)
|
||||
U0 @messagebox_error(U8* str, U64 callback = NULL, JsonArray* options = NULL)
|
||||
{
|
||||
if (!options || !options->length) {
|
||||
options = @messagebox_default_info;
|
||||
}
|
||||
@messagebox_msg(str, MESSAGEBOX_TYPE_ERROR, MESSAGEBOX_WIN_ICON_ERR,
|
||||
MESSAGEBOX_ICON_ERR, options, callback);
|
||||
MESSAGEBOX_ICON_ERR, callback, options);
|
||||
}
|
||||
|
||||
U0 @messagebox_info(U8* str, U8* options = NULL, U64 callback = NULL)
|
||||
U0 @messagebox_info(U8* str, U64 callback = NULL, JsonArray* options = NULL)
|
||||
{
|
||||
if (!options || !options->length) {
|
||||
options = @messagebox_default_info;
|
||||
}
|
||||
@messagebox_msg(str, MESSAGEBOX_TYPE_INFO, MESSAGEBOX_WIN_ICON_INFO,
|
||||
MESSAGEBOX_ICON_INFO, options, callback);
|
||||
MESSAGEBOX_ICON_INFO, callback, options);
|
||||
}
|
||||
|
||||
U0 @messagebox_confirm(U8* str, U64 callback = NULL, JsonArray* options = NULL)
|
||||
{
|
||||
if (!options || !options->length) {
|
||||
options = @messagebox_default_confirm;
|
||||
}
|
||||
@messagebox_msg(str, MESSAGEBOX_TYPE_CONFIRM, MESSAGEBOX_WIN_ICON_INFO,
|
||||
MESSAGEBOX_ICON_INFO, callback, options);
|
||||
}
|
||||
|
||||
class @messagebox
|
||||
{
|
||||
U0* (*Alert)(U8* str, U8* options = NULL, U64 callback = NULL);
|
||||
U0* (*Error)(U8* str, U8* options = NULL, U64 callback = NULL);
|
||||
U0* (*Info)(U8* str, U8* options = NULL, U64 callback = NULL);
|
||||
U0* (*Alert)(U8* str, U64 callback = NULL, JsonArray* options = NULL);
|
||||
U0* (*Error)(U8* str, U64 callback = NULL, JsonArray* options = NULL);
|
||||
U0* (*Info)(U8* str, U64 callback = NULL, JsonArray* options = NULL);
|
||||
U0* (*Confirm)(U8* str, U64 callback = NULL, JsonArray* options = NULL);
|
||||
};
|
||||
|
||||
@messagebox MessageBox;
|
||||
MessageBox.Alert = &@messagebox_alert;
|
||||
MessageBox.Error = &@messagebox_error;
|
||||
MessageBox.Info = &@messagebox_info;
|
||||
MessageBox.Confirm = &@messagebox_confirm;
|
||||
|
||||
"messagebox ";
|
Loading…
Add table
Add a link
Reference in a new issue