# core/component/paint (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/core/component/paint/

Color fill component. (paints the node's content_size area as a solid / rounded rectangle)

## Paint (struct) (Default, Component)

Color fill component. (paints the node's content_size area in one color)
- Paints a rounded rectangle if the round size is greater than 0, otherwise a sharp rectangle. (initially white, round size 0)
- It only draws, so it does not receive tick. Sprite paints with this when it has no image.

Example: A round blue panel

```rust
use vanilla::{Color, NodeTree, Paint, Vector2};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let panel_id = node_tree.create_child(root_id, "Panel");
node_tree[panel_id].set_content_size(Vector2::create(240.0, 120.0));
let paint = node_tree.add_component(panel_id, Paint::new()).unwrap();
paint.set_color("#3366cc");
paint.set_round_size(16.0);

let paint = node_tree[panel_id].get_component::<Paint>().unwrap();
assert_eq!(paint.get_color(), Color::create_from_hex("#3366cc"));
assert_eq!(paint.get_round_size(), 16.0);
```

- `pub fn new() -> Paint` (constructor, since 0.3.2): Constructor.
  - returns Paint: New component, white, round size 0.
- `pub fn create_with_color(color: impl Into<Color>) -> Paint` (static, since 0.3.2): Constructor with a color.
  - `color` impl Into<Color>: Color to paint. (a Color or a string such as "#rrggbb")
  - returns Paint: New component that paints in that color. (round size 0)

  Example: Create from a color string and attach to a node

  ```rust
  use vanilla::{Color, NodeTree, Paint};
  
  let mut node_tree = NodeTree::new();
  let root_id = node_tree.get_root_id();
  let node_id = node_tree.create_child(root_id, "Background");
  let paint = node_tree.add_component(node_id, Paint::create_with_color("#ff0000")).unwrap();
  assert_eq!(paint.get_color(), Color::create(1.0, 0.0, 0.0, 1.0));
  
  let half_black = Paint::create_with_color(Color::black().with_alpha(0.5));
  assert_eq!(half_black.get_color().alpha, 0.5);
  ```

- `pub fn draw_paint(&self, transform: &NodeTransform, graphic: &mut Graphic)` (method, since 0.3.2): Draw. (Sprite also uses this when it has no image)
  - Fills the (0, 0, content_size width, height) rectangle in node content coordinates with the current color. The Graphic's fill color changes to this color.
  - `transform` &NodeTransform: Node transform to paint. (reads content_size)
  - `graphic` &mut Graphic: Graphic to draw to. (with the node transform applied)
- `pub fn set_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): Sets the color. (a Color or a string such as "#rrggbb")
  - `color` impl Into<Color>: Color to paint. (alpha is the opacity)
- `pub fn get_color(&self) -> Color` (method, since 0.3.2): Returns the color.
  - returns Color: The paint color.
- `pub fn set_round_size(&mut self, round_size: f64)` (method, since 0.3.2): Sets the round size.
  - `round_size` f64: Corner round size. (node coordinates, a sharp rectangle if 0 or less)
- `pub fn get_round_size(&self) -> f64` (method, since 0.3.2): Returns the round size.
  - returns f64: Corner round size. (node coordinates)
