# ui/uiwindow (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/ui/uiwindow/

A single window in the window stack. (vanilla.js ui/uiwindow.js, UIWindow)
- Dims the whole area (presses do not pass through to what is behind) and shows a panel in the center. The dim also covers the safe area (set_view_bleed).
- The panel widens to fit the area's width but does not exceed maximum_width. Its height is the value returned by layout_content, and if it is larger than the area the whole panel is scaled down.
- The open and close motion is PopupMotion. When the close motion finishes, the window layer (UIWindowLayer) removes the node. (it does not receive presses in the meantime)
- Pressing outside (the dim) closes it. Turned off per window with set_outside_close_enabled. The window layer's close_top_window (back) also follows this value.
- Node structure: window (area size) ├ dim (Paint + UIButton) └ frame (panel center pivot, motion scale) └ panel (a single Paint, content goes here)
- Differences from the original:
  - In the original it is a node inheriting WorldNode, and derived classes override layoutContent, layoutPanel, applyMotion, setCovered, handleWheel, dispose.
    The Rust version is a component attached to the window node, and the override points are the UIWindowBehavior trait. (the default implementation is UIWindowDefaultBehavior,
    and an override that wants to call the default like the original super uses UIWindow::layout_panel_default, apply_motion_default, set_covered_default)
    The panel look (shadow, border, gloss) is done by the game attaching decoration nodes to the frame in build (set_sibling_index(0) for behind the panel) and placing them in layout_panel.
  - The window node is created under the window layer node with UIWindow::create(node_tree, layer_id, name, behavior). When the close motion finishes, it is detached from the layer and not removed, so
    the same window node can be opened again as in the original. (UIWindowLayer::open_window) The original window attaches to the layer when opened, so create keeps the node off until it is opened.
    When attached, it does not turn the node off as the original constructor does. (so the UI document reads and writes the window node as active, as in the original)
  - Closing goes through the window layer. Scene and callback code calls UIWindow::close_in_tree(node_tree, window_id).
  - The notification (set_close_event) is an argumentless `Box<dyn FnMut()>`. (same form as the PopupMotion notification, node changes are done by the scene checking the state in tick)
  - As in the original, GameSceneBase passes wheel input pointing inside the window layer to UIWindowLayer::scroll_window_at so the top window (UIWindowBehavior::handle_wheel) gets it first,
    and if it does not take it, the scroll view at that spot does. Wheel input that reaches a window through the engine's wheel delivery (from the pointed node toward the parents) without going through GameSceneBase is also taken by the window and always swallowed.
  - The panel and dim Paints are components of nodes, so get_panel_paint and get_dim_paint take the tree.

## UIWindowEvent (type)

Notification. (no arguments)

```rust
pub type UIWindowEvent = Box<dyn FnMut()>
```

## UIWindowParts (struct) (Clone, Copy, Debug, PartialEq)

The window's nodes and current layout values. (received by UIWindowBehavior)

Example: Reading the panel position of an opened window

```rust
use vanilla::{NodeTree, Rect, UIWindow, UIWindowDefaultBehavior, UIWindowLayer};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
	window_layer.set_view_size(tree, 800.0, 600.0, 1.0);
});
let window_id = UIWindow::create(&mut node_tree, layer_id, "notice", Box::new(UIWindowDefaultBehavior));
node_tree[window_id].get_component_mut::<UIWindow>().expect("window").set_panel_height(300.0);
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
let parts = node_tree[window_id].get_component::<UIWindow>().expect("window").get_parts().expect("parts");
assert_eq!(parts.window_id, window_id);
assert_eq!(parts.view_width, 800.0);
assert_eq!(parts.panel_rect, Rect::create(160.0, 150.0, 480.0, 300.0));
assert_eq!(parts.panel_scale, 1.0);
```

- `pub window_id: NodeId` (field, since 0.4.0): Window node. (the node with UIWindow attached, area size)
  - returns NodeId
- `pub dim_id: NodeId` (field, since 0.4.0): Dim node. (Paint + UIButton, receives outside presses)
  - returns NodeId
- `pub frame_id: NodeId` (field, since 0.4.0): Frame node. (panel center pivot, the motion scale is applied)
  - returns NodeId
