mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
228 lines
5.9 KiB
Plaintext
228 lines
5.9 KiB
Plaintext
---
|
|
sidebar_position: 4
|
|
---
|
|
|
|
# Window 窗口
|
|
|
|
这些方法可以控制应用程序窗口。
|
|
|
|
### WindowSetTitle 窗口标题
|
|
|
|
设置窗口标题栏中的文本。
|
|
|
|
Go: `WindowSetTitle(ctx context.Context, title string)`<br/> JS: `WindowSetTitle(title: string)`
|
|
|
|
### WindowFullscreen 窗口全屏
|
|
|
|
使窗口全屏。
|
|
|
|
Go: `WindowFullscreen(ctx context.Context)`<br/> JS: `WindowFullscreen()`
|
|
|
|
### WindowUnfullscreen 窗口取消全屏
|
|
|
|
恢复全屏之前的先前窗口尺寸和位置。
|
|
|
|
Go: `WindowUnfullscreen(ctx context.Context)`<br/> JS: `WindowUnfullscreen()`
|
|
|
|
### WindowIsFullscreen 窗口是否全屏
|
|
|
|
如果窗口是全屏的,则返回 true。
|
|
|
|
Go: `WindowIsFullscreen(ctx context.Context) bool`<br/> JS: `WindowIsFullscreen() bool`
|
|
|
|
### WindowCenter 窗口居中
|
|
|
|
使窗口在当前窗口所在的监视器上居中。
|
|
|
|
Go: `WindowCenter(ctx context.Context)`<br/> JS: `WindowCenter()`
|
|
|
|
### WindowExecJS 窗口执行JS代码
|
|
|
|
在窗口中执行任意 JS 代码。
|
|
|
|
此方法在浏览器中异步运行代码并立即返回。 如果脚本导致任何错误,它们将只在浏览器控制台中可用。
|
|
|
|
Go: `WindowExecJS(ctx context.Context, js string)`
|
|
|
|
### WindowReload 窗口重新加载
|
|
|
|
执行“重新加载”(重新加载当前页面)。
|
|
|
|
Go: `WindowReload(ctx context.Context)`<br/> JS: `WindowReload()`
|
|
|
|
### WindowReloadApp 重新加载应用程序前端。
|
|
|
|
重新加载应用程序前端。
|
|
|
|
Go: `WindowReloadApp(ctx context.Context)`<br/> JS: `WindowReloadApp()`
|
|
|
|
### WindowSetSystemDefaultTheme 窗口设置系统默认主题
|
|
|
|
仅限 Windows。
|
|
|
|
Go: `WindowSetSystemDefaultTheme(ctx context.Context)`<br/> JS: `WindowSetSystemDefaultTheme()`
|
|
|
|
将窗口主题设置为系统默认值(暗/亮)。
|
|
|
|
### WindowSetLightTheme 窗口设置浅色主题
|
|
|
|
仅限 Windows。
|
|
|
|
Go: `WindowSetLightTheme(ctx context.Context)`<br/> JS: `WindowSetLightTheme()`
|
|
|
|
将窗口主题设置为浅色。
|
|
|
|
### WindowSetDarkTheme 窗口设置深色主题
|
|
|
|
仅限 Windows。
|
|
|
|
Go: `WindowSetDarkTheme(ctx context.Context)`<br/> JS: `WindowSetDarkTheme()`
|
|
|
|
将窗口主题设置为深色。
|
|
|
|
### WindowShow 显示窗口
|
|
|
|
显示窗口,如果它当前是隐藏的。
|
|
|
|
Go: `WindowShow(ctx context.Context)`<br/> JS: `WindowShow()`
|
|
|
|
### WindowShow 隐藏窗口
|
|
|
|
如果当前可见,则隐藏窗口。
|
|
|
|
Go: `WindowHide(ctx context.Context)`<br/> JS: `WindowHide()`
|
|
|
|
### WindowIsNormal 窗口是否为正常
|
|
|
|
如果窗口未最小化、最大化或全屏,则返回 true。
|
|
|
|
Go: `WindowIsNormal(ctx context.Context) bool`<br/> JS: `WindowIsNormal() bool`
|
|
|
|
### WindowSetSize 设置窗口尺寸
|
|
|
|
设置窗口的宽度和高度。
|
|
|
|
Go: `WindowSetSize(ctx context.Context, width int, height int)`<br/> JS: `WindowSetSize(width: number, height: number)`
|
|
|
|
### WindowGetSize 获取窗口尺寸
|
|
|
|
获取窗口的宽度和高度。
|
|
|
|
Go: `WindowGetSize(ctx context.Context) (width int, height int)`<br/> JS: `WindowGetSize() : Size`
|
|
|
|
### WindowSetMinSize 设置窗口最小尺寸
|
|
|
|
设置窗口最小尺寸。 如果窗口当前小于给定尺寸,将调整窗口大小。
|
|
|
|
设置大小 `0,0` 将禁用此约束。
|
|
|
|
Go: `WindowSetMinSize(ctx context.Context, width int, height int)`<br/> JS: `WindowSetMinSize(width: number, height: number)`
|
|
|
|
### WindowSetMaxSize 设置窗口最大尺寸
|
|
|
|
设置窗口最大尺寸。 如果窗口当前大于给定尺寸,将调整窗口大小。
|
|
|
|
设置大小 `0,0` 将禁用此约束。
|
|
|
|
Go: `WindowSetMaxSize(ctx context.Context, width int, height int)`<br/> JS: `WindowSetMaxSize(width: number, height: number)`
|
|
|
|
### WindowSetAlwaysOnTop 设置窗口置顶
|
|
|
|
设置窗口置顶或取消置顶。
|
|
|
|
Go: `WindowSetAlwaysOnTop(ctx context.Context, b bool)`<br/> JS: `WindowSetAlwaysOnTop(b: Boolen)`
|
|
|
|
### WindowSetPosition 设置窗口位置
|
|
|
|
设置相对于窗口当前所在监视器的窗口位置。
|
|
|
|
Go: `WindowSetPosition(ctx context.Context, x int, y int)`<br/> JS: `WindowSetPosition(x: number, y: number)`
|
|
|
|
### WindowGetPosition 获取窗口位置
|
|
|
|
获取相对于窗口当前所在监视器的窗口位置。
|
|
|
|
Go: `WindowGetPosition(ctx context.Context) (x int, y int)`<br/> JS: `WindowGetPosition() : Position`
|
|
|
|
### WindowMaximise 窗口最大化
|
|
|
|
最大化窗口以填满屏幕。
|
|
|
|
Go: `WindowMaximise(ctx context.Context)`<br/> JS: `WindowMaximise()`
|
|
|
|
### WindowUnmaximise 窗口取消最大化
|
|
|
|
将窗口恢复到最大化之前的尺寸和位置。
|
|
|
|
Go: `WindowUnmaximise(ctx context.Context)`<br/> JS: `WindowUnmaximise()`
|
|
|
|
### WindowIsMaximised 窗口是否最大化
|
|
|
|
如果窗口最大化,则返回 true。
|
|
|
|
Go: `WindowIsMaximised(ctx context.Context) bool`<br/> JS: `WindowIsMaximised() bool`
|
|
|
|
### WindowToggleMaximise 窗口最大化切换
|
|
|
|
在最大化和未最大化之间切换。
|
|
|
|
Go: `WindowToggleMaximise(ctx context.Context)`<br/> JS: `WindowToggleMaximise()`
|
|
|
|
### WindowMinimise 窗口最小化。
|
|
|
|
最小化窗口。
|
|
|
|
Go: `WindowMinimise(ctx context.Context)`<br/> JS: `WindowMinimise()`
|
|
|
|
### WindowUnminimise 窗口取消最小化
|
|
|
|
将窗口恢复到最小化之前的尺寸和位置。
|
|
|
|
Go: `WindowUnminimise(ctx context.Context)`<br/> JS: `WindowUnminimise()`
|
|
|
|
### WindowIsMinimised 窗口是否最小化
|
|
|
|
如果窗口最小化,则返回 true。
|
|
|
|
Go: `WindowIsMinimised(ctx context.Context) bool`<br/> JS: `WindowIsMinimised() bool`
|
|
|
|
### WindowSetBackgroundColour 窗口设置背景色
|
|
|
|
将窗口的背景颜色设置为给定的 RGBA 颜色定义。 这种颜色将显示所有透明像素。
|
|
|
|
R、G、B 和 A 的有效值为 0-255。
|
|
|
|
:::info Windows
|
|
|
|
在 Windows 上,仅支持 0 或 255 的 alpha 值。 任何非 0 的值都将被视为 255。
|
|
|
|
:::
|
|
|
|
Go: `WindowSetBackgroundColour(ctx context.Context, R, G, B, A uint8)`<br/> JS: `WindowSetBackgroundColour(R, G, B, A)`
|
|
|
|
### WindowPrint
|
|
|
|
Opens tha native print dialog.
|
|
|
|
Go: `WindowPrint(ctx context.Context)`<br/> JS: `WindowPrint()`
|
|
|
|
## TypeScript 对象定义
|
|
|
|
### Position(位置)
|
|
|
|
```ts
|
|
interface Position {
|
|
x: number;
|
|
y: number;
|
|
}
|
|
```
|
|
|
|
### Size(尺寸)
|
|
|
|
```ts
|
|
interface Size {
|
|
w: number;
|
|
h: number;
|
|
}
|
|
```
|