Skip to content

Commit

Permalink
Merge pull request #274 from AuroraZiling/main
Browse files Browse the repository at this point in the history
Docs update for `Hosts`
  • Loading branch information
kikipoulet authored Aug 16, 2024
2 parents 4e48828 + 94a4cfe commit 4095bef
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 20 deletions.
17 changes: 11 additions & 6 deletions docs/docs/.vitepress/config/en.mts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export const en = defineConfig({
{ text: 'Expander', link: '/documentation/controls/data/expander' },
]
},
{
text: 'Notification',
items: [
{ text: 'InfoBar', link: '/documentation/controls/notification/infobar' },
{ text: 'InfoBadge', link: '/documentation/controls/notification/infobadge' },
]
},
{
text: 'System',
items: [
Expand All @@ -101,13 +108,11 @@ export const en = defineConfig({
]
},
{
text: 'Notification',
text: 'Hosts',
items: [
{ text: 'Dialog', link: '/documentation/notification/dialog' },
{ text: 'Toast', link: '/documentation/notification/toast' },
{ text: 'MessageBox', link: '/documentation/notification/messagebox' },
{ text: 'InfoBar', link: '/documentation/notification/infobar' },
{ text: 'InfoBadge', link: '/documentation/notification/infobadge' },
{ text: 'About Hosts', link: '/documentation/hosts/hosts' },
{ text: 'Dialog', link: '/documentation/hosts/dialog' },
{ text: 'Toast', link: '/documentation/hosts/toast' },
]
},
{
Expand Down
17 changes: 11 additions & 6 deletions docs/docs/.vitepress/config/zh.mts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export const zh = defineConfig({
{ text: 'Expander', link: '/zh/documentation/controls/data/expander' },
]
},
{
text: '提醒',
items: [
{ text: 'InfoBar', link: '/zh/documentation/controls/notification/infobar' },
{ text: 'InfoBadge', link: '/zh/documentation/controls/notification/infobadge' },
]
},
{
text: '系统 API',
items: [
Expand All @@ -101,13 +108,11 @@ export const zh = defineConfig({
]
},
{
text: '通知',
text: '可选窗口控件',
items: [
{ text: 'Dialog', link: '/zh/documentation/notification/dialog' },
{ text: 'Toast', link: '/zh/documentation/notification/toast' },
{ text: 'MessageBox', link: '/zh/documentation/notification/messagebox' },
{ text: 'InfoBar', link: '/zh/documentation/notification/infobar' },
{ text: 'InfoBadge', link: '/zh/documentation/notification/infobadge' },
{ text: '有关 Hosts', link: '/zh/documentation/hosts/hosts' },
{ text: 'Dialog', link: '/zh/documentation/hosts/dialog' },
{ text: 'Toast', link: '/zh/documentation/hosts/toast' },
]
},
{
Expand Down
14 changes: 6 additions & 8 deletions docs/docs/documentation/hosts/toast.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class ExampleViewModel
}
```

Is is possible to set `MaxToasts` to limit the number of toasts displayed in any given host.
It is possible to set `MaxToasts` to limit the number of toasts displayed in any given host.

---

If you do not wish to use MVVM, or would rather a simpler solution that "just works", then you can choose to implement it like this:

Expand All @@ -49,19 +51,15 @@ public class MainWindow : SukiWindow
ToastHost.Manager = ToastManager;
}
}

// and then...
MainWindow.ToastManager.CreateToast()
.Queue();
```

### Usage

```cs
MainWindow.ToastManager.CreateToast()
.Queue();
```


## Displaying Toasts

In order to construct and therefore display toasts, a fluent style builder is provided that makes constructing toasts simple. To begin constructing a toast, it's recommended to call the extension method `.CreateToast()` on the `ISukiToastManager` instance you want it to be displayed in.
Expand All @@ -70,7 +68,7 @@ From here method calls can be chained to construct the toast as desired, most of

Finally to display a toast the `.Queue()` method can be called to immediately queue the toast for display.

Here is a simple example, expanding on the ViewModel above:
Here is a simple example, expanding on the `ViewModel` above:

```cs
public void DisplayToast()
Expand Down
5 changes: 5 additions & 0 deletions docs/docs/zh/documentation/hosts/dialog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Dialogs

SukiUI 提供了一个用于弹出对话框的[可选窗口控件](./hosts),该控件可以很轻易地在 `SukiWindow.Hosts` 添加(这也是最推荐且能达到最佳效果的使用方法)

该对话框对 MVVM 设计模式友好,同时你也可以通过 `ISukiDialogManager` 来获得给定的 `SukiDialogHost` 实例,从而显示对话框。
14 changes: 14 additions & 0 deletions docs/docs/zh/documentation/hosts/hosts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Hosts

SukiUI 在 `SukiWindow` 内提供了 `Hosts` 属性,可以在该属性内添加任意控件,而这些控件将会显示在其他所有子控件的上层(包括标题栏)

```xml
<!-- XMLNS 定义已略去 -->
<suki:SukiWindow>
<suki:SukiWindow.Hosts>
<!-- 你的控件 -->
</suki:SukiWindow.Hosts>
</suki:SukiWindow>
```

SukiUI 本身提供两个可选的窗口控件,即 [SukiDialogHost](./dialog)[SukiToastHost](./toast)
120 changes: 120 additions & 0 deletions docs/docs/zh/documentation/hosts/toast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Toasts

SukiUI 提供了一个用于弹出消息提醒的[可选窗口控件](./hosts),该控件可以很轻易地在 `SukiWindow.Hosts` 添加(这也是最推荐且能达到最佳效果的使用方法)

该消息提醒控件对 MVVM 设计模式友好,同时你也可以通过 `ISukiToastManager` 来获得给定的 `SukiToastHost` 实例,从而显示提示消息。

以下是一些 MVVM 设计模式下使用的例子:

### View
```xml
<!-- XMLNS 定义已略去 -->
<suki:SukiWindow>
<suki:SukiWindow.Hosts>
<suki:SukiToastHost Manager="{Binding ToastManager}"/>
</suki:SukiWindow.Hosts>
<suki:SukiWindow>
```

### ViewModel
```cs
public class ExampleViewModel
{
public ISukiToastManager ToastManager { get; } = new();
}
```

可以通过修改 `MaxToasts` 的值以达到限制消息弹出数量的效果

---

如果你并未使用 MVVM 设计模式,只是想做一些简单实现,可以参考以下方法:

### AXAML
```xml
<!-- XMLNS 定义已略去 -->
<suki:SukiWindow>
<suki:SukiWindow.Hosts>
<suki:SukiToastHost Name="ToastManager"/>
</suki:SukiWindow.Hosts>
<suki:SukiWindow>
```

### Code-Behind
```cs
public class MainWindow : SukiWindow
{
public static ISukiToastManager ToastManager = new SukiToastManager();

public MainWindow()
{
InitializeComponent();
ToastHost.Manager = ToastManager;
}
}
```

### 用法

```cs
MainWindow.ToastManager.CreateToast()
.Queue();
```

## 显示消息提醒

SukiUI 实现了一个现代的消息构造器。构造时推荐在 `ISukiToastManager` 的实例上调用 `.CreateToast()` 扩展方法

构造操作的体验是链式的,且均提供了 XML 文档

最后通过调用 `.Queue()` 方法来让该消息进入队列中,并立即显示消息

以下是在 `ViewModel` 中的用例:

```cs
public void DisplayToast()
{
ToastManager.CreateToast()
.WithTitle("Example Toast")
.WithContent("The content of an example toast can be seen here.")
.Queue();
}
```

## 自动消失

通常地,当消息提醒数量超过预设的最大值后,最老的消息将会立即消失以腾出空间。

但是,你也可以通过调用 `.Dismiss()` 方法来设置消失的条件

以下是让一个消息在3秒钟后/被点击后消失的用例:

```cs
public void DisplayToast()
{
ToastManager.CreateToast()
.Dismiss().After(TimeSpan.FromSeconds(3))
.Dismiss().ByClicking()
.Queue();
}
```

## 交互

SukiUI 提供了两个默认的消息回调,分别是 `.OnClicked()``.OnDismissed()`

同时,可以通过 `.WithActionButton()` 方法来实现更复杂的交互操作

以下是一个显示3秒钟后消失,点击后和消失后会调用命令行输出,按特定按钮会触发 Action 的消息用例:

```cs
public void DisplayToast()
{
ToastManager.CreateToast()
.Dismiss().After(TimeSpan.FromSeconds(3))
.OnClicked(_ => Console.WriteLine("Toast Clicked!"))
.OnDismissed(_ => Console.WriteLine("Toast Was Dismissed!"))
.WithActionButton("Dismiss", _ => { }, true)
.Queue();
}
```
Empty file.
Empty file.
Empty file.

0 comments on commit 4095bef

Please sign in to comment.