# ui/uitoast (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/ui/uitoast/

토스트.

## UIToast extends WorldNode

토스트.
- show(message) 로 알약 모양 알림이 아래에서 떠올라 잠시 머문 뒤 사라진다.
- 여러 번 부르면 줄을 세워 하나씩 보여 준다. (여러 게임이 화면마다 복붙하던 패턴)
- 씬 뿌리의 맨 위(마지막 자식)에 addChild 해 두고 쓴다.
- 사용:
    const toast = new UIToast();
    scene.getRoot().addChild(toast);
    toast.show("저장되었습니다.");

예제: 알림 두 개를 줄 세워 띄우기

```js
import { Engine, EngineConfiguration, UIScene, UIToast, Color } from "./build/vanilla.js";

class ToastScene extends UIScene {
	create() {
		super.create();
		const toast = new UIToast({ width: 320, height: 40, restY: 300, holdSeconds: 1.2, backgroundColor: new Color(0.07, 0.09, 0.13, 0.95) });
		const root = this.getRoot();
		root.addChild(toast);
		toast.show("Game saved");
		toast.show("Achievement unlocked");
		const isShowing = toast.isShowing();
		console.log(isShowing);
	}
}

const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
const scene = new ToastScene();
scene.setLoadingMinDurationMs(0);
engine.run(scene);
```

- `constructor(options = {})` (constructor, since 0.3.0): 생성.
  - `options` object: { width = 400, height = 48, restY = 560, holdSeconds = 1.8, backgroundColor?, textColor? }
- `show(messageText)` (method, since 0.3.0): 토스트 표시. (표시 중이면 줄을 선다)
  - `messageText` string: 알림 글. (떠 있는 것이 없으면 곧바로 띄우고, 있으면 줄 끝에 넣는다)
- `tick(timeDelta)` (method, since 0.3.0): 갱신.
  - `timeDelta` number: 지난 프레임부터의 시간. (초, 나오기 0.24 초, 머물기 holdSeconds, 사라지기 0.2 초)
- `setRestY(restY)` (method, since 0.3.0): 표시 자리(가운데 세로 좌표) 설정.
  - `restY` number: 머무는 자리의 가운데 세로 좌표. (부모 로컬 픽셀, 나올 때 28 픽셀 아래에서 떠오른다)
- `setRestX(restX)` (method, since 0.3.0): 표시 자리(가운데 가로 좌표) 설정. (null 이면 부모 가로 중앙)
  - `restX` number | null: 가운데 가로 좌표. (부모 로컬 픽셀, null 이면 부모 너비의 반, 부모 크기가 0 이면 480)
- `setHoldSeconds(holdSeconds)` (method, since 0.3.0): 머무는 시간 설정.
  - `holdSeconds` number: 머무는 초. (다 나온 뒤부터 센다)
- `isShowing()` (method, since 0.3.0): 표시 중 여부.
  - returns boolean: 나오는 중, 머무는 중, 사라지는 중이면 참.
