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

Commit

Permalink
feat: add message
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Sep 30, 2019
1 parent 9f557f6 commit 343a3df
Show file tree
Hide file tree
Showing 19 changed files with 498 additions and 190 deletions.
10 changes: 5 additions & 5 deletions demo/app/assets/views/documentation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@
Radio
</a>
</w>
<w class="nav-item">
<a class="nav-link" href="components/message.xml" target="demo-content">
Message
</a>
</w>
<w class="nav-item">
<a class="nav-link" href="components/modal.xml" target="demo-content">
Modal
Expand All @@ -105,11 +110,6 @@
Tooltips
</a>
</w>
<w class="nav-item">
<a class="nav-link" href="components/toasts.xml" target="demo-content">
Toasts
</a>
</w>
<w class="nav-item">
<a class="nav-link" href="components/spinners.xml" target="demo-content">
Spinners
Expand Down
5 changes: 3 additions & 2 deletions demo/demo.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ xcopy "$(SolutionDir)dist\assets" "$(ProjectDir)app\assets" /S /Y</Command>
<ClCompile Include="src\main.c" />
<ClCompile Include="src\navigation.c" />
<ClCompile Include="src\ui\helpers\ui_helper.c" />
<ClCompile Include="src\ui\views\documentation_view.c" />
<ClCompile Include="src\ui\views\home_view.c" />
<ClCompile Include="src\ui\views\documentation-view.c" />
<ClCompile Include="src\ui\views\home-view.c" />
<ClCompile Include="src\ui\views\message-view.c" />
<ClCompile Include="src\ui\views\navbar.c" />
</ItemGroup>
<ItemGroup>
Expand Down
11 changes: 7 additions & 4 deletions demo/demo.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@
<ClCompile Include="src\navigation.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\ui\views\documentation_view.c">
<ClCompile Include="src\ui\helpers\ui_helper.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\ui\views\home_view.c">
<ClCompile Include="src\ui\views\navbar.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\ui\helpers\ui_helper.c">
<ClCompile Include="src\ui\views\home-view.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\ui\views\navbar.c">
<ClCompile Include="src\ui\views\documentation-view.c">
<Filter>源文件</Filter>
</ClCompile>
<ClCompile Include="src\ui\views\message-view.c">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
Expand Down
25 changes: 13 additions & 12 deletions demo/include/ui.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#define ID_SIDEBAR_LINKS "demo-sidebar-links"
#define ID_NAVBAR_LINKS "demo-navbar-links"
#define ID_LINK_NAV_HOME "navbar-link-home"
#define ID_LINK_NAV_DOCS "navbar-link-docs"
#define ID_LINK_GETTING_STARTED "doc-link-getting-strted"
#define ID_SIDEBAR_LINKS "demo-sidebar-links"
#define ID_NAVBAR_LINKS "demo-navbar-links"
#define ID_LINK_NAV_HOME "navbar-link-home"
#define ID_LINK_NAV_DOCS "navbar-link-docs"
#define ID_LINK_GETTING_STARTED "doc-link-getting-strted"

typedef enum NavigationPointId {
NAV_NONE,
Expand All @@ -11,13 +11,14 @@ typedef enum NavigationPointId {
NAV_TOTAL_NUM
} NavigationPointId;

void ActiveLink(LCUI_Widget parent, const char *link_id);

void ActiveLink( LCUI_Widget parent, const char *link_id );
void Navbar_Init(void);
void Navigation_Init(void);

void Navbar_Init( void );
void Navigation_Init( void );
void DocumentationView_Init(void);
void DocumentationView_Free(void);
void HomeView_Init(void);
void HomeView_Free(void);

void DocumentationView_Init( void );
void DocumentationView_Free( void );
void HomeView_Init( void );
void HomeView_Free( void );
void UI_InitMessageView(void);
1 change: 1 addition & 0 deletions demo/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ int main(int argc, char **argv)
Widget_Unwrap(pack);
Widget_SetTitleW(root, L"LC Design - A UI component framework for building LCUI application.");
Navigation_Init();
UI_InitMessageView();
Navbar_Init();
return LCUI_Main();
}
File renamed without changes.
77 changes: 77 additions & 0 deletions demo/src/ui/views/message-view.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include <LCUI.h>
#include <LCUI/gui/widget.h>
#include <LCDesign/ui/components/message.h>

static LCUI_WidgetPrototype message_view_proto;

static void OpenNormalMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenInfoMessage(L"This is a normal message", 3000);
}

static void OpenSuccessMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenSuccessMessage(L"This is a success message", 3000);
}

static void OpenWarningMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenWarningMessage(L"This is a warning message", 3000);
}

static void OpenErrorMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenErrorMessage(L"This is a error message", 3000);
}

