mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
refactor
This commit is contained in:
parent
005f07be8d
commit
51552c0bab
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* File: demo1_app.c
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: basic class of all widget
|
||||
* Brief: basic demo
|
||||
*
|
||||
* Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* File: demo1_app.c
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: basic class of all widget
|
||||
* Brief: demoui
|
||||
*
|
||||
* Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* File: demo_main.c
|
||||
* File: preview_ui.c
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: demo main
|
||||
* Brief: preview ui
|
||||
*
|
||||
* Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
@ -20,7 +20,6 @@
|
||||
*/
|
||||
|
||||
#include "awtk.h"
|
||||
#include "ext_widgets.h"
|
||||
#include "tkc/fs.h"
|
||||
#include "tkc/mem.h"
|
||||
#include "tkc/utils.h"
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "awtk_base.h"
|
||||
#include "awtk_global.h"
|
||||
#include "awtk_widgets.h"
|
||||
#include "blend/image_g2d.h"
|
||||
|
||||
#ifndef WITHOUT_EXT_WIDGETS
|
||||
#include "awtk_ext_widgets.h"
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "base/canvas.h"
|
||||
#include "tkc/time_now.h"
|
||||
#include "tkc/color_parser.h"
|
||||
#include "base/wuxiaolin.inc"
|
||||
#include "base/system_info.h"
|
||||
|
||||
#include "base/lcd_profile.h"
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include "base/keys.h"
|
||||
#include "base/enums.h"
|
||||
#include "base/widget.h"
|
||||
#include "widgets/edit.h"
|
||||
#include "base/input_method.h"
|
||||
#include "base/window_animator.h"
|
||||
#include "base/assets_manager.h"
|
||||
|
||||
|
@ -20,17 +20,21 @@
|
||||
*/
|
||||
|
||||
#include "tkc/mem.h"
|
||||
|
||||
#include "tkc/value.h"
|
||||
#include "tkc/utils.h"
|
||||
#include "widgets/window.h"
|
||||
#include "widgets/dialog.h"
|
||||
#include "base/widget_factory.h"
|
||||
|
||||
#ifndef AWTK_NOGUI
|
||||
#include "widgets/row.h"
|
||||
#include "widgets/grid.h"
|
||||
#include "widgets/view.h"
|
||||
#include "tkc/utils.h"
|
||||
#include "widgets/image.h"
|
||||
#include "widgets/label.h"
|
||||
#include "tkc/value.h"
|
||||
#include "widgets/overlay.h"
|
||||
#include "widgets/window.h"
|
||||
#include "widgets/button.h"
|
||||
#include "widgets/dialog.h"
|
||||
#include "widgets/slider.h"
|
||||
#include "widgets/edit.h"
|
||||
#include "widgets/pages.h"
|
||||
@ -53,9 +57,8 @@
|
||||
#include "widgets/combo_box.h"
|
||||
#include "widgets/color_tile.h"
|
||||
#include "widgets/combo_box_item.h"
|
||||
#include "base/window_manager.h"
|
||||
#include "base/widget_factory.h"
|
||||
#include "widgets/calibration_win.h"
|
||||
#endif/*AWTK_NOGUI*/
|
||||
|
||||
static widget_factory_t* widget_factory_init(widget_factory_t* factory);
|
||||
static ret_t widget_factory_deinit(widget_factory_t* factory);
|
||||
@ -72,10 +75,11 @@ static int32_t creator_item_cmp(const creator_item_t* iter, const char* type) {
|
||||
|
||||
static const creator_item_t s_builtin_creators[] = {
|
||||
{WIDGET_TYPE_DIALOG, dialog_create},
|
||||
{WIDGET_TYPE_NORMAL_WINDOW, window_create},
|
||||
#ifndef AWTK_NOGUI
|
||||
{WIDGET_TYPE_DIALOG_TITLE, dialog_title_create},
|
||||
{WIDGET_TYPE_DIALOG_CLIENT, dialog_client_create},
|
||||
{WIDGET_TYPE_OVERLAY, overlay_create},
|
||||
{WIDGET_TYPE_NORMAL_WINDOW, window_create},
|
||||
{WIDGET_TYPE_IMAGE, image_create},
|
||||
{WIDGET_TYPE_BUTTON, button_create},
|
||||
{WIDGET_TYPE_LABEL, label_create},
|
||||
@ -103,7 +107,9 @@ static const creator_item_t s_builtin_creators[] = {
|
||||
{WIDGET_TYPE_APP_BAR, app_bar_create},
|
||||
{WIDGET_TYPE_SYSTEM_BAR, system_bar_create},
|
||||
{WIDGET_TYPE_CALIBRATION_WIN, calibration_win_create},
|
||||
{WIDGET_TYPE_COLOR_TILE, color_tile_create}};
|
||||
{WIDGET_TYPE_COLOR_TILE, color_tile_create}
|
||||
#endif/**AWTK_NOGUI*/
|
||||
};
|
||||
|
||||
static const creator_item_t* widget_factory_find_builtin_creator(const char* type) {
|
||||
uint32_t i = 0;
|
||||
|
@ -19,7 +19,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "widgets/view.h"
|
||||
#include "tkc/utf8.h"
|
||||
#include "base/enums.h"
|
||||
#include "widgets/dialog.h"
|
||||
|
@ -21,14 +21,10 @@
|
||||
|
||||
#include "tkc/mem.h"
|
||||
#include "base/idle.h"
|
||||
#include "widgets/label.h"
|
||||
#include "widgets/button.h"
|
||||
#include "base/enums.h"
|
||||
#include "tkc/utils.h"
|
||||
#include "base/layout.h"
|
||||
#include "widgets/dialog.h"
|
||||
#include "widgets/dialog_title.h"
|
||||
#include "widgets/dialog_client.h"
|
||||
#include "base/main_loop.h"
|
||||
#include "base/image_manager.h"
|
||||
#include "base/window_manager.h"
|
||||
@ -109,24 +105,6 @@ widget_t* dialog_create(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
return window_base_create(parent, TK_REF_VTABLE(dialog), x, y, w, h);
|
||||
}
|
||||
|
||||
widget_t* dialog_create_simple(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
widget_t* title = NULL;
|
||||
widget_t* client = NULL;
|
||||
widget_t* widget = dialog_create(parent, x, y, w, h);
|
||||
dialog_t* dialog = DIALOG(widget);
|
||||
return_value_if_fail(dialog != NULL, NULL);
|
||||
|
||||
title = dialog_title_create(widget, 0, 0, 0, 0);
|
||||
widget_set_self_layout_params(title, "0", "0", "100%", "30");
|
||||
|
||||
client = dialog_client_create(widget, 0, 0, 0, 0);
|
||||
widget_set_self_layout_params(client, "0", "bottom", "100%", "-30");
|
||||
|
||||
widget_layout(widget);
|
||||
|
||||
return WIDGET(dialog);
|
||||
}
|
||||
|
||||
ret_t dialog_set_title(widget_t* widget, const char* title) {
|
||||
dialog_t* dialog = DIALOG(widget);
|
||||
return_value_if_fail(dialog != NULL && title != NULL, RET_BAD_PARAMS);
|
||||
@ -144,6 +122,21 @@ static ret_t dialog_idle_close(const idle_info_t* info) {
|
||||
return dialog_close(WIDGET(info->ctx));
|
||||
}
|
||||
|
||||
widget_t* dialog_get_title(widget_t* widget) {
|
||||
dialog_t* dialog = DIALOG(widget);
|
||||
return_value_if_fail(dialog != NULL, NULL);
|
||||
|
||||
return dialog->title;
|
||||
}
|
||||
|
||||
widget_t* dialog_get_client(widget_t* widget) {
|
||||
dialog_t* dialog = DIALOG(widget);
|
||||
return_value_if_fail(dialog != NULL, NULL);
|
||||
|
||||
return dialog->client;
|
||||
}
|
||||
|
||||
|
||||
uint32_t dialog_modal(widget_t* widget) {
|
||||
#ifdef AWTK_WEB
|
||||
log_debug("awtk web not support dialog_modal\n");
|
||||
@ -212,212 +205,3 @@ widget_t* dialog_cast(widget_t* widget) {
|
||||
return widget;
|
||||
}
|
||||
|
||||
widget_t* dialog_get_title(widget_t* widget) {
|
||||
dialog_t* dialog = DIALOG(widget);
|
||||
return_value_if_fail(dialog != NULL, NULL);
|
||||
|
||||
return dialog->title;
|
||||
}
|
||||
|
||||
widget_t* dialog_get_client(widget_t* widget) {
|
||||
dialog_t* dialog = DIALOG(widget);
|
||||
return_value_if_fail(dialog != NULL, NULL);
|
||||
|
||||
return dialog->client;
|
||||
}
|
||||
|
||||
#include "base/window_manager.h"
|
||||
|
||||
#define OK_STYLE_NAME "default"
|
||||
#define CANCEL_STYLE_NAME "default"
|
||||
|
||||
static ret_t on_ok_to_quit(void* ctx, event_t* e) {
|
||||
widget_t* dlg = WIDGET(ctx);
|
||||
dialog_quit(dlg, RET_OK);
|
||||
|
||||
return RET_REMOVE;
|
||||
}
|
||||
|
||||
static ret_t on_cancel_to_quit(void* ctx, event_t* e) {
|
||||
widget_t* dlg = WIDGET(ctx);
|
||||
dialog_quit(dlg, RET_FAIL);
|
||||
|
||||
return RET_REMOVE;
|
||||
}
|
||||
|
||||
static ret_t on_timer_to_quit(const timer_info_t* info) {
|
||||
widget_t* dlg = WIDGET(info->ctx);
|
||||
|
||||
dialog_quit(dlg, 0);
|
||||
|
||||
return RET_REMOVE;
|
||||
}
|
||||
|
||||
/*simple dialogs*/
|
||||
|
||||
static ret_t dialog_get_size_limits(rect_t* r) {
|
||||
uint32_t min_w = 128;
|
||||
uint32_t max_w = 0;
|
||||
uint32_t min_h = 30;
|
||||
uint32_t max_h = 0;
|
||||
widget_t* wm = window_manager();
|
||||
|
||||
max_w = wm->w * 0.8;
|
||||
max_h = wm->h * 0.8;
|
||||
|
||||
r->x = min_w;
|
||||
r->w = max_w;
|
||||
r->y = min_h;
|
||||
r->h = max_h;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static widget_t* dialog_create_label(const char* text) {
|
||||
rect_t r;
|
||||
widget_t* label = NULL;
|
||||
|
||||
dialog_get_size_limits(&r);
|
||||
|
||||
label = label_create(NULL, 0, 0, 0, 0);
|
||||
return_value_if_fail(label != NULL, NULL);
|
||||
|
||||
widget_set_text_utf8(label, text);
|
||||
label_resize_to_content(label, r.x, r.w, r.y, r.h);
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
ret_t dialog_toast(const char* text, uint32_t duration) {
|
||||
widget_t* label = NULL;
|
||||
widget_t* dialog = NULL;
|
||||
return_value_if_fail(text != NULL, RET_BAD_PARAMS);
|
||||
|
||||
label = dialog_create_label(text);
|
||||
return_value_if_fail(label != NULL, RET_OOM);
|
||||
|
||||
dialog = dialog_create(NULL, 0, 0, label->w, label->h);
|
||||
goto_error_if_fail(dialog != NULL);
|
||||
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_ANIM_HINT, "fade(duration=500)");
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_THEME, "dialog_toast");
|
||||
widget_add_child(dialog, label);
|
||||
|
||||
widget_on(dialog, EVT_POINTER_UP, on_ok_to_quit, dialog);
|
||||
widget_add_timer(dialog, on_timer_to_quit, duration);
|
||||
|
||||
return (ret_t)dialog_modal(dialog);
|
||||
error:
|
||||
widget_destroy(label);
|
||||
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
ret_t dialog_info_ex(const char* text, const char* title_text, const char* theme) {
|
||||
uint32_t w = 0;
|
||||
uint32_t h = 0;
|
||||
char params[128];
|
||||
widget_t* ok = NULL;
|
||||
widget_t* label = NULL;
|
||||
widget_t* dialog = NULL;
|
||||
widget_t* title = NULL;
|
||||
widget_t* client = NULL;
|
||||
return_value_if_fail(text != NULL, RET_BAD_PARAMS);
|
||||
|
||||
label = dialog_create_label(text);
|
||||
return_value_if_fail(label != NULL, RET_OOM);
|
||||
|
||||
tk_snprintf(params, sizeof(params) - 1, "default(x=10, y=10, w=%d, h=%d)", label->w, label->h);
|
||||
widget_set_self_layout(label, params);
|
||||
|
||||
h = label->h + 90;
|
||||
w = tk_max(label->w, 128) + 40;
|
||||
dialog = dialog_create_simple(NULL, 0, 0, w, h);
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_THEME, theme);
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_HIGHLIGHT, "default(alpha=40)");
|
||||
|
||||
client = dialog_get_client(dialog);
|
||||
title = dialog_get_title(dialog);
|
||||
|
||||
widget_set_tr_text(title, title_text);
|
||||
widget_add_child(client, label);
|
||||
|
||||
ok = button_create(client, 0, 0, 0, 0);
|
||||
widget_set_tr_text(ok, "OK");
|
||||
widget_set_self_layout(ok, "default(x=c, y=bottom:10, w=50%, h=30)");
|
||||
widget_on(ok, EVT_CLICK, on_ok_to_quit, dialog);
|
||||
|
||||
if (dialog != NULL && ok != NULL) {
|
||||
widget_layout(dialog);
|
||||
|
||||
return (ret_t)dialog_modal(dialog);
|
||||
} else {
|
||||
widget_destroy(dialog);
|
||||
|
||||
return RET_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
ret_t dialog_info(const char* title, const char* text) {
|
||||
title = title != NULL ? title : "Infomation";
|
||||
return dialog_info_ex(text, title, "dialog_info");
|
||||
}
|
||||
|
||||
ret_t dialog_warn(const char* title, const char* text) {
|
||||
title = title != NULL ? title : "Warning";
|
||||
return dialog_info_ex(text, title, "dialog_warn");
|
||||
}
|
||||
|
||||
ret_t dialog_confirm(const char* stitle, const char* text) {
|
||||
uint32_t w = 0;
|
||||
uint32_t h = 0;
|
||||
char params[128];
|
||||
widget_t* ok = NULL;
|
||||
widget_t* cancel = NULL;
|
||||
widget_t* label = NULL;
|
||||
widget_t* dialog = NULL;
|
||||
widget_t* title = NULL;
|
||||
widget_t* client = NULL;
|
||||
return_value_if_fail(text != NULL, RET_BAD_PARAMS);
|
||||
|
||||
stitle = stitle != NULL ? stitle : "Confirm";
|
||||
label = dialog_create_label(text);
|
||||
return_value_if_fail(label != NULL, RET_OOM);
|
||||
|
||||
tk_snprintf(params, sizeof(params) - 1, "default(x=10, y=10, w=%d, h=%d)", label->w, label->h);
|
||||
widget_set_self_layout(label, params);
|
||||
|
||||
h = label->h + 90;
|
||||
w = tk_max(label->w, 128) + 40;
|
||||
dialog = dialog_create_simple(NULL, 0, 0, w, h);
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_THEME, "dialog_confirm");
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_HIGHLIGHT, "default(alpha=40)");
|
||||
|
||||
client = dialog_get_client(dialog);
|
||||
title = dialog_get_title(dialog);
|
||||
|
||||
widget_set_tr_text(title, stitle);
|
||||
widget_add_child(client, label);
|
||||
|
||||
ok = button_create(client, 0, 0, 0, 0);
|
||||
widget_set_tr_text(ok, "OK");
|
||||
widget_use_style(ok, OK_STYLE_NAME);
|
||||
widget_set_self_layout(ok, "default(x=10%, y=bottom:10, w=30%, h=30)");
|
||||
widget_on(ok, EVT_CLICK, on_ok_to_quit, dialog);
|
||||
|
||||
cancel = button_create(client, 0, 0, 0, 0);
|
||||
widget_set_tr_text(cancel, "Cancel");
|
||||
widget_use_style(cancel, CANCEL_STYLE_NAME);
|
||||
widget_set_self_layout(cancel, "default(x=r:10%, y=bottom:10, w=30%, h=30)");
|
||||
widget_on(cancel, EVT_CLICK, on_cancel_to_quit, dialog);
|
||||
|
||||
if (dialog != NULL && ok != NULL) {
|
||||
widget_layout(dialog);
|
||||
|
||||
return (ret_t)dialog_modal(dialog);
|
||||
} else {
|
||||
widget_destroy(dialog);
|
||||
|
||||
return RET_FAIL;
|
||||
}
|
||||
}
|
||||
|
240
src/widgets/dialog_helper.c
Normal file
240
src/widgets/dialog_helper.c
Normal file
@ -0,0 +1,240 @@
|
||||
/**
|
||||
* File: dialog_helper.c
|
||||
* Author: AWTK Develop Team
|
||||
* Brief: dialogi helper
|
||||
*
|
||||
* Copyright (c) 2018 - 2019 Guangzhou ZHIYUAN Electronics Co.,Ltd.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* License file for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* History:
|
||||
* ================================================================
|
||||
* 2018-01-13 Li XianJing <xianjimli@hotmail.com> created
|
||||
*
|
||||
*/
|
||||
#include "tkc/utils.h"
|
||||
#include "widgets/label.h"
|
||||
#include "widgets/dialog.h"
|
||||
#include "widgets/button.h"
|
||||
#include "widgets/dialog_title.h"
|
||||
#include "widgets/dialog_client.h"
|
||||
|
||||
widget_t* dialog_create_simple(widget_t* parent, xy_t x, xy_t y, wh_t w, wh_t h) {
|
||||
widget_t* title = NULL;
|
||||
widget_t* client = NULL;
|
||||
widget_t* widget = dialog_create(parent, x, y, w, h);
|
||||
dialog_t* dialog = DIALOG(widget);
|
||||
return_value_if_fail(dialog != NULL, NULL);
|
||||
|
||||
title = dialog_title_create(widget, 0, 0, 0, 0);
|
||||
widget_set_self_layout_params(title, "0", "0", "100%", "30");
|
||||
|
||||
client = dialog_client_create(widget, 0, 0, 0, 0);
|
||||
widget_set_self_layout_params(client, "0", "bottom", "100%", "-30");
|
||||
|
||||
widget_layout(widget);
|
||||
|
||||
return WIDGET(dialog);
|
||||
}
|
||||
|
||||
#include "base/window_manager.h"
|
||||
|
||||
#define OK_STYLE_NAME "default"
|
||||
#define CANCEL_STYLE_NAME "default"
|
||||
|
||||
static ret_t on_ok_to_quit(void* ctx, event_t* e) {
|
||||
widget_t* dlg = WIDGET(ctx);
|
||||
dialog_quit(dlg, RET_OK);
|
||||
|
||||
return RET_REMOVE;
|
||||
}
|
||||
|
||||
static ret_t on_cancel_to_quit(void* ctx, event_t* e) {
|
||||
widget_t* dlg = WIDGET(ctx);
|
||||
dialog_quit(dlg, RET_FAIL);
|
||||
|
||||
return RET_REMOVE;
|
||||
}
|
||||
|
||||
static ret_t on_timer_to_quit(const timer_info_t* info) {
|
||||
widget_t* dlg = WIDGET(info->ctx);
|
||||
|
||||
dialog_quit(dlg, 0);
|
||||
|
||||
return RET_REMOVE;
|
||||
}
|
||||
|
||||
/*simple dialogs*/
|
||||
|
||||
static ret_t dialog_get_size_limits(rect_t* r) {
|
||||
uint32_t min_w = 128;
|
||||
uint32_t max_w = 0;
|
||||
uint32_t min_h = 30;
|
||||
uint32_t max_h = 0;
|
||||
widget_t* wm = window_manager();
|
||||
|
||||
max_w = wm->w * 0.8;
|
||||
max_h = wm->h * 0.8;
|
||||
|
||||
r->x = min_w;
|
||||
r->w = max_w;
|
||||
r->y = min_h;
|
||||
r->h = max_h;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
static widget_t* dialog_create_label(const char* text) {
|
||||
rect_t r;
|
||||
widget_t* label = NULL;
|
||||
|
||||
dialog_get_size_limits(&r);
|
||||
|
||||
label = label_create(NULL, 0, 0, 0, 0);
|
||||
return_value_if_fail(label != NULL, NULL);
|
||||
|
||||
widget_set_text_utf8(label, text);
|
||||
label_resize_to_content(label, r.x, r.w, r.y, r.h);
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
ret_t dialog_toast(const char* text, uint32_t duration) {
|
||||
widget_t* label = NULL;
|
||||
widget_t* dialog = NULL;
|
||||
return_value_if_fail(text != NULL, RET_BAD_PARAMS);
|
||||
|
||||
label = dialog_create_label(text);
|
||||
return_value_if_fail(label != NULL, RET_OOM);
|
||||
|
||||
dialog = dialog_create(NULL, 0, 0, label->w, label->h);
|
||||
goto_error_if_fail(dialog != NULL);
|
||||
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_ANIM_HINT, "fade(duration=500)");
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_THEME, "dialog_toast");
|
||||
widget_add_child(dialog, label);
|
||||
|
||||
widget_on(dialog, EVT_POINTER_UP, on_ok_to_quit, dialog);
|
||||
widget_add_timer(dialog, on_timer_to_quit, duration);
|
||||
|
||||
return (ret_t)dialog_modal(dialog);
|
||||
error:
|
||||
widget_destroy(label);
|
||||
|
||||
return RET_FAIL;
|
||||
}
|
||||
|
||||
ret_t dialog_info_ex(const char* text, const char* title_text, const char* theme) {
|
||||
uint32_t w = 0;
|
||||
uint32_t h = 0;
|
||||
char params[128];
|
||||
widget_t* ok = NULL;
|
||||
widget_t* label = NULL;
|
||||
widget_t* dialog = NULL;
|
||||
widget_t* title = NULL;
|
||||
widget_t* client = NULL;
|
||||
return_value_if_fail(text != NULL, RET_BAD_PARAMS);
|
||||
|
||||
label = dialog_create_label(text);
|
||||
return_value_if_fail(label != NULL, RET_OOM);
|
||||
|
||||
tk_snprintf(params, sizeof(params) - 1, "default(x=10, y=10, w=%d, h=%d)", label->w, label->h);
|
||||
widget_set_self_layout(label, params);
|
||||
|
||||
h = label->h + 90;
|
||||
w = tk_max(label->w, 128) + 40;
|
||||
dialog = dialog_create_simple(NULL, 0, 0, w, h);
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_THEME, theme);
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_HIGHLIGHT, "default(alpha=40)");
|
||||
|
||||
client = dialog_get_client(dialog);
|
||||
title = dialog_get_title(dialog);
|
||||
|
||||
widget_set_tr_text(title, title_text);
|
||||
widget_add_child(client, label);
|
||||
|
||||
ok = button_create(client, 0, 0, 0, 0);
|
||||
widget_set_tr_text(ok, "OK");
|
||||
widget_set_self_layout(ok, "default(x=c, y=bottom:10, w=50%, h=30)");
|
||||
widget_on(ok, EVT_CLICK, on_ok_to_quit, dialog);
|
||||
|
||||
if (dialog != NULL && ok != NULL) {
|
||||
widget_layout(dialog);
|
||||
|
||||
return (ret_t)dialog_modal(dialog);
|
||||
} else {
|
||||
widget_destroy(dialog);
|
||||
|
||||
return RET_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
ret_t dialog_info(const char* title, const char* text) {
|
||||
title = title != NULL ? title : "Infomation";
|
||||
return dialog_info_ex(text, title, "dialog_info");
|
||||
}
|
||||
|
||||
ret_t dialog_warn(const char* title, const char* text) {
|
||||
title = title != NULL ? title : "Warning";
|
||||
return dialog_info_ex(text, title, "dialog_warn");
|
||||
}
|
||||
|
||||
ret_t dialog_confirm(const char* stitle, const char* text) {
|
||||
uint32_t w = 0;
|
||||
uint32_t h = 0;
|
||||
char params[128];
|
||||
widget_t* ok = NULL;
|
||||
widget_t* cancel = NULL;
|
||||
widget_t* label = NULL;
|
||||
widget_t* dialog = NULL;
|
||||
widget_t* title = NULL;
|
||||
widget_t* client = NULL;
|
||||
return_value_if_fail(text != NULL, RET_BAD_PARAMS);
|
||||
|
||||
stitle = stitle != NULL ? stitle : "Confirm";
|
||||
label = dialog_create_label(text);
|
||||
return_value_if_fail(label != NULL, RET_OOM);
|
||||
|
||||
tk_snprintf(params, sizeof(params) - 1, "default(x=10, y=10, w=%d, h=%d)", label->w, label->h);
|
||||
widget_set_self_layout(label, params);
|
||||
|
||||
h = label->h + 90;
|
||||
w = tk_max(label->w, 128) + 40;
|
||||
dialog = dialog_create_simple(NULL, 0, 0, w, h);
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_THEME, "dialog_confirm");
|
||||
widget_set_prop_str(dialog, WIDGET_PROP_HIGHLIGHT, "default(alpha=40)");
|
||||
|
||||
client = dialog_get_client(dialog);
|
||||
title = dialog_get_title(dialog);
|
||||
|
||||
widget_set_tr_text(title, stitle);
|
||||
widget_add_child(client, label);
|
||||
|
||||
ok = button_create(client, 0, 0, 0, 0);
|
||||
widget_set_tr_text(ok, "OK");
|
||||
widget_use_style(ok, OK_STYLE_NAME);
|
||||
widget_set_self_layout(ok, "default(x=10%, y=bottom:10, w=30%, h=30)");
|
||||
widget_on(ok, EVT_CLICK, on_ok_to_quit, dialog);
|
||||
|
||||
cancel = button_create(client, 0, 0, 0, 0);
|
||||
widget_set_tr_text(cancel, "Cancel");
|
||||
widget_use_style(cancel, CANCEL_STYLE_NAME);
|
||||
widget_set_self_layout(cancel, "default(x=r:10%, y=bottom:10, w=30%, h=30)");
|
||||
widget_on(cancel, EVT_CLICK, on_cancel_to_quit, dialog);
|
||||
|
||||
if (dialog != NULL && ok != NULL) {
|
||||
widget_layout(dialog);
|
||||
|
||||
return (ret_t)dialog_modal(dialog);
|
||||
} else {
|
||||
widget_destroy(dialog);
|
||||
|
||||
return RET_FAIL;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user