Skip to content
This repository was archived by the owner on Jun 17, 2024. It is now read-only.

Commit a8885c5

Browse files
committed
feat: add notification
1 parent 79493a1 commit a8885c5

File tree

14 files changed

+813
-1
lines changed

14 files changed

+813
-1
lines changed

demo/app/assets/views/documentation.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@
100100
Message
101101
</a>
102102
</w>
103+
<w class="nav-item">
104+
<a class="nav-link" href="components/notification.xml" target="demo-content">
105+
Notification
106+
</a>
107+
</w>
103108
<w class="nav-item">
104109
<a class="nav-link" href="components/modal.xml" target="demo-content">
105110
Modal

demo/demo.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ xcopy "$(SolutionDir)dist\assets" "$(ProjectDir)app\assets" /S /Y</Command>
192192
<ClCompile Include="src\ui\views\home-view.c" />
193193
<ClCompile Include="src\ui\views\message-view.c" />
194194
<ClCompile Include="src\ui\views\navbar.c" />
195+
<ClCompile Include="src\ui\views\notification-view.c" />
195196
</ItemGroup>
196197
<ItemGroup>
197198
<ClInclude Include="include\ui.h" />

demo/demo.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
<ClCompile Include="src\ui\views\message-view.c">
3737
<Filter>源文件</Filter>
3838
</ClCompile>
39+
<ClCompile Include="src\ui\views\notification-view.c">
40+
<Filter>源文件</Filter>
41+
</ClCompile>
3942
</ItemGroup>
4043
<ItemGroup>
4144
<ClInclude Include="include\ui.h">

demo/include/ui.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ void HomeView_Init(void);
2222
void HomeView_Free(void);
2323

2424
void UI_InitMessageView(void);
25+
void UI_InitNotificationView(void);

demo/src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ int main(int argc, char **argv)
2424
Widget_SetTitleW(root, L"LC Design - A UI component framework for building LCUI application.");
2525
Navigation_Init();
2626
UI_InitMessageView();
27+
UI_InitNotificationView();
2728
Navbar_Init();
2829
return LCUI_Main();
2930
}

demo/src/ui/views/notification-view.c

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
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

Comments
 (0)