mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 13:51:10 +08:00
195 lines
3.9 KiB
Plaintext
195 lines
3.9 KiB
Plaintext
---
|
||
title: 窗口
|
||
sidebar_position: 4
|
||
---
|
||
|
||
# 窗口
|
||
|
||
## 概述
|
||
|
||
这些方法可以控制应用程序窗口。
|
||
|
||
### 窗口标题
|
||
|
||
Go 方法签名: `WindowSetTitle(ctx context.Context, title string)`
|
||
|
||
JS 方法签名: `WindowSetTitle(title: string)`
|
||
|
||
设置窗口标题栏中的文本。
|
||
|
||
### 窗口全屏
|
||
|
||
Go 方法签名: `WindowFullscreen(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowFullscreen()`
|
||
|
||
使窗口全屏。
|
||
|
||
### 窗口取消全屏
|
||
|
||
Go 方法签名: `WindowUnfullscreen(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowUnfullscreen()`
|
||
|
||
在全屏之前恢复先前的窗口尺寸和位置。
|
||
|
||
### 窗口居中
|
||
|
||
Go 方法签名: `WindowCenter(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowCenter()`
|
||
|
||
使窗口在当前窗口所在的监视器上居中。
|
||
|
||
### 窗口重新加载
|
||
|
||
Go 方法签名: `WindowReload(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowReload()`
|
||
|
||
执行“重新加载”(重新加载 index.html)
|
||
|
||
### 显示窗口
|
||
|
||
Go 方法签名: `WindowShow(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowShow()`
|
||
|
||
如果窗口当前处于隐藏状态,则显示该窗口。
|
||
|
||
### 隐藏窗口
|
||
|
||
Go 方法签名: `WindowHide(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowHide()`
|
||
|
||
隐藏窗口(如果当前可见)。
|
||
|
||
### 设置窗口尺寸
|
||
|
||
Go 方法签名: `WindowSetSize(ctx context.Context, width int, height int)`
|
||
|
||
JS 方法签名: `WindowSetSize(size: Size)`
|
||
|
||
设置窗口的宽度和高度。
|
||
|
||
### 获取窗口尺寸
|
||
|
||
Go 方法签名: `WindowGetSize(ctx context.Context) (width int, height int)`
|
||
|
||
JS 方法签名: `WindowGetSize() : Size`
|
||
|
||
获取窗口的宽度和高度。
|
||
|
||
### 设置窗口最小尺寸
|
||
|
||
Go 方法签名: `WindowSetMinSize(ctx context.Context, width int, height int)`
|
||
|
||
JS 方法签名: `WindowSetMinSize(size: Size)`
|
||
|
||
设置最小窗口大小。如果窗口当前小于给定尺寸,将调整窗口大小。
|
||
|
||
将大小设置为 `0,0` 将禁用此约束。
|
||
|
||
### 设置窗口最大尺寸
|
||
|
||
Go 方法签名: `WindowSetMaxSize(ctx context.Context, width int, height int)`
|
||
|
||
JS 方法签名: `WindowSetMaxSize(size: Size)`
|
||
|
||
设置最大窗口大小。如果窗口当前大于给定尺寸,将调整窗口大小。
|
||
|
||
将大小设置为 `0,0` 将禁用此约束。
|
||
|
||
### 设置窗口位置
|
||
|
||
Go 方法签名: `WindowSetPosition(ctx context.Context, x int, y int)`
|
||
|
||
JS 方法签名: `WindowSetPosition(position: Position)`
|
||
|
||
设置相对于窗口当前所在监视器的窗口位置。
|
||
|
||
### 获取窗口位置
|
||
|
||
Go 方法签名: `WindowGetPosition(ctx context.Context) (x int, y int)`
|
||
|
||
JS 方法签名: `WindowGetPosition() : Position`
|
||
|
||
获取相对于窗口当前所在显示器的窗口位置。
|
||
|
||
### 窗口最大化
|
||
|
||
Go 方法签名: `WindowMaximise(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowMaximise()`
|
||
|
||
最大化窗口以填满屏幕。
|
||
|
||
### 窗口取消最大化
|
||
|
||
Go 方法签名: `WindowUnmaximise(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowUnmaximise()`
|
||
|
||
将窗口恢复到最大化之前的尺寸和位置。
|
||
|
||
### 窗口最大化切换
|
||
|
||
Go 方法签名: `WindowToggleMaximise(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowToggleMaximise()`
|
||
|
||
在最大化和最大化之间切换。
|
||
|
||
### 窗口最小化
|
||
|
||
Go 方法签名: `WindowMinimise(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowMinimise()`
|
||
|
||
最小化窗口。
|
||
|
||
### 窗口取消最小化
|
||
|
||
Go 方法签名: `WindowUnminimise(ctx context.Context)`
|
||
|
||
JS 方法签名: `WindowUnminimise()`
|
||
|
||
将窗口恢复到最小化之前的尺寸和位置。
|
||
|
||
### 窗口设置 RGBA
|
||
|
||
Go 方法签名: `WindowSetRGBA(ctx context.Context, R, G, B, A uint8)`
|
||
|
||
JS 方法签名: `WindowSetRGBA(R, G, B, A)`
|
||
|
||
将窗口的背景颜色设置为给定的 RGBA 颜色定义。此颜色将显示所有透明像素。
|
||
|
||
R、G、B 和 A 的有效值为 0-255。
|
||
|
||
:::info Windows
|
||
|
||
在 Windows 上,仅支持 0 或 255 的 alpha 值。任何不为 0 的值都将被视为 255。
|
||
|
||
:::
|
||
|
||
## Typescript 对象定义
|
||
|
||
### 位置
|
||
|
||
```ts
|
||
interface Position {
|
||
x: number;
|
||
y: number;
|
||
}
|
||
```
|
||
|
||
### 尺寸
|
||
|
||
```ts
|
||
interface Size {
|
||
w: number;
|
||
h: number;
|
||
}
|
||
```
|