- `pub panel_id: NodeId` (field, since 0.4.0): Panel node. (a single Paint, content is attached here)
  - returns NodeId
- `pub view_width: f64` (field, since 0.4.0): Size of the last received area. (UI layer units)
  - returns f64
- `pub view_height: f64` (field, since 0.4.0): Height of the last received area. (UI layer units)
  - returns f64
- `pub margin: f64` (field, since 0.4.0): Distance between the area edge and the panel. (UI layer units, default 16)
  - returns f64
- `pub panel_height: f64` (field, since 0.4.0): Panel height returned by the layout_content default.
  - returns f64
- `pub panel_rect: Rect` (field, since 0.4.0): Rect of the last placed panel. (window coordinates, before motion, size multiplied by the shrink scale)
  - returns Rect
- `pub panel_scale: f64` (field, since 0.4.0): Scale by which the panel was shrunk because it was larger than the area. (1 or less)
  - returns f64

## UIWindowBehavior (trait) (Any)

The window's override points. (methods that original UIWindow derived classes override)
- Only as_any and as_any_mut must be implemented (they return `self`), and the rest are overridden only as needed.

Example: A window that sets its panel height and receives the close

```rust
use std::any::Any;
use vanilla::{NodeTree, UIWindow, UIWindowBehavior, UIWindowLayer, UIWindowParts};

struct NoticeWindow {
	is_closed: bool,
}

impl UIWindowBehavior for NoticeWindow {
	fn as_any(&self) -> &dyn Any {
		self
	}

	fn as_any_mut(&mut self) -> &mut dyn Any {
		self
	}

	fn layout_content(&mut self, _node_tree: &mut NodeTree, _parts: &UIWindowParts, _panel_width: f64) -> f64 {
		200.0
	}

	fn handle_closed(&mut self) {
		self.is_closed = true;
	}
}

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
	window_layer.set_view_size(tree, 800.0, 600.0, 1.0);
});
let window_id = UIWindow::create(&mut node_tree, layer_id, "notice", Box::new(NoticeWindow { is_closed: false }));
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
assert_eq!(node_tree[window_id].get_component::<UIWindow>().expect("window").get_panel_rect().size.y, 200.0);
UIWindow::close_in_tree(&mut node_tree, window_id);
let window = node_tree[window_id].get_component::<UIWindow>().expect("window");
assert!(window.get_behavior::<NoticeWindow>().expect("notice").is_closed);
```

- `fn as_any(&self) -> &dyn Any` (method, since 0.4.0): Takes it out as the concrete type. (used by UIWindow::get_behavior, the mutable version as_any_mut is used by get_behavior_mut)
  - returns &dyn Any: Itself. (`&dyn Any`, UIWindow::get_behavior takes it out with downcast_ref)
- `fn as_any_mut(&mut self) -> &mut dyn Any` (method, since 0.4.0): Takes it out as the concrete type. (for modification, used by UIWindow::get_behavior_mut)
  - returns &mut dyn Any: Itself. (`&mut dyn Any`, UIWindow::get_behavior_mut takes it out with downcast_mut)
- `fn build(&mut self, _node_tree: &mut NodeTree, _parts: &UIWindowParts)` (method, since 0.4.0): Once after the window node is fully created. (creates the content and decoration nodes, where the original derived class constructor goes)
  - `_node_tree` &mut NodeTree: Node tree holding the window.
  - `_parts` &UIWindowParts: The window's nodes. (content goes under the panel parts.panel_id, decorations that grow and shrink with the panel go under the frame parts.frame_id. The area size is still the initial value 1)
- `fn layout_content(&mut self, _node_tree: &mut NodeTree, parts: &UIWindowParts, _panel_width: f64) -> f64` (method, since 0.4.0): Lays out the content. (places the content inside the panel and returns the panel's height, default is parts.panel_height)
  - `_node_tree` &mut NodeTree: Node tree holding the window.
  - `parts` &UIWindowParts: The window's nodes and current layout values. (view_width, view_height are this area's size, panel_rect and panel_scale are still the previous values)
  - `_panel_width` f64: Panel width. (area width - margin x 2 clamped to the width limit, 1 or more, UI layer units)
  - returns f64: Panel height. (UI layer units, raised to 1 if less than 1. If larger than area height - margin x 2, the window scales down the whole panel)
