Skip to content

Commit

Permalink
feat: add notification
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Oct 1, 2019
1 parent 79493a1 commit a8885c5
Show file tree
Hide file tree
Showing 14 changed files with 813 additions and 1 deletion.
5 changes: 5 additions & 0 deletions demo/app/assets/views/documentation.xml
Expand Up @@ -100,6 +100,11 @@
Message
</a>
</w>
<w class="nav-item">
<a class="nav-link" href="components/notification.xml" target="demo-content">
Notification
</a>
</w>
<w class="nav-item">
<a class="nav-link" href="components/modal.xml" target="demo-content">
Modal
Expand Down
1 change: 1 addition & 0 deletions demo/demo.vcxproj
Expand Up @@ -192,6 +192,7 @@ xcopy "$(SolutionDir)dist\assets" "$(ProjectDir)app\assets" /S /Y</Command>
<ClCompile Include="src\ui\views\home-view.c" />
<ClCompile Include="src\ui\views\message-view.c" />
<ClCompile Include="src\ui\views\navbar.c" />
<ClCompile Include="src\ui\views\notification-view.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\ui.h" />
Expand Down
3 changes: 3 additions & 0 deletions demo/demo.vcxproj.filters
Expand Up @@ -36,6 +36,9 @@
<ClCompile Include="src\ui\views\message-view.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\ui\views\notification-view.c">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\ui.h">
Expand Down
1 change: 1 addition & 0 deletions demo/include/ui.h
Expand Up @@ -22,3 +22,4 @@ void HomeView_Init(void);
void HomeView_Free(void);

void UI_InitMessageView(void);
void UI_InitNotificationView(void);
1 change: 1 addition & 0 deletions demo/src/main.c
Expand Up @@ -24,6 +24,7 @@ int main(int argc, char **argv)
Widget_SetTitleW(root, L"LC Design - A UI component framework for building LCUI application.");
Navigation_Init();
UI_InitMessageView();
UI_InitNotificationView();
Navbar_Init();
return LCUI_Main();
}
182 changes: 182 additions & 0 deletions demo/src/ui/views/notification-view.c
@@ -0,0 +1,182 @@
#include <LCUI.h>
#include <LCUI/gui/widget.h>
#include <LCDesign/ui/components/icon.h>
#include <LCDesign/ui/components/notification.h>

static LCUI_WidgetPrototype notification_view_proto;

static void OpenBasicNotification(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenNormalNotification(
L"Notification Title",
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.",
NULL, 4500);
}

static void OpenNotificationAtTopLeft(LCUI_Widget w, LCUI_WidgetEvent e,
void *arg)
{
LCDesign_OpenNormalNotification(
L"Notification Title",
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.",
"top-left", 4500);
}

static void OpenNotificationAtTopRight(LCUI_Widget w, LCUI_WidgetEvent e,
void *arg)
{
LCDesign_OpenNormalNotification(
L"Notification Title",
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.",
"top-right", 4500);
}

static void OpenNotificationAtBottomLeft(LCUI_Widget w, LCUI_WidgetEvent e,
void *arg)
{
LCDesign_OpenNormalNotification(
L"Notification Title",
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.",
"bottom-left", 4500);
}

static void OpenNotificationAtBottomRight(LCUI_Widget w, LCUI_WidgetEvent e,
void *arg)
{
LCDesign_OpenNormalNotification(
L"Notification Title",
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.",
"bottom-right", 4500);
}

static void OpenNotificationCustomDuration(LCUI_Widget w, LCUI_WidgetEvent e,
void *arg)
{
LCDesign_OpenNormalNotification(
L"Notification Title",
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.",
NULL, 0);
}

static void OpenSuccessNotification(LCUI_Widget w, LCUI_WidgetEvent e,
void *arg)
{
LCDesign_OpenSuccessNotification(
L"Notification Title",
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.",
NULL, 4500);
}

static void OpenInfoNotification(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenInfoNotification(
L"Notification Title",
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.",
NULL, 4500);
}

static void OpenWarningNotification(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenWarningNotification(
L"Notification Title",
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.",
NULL, 4500);
}

static void OpenErrorNotification(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenErrorNotification(
L"Notification Title",
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.",
NULL, 4500);
}

static void OpenNotificationCustomIcon(LCUI_Widget w, LCUI_WidgetEvent e,
void *arg)
{
LCUI_Widget icon;
LCDesign_NotificationConfigRec config;

icon = LCUIWidget_New("icon");
Icon_SetName(icon, "emoticon-happy-outline");
Widget_SetStyleString(icon, "color", "#108ee9");

config.icon = icon;
config.duration = 4500;
config.placement = NULL;
config.title = L"Notification Title";
config.description =
L"This is the content of the notification. This is the content of "
L"the notification. This is the content of the notification.";
LCDesign_OpenNotification(&config);
}

static void NotificationView_OnReady(LCUI_Widget w, LCUI_WidgetEvent e,
void *arg)
{
Dict *dict;
LCUI_Widget btn;

dict = Widget_CollectReferences(w);

btn = Dict_FetchValue(dict, "notification-basic");
Widget_BindEvent(btn, "click", OpenBasicNotification, NULL, NULL);

btn = Dict_FetchValue(dict, "notification-top-left");
Widget_BindEvent(btn, "click", OpenNotificationAtTopLeft, NULL, NULL);

btn = Dict_FetchValue(dict, "notification-top-right");
Widget_BindEvent(btn, "click", OpenNotificationAtTopRight, NULL, NULL);

btn = Dict_FetchValue(dict, "notification-bottom-left");
Widget_BindEvent(btn, "click", OpenNotificationAtBottomLeft, NULL,
NULL);

btn = Dict_FetchValue(dict, "notification-bottom-right");
Widget_BindEvent(btn, "click", OpenNotificationAtBottomRight, NULL,
NULL);

btn = Dict_FetchValue(dict, "notification-custom-duration");
Widget_BindEvent(btn, "click", OpenNotificationCustomDuration, NULL,
NULL);

btn = Dict_FetchValue(dict, "notification-success");
Widget_BindEvent(btn, "click", OpenSuccessNotification, NULL, NULL);

btn = Dict_FetchValue(dict, "notification-info");
Widget_BindEvent(btn, "click", OpenInfoNotification, NULL, NULL);

btn = Dict_FetchValue(dict, "notification-warning");
Widget_BindEvent(btn, "click", OpenWarningNotification, NULL, NULL);

btn = Dict_FetchValue(dict, "notification-error");
Widget_BindEvent(btn, "click", OpenErrorNotification, NULL, NULL);

btn = Dict_FetchValue(dict, "notification-custom-icon");
Widget_BindEvent(btn, "click", OpenNotificationCustomIcon, NULL, NULL);

Dict_Release(dict);
Widget_UnbindEvent(w, "ready", NotificationView_OnReady);
}

static void NotificationView_OnInit(LCUI_Widget w)
{
Widget_BindEvent(w, "ready", NotificationView_OnReady, NULL, NULL);
}

void UI_InitNotificationView(void)
{
notification_view_proto =
LCUIWidget_NewPrototype("notification-view", NULL);
notification_view_proto->init = NotificationView_OnInit;
}

0 comments on commit a8885c5

Please sign in to comment.