Skip to content

Commit 856f86e

Browse files
🔄 Sync from private repository - 2026-03-05 03:06:50
1 parent 2cd63af commit 856f86e

7 files changed

Lines changed: 740 additions & 24 deletions

File tree

API.en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,7 @@ Create a HUD window
19931993

19941994
| Name | Type | Description | Optional |
19951995
|------|------|-------------|----------|
1996-
| `config` | `object` | Window config { id?, width?, height?, x?, y?, draggable?, dismissible?, autoClear?, style? }, style is { backgroundColor?, textColor?, fontSize?, fontWeight?, cornerRadius?, padding?, opacity?, shadow? } | No |
1996+
| `config` | `object` | Window config { id?, width?, height?, x?, y?, alignment?, draggable?, dismissible?, autoClear?, style? }, alignment: 'leading'\|'center'\|'trailing'\|'fill' (default leading), style is { backgroundColor?, textColor?, fontSize?, fontWeight?, cornerRadius?, padding?, opacity?, shadow? } | No |
19971997

19981998
**Returns:** `Window`
19991999

API.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ HUD 浮窗系统 - 创建悬浮窗口和 UI 元素
19921992

19931993
| Name | Type | Description | Optional |
19941994
|------|------|-------------|----------|
1995-
| `config` | `object` | 窗口配置 { id?, width?, height?, x?, y?, draggable?, dismissible?, autoClear?, style? },style 为 { backgroundColor?, textColor?, fontSize?, fontWeight?, cornerRadius?, padding?, opacity?, shadow? } | No |
1995+
| `config` | `object` | 窗口配置 { id?, width?, height?, x?, y?, alignment?, draggable?, dismissible?, autoClear?, style? },alignment: 'leading'\|'center'\|'trailing'\|'fill'(默认 leading),style 为 { backgroundColor?, textColor?, fontSize?, fontWeight?, cornerRadius?, padding?, opacity?, shadow? } | No |
19961996

19971997
**Returns:** `Window`
19981998

TrollScript-Private

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit 505e609888b56782d01c733584dccbad632b08e2
1+
Subproject commit 960686073b569e8bcaa9781dd9ec13ba75a2fd5f

