# misc/indicator (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/misc/indicator/

Indicator. (a spinning gear-shaped loading indicator)
- A port of the original misc/indicator.js. It is a plain object, not a node, so the owner calls tick and draw.
  Draws 8 teeth extending outward from the center and a thick inner ring, rotating.
- As in the original, line ends are square. set_color takes a Color or a string ("#ffffff", etc., Color's `From<&str>`).
  build_teeth_segments, get_radius, get_rotation also exist in the original.

## Indicator (struct) (Clone, Debug, Default)

Indicator.

Example: Spins only while visible

```rust
use vanilla::Indicator;

let mut indicator = Indicator::new();
indicator.set_speed(2.0);
indicator.tick(0.5);
assert_eq!(indicator.get_rotation(), 1.0);

indicator.set_visible(false);
indicator.tick(0.5);
assert_eq!(indicator.get_rotation(), 1.0);
```

Example: Draw a loading indicator at the screen center

```rust
use vanilla::{Graphic, Indicator};

fn create_loading_indicator() -> Indicator {
	let mut indicator = Indicator::new();
	indicator.set_position(640.0, 360.0);
	indicator.set_radius(32.0);
	indicator.set_color("#ffcc00");
	indicator
}

fn draw_loading(indicator: &mut Indicator, graphic: &mut Graphic, time_delta: f64) {
	indicator.tick(time_delta);
	indicator.draw(graphic);
}
```

- `pub fn new() -> Indicator` (constructor, since 0.3.2): Constructor. (radius 20, white, 0.75 turns per second, visible)
  - returns Indicator: An indicator at position (0, 0) with rotation 0.
- `pub fn tick(&mut self, time_delta: f64)` (method, since 0.3.2): Update. (accumulates the rotation angle only while visible)
  - `time_delta` f64: Time elapsed since the last frame. (seconds)
- `pub fn build_teeth_segments(&self) -> Vec<(Vector2, Vector2)>` (method, since 0.3.2): List of teeth segments. (relative to the center before rotation, from slightly inside the inner ring to the outer end)
  - returns Vec<(Vector2, Vector2)>: (inner end, outer end) of the 8 teeth. The inner end is 0.4 times the radius and the outer end is at the radius distance, every 45 degrees clockwise (y down) starting from 0 radians (right).
- `pub fn draw(&self, graphic: &mut Graphic)` (method, since 0.3.2): Draw. (translates to the position, rotates, and draws the teeth and the inner ring with lines)
  - Draws nothing when hidden. Teeth thickness is 0.2 times the radius, and the inner ring is at 0.5 times the radius with 0.3 times thickness. The drawing state is restored to what it was on entry.
  - `graphic` &mut Graphic: Graphic to draw with.
- `pub fn set_position(&mut self, x: f64, y: f64)` (method, since 0.3.2): Sets the position. (center coordinate)
  - `x` f64: Center x. (in the coordinate system used when drawing)
  - `y` f64: Center y. (in the coordinate system used when drawing)
- `pub fn get_position(&self) -> Vector2` (method, since 0.3.2): Returns the position.
  - returns Vector2: Center coordinate.
- `pub fn set_radius(&mut self, radius: f64)` (method, since 0.3.2): Sets the size. (radius, at least 1)
  - `radius` f64: Radius to the outer end of the teeth. (1 if less than 1)
- `pub fn get_radius(&self) -> f64` (method, since 0.3.2): Returns the volume.
  - returns f64: Radius. (initially 20)
- `pub fn set_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): Sets the color.
  - `color` impl Into<Color>: Color of the teeth and the ring. (a Color or a "#ffffff" style string)
- `pub fn set_speed(&mut self, speed_radians_per_second: f64)` (method, since 0.3.2): Sets the rotation speed. (radians / second)
  - `speed_radians_per_second` f64: Rotation speed. (radians / second, initially 1.5π, negative spins backward)
- `pub fn get_rotation(&self) -> f64` (method, since 0.3.2): Returns the rotation angle. (radians)
  - returns f64: Rotation angle accumulated so far. (radians, not wrapped every turn)
- `pub fn set_visible(&mut self, is_visible: bool)` (method, since 0.3.2): Sets whether it is displayed.
  - `is_visible` bool: If true, draws and spins. If false, draws nothing and the rotation stops too.
- `pub fn get_visible(&self) -> bool` (method, since 0.3.2): Returns whether it is displayed.
  - returns bool: True if visible.
