# ui/uicontrol (vanilla-engine 0.4.0)

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

UI control. (UIControl of the original ui/uicontrol.js)
- Base of widgets that take user input (touch). Sits on top of UIView like UIKit's UIControl.
- The original inherits UIView and only changes the name. The Rust version embeds UIView and passes through content and the background color.
  UIButton and UISlider embed this.

## UIControl (struct) (Default, Component)

UI control.
- Embeds UIView and passes through the content node and the background color. Widgets that take touches (UIButton, UISlider) embed this.

Example: Attach to a node and use the content node and the background color

```rust
use vanilla::{Color, NodeTree, UIControl};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let control_id = node_tree.create_child(root_id, "control");
let control = node_tree.add_component(control_id, UIControl::new()).unwrap();
control.set_background_color("#334455");
assert!(control.get_content().is_some());
assert_eq!(control.get_background_color(), Color::from("#334455"));
assert_eq!(control.get_uiview().get_background_color(), control.get_background_color());
```

- `pub fn new() -> UIControl` (constructor, since 0.3.2): Constructor.
  - returns UIControl: New control. (the content node is created when attached to a tree)
- `pub fn get_uiview(&self) -> &UIView` (method, since 0.3.2): Returns the embedded view.
  - returns &UIView: Reference to the embedded UIView.
- `pub fn get_uiview_mut(&mut self) -> &mut UIView` (method, since 0.3.2): Returns the embedded view. (mutable)
  - returns &mut UIView: Mutable reference to the embedded UIView.
- `pub fn get_content(&self) -> Option<NodeId>` (method, since 0.3.2): Content node handle.
  - returns Option<NodeId>: content node. None before being attached to a tree.
- `pub fn set_background_color(&mut self, background_color: impl Into<Color>)` (method, since 0.3.2): Sets the background color.
  - `background_color` impl Into<Color>: Background color. (not painted if alpha is 0)
- `pub fn get_background_color(&self) -> Color` (method, since 0.3.2): Returns the background color.
  - returns Color: Background color. (default is white with alpha 0)