static void OpenCustomDurationMessage(LCUI_Widget w, LCUI_WidgetEvent e,
void *arg)
{
LCDesign_OpenSuccessMessage(L"This is a prompt message for success, "
L"and it will disappear in 10 seconds",
10000);
}

static void OpenLoadingMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenLoadingMessage(L"Action in progress..", 3000);
}

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

dict = Widget_CollectReferences(w);
btn = Dict_FetchValue(dict, "open-normal-message");
Widget_BindEvent(btn, "click", OpenNormalMessage, NULL, NULL);

btn = Dict_FetchValue(dict, "open-success-message");
Widget_BindEvent(btn, "click", OpenSuccessMessage, NULL, NULL);

btn = Dict_FetchValue(dict, "open-warning-message");
Widget_BindEvent(btn, "click", OpenWarningMessage, NULL, NULL);

btn = Dict_FetchValue(dict, "open-error-message");
Widget_BindEvent(btn, "click", OpenErrorMessage, NULL, NULL);

btn = Dict_FetchValue(dict, "open-custom-duration-message");
Widget_BindEvent(btn, "click", OpenCustomDurationMessage, NULL, NULL);

btn = Dict_FetchValue(dict, "open-loading-message");
Widget_BindEvent(btn, "click", OpenLoadingMessage, NULL, NULL);

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

static void MessageView_OnInit(LCUI_Widget w)
{
Widget_BindEvent(w, "ready", MessageView_OnReady, NULL, NULL);
}

void UI_InitMessageView(void)
{
message_view_proto = LCUIWidget_NewPrototype("message-view", NULL);
message_view_proto->init = MessageView_OnInit;
}
137 changes: 137 additions & 0 deletions docs/components/message.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Message

Display global messages as feedback in response to user operations.

## Normal prompt

Normal message for information.

``` embedded-xml
<w class="button-container">
<button ref="open-normal-message" class="btn btn-primary">Display normal message</button>
</w>
```

``` c
#include <LCUI.h>
#include <LCUI/gui/widget.h>
#include <LCDesign/ui/components/message.h>

static void OpenMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenInfoMessage(L"This is a normal message", 3000);
}

// ... other code

LCUI_Widget btn = LCUIWidget_GetById("btn-open-message");
Widget_BindEvent(btn, "click", OpenMessage, NULL, NULL);

// ... other code
```
## Other types of message
Messages of success, error and warning types.
``` embedded-xml
<w class="button-container">
<button ref="open-success-message" class="btn">Success</button>
<button ref="open-error-message" class="btn">Error</button>
<button ref="open-warning-message" class="btn">Warning</button>
</w>
```

``` c
#include <LCUI.h>
#include <LCUI/gui/widget.h>
#include <LCDesign/ui/components/message.h>

static void OpenSuccessMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenSuccessMessage(L"This is a success message", 3000);
}

static void OpenWarningMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenWarningMessage(L"This is a warning message", 3000);
}

static void OpenErrorMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenErrorMessage(L"This is a error message", 3000);
}

// ... other code

LCUI_Widget btn;

btn = LCUIWidget_GetById("btn-open-success-message");
Widget_BindEvent(btn, "click", OpenSuccessMessage, NULL, NULL);

btn = LCUIWidget_GetById("btn-open-warning-message");
Widget_BindEvent(btn, "click", OpenWarningMessage, NULL, NULL);

btn = LCUIWidget_GetById("btn-open-error-message");
Widget_BindEvent(btn, "click", OpenErrorMessage, NULL, NULL);

// ... other code
```
## Customize duration
Customize message display duration to `10s`.
``` embedded-xml
<w class="button-container">
<button ref="open-custom-duration-message" class="btn">Customized display duration</button>
</w>
```

``` c
#include <LCUI.h>
#include <LCUI/gui/widget.h>
#include <LCDesign/ui/components/message.h>

static void OpenMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenSuccessMessage(L"This is a prompt message for success, "
L"and it will disappear in 10 seconds",
10000);
}

// ... other code

LCUI_Widget btn = LCUIWidget_GetById("btn-open-message");
Widget_BindEvent(btn, "click", OpenMessage, NULL, NULL);

// ... other code
```
## Message with loading indicator
Display a global loading indicator, which is dismissed by itself asynchronously.
``` embedded-xml
<w class="button-container">
<button ref="open-loading-message" class="btn">Display a loading indicator</button>
</w>
```

``` c
#include <LCUI.h>
#include <LCUI/gui/widget.h>
#include <LCDesign/ui/components/message.h>

static void OpenMessage(LCUI_Widget w, LCUI_WidgetEvent e, void *arg)
{
LCDesign_OpenLoadingMessage(L"Action in progress..", 3000);
}

// ... other code

LCUI_Widget btn = LCUIWidget_GetById("btn-open-message");
Widget_BindEvent(btn, "click", OpenMessage, NULL, NULL);

// ... other code
```
Loading

0 comments on commit 343a3df

Please sign in to comment.