- `fn layout_panel(&mut self, node_tree: &mut NodeTree, parts: &UIWindowParts, panel_width: f64, panel_height: f64)` (method, since 0.4.0): Lays out the panel. (sets the panel size, if there are decorations override this and place them after layout_panel_default)
  - `node_tree` &mut NodeTree: Node tree holding the window.
  - `parts` &UIWindowParts: The window's nodes and the values laid out this time. (after panel_rect and panel_scale are set)
  - `panel_width` f64: Panel width. (before scaling down, UI layer units)
  - `panel_height` f64: Panel height returned by layout_content. (before scaling down, 1 or more)
- `fn apply_motion(&mut self, node_tree: &mut NodeTree, parts: &UIWindowParts, popup_motion: &PopupMotion)` (method, since 0.4.0): Applies the motion to the frame and the dim. (default: frame scale = reduced scale x motion scale, dim strength = motion ratio)
  - Called on relayout, when an open or close motion starts, and every tick.
  - `node_tree` &mut NodeTree: Node tree holding the window.
  - `parts` &UIWindowParts: The window's nodes and current layout values.
  - `popup_motion` &PopupMotion: The window's motion. (get_scale is the frame scale, get_dim_ratio is the dim strength from 0 ~ 1)
- `fn set_covered(&mut self, node_tree: &mut NodeTree, parts: &UIWindowParts, is_covered: bool)` (method, since 0.4.0): Notifies whether it is covered by another window. (by default turns the window node off when covered and on when revealed)
  - `node_tree` &mut NodeTree: Node tree holding the window.
  - `parts` &UIWindowParts: The window's nodes and current layout values.
  - `is_covered` bool: true if another window is open above, false once it becomes the top.
- `fn handle_wheel(&mut self, _node_tree: &mut NodeTree, _parts: &UIWindowParts, _view_input_position: Vector2, _wheel_delta: Vector2) -> bool` (method, since 0.4.0): Wheel input not taken by the scroll view at that spot. (true if taken, the window swallows the wheel either way)
  - `_node_tree` &mut NodeTree: Node tree holding the window.
  - `_parts` &UIWindowParts: The window's nodes and current layout values.
  - `_view_input_position` Vector2: Position where the wheel was rolled. (view coordinates)
  - `_wheel_delta` Vector2: Amount the wheel was rolled.
  - returns bool: true if taken. (default false, if false UIWindowLayer::scroll_window_at passes it to the scroll view at that spot)
- `fn handle_closed(&mut self)` (method, since 0.4.0): Removed from the window layer. (close, outside press, close_all_windows alike, after the set_close_event notification)
- `fn is_layout_pending(&self, _node_tree: &NodeTree, _parts: &UIWindowParts) -> bool` (method, since 0.4.0): Whether layout needs to be redone. (true while waiting for a size known only after drawing, the window lays out again in tick)
  - `_node_tree` &NodeTree: Node tree holding the window.
  - `_parts` &UIWindowParts: The window's nodes and current layout values.
  - returns bool: true if it needs to be laid out again. (if true, it is laid out again with UIWindow::refresh_layout in that tick, default false)
- `fn dispose(&mut self, _node_tree: &mut NodeTree, _parts: &UIWindowParts)` (method, since 0.4.0): When the window layer detaches the window. (cleans up what was attached outside the engine, the node is not deleted and remains so it can be shown again)
  - `_node_tree` &mut NodeTree: Node tree holding the window.
  - `_parts` &UIWindowParts: The window's nodes and current layout values.

## UIWindowDefaultBehavior (struct) (UIWindowBehavior)

Default window. (nothing overridden, panel height is UIWindow::set_panel_height)

Example: A window that only sets its panel height

```rust
use vanilla::{UIWindow, UIWindowDefaultBehavior};

let mut window = UIWindow::create_with_behavior(Box::new(UIWindowDefaultBehavior));
window.set_panel_height(320.0);
assert_eq!(window.get_panel_height(), 320.0);
assert!(window.get_behavior::<UIWindowDefaultBehavior>().is_some());
```

