# ui/uiconfirmwindow (vanilla.js 0.4.0)

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

Confirm window. (title, question text, two buttons: cancel and confirm)

## UIConfirmWindow extends UIWindow

Confirm window. (title, question text, two buttons: cancel and confirm)
- Being a UIWindow, it is opened with UIWindowLayer. The question text wraps at the panel width and the panel height is set by the number of lines.
  If the text is long and exceeds the area height, only the text box scrolls and the two buttons are always visible.
- The buttons are cancel on the left and confirm (emphasized) on the right. For right-to-left languages (setRightToLeft) the order is reversed.
- Pressing confirm closes it after the confirm notification. Closing via cancel, pressing outside, closeTopWindow or closeAllWindows gives the cancel notification.
- The panel look is the same as UIWindow. Button and text colors are changed by getting the nodes with getConfirmButtonNode() and the like.
- Usage:
    const confirmWindow = new UIConfirmWindow("quit", { title: "Quit", message: "Do you really want to quit?", cancelText: "Cancel", confirmText: "Quit" });
    confirmWindow.setConfirmEvent(() => { leave(); });
    windowLayer.openWindow(confirmWindow);

Example: A confirm window asking to quit

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

class ConfirmScene extends UIScene {
	initialize(engine) {
		super.initialize(engine);
		const root = this.getRoot();
		const rootSize = root.getContentSize();
		const windowLayer = new UIWindowLayer();
		root.addChild(windowLayer);
		windowLayer.setViewSize(rootSize.x, rootSize.y);

		const confirmWindow = new UIConfirmWindow("quit", { title: "Quit", message: "Your progress is saved. Quit the game now?", cancelText: "Stay", confirmText: "Quit" });
		confirmWindow.setConfirmEvent(() => {
			console.log("quit");
		});
		confirmWindow.setCancelEvent(() => {
			console.log("stay");
		});
		windowLayer.openWindow(confirmWindow);
	}
}

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

- `constructor(name = "UIConfirmWindow", options = {})` (constructor, since 0.4.0): Constructor.
  - `name` string: Window name.
  - `options` object: { title = "", message = "", cancelText = "취소", confirmText = "확인" }
- `static createBoxNode(nodeName)` (static, since 0.4.0): Creates an empty node with a top-left pivot.
  - `nodeName` string: Node name.
  - returns WorldNode: A new node with its pivot and anchor at the top left.
- `static createButtonNode(nodeName, labelText, fillColor)` (static, since 0.4.0): Creates a button node. (rounded Paint + UIButton + UILabel)
  - `nodeName` string: Node name.
  - `labelText` string: Button text.
  - `fillColor` Color: Button background color.
  - returns WorldNode: Button node. (height 52, the width is set by layoutContent)
- `setTitle(title)` (method, since 0.4.0): Sets the title. (an empty string removes the title line, lays out again if open)
  - `title` string: Title text.
- `setMessage(message)` (method, since 0.4.0): Sets the question text. (lays out again if open)
  - `message` string: Question text. (wrapped to the panel width)
- `setButtonTexts(cancelText, confirmText)` (method, since 0.4.0): Sets the button texts.
  - `cancelText` string: Cancel button text.
  - `confirmText` string: Confirm button text.
- `setRightToLeft(isRightToLeft)` (method, since 0.4.0): Sets whether the language is right-to-left. (if true, cancel is on the right, confirm on the left, and text runs right to left)
  - `isRightToLeft` boolean: If true, a right-to-left language.
- `isRightToLeft()` (method, since 0.4.0): Whether the language is right-to-left.
  - returns boolean: True if a right-to-left language.
- `setConfirmEvent(confirmEvent)` (method, since 0.4.0): Sets the confirm notification.
  - `confirmEvent` Function | null: () => void
- `setCancelEvent(cancelEvent)` (method, since 0.4.0): Sets the cancel notification. (cancel button, pressing outside, when the window layer closes it)
  - `cancelEvent` Function | null: () => void
- `confirm()` (method, since 0.4.0): Confirms. (calls the confirm notification and closes, does nothing if not open)
- `handleClosed()` (method, since 0.4.0): Removed from the window layer. (cancel notification unless confirmed)
- `refreshIfOpen()` (method, since 0.4.0): Lays out again if open.
- `getTitleNode()` (method, since 0.4.0): Returns the title node.
  - returns WorldNode: Title node. (has a UILabel attached)
- `getMessageNode()` (method, since 0.4.0): Returns the question text node.
  - returns WorldNode: Question text node. (has a UILabel attached)
- `getMessageScrollView()` (method, since 0.4.0): Returns the scroll box of the question text.
  - returns UIScrollView: Scroll view for the question text. (drags only vertically)
- `getCancelButtonNode()` (method, since 0.4.0): Returns the cancel button node.
  - returns WorldNode: Cancel button node. (has Paint, UIButton and UILabel attached)
- `getConfirmButtonNode()` (method, since 0.4.0): Returns the confirm button node.
  - returns WorldNode: Confirm button node. (has Paint, UIButton and UILabel attached)
- `measureMessageHeight(textWidth)` (method, since 0.4.0): Height of the question text when wrapped at that width.
  - `textWidth` number: Width to wrap at. (UI layer units, also set as the text's word wrap width)
  - returns number: Height of the question text. (UI layer units, rounded up)
- `layoutContent(panelWidth)` (method, since 0.4.0): Lays out the content. (title → text scroll box → two buttons, returns the panel's height)
  - `panelWidth` number: Panel width. (UI layer units)
  - returns number: Panel height. (UI layer units, the sum of the padding, title, text area and button row)
