vanilladocs
vanillapunch.com
API / misc/indicator

misc/indicator

인디케이터. (돌아가는 톱니바퀴 모양 로딩 표시)

  • 원본 misc/indicator.js 를 옮긴 것이다. 노드가 아닌 그냥 객체라서, 들고 있는 쪽이 tick 과 draw 를 불러 준다. 중심에서 바깥으로 뻗는 톱니 8 개와 두꺼운 안쪽 링을 회전시켜 그린다.
  • 원본과 같이 선 끝은 각지다. set_color 는 Color 와 글("#ffffff" 등, Color 의 From<&str>)을 받는다. build_teeth_segments, get_radius, get_rotation 은 원본에도 있다.

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.

Indicatorstruct traits Clone, Debug, Default

짝Counterpart: vanilla.js Indicator소스source

인디케이터.

Indicator.

예제Example보일 때만 돈다Spins only while visible
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
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);
}
생성자constructorpub fn new() -> Indicator#0.3.2 부터since 0.3.2소스source

생성. (반지름 20, 흰색, 초당 0.75 바퀴, 보임)

Constructor. (radius 20, white, 0.75 turns per second, visible)

반환ReturnsIndicator 위치 (0, 0), 회전 0 인 인디케이터.An indicator at position (0, 0) with rotation 0.

짝Counterpart: vanilla.js Indicator.constructor

메서드methodpub fn tick(&mut self, time_delta: f64)#0.3.2 부터since 0.3.2소스source

갱신. (보일 때만 회전 각도를 쌓는다)

Update. (accumulates the rotation angle only while visible)

time_deltaf64
지난 프레임부터 흐른 시간. (초)Time elapsed since the last frame. (seconds)

짝Counterpart: vanilla.js Indicator.tick

메서드methodpub fn build_teeth_segments(&self) -> Vec<(Vector2, Vector2)>#0.3.2 부터since 0.3.2소스source

톱니 선분 목록. (회전 전 가운데 기준. 안쪽 링보다 살짝 안쪽에서 바깥 끝까지)

List of teeth segments. (relative to the center before rotation, from slightly inside the inner ring to the outer end)

반환ReturnsVec<(Vector2, Vector2)> 톱니 8 개의 (안쪽 끝, 바깥 끝). 안쪽 끝은 반지름의 0.4 배, 바깥 끝은 반지름 거리이고, 0 라디안(오른쪽)부터 시계 방향(y 아래)으로 45 도씩이다.(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).

짝Counterpart: vanilla.js Indicator.buildTeethSegments

메서드methodpub fn draw(&self, graphic: &mut Graphic)#0.3.2 부터since 0.3.2소스source

출력. (위치로 옮기고 돌린 뒤 톱니와 안쪽 링을 선으로 그린다)

  • 숨겨 있으면 그리지 않는다. 톱니 굵기는 반지름의 0.2 배, 안쪽 링은 반지름 0.5 배 자리에 0.3 배 굵기다. 그리기 상태는 들어올 때로 되돌린다.

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.

짝Counterpart: vanilla.js Indicator.draw

메서드methodpub fn set_position(&mut self, x: f64, y: f64)#0.3.2 부터since 0.3.2소스source

위치 설정. (가운데 좌표)

Sets the position. (center coordinate)

xf64
가운데 x. (그릴 때의 좌표계)Center x. (in the coordinate system used when drawing)
yf64
가운데 y. (그릴 때의 좌표계)Center y. (in the coordinate system used when drawing)

짝Counterpart: vanilla.js Indicator.setPosition

메서드methodpub fn get_position(&self) -> Vector2#0.3.2 부터since 0.3.2소스source

위치 반환.

Returns the position.

반환ReturnsVector2 가운데 좌표.Center coordinate.

짝Counterpart: vanilla.js Indicator.getPosition

메서드methodpub fn set_radius(&mut self, radius: f64)#0.3.2 부터since 0.3.2소스source

크기 설정. (반지름, 1 이상)

Sets the size. (radius, at least 1)

radiusf64
톱니 바깥 끝까지의 반지름. (1 보다 작으면 1)Radius to the outer end of the teeth. (1 if less than 1)

짝Counterpart: vanilla.js Indicator.setRadius

메서드methodpub fn get_radius(&self) -> f64#0.3.2 부터since 0.3.2소스source

크기 반환.

Returns the volume.

반환Returnsf64 반지름. (처음 20)Radius. (initially 20)

짝Counterpart: vanilla.js Indicator.getRadius

메서드methodpub fn set_color(&mut self, color: impl Into<Color>)#0.3.2 부터since 0.3.2소스source

색 설정.

Sets the color.

colorimpl Into<Color>
톱니와 링의 색. (Color 나 "#ffffff" 꼴 글)Color of the teeth and the ring. (a Color or a "#ffffff" style string)

짝Counterpart: vanilla.js Indicator.setColor

메서드methodpub fn set_speed(&mut self, speed_radians_per_second: f64)#0.3.2 부터since 0.3.2소스source

회전 속도 설정. (라디안 / 초)

Sets the rotation speed. (radians / second)

speed_radians_per_secondf64
회전 속도. (라디안 / 초, 처음 1.5π, 음수면 거꾸로 돈다)Rotation speed. (radians / second, initially 1.5π, negative spins backward)

짝Counterpart: vanilla.js Indicator.setSpeed

메서드methodpub fn get_rotation(&self) -> f64#0.3.2 부터since 0.3.2소스source

회전 각도 반환. (라디안)

Returns the rotation angle. (radians)

반환Returnsf64 지금까지 쌓인 회전 각도. (라디안, 한 바퀴마다 되감지 않는다)Rotation angle accumulated so far. (radians, not wrapped every turn)

짝Counterpart: vanilla.js Indicator.getRotation

메서드methodpub fn set_visible(&mut self, is_visible: bool)#0.3.2 부터since 0.3.2소스source

출력 여부 설정.

Sets whether it is displayed.

is_visiblebool
참이면 그리고 돈다. 거짓이면 그리지 않고 회전도 멈춘다.If true, draws and spins. If false, draws nothing and the rotation stops too.

짝Counterpart: vanilla.js Indicator.setVisible

메서드methodpub fn get_visible(&self) -> bool#0.3.2 부터since 0.3.2소스source

출력 여부 반환.

Returns whether it is displayed.

반환Returnsbool 보이면 true.True if visible.

짝Counterpart: vanilla.js Indicator.getVisible