|
| 1 | +#include <LCUI.h> |
| 2 | +#include <LCUI/gui/widget.h> |
| 3 | +#include <LCDesign/ui/components/icon.h> |
| 4 | +#include <LCDesign/ui/components/notification.h> |
| 5 | + |
| 6 | +static LCUI_WidgetPrototype notification_view_proto; |
| 7 | + |
| 8 | +static void OpenBasicNotification(LCUI_Widget w, LCUI_WidgetEvent e, void *arg) |
| 9 | +{ |
| 10 | + LCDesign_OpenNormalNotification( |
| 11 | + L"Notification Title", |
| 12 | + L"This is the content of the notification. This is the content of " |
| 13 | + L"the notification. This is the content of the notification.", |
| 14 | + NULL, 4500); |
| 15 | +} |
| 16 | + |
| 17 | +static void OpenNotificationAtTopLeft(LCUI_Widget w, LCUI_WidgetEvent e, |
| 18 | + void *arg) |
| 19 | +{ |
| 20 | + LCDesign_OpenNormalNotification( |
| 21 | + L"Notification Title", |
| 22 | + L"This is the content of the notification. This is the content of " |
| 23 | + L"the notification. This is the content of the notification.", |
| 24 | + "top-left", 4500); |
| 25 | +} |
| 26 | + |
| 27 | +static void OpenNotificationAtTopRight(LCUI_Widget w, LCUI_WidgetEvent e, |
| 28 | + void *arg) |
| 29 | +{ |
| 30 | + LCDesign_OpenNormalNotification( |
| 31 | + L"Notification Title", |
| 32 | + L"This is the content of the notification. This is the content of " |
| 33 | + L"the notification. This is the content of the notification.", |
| 34 | + "top-right", 4500); |
| 35 | +} |
| 36 | + |
| 37 | +static void OpenNotificationAtBottomLeft(LCUI_Widget w, LCUI_WidgetEvent e, |
| 38 | + void *arg) |
| 39 | +{ |
| 40 | + LCDesign_OpenNormalNotification( |
| 41 | + L"Notification Title", |
| 42 | + L"This is the content of the notification. This is the content of " |
| 43 | + L"the notification. This is the content of the notification.", |
| 44 | + "bottom-left", 4500); |
| 45 | +} |
| 46 | + |
| 47 | +static void OpenNotificationAtBottomRight(LCUI_Widget w, LCUI_WidgetEvent e, |
| 48 | + void *arg) |
| 49 | +{ |
| 50 | + LCDesign_OpenNormalNotification( |
| 51 | + L"Notification Title", |
| 52 | + L"This is the content of the notification. This is the content of " |
| 53 | + L"the notification. This is the content of the notification.", |
| 54 | + "bottom-right", 4500); |
| 55 | +} |
| 56 | + |
| 57 | +static void OpenNotificationCustomDuration(LCUI_Widget w, LCUI_WidgetEvent e, |
| 58 | + void *arg) |
| 59 | +{ |
| 60 | + LCDesign_OpenNormalNotification( |
| 61 | + L"Notification Title", |
| 62 | + L"This is the content of the notification. This is the content of " |
| 63 | + L"the notification. This is the content of the notification.", |
| 64 | + NULL, 0); |
| 65 | +} |
| 66 | + |
| 67 | +static void OpenSuccessNotification(LCUI_Widget w, LCUI_WidgetEvent e, |
| 68 | + void *arg) |
| 69 | +{ |
| 70 | + LCDesign_OpenSuccessNotification( |
| 71 | + L"Notification Title", |
| 72 | + L"This is the content of the notification. This is the content of " |
| 73 | + L"the notification. This is the content of the notification.", |
| 74 | + NULL, 4500); |
| 75 | +} |
| 76 | + |
| 77 | +static void OpenInfoNotification(LCUI_Widget w, LCUI_WidgetEvent e, void *arg) |
| 78 | +{ |
| 79 | + LCDesign_OpenInfoNotification( |
| 80 | + L"Notification Title", |
| 81 | + L"This is the content of the notification. This is the content of " |
| 82 | + L"the notification. This is the content of the notification.", |
| 83 | + NULL, 4500); |
| 84 | +} |
| 85 | + |
| 86 | +static void OpenWarningNotification(LCUI_Widget w, LCUI_WidgetEvent e, void *arg) |
| 87 | +{ |
| 88 | + LCDesign_OpenWarningNotification( |
| 89 | + L"Notification Title", |
| 90 | + L"This is the content of the notification. This is the content of " |
| 91 | + L"the notification. This is the content of the notification.", |
| 92 | + NULL, 4500); |
| 93 | +} |
| 94 | + |
| 95 | +static void OpenErrorNotification(LCUI_Widget w, LCUI_WidgetEvent e, void *arg) |
| 96 | +{ |
| 97 | + LCDesign_OpenErrorNotification( |
| 98 | + L"Notification Title", |
| 99 | + L"This is the content of the notification. This is the content of " |
| 100 | + L"the notification. This is the content of the notification.", |
| 101 | + NULL, 4500); |
| 102 | +} |
| 103 | + |
| 104 | +static void OpenNotificationCustomIcon(LCUI_Widget w, LCUI_WidgetEvent e, |
| 105 | + void *arg) |
| 106 | +{ |
| 107 | + LCUI_Widget icon; |
| 108 | + LCDesign_NotificationConfigRec config; |
| 109 | + |
| 110 | + icon = LCUIWidget_New("icon"); |
| 111 | + Icon_SetName(icon, "emoticon-happy-outline"); |
| 112 | + Widget_SetStyleString(icon, "color", "#108ee9"); |
| 113 | + |
| 114 | + config.icon = icon; |
| 115 | + config.duration = 4500; |
| 116 | + config.placement = NULL; |
| 117 | + config.title = L"Notification Title"; |
| 118 | + config.description = |
| 119 | + L"This is the content of the notification. This is the content of " |
| 120 | + L"the notification. This is the content of the notification."; |
| 121 | + LCDesign_OpenNotification(&config); |
| 122 | +} |
| 123 | + |
| 124 | +static void NotificationView_OnReady(LCUI_Widget w, LCUI_WidgetEvent e, |
| 125 | + void *arg) |
| 126 | +{ |
| 127 | + Dict *dict; |
| 128 | + LCUI_Widget btn; |
| 129 | + |
| 130 | + dict = Widget_CollectReferences(w); |
| 131 | + |
| 132 | + btn = Dict_FetchValue(dict, "notification-basic"); |
| 133 | + Widget_BindEvent(btn, "click", OpenBasicNotification, NULL, NULL); |
| 134 | + |
| 135 | + btn = Dict_FetchValue(dict, "notification-top-left"); |
| 136 | + Widget_BindEvent(btn, "click", OpenNotificationAtTopLeft, NULL, NULL); |
| 137 | + |
| 138 | + btn = Dict_FetchValue(dict, "notification-top-right"); |
| 139 | + Widget_BindEvent(btn, "click", OpenNotificationAtTopRight, NULL, NULL); |
| 140 | + |
| 141 | + btn = Dict_FetchValue(dict, "notification-bottom-left"); |
| 142 | + Widget_BindEvent(btn, "click", OpenNotificationAtBottomLeft, NULL, |
| 143 | + NULL); |
| 144 | + |
| 145 | + btn = Dict_FetchValue(dict, "notification-bottom-right"); |
| 146 | + Widget_BindEvent(btn, "click", OpenNotificationAtBottomRight, NULL, |
| 147 | + NULL); |
| 148 | + |
| 149 | + btn = Dict_FetchValue(dict, "notification-custom-duration"); |
| 150 | + Widget_BindEvent(btn, "click", OpenNotificationCustomDuration, NULL, |
| 151 | + NULL); |
| 152 | + |
| 153 | + btn = Dict_FetchValue(dict, "notification-success"); |
| 154 | + Widget_BindEvent(btn, "click", OpenSuccessNotification, NULL, NULL); |
| 155 | + |
| 156 | + btn = Dict_FetchValue(dict, "notification-info"); |
| 157 | + Widget_BindEvent(btn, "click", OpenInfoNotification, NULL, NULL); |
| 158 | + |
| 159 | + btn = Dict_FetchValue(dict, "notification-warning"); |
| 160 | + Widget_BindEvent(btn, "click", OpenWarningNotification, NULL, NULL); |
| 161 | + |
| 162 | + btn = Dict_FetchValue(dict, "notification-error"); |
| 163 | + Widget_BindEvent(btn, "click", OpenErrorNotification, NULL, NULL); |
| 164 | + |
| 165 | + btn = Dict_FetchValue(dict, "notification-custom-icon"); |
| 166 | + Widget_BindEvent(btn, "click", OpenNotificationCustomIcon, NULL, NULL); |
| 167 | + |
| 168 | + Dict_Release(dict); |
| 169 | + Widget_UnbindEvent(w, "ready", NotificationView_OnReady); |
| 170 | +} |
| 171 | + |
| 172 | +static void NotificationView_OnInit(LCUI_Widget w) |
| 173 | +{ |
| 174 | + Widget_BindEvent(w, "ready", NotificationView_OnReady, NULL, NULL); |
| 175 | +} |
| 176 | + |
| 177 | +void UI_InitNotificationView(void) |
| 178 | +{ |
| 179 | + notification_view_proto = |
| 180 | + LCUIWidget_NewPrototype("notification-view", NULL); |
| 181 | + notification_view_proto->init = NotificationView_OnInit; |
| 182 | +} |
0 commit comments