npm/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ declare const display: Display;
841841
interface Hud {
842842
/**
843843
* 创建 HUD 窗口
844-
* @param config 窗口配置 { id?, width?, height?, x?, y?, draggable?, dismissible?, autoClear?, style? },style 为 { backgroundColor?, textColor?, fontSize?, fontWeight?, cornerRadius?, padding?, opacity?, shadow? }
844+
* @param config 窗口配置 { id?, width?, height?, x?, y?, alignment?, draggable?, dismissible?, autoClear?, style? },alignment: 'leading'|'center'|'trailing'|'fill'(默认 leading),style 为 { backgroundColor?, textColor?, fontSize?, fontWeight?, cornerRadius?, padding?, opacity?, shadow? }
845845
* @returns 窗口对象,可用于添加元素和控制窗口
846846
*/
847847
createWindow(config: Record<string, any>): any;

templates/API/HUD.md

Lines changed: 167 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ win.show();
7272
| `height` | `number` | 100 | 窗口高度 |
7373
| `x` | `number` | 居中 | 窗口 X 坐标 |
7474
| `y` | `number` | 居中 | 窗口 Y 坐标 |
75-
| `draggable` | `boolean` | false | 是否可拖拽 |
75+
| `draggable` | `boolean` | true | 是否可拖拽 |
7676
| `dismissible` | `boolean` | true | 是否可通过手势关闭 |
7777
| `autoClear` | `number` | - | 自动关闭时间(秒),不设置则不自动关闭 |
78+
| `alignment` | `string` | `'leading'` | 内容对齐方式: `'leading'` \| `'center'` \| `'trailing'` \| `'fill'` |
7879
| `style` | `object` | - | 窗口样式,详见 [样式配置](#样式配置) |
7980

8081
**返回:** `Window` — 窗口对象
@@ -98,7 +99,6 @@ const win = hud.createWindow({
9899

99100
---
100101

101-
102102
#### `hud.getWindow(id)`
103103

104104
获取窗口是否被创建。
@@ -165,7 +165,10 @@ console.log('当前窗口数量:', windowIds.length);
165165
| 字段 | 类型 | 必填 | 说明 |
166166
|------|------|------|------|
167167
| `config.text` | `string` || 文本内容 |
168+
| `config.width` | `number` || 固定宽度 |
169+
| `config.height` | `number` || 固定高度 |
168170
| `config.style` | `object` || 文本样式,详见 [样式配置](#样式配置) |
171+
| `config.onClick` | `function` || 点击回调函数 |
169172

170173
**返回:** `Text` — 文本元素对象
171174

@@ -185,6 +188,8 @@ const label = win.addText({
185188
| 字段 | 类型 | 必填 | 说明 |
186189
|------|------|------|------|
187190
| `config.title` | `string` || 按钮标题 |
191+
| `config.width` | `number` || 固定宽度 |
192+
| `config.height` | `number` || 固定高度 |
188193
| `config.style` | `object` || 按钮样式 |
189194
| `config.onClick` | `function` || 点击回调函数 |
190195

@@ -212,6 +217,7 @@ const btn = win.addButton({
212217
| `config.systemName` | `string` | 二选一 | SF Symbol 图标名称 |
213218
| `config.width` | `number` || 图片宽度 |
214219
| `config.height` | `number` || 图片高度 |
220+
| `config.onClick` | `function` || 点击回调函数 |
215221

216222
**返回:** `Image` — 图片元素对象
217223

@@ -232,8 +238,9 @@ win.addImage({ path: '/var/mobile/Documents/photo.png', width: 100, height: 100
232238
| 字段 | 类型 | 默认值 | 说明 |
233239
|------|------|--------|------|
234240
| `config.axis` | `string` | `'vertical'` | 排列方向: `'horizontal'` \| `'vertical'` |
235-
| `config.spacing` | `number` | 8 | 子元素间距 |
236-
| `config.alignment` | `string` | `'center'` | 对齐方式: `'leading'` \| `'center'` \| `'trailing'` \| `'fill'` |
241+
| `config.spacing` | `number` | `0` | 子元素间距 |
242+
| `config.alignment` | `string` | `'leading'` | 对齐方式: `'leading'` \| `'center'` \| `'trailing'` \| `'fill'` |
243+
| `config.distribution` | `string` | `'fill'` | 分布方式: `'fill'` \| `'fillEqually'` \| `'equalSpacing'` \| `'equalCentering'` |
237244
| `config.style` | `object` | - | 堆栈样式 |
238245

239246
**返回:** `Stack` — 堆栈容器对象
@@ -350,6 +357,24 @@ win.setStyle({
350357

351358
---
352359

360+
#### `win.setAlignment(alignment)`
361+
362+
设置窗口内容的对齐方式。控制窗口内所有子元素的水平对齐行为。
363+
364+
| 参数 | 类型 | 说明 |
365+
|------|------|------|
366+
| `alignment` | `string` | 对齐方式: `'leading'` \| `'center'` \| `'trailing'` \| `'fill'` |
367+
368+
```javascript
369+
// 让所有子元素撑满窗口宽度
370+
win.setAlignment('fill');
371+
372+
// 让所有子元素居中
373+
win.setAlignment('center');
374+
```
375+
376+
---
377+
353378
#### `win.getBounds()`
354379

355380
获取窗口的当前位置和大小。
@@ -377,6 +402,22 @@ if (win.isVisible()) {
377402

378403
---
379404

405+
#### `win.onDismiss(callback)`
406+
407+
设置窗口关闭时的回调函数。当窗口通过 `dismiss()` 或点击外部区域关闭时触发。
408+
409+
| 参数 | 类型 | 说明 |
410+
|------|------|------|
411+
| `callback` | `function` | 关闭回调函数 |
412+
413+
```javascript
414+
win.onDismiss(() => {
415+
console.log('窗口已关闭');
416+
});
417+
```
418+
419+
---
420+
380421
### Stack 堆栈容器
381422

382423
`Stack` 对象由 `win.addStack()` 或其他堆栈的 `addStack()` 返回。堆栈容器类似于 iOS WidgetStack,可以包含文本、按钮、图片等子元素。
@@ -452,6 +493,62 @@ if (win.isVisible()) {
452493

453494
---
454495

496+
#### `stack.addStack(config?)`
497+
498+
向堆栈添加嵌套堆栈容器。参数同 `win.addStack()`
499+
500+
**返回:** `Stack`
501+
502+
---
503+
504+
#### `stack.addLoading(config?)`
505+
506+
向堆栈添加加载指示器。参数同 `win.addLoading()`
507+
508+
**返回:** `Loading`
509+
510+
---
511+
512+
#### `stack.addScrollView(config?)`
513+
514+
向堆栈添加滚动视图。参数同 `win.addScrollView()`
515+
516+
**返回:** `ScrollView`
517+
518+
---
519+
520+
#### `stack.addList(config?)`
521+
522+
向堆栈添加列表视图。参数同 `win.addList()`
523+
524+
**返回:** `List`
525+
526+
---
527+
528+
#### `stack.addWebView(config?)`
529+
530+
向堆栈添加网页视图。参数同 `win.addWebView()`
531+
532+
**返回:** `WebView`
533+
534+
---
535+
536+
#### `stack.onClick(callback)`
537+
538+
设置堆栈的点击回调函数。当子元素有自己的回调时,堆栈的点击不会触发。
539+
540+
| 参数 | 类型 | 说明 |
541+
|------|------|------|
542+
| `callback` | `function` | 点击回调函数 |
543+
544+
```javascript
545+
stack.onClick(() => {
546+
console.log('堆栈被点击');
547+
});
548+
```
549+
550+
---
551+
455552
### Text 文本元素
456553

457554
`Text` 对象由 `addText()` 返回,用于显示和控制文本内容。
@@ -470,6 +567,34 @@ label.setText('更新后的文本');
470567

471568
---
472569

570+
#### `text.setColor(color)`
571+
572+
设置文本颜色。
573+
574+
| 参数 | 类型 | 说明 |
575+
|------|------|------|
576+
| `color` | `string` | 颜色值(十六进制) |
577+
578+
```javascript
579+
label.setColor('#FF3B30');
580+
```
581+
582+
---
583+
584+
#### `text.setFontSize(size)`
585+
586+
设置字体大小。
587+
588+
| 参数 | 类型 | 说明 |
589+
|------|------|------|
590+
| `size` | `number` | 字体大小 |
591+
592+
```javascript
593+
label.setFontSize(20);
594+
```
595+
596+
---
597+
473598
#### `text.setStyle(style)`
474599

475600
更新文本样式。
@@ -482,6 +607,8 @@ label.setText('更新后的文本');
482607
| `backgroundColor` | `string` | 背景颜色 |
483608
| `cornerRadius` | `number` | 圆角半径 |
484609
| `padding` | `number` | 内边距 |
610+
| `width` | `number` | 固定宽度 |
611+
| `height` | `number` | 固定高度 |
485612

486613
---
487614

@@ -503,6 +630,22 @@ label.update({
503630

504631
---
505632

633+
#### `text.onClick(callback)`
634+
635+
设置文本的点击回调函数。
636+
637+
| 参数 | 类型 | 说明 |
638+
|------|------|------|
639+
| `callback` | `function` | 点击回调函数 |
640+
641+
```javascript
642+
label.onClick(() => {
643+
console.log('文本被点击');
644+
});
645+
```
646+
647+
---
648+
506649
#### `text.remove()`
507650

508651
从父容器中移除该文本元素。
@@ -534,6 +677,8 @@ label.update({
534677
| `fontSize` | `number` | 字体大小 |
535678
| `cornerRadius` | `number` | 圆角半径 |
536679
| `padding` | `number` | 内边距 |
680+
| `width` | `number` | 固定宽度 |
681+
| `height` | `number` | 固定高度 |
537682

538683
---
539684

@@ -612,6 +757,22 @@ img.update({ path: '/new/path.png', width: 64, height: 64 });
612757

613758
---
614759

760+
#### `img.onClick(callback)`
761+
762+
设置图片的点击回调函数。
763+
764+
| 参数 | 类型 | 说明 |
765+
|------|------|------|
766+
| `callback` | `function` | 点击回调函数 |
767+
768+
```javascript
769+
img.onClick(() => {
770+
console.log('图片被点击');
771+
});
772+
```
773+
774+
---
775+
615776
#### `img.remove()`
616777

617778
从父容器中移除该图片元素。
@@ -1667,6 +1828,8 @@ win.show();
16671828
| `padding` | `number` | 内边距 | `16` |
16681829
| `opacity` | `number` | 不透明度 (0-1) | `0.9` |
16691830
| `shadow` | `boolean` | 是否显示阴影 | `true` |
1831+
| `width` | `number` | 固定宽度 | `80` |
1832+
| `height` | `number` | 固定高度 | `40` |
16701833

16711834
### 颜色格式
16721835

0 commit comments

Comments
 (0)