# ui/uiprogressview (vanilla-engine 0.4.0)

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

Progress display. (UIProgressView, ProgressDirection of the original ui/uiprogressview.js)
- Uses the host's content_size area as the track and draws the fill by the value ratio. Takes no input.
- The track color is UIView's background color as in the original. (set_track_color is another name for set_background_color)
- When the opposite value (secondary_value) is set, draws a second fill that fills from the end opposite the progress direction. (the original null is None)

## UIProgressView (struct) (Default, Component)

Progress display.

Example: Health bar

```rust
use vanilla::{NodeTree, ProgressDirection, UIProgressView, Vector2};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let bar_id = node_tree.create_child(root_id, "HealthBar");
node_tree[bar_id].set_content_size(Vector2::create(200.0, 12.0));
let progress_view = node_tree.add_component(bar_id, UIProgressView::new()).expect("progress");
progress_view.set_range(0.0, 120.0);
progress_view.set_value(90.0);
progress_view.set_corner_radius(6.0);
assert_eq!(progress_view.get_ratio(), 0.75);
assert_eq!(progress_view.get_direction(), ProgressDirection::Horizontal);
```

- `pub fn new() -> UIProgressView` (constructor, since 0.3.2): Constructor. (value 0, range 0 ~ 1, gray track, blue fill)
  - returns UIProgressView: Progress display before being attached. (horizontal direction, no opposite value)
- `pub fn get_uiview(&self) -> &UIView` (method, since 0.3.2): Returns the embedded view.
  - returns &UIView: 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: 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. (track color)
  - `background_color` impl Into<Color>: Track color. (default `Color::create(0.7, 0.7, 0.7, 1.0)`)
- `pub fn get_background_color(&self) -> Color` (method, since 0.3.2): Returns the background color. (track color)
  - returns Color: Track color.
- `pub fn get_ratio(&self) -> f64` (method, since 0.3.2): Returns the 0 ~ 1 ratio.
  - returns f64: Position of the value within the range. (0 ~ 1, 0 if the maximum is not greater than the minimum)
- `pub fn set_value(&mut self, value: f64)` (method, since 0.3.2): Sets the value. (clamped to the range)
  - `value` f64: Value. (clamped to minimum ~ maximum)
- `pub fn get_value(&self) -> f64` (method, since 0.3.2): Returns the value.
  - returns f64: Value. (default 0)
- `pub fn set_range(&mut self, min_value: f64, max_value: f64)` (method, since 0.3.2): Sets the range. (reclamps the current value to the new range)
  - The opposite value is not reclamped. (same as the original, the ratio is clamped to 0 ~ 1 when drawing)
  - `min_value` f64: Minimum value. (where the ratio is 0)
  - `max_value` f64: Maximum value. (where the ratio is 1)

  Example: Changing the range clamps the value to the new range

  ```rust
  use vanilla::UIProgressView;
  
  let mut progress_view = UIProgressView::new();
  progress_view.set_value(0.8);
  progress_view.set_range(0.0, 0.5);
  assert_eq!(progress_view.get_value(), 0.5);
  progress_view.set_range(10.0, 20.0);
  assert_eq!(progress_view.get_value(), 10.0);
  assert_eq!(progress_view.get_ratio(), 0.0);
  ```

- `pub fn get_min_value(&self) -> f64` (method, since 0.3.2): Returns the minimum value.
  - returns f64: Minimum value. (default 0)
- `pub fn get_max_value(&self) -> f64` (method, since 0.3.2): Returns the maximum value.
  - returns f64: Maximum value. (default 1)
- `pub fn set_secondary_value(&mut self, secondary_value: Option<f64>)` (method, since 0.3.2): Sets the opposite value. (None turns it off. clamped to the range)
  - `secondary_value` Option<f64>: Value of the second fill that fills from the end opposite the progress direction. (not drawn if None)

  Example: The opposing side of a versus gauge

  ```rust
  use vanilla::UIProgressView;
  
  let mut progress_view = UIProgressView::new();
  progress_view.set_range(0.0, 100.0);
  progress_view.set_value(40.0);
  progress_view.set_secondary_value(Some(35.0));
  assert_eq!(progress_view.get_secondary_value(), Some(35.0));
  progress_view.set_secondary_value(Some(150.0));
  assert_eq!(progress_view.get_secondary_value(), Some(100.0));
  progress_view.set_secondary_value(None);
  assert_eq!(progress_view.get_secondary_value(), None);
  ```

- `pub fn get_secondary_value(&self) -> Option<f64>` (method, since 0.3.2): Returns the opposite value.
  - returns Option<f64>: Opposite value. (None when off, default None)
- `pub fn set_secondary_fill_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): Sets the opposite fill color.
  - `color` impl Into<Color>: Opposite fill color. (default `Color::create(0.94, 0.33, 0.31, 1.0)`)
- `pub fn get_secondary_fill_color(&self) -> Color` (method, since 0.3.2): Returns the opposite fill color.
  - returns Color: Opposite fill color.
- `pub fn set_track_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): Sets the track color. (background color)
  - `color` impl Into<Color>: Track color. (same as set_background_color)
- `pub fn get_track_color(&self) -> Color` (method, since 0.3.2): Returns the track color. (background color)
  - returns Color: Track color.
- `pub fn set_fill_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): Sets the fill color.
  - `color` impl Into<Color>: Fill color. (default `Color::create(0.23, 0.51, 0.96, 1.0)`)
- `pub fn get_fill_color(&self) -> Color` (method, since 0.3.2): Returns the fill color.
  - returns Color: Fill color.
- `pub fn set_corner_radius(&mut self, corner_radius: f64)` (method, since 0.3.2): Sets the rounded corner radius.
  - `corner_radius` f64: Corner radius of the track and fill. (square corners if 0 or less, default 0)
- `pub fn get_corner_radius(&self) -> f64` (method, since 0.3.2): Returns the rounded corner radius.
  - returns f64: Corner radius. (default 0)
- `pub fn set_direction(&mut self, direction: ProgressDirection)` (method, since 0.3.2): Sets the direction.
  - `direction` ProgressDirection: Progress direction. (Horizontal fills from the left, Vertical from the bottom. the opposite value from the opposite end)
- `pub fn get_direction(&self) -> ProgressDirection` (method, since 0.3.2): Returns the direction.
  - returns ProgressDirection: Progress direction. (default Horizontal)

## ProgressDirection (enum) (Clone, Copy, Debug, PartialEq, Eq)

Progress direction.

- `Horizontal`: Fills from left to right.
- `Vertical`: Fills from bottom to top.