## UIWindow (struct) (UIDocumentNode, Component)

Window.

Example: Opening and closing on the window layer

```rust
use std::cell::Cell;
use std::rc::Rc;
use vanilla::{Engine, EngineConfiguration, NodeTree, UIWindow, UIWindowDefaultBehavior, UIWindowLayer};

let engine = Engine::new(EngineConfiguration::new());
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
	window_layer.set_view_size(tree, 800.0, 600.0, 1.0);
});
let window_id = UIWindow::create(&mut node_tree, layer_id, "settings", Box::new(UIWindowDefaultBehavior));
let close_count = Rc::new(Cell::new(0));
let close_counter = close_count.clone();
if let Some(window) = node_tree[window_id].get_component_mut::<UIWindow>() {
	window.set_panel_height(300.0);
	window.set_close_event(Some(Box::new(move || {
		close_counter.set(close_counter.get() + 1);
	})));
}
UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
assert!(node_tree[window_id].is_active());
node_tree.tick(&engine, 0.5);
UIWindow::close_in_tree(&mut node_tree, window_id);
assert_eq!(close_count.get(), 1);
node_tree.tick(&engine, 0.3);
node_tree.tick(&engine, 0.016);
assert_eq!(node_tree.get_parent_id(window_id), None);
```

- `pub fn create_with_behavior(behavior: Box<dyn UIWindowBehavior>) -> UIWindow` (static, since 0.4.0): Constructor. (attach to a node with node_tree.add_component, usually UIWindow::create)
  - `behavior` Box<dyn UIWindowBehavior>: Override points. (UIWindowDefaultBehavior or a value implemented by the game)
  - returns UIWindow: Window before being attached. (width limit 480, margin 16, panel height 240, outside close on)
- `pub fn create(node_tree: &mut NodeTree, layer_id: NodeId, name: &str, behavior: Box<dyn UIWindowBehavior>) -> NodeId` (static, since 0.4.0): Creates a window node. (creates a name node under the layer_id window layer node and attaches the window, opening is UIWindowLayer::open_window)
  - `node_tree` &mut NodeTree: Node tree.
  - `layer_id` NodeId: Window layer node. (the one returned by UIWindowLayer::create)
  - `name` &str: Window node name. (the dim, frame and panel nodes are this name followed by Dim, Frame, Panel)
  - `behavior` Box<dyn UIWindowBehavior>: Override points.
  - returns NodeId: The created window node. (off since it is not opened yet)

  Example: A created window stays off until it is opened

  ```rust
  use vanilla::{NodeTree, UIWindow, UIWindowDefaultBehavior, UIWindowLayer};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
  let window_id = UIWindow::create(&mut node_tree, layer_id, "help", Box::new(UIWindowDefaultBehavior));
  assert!(!node_tree[window_id].is_active());
  let panel_id = node_tree[window_id].get_component::<UIWindow>().expect("window").get_panel_node().expect("panel");
  assert_eq!(node_tree[panel_id].get_name(), "helpPanel");
  UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
  assert!(node_tree[window_id].is_active());
  ```

