# ui/uitoast (vanilla.js 0.4.0)

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

Toast.

## UIToast extends WorldNode

Toast.
- show(message) makes a pill-shaped notification rise from the bottom, stay briefly, then disappear.
- Calling it several times queues them and shows them one by one. (a pattern several games copy-pasted per screen)
- addChild it at the top (last child) of the scene root before use.
- Usage:
    const toast = new UIToast();
    scene.getRoot().addChild(toast);
    toast.show("Saved.");

Example: Queuing two notifications

```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): Constructor.
  - `options` object: { width = 400, height = 48, restY = 560, holdSeconds = 1.8, backgroundColor?, textColor? }
- `show(messageText)` (method, since 0.3.0): Shows a toast. (queued if one is showing)
  - `messageText` string: Notification text. (shown right away if nothing is shown, otherwise added to the end of the queue)
- `tick(timeDelta)` (method, since 0.3.0): Update.
  - `timeDelta` number: Time since the last frame. (seconds, enter 0.24 seconds, hold holdSeconds, exit 0.2 seconds)
- `setRestY(restY)` (method, since 0.3.0): Sets the display position (center vertical coordinate).
  - `restY` number: Vertical center coordinate of the resting position. (parent local pixels, rises from 28 pixels below when entering)
- `setRestX(restX)` (method, since 0.3.0): Sets the display position (center horizontal coordinate). (null means the parent's horizontal center)
  - `restX` number | null: Horizontal center coordinate. (parent local pixels, half the parent width if null, 480 if the parent size is 0)
- `setHoldSeconds(holdSeconds)` (method, since 0.3.0): Sets the stay duration.
  - `holdSeconds` number: Seconds to stay. (counted after it has fully entered)
- `isShowing()` (method, since 0.3.0): Whether it is showing.
  - returns boolean: True while entering, staying or exiting.