- `pub fn close_in_tree(node_tree: &mut NodeTree, window_id: NodeId)` (static, since 0.4.0): Closes the window. (finds the window node's window layer and calls close_window, called from scene code and button callbacks, does nothing if not open)
  - `node_tree` &mut NodeTree: Node tree. (context.get_node_tree_mut() in button callbacks)
  - `window_id` NodeId: Window node to close.

  Example: A close button inside the panel

  ```rust
  use vanilla::{ComponentContext, NodeId, UIButton, UIWindow};
  
  fn bind_close_button(button: &mut UIButton, window_id: NodeId) {
  	button.set_clicked_event(Box::new(move |_button: &mut UIButton, context: &mut ComponentContext| {
  		UIWindow::close_in_tree(context.get_node_tree_mut(), window_id);
  	}));
  }
  ```

- `pub fn refresh_layout_in_tree(node_tree: &mut NodeTree, window_id: NodeId)` (static, since 0.4.0): Lays out the window again. (when the content changes and the panel height differs, from scene code)
  - `node_tree` &mut NodeTree: Node tree.
  - `window_id` NodeId: Window node to lay out again. (does nothing if there is no UIWindow)

  Example: Changing the panel height and laying out again

  ```rust
  use vanilla::{NodeTree, UIWindow, UIWindowDefaultBehavior, UIWindowLayer};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
  node_tree.with_component_mut::<UIWindowLayer, _>(layer_id, |window_layer, tree| {
  	window_layer.set_view_size(tree, 800.0, 600.0, 1.0);
  });
  let window_id = UIWindow::create(&mut node_tree, layer_id, "list", Box::new(UIWindowDefaultBehavior));
  UIWindowLayer::open_window_in_tree(&mut node_tree, layer_id, window_id);
  node_tree[window_id].get_component_mut::<UIWindow>().expect("window").set_panel_height(400.0);
  UIWindow::refresh_layout_in_tree(&mut node_tree, window_id);
  assert_eq!(node_tree[window_id].get_component::<UIWindow>().expect("window").get_panel_rect().size.y, 400.0);
  ```

- `pub fn get_behavior<T: UIWindowBehavior>(&self) -> Option<&T>` (method, since 0.4.0): Takes out the override points. (if the concrete type matches)
  - returns Option<&T>: `Some(&T)` if the override points are T, None if another type.
- `pub fn get_behavior_mut<T: UIWindowBehavior>(&mut self) -> Option<&mut T>` (method, since 0.4.0): Takes out the override points. (for modification)
  - returns Option<&mut T>: `Some(&mut T)` if the override points are T, None if another type.

  Example: Setting a confirm notification on a confirm window

  ```rust
  use vanilla::{NodeTree, UIConfirmWindow, UIConfirmWindowOptions, UIWindow, UIWindowDefaultBehavior, UIWindowLayer};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
  let window_id = UIConfirmWindow::create(&mut node_tree, layer_id, "quit", UIConfirmWindowOptions::default());
  let window = node_tree[window_id].get_component_mut::<UIWindow>().expect("window");
  if let Some(confirm_window) = window.get_behavior_mut::<UIConfirmWindow>() {
  	confirm_window.set_confirm_event(Some(Box::new(|| {})));
  }
  assert!(window.get_behavior_mut::<UIWindowDefaultBehavior>().is_none());
  ```

- `pub fn get_parts(&self) -> Option<UIWindowParts>` (method, since 0.4.0): The window's nodes and current layout values. (None if not created yet)
  - returns Option<UIWindowParts>: Nodes and layout values. (None if not attached to the tree yet)
- `pub fn get_panel_node(&self) -> Option<NodeId>` (method, since 0.4.0): Panel node. (content is attached here)
  - returns Option<NodeId>: Panel node. (None if not attached to the tree yet)
- `pub fn get_frame_node(&self) -> Option<NodeId>` (method, since 0.4.0): Frame node. (decorations that grow and shrink with the panel are attached here)
  - returns Option<NodeId>: Frame node. (None if not attached to the tree yet)
- `pub fn get_dim_node(&self) -> Option<NodeId>` (method, since 0.4.0): Dim node.
  - returns Option<NodeId>: Dim node. (None if not attached to the tree yet)
- `pub fn get_panel_paint<'a>(&self, node_tree: &'a NodeTree) -> Option<&'a Paint>` (method, since 0.4.0): The panel's Paint. (the default panel graphic, for changing or turning it off. None if not attached yet)
  - `node_tree` &'a NodeTree: Node tree holding the window.
  - returns Option<&'a Paint>: The panel node's Paint. (None if not attached yet or if there is no panel node or Paint)
- `pub fn get_panel_paint_mut<'a>(&self, node_tree: &'a mut NodeTree) -> Option<&'a mut Paint>` (method, since 0.4.0): The panel's Paint. (for modification)
  - `node_tree` &'a mut NodeTree: Node tree holding the window.
  - returns Option<&'a mut Paint>: The panel node's Paint. (None if not attached yet or if there is no panel node or Paint)

  Example: Changing the panel color after attaching

  ```rust
  use vanilla::{Color, NodeTree, Paint, UIWindow, UIWindowDefaultBehavior, UIWindowLayer};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let layer_id = UIWindowLayer::create(&mut node_tree, root_id);
  let window_id = UIWindow::create(&mut node_tree, layer_id, "shop", Box::new(UIWindowDefaultBehavior));
  let panel_id = node_tree.with_component_mut::<UIWindow, _>(window_id, |window, tree| {
  	if let Some(panel_paint) = window.get_panel_paint_mut(tree) {
  		panel_paint.set_color(Color::create(0.2, 0.1, 0.1, 1.0));
  	}
  	window.get_panel_node()
  }).flatten().expect("panel");
  assert_eq!(node_tree[panel_id].get_component::<Paint>().expect("paint").get_color(), Color::create(0.2, 0.1, 0.1, 1.0));
  ```

- `pub fn get_dim_paint<'a>(&self, node_tree: &'a NodeTree) -> Option<&'a Paint>` (method, since 0.4.0): The dim's Paint. (None if not attached yet)
  - `node_tree` &'a NodeTree: Node tree holding the window.
  - returns Option<&'a Paint>: The dim node's Paint. (None if not attached yet or if there is no dim node or Paint)
- `pub fn get_dim_paint_mut<'a>(&self, node_tree: &'a mut NodeTree) -> Option<&'a mut Paint>` (method, since 0.4.0): The dim's Paint. (for modification)
  - `node_tree` &'a mut NodeTree: Node tree holding the window.
  - returns Option<&'a mut Paint>: The dim node's Paint. (None if not attached yet or if there is no dim node or Paint)
- `pub fn get_view_width(&self) -> f64` (method, since 0.4.0): Width of the last received area. (UI layer units)
  - returns f64: Area width. (1 or more, 1 before receiving)
- `pub fn get_view_height(&self) -> f64` (method, since 0.4.0): Height of the last received area. (UI layer units)
  - returns f64: Area height. (1 or more, 1 before receiving)
- `pub fn get_margin(&self) -> f64` (method, since 0.4.0): Returns the distance between the area edge and the panel.
  - returns f64: Distance. (UI layer units, default 16)
- `pub fn get_panel_height(&self) -> f64` (method, since 0.4.0): Returns the panel height. (the set_panel_height value)
  - returns f64: Panel height. (UI layer units, default 240)
- `pub fn get_panel_rect(&self) -> Rect` (method, since 0.4.0): Rect of the last placed panel. (window coordinates, before motion, size multiplied by the shrink scale)
  - returns Rect: The panel's rectangle. ((0, 0, 1, 1) before layout)
- `pub fn get_panel_scale(&self) -> f64` (method, since 0.4.0): Scale by which the panel was shrunk because it was larger than the area. (1 or less)
  - returns f64: Scale. (greater than 0 and at most 1, 1 if not scaled down)
- `pub fn handle_wheel(&mut self, node_tree: &mut NodeTree, view_input_position: Vector2, wheel_delta: Vector2) -> bool` (method, since 0.4.0): Receives the wheel. (UIWindowBehavior::handle_wheel, true if taken, original handleWheel)
  - `node_tree` &mut NodeTree: Node tree holding the window.
  - `view_input_position` Vector2: Position where the wheel was rolled. (view coordinates)
  - `wheel_delta` Vector2: Amount the wheel was rolled.
  - returns bool: true if the override points took it. (false if not attached to the tree yet)
- `pub fn get_popup_motion(&self) -> &PopupMotion` (method, since 0.4.0): Returns the motion.
  - returns &PopupMotion: The window's open and close motion.
- `pub fn get_popup_motion_mut(&mut self) -> &mut PopupMotion` (method, since 0.4.0): Returns the motion. (for modification, opens and closes without motion via set_instant_enabled)
  - returns &mut PopupMotion: The window's open and close motion.
- `pub fn set_outside_close_enabled(&mut self, is_outside_close_enabled: bool)` (method, since 0.4.0): Sets whether an outside press (and the window layer's close_top_window) closes it. (default true)
  - `is_outside_close_enabled` bool: true if it closes on outside press and back.
- `pub fn is_outside_close_enabled(&self) -> bool` (method, since 0.4.0): Whether pressing outside closes it.
  - returns bool: true if it closes. (default true)
- `pub fn set_close_event(&mut self, close_event: Option<UIWindowEvent>)` (method, since 0.4.0): Sets the notification for when it is removed from the window layer.
  - `close_event` Option<UIWindowEvent>: Notification. (None turns it off, called before UIWindowBehavior::handle_closed)
- `pub fn set_maximum_width(&mut self, maximum_width: f64)` (method, since 0.4.0): Sets the window's width limit. (narrower than that if the area is narrow, from the next layout)
  - `maximum_width` f64: Panel width limit. (UI layer units, 1 if less than 1)
- `pub fn get_maximum_width(&self) -> f64` (method, since 0.4.0): Returns the window's width limit.
  - returns f64: Panel width limit. (UI layer units, default 480)
- `pub fn set_margin(&mut self, margin: f64)` (method, since 0.4.0): Sets the distance between the area edge and the panel.
  - `margin` f64: Distance. (UI layer units, 0 if less than 0, from the next layout)
- `pub fn set_panel_height(&mut self, panel_height: f64)` (method, since 0.4.0): Sets the panel height. (used by windows that do not override layout_content)
  - `panel_height` f64: Panel height. (UI layer units, 1 if less than 1, from the next layout)
- `pub fn set_dim_color(&mut self, dim_color: impl Into<Color>)` (method, since 0.4.0): Sets the dim color. (only stores the value, set it before attaching. To change it after attaching, change the Paint color of the dim node)
  - `dim_color` impl Into<Color>: Dim color. (default `Color::create(0.0, 0.0, 0.0, 0.55)`, applied to the dim Paint when attached to the tree)
- `pub fn set_panel_color(&mut self, panel_color: impl Into<Color>)` (method, since 0.4.0): Sets the panel color. (only stores the value, set it before attaching. To change it after attaching, change the Paint color of the panel node)
  - `panel_color` impl Into<Color>: Panel color. (default `Color::create(0.13, 0.15, 0.2, 1.0)`, applied to the panel Paint when attached to the tree)
- `pub fn get_window_layer_id(&self) -> Option<NodeId>` (method, since 0.4.0): The window layer node it is open on. (None before opening or after removal)
  - returns Option<NodeId>: Window layer node. (Some only while open)
- `pub fn set_window_layer_id(&mut self, window_layer_id: Option<NodeId>)` (method, since 0.4.0): Sets the window layer node it is open on. (called by the window layer)
  - `window_layer_id` Option<NodeId>: The window layer node it is open on. (None when removed)
- `pub fn get_view_bleed(&self) -> [f64; 4]` (method, since 0.4.0): Returns the extra coverage width beyond the area. (top, right, bottom, left)
  - returns [f64; 4]: `[top, right, bottom, left]` widths. (UI layer units, all 0 initially)
- `pub fn set_view_bleed(&mut self, node_tree: &mut NodeTree, top: f64, right: f64, bottom: f64, left: f64)` (method, since 0.4.0): Notifies the extra width covered outside the area. (safe area, UI layer units, the dim covers underneath it too)
  - `node_tree` &mut NodeTree: Node tree holding the window.
  - `top` f64: Extra coverage width upward. (0 if less than 0)
  - `right` f64: Extra coverage width to the right. (0 if less than 0)
  - `bottom` f64: Extra coverage width downward. (0 if less than 0)
  - `left` f64: Extra coverage width to the left. (0 if less than 0)
- `pub fn set_view_size(&mut self, node_tree: &mut NodeTree, view_width: f64, view_height: f64)` (method, since 0.4.0): Notifies the area size. (covers it with the dim, sets the panel width, lays out the content, then centers it)
  - `node_tree` &mut NodeTree: Node tree holding the window.
  - `view_width` f64: Area width. (UI layer units, 1 if less than 1)
  - `view_height` f64: Area height. (UI layer units, 1 if less than 1)
- `pub fn refresh_layout(&mut self, node_tree: &mut NodeTree)` (method, since 0.4.0): Lays out again. (with the last area size)
  - `node_tree` &mut NodeTree: Node tree holding the window. (does nothing if not attached to the tree yet)
- `pub fn layout_panel_default(node_tree: &mut NodeTree, parts: &UIWindowParts, panel_width: f64, panel_height: f64)` (static, since 0.4.0): Default panel layout. (the panel at the frame's top left at its size)
  - `node_tree` &mut NodeTree: Node tree holding the window.
  - `parts` &UIWindowParts: The window's nodes and current layout values.
  - `panel_width` f64: Panel width. (before scaling down, UI layer units)
  - `panel_height` f64: Panel height. (before scaling down, UI layer units)

  Example: Placing a frame shadow decoration after the default panel layout

  ```rust
  use std::any::Any;
  use vanilla::{NodeId, NodeTree, UIWindow, UIWindowBehavior, UIWindowParts, Vector2};
  
  struct ShadowWindow {
  	shadow_id: Option<NodeId>,
  }
  
  impl UIWindowBehavior for ShadowWindow {
  	fn as_any(&self) -> &dyn Any {
  		self
  	}
  
  	fn as_any_mut(&mut self) -> &mut dyn Any {
  		self
  	}
  
  	fn build(&mut self, node_tree: &mut NodeTree, parts: &UIWindowParts) {
  		let shadow_id = node_tree.create_child(parts.frame_id, "Shadow");
  		node_tree.set_sibling_index(shadow_id, 0);
  		self.shadow_id = Some(shadow_id);
  	}
  
  	fn layout_panel(&mut self, node_tree: &mut NodeTree, parts: &UIWindowParts, panel_width: f64, panel_height: f64) {
  		UIWindow::layout_panel_default(node_tree, parts, panel_width, panel_height);
  		if let Some(shadow_node) = self.shadow_id.and_then(|shadow_id| node_tree.get_node_mut(shadow_id)) {
  			shadow_node.set_content_size(Vector2::create(panel_width + 8.0, panel_height + 8.0));
  		}
  	}
  }
  ```

- `pub fn apply_motion_default(node_tree: &mut NodeTree, parts: &UIWindowParts, popup_motion: &PopupMotion)` (static, since 0.4.0): Default motion application. (frame scale = reduced scale x motion scale, dim strength = motion ratio)
  - `node_tree` &mut NodeTree: Node tree holding the window.
  - `parts` &UIWindowParts: The window's nodes and current layout values. (uses panel_scale)
  - `popup_motion` &PopupMotion: The window's motion. (uses get_scale, get_dim_ratio)
- `pub fn set_covered_default(node_tree: &mut NodeTree, parts: &UIWindowParts, is_covered: bool)` (static, since 0.4.0): Default covering. (turns the window node off when covered and on when revealed)
  - `node_tree` &mut NodeTree: Node tree holding the window.
  - `parts` &UIWindowParts: The window's nodes and current layout values.
  - `is_covered` bool: true if another window is open above.
- `pub fn set_covered(&mut self, node_tree: &mut NodeTree, is_covered: bool)` (method, since 0.4.0): Notifies whether it is covered. (called by the window layer)
  - `node_tree` &mut NodeTree: Node tree holding the window.
  - `is_covered` bool: true if another window is open above. (passed to UIWindowBehavior::set_covered)
- `pub fn start_open_motion(&mut self, node_tree: &mut NodeTree)` (method, since 0.4.0): Starts the open motion. (called by the window layer when opening, turns the window node on)
  - `node_tree` &mut NodeTree: Node tree holding the window.
- `pub fn start_close_motion(&mut self, node_tree: &mut NodeTree)` (method, since 0.4.0): Starts the close motion. (called by the window layer when removing, it does not receive presses in the meantime)
  - `node_tree` &mut NodeTree: Node tree holding the window.
- `pub fn is_close_motion_finished(&self) -> bool` (method, since 0.4.0): Whether the close motion has finished.
  - returns bool: true if the motion is in the closed state. (true even if never opened, true right after closing for instant transitions)
- `pub fn handle_closed(&mut self)` (method, since 0.4.0): Removed from the window layer. (called by the window layer: notification → UIWindowBehavior::handle_closed)
- `pub fn dispose(&mut self, node_tree: &mut NodeTree)` (method, since 0.4.0): When the window layer detaches the window. (called by the window layer, the node is not deleted and remains so it can be shown again)
  - `node_tree` &mut NodeTree: Node tree holding the window. (passed to UIWindowBehavior::dispose)
