vanilladocs
vanillapunch.com
API / misc/loadingprogress

misc/loadingprogress

로딩 진행률. (원본 misc/loadingprogress.js)

  • 로딩의 단계가 알려 준 정도(set_progress, 0 ~ 1, 줄어들지 않음)를 보이는 정도(get_shown_progress)가 부드럽게 따라간다. 받기가 몰려 진행률이 한 번에 뛰어도 막대가 튀지 않고 미끄러진다.
  • 매 프레임 update(time_delta) 를 부른다. 따라가는 몫은 1 - exp(-빠르기 * 시간) 이라 프레임 간격이 달라도 같은 빠르기다.

Loading progress. (original misc/loadingprogress.js)

  • The shown progress (get_shown_progress) smoothly follows the progress reported by the loading stages (set_progress, 0 ~ 1, never decreasing). Even when downloads bunch up and the progress jumps at once, the bar slides instead of jumping.
  • Call update(time_delta) every frame. The follow fraction is 1 - exp(-rate * time), so the speed is the same regardless of frame interval.

LoadingProgressstruct traits Clone, Debug, Default

짝Counterpart: vanilla.js LoadingProgress소스source

로딩 진행률.

  • 받기 단계가 set_progress 로 알리고, 매 프레임 update 한 뒤 get_shown_progress 로 막대를 그린다.

Loading progress.

  • Download stages report with set_progress, and after update every frame, draw the bar with get_shown_progress.
예제Example알린 정도를 부드럽게 따라가기Smoothly follow the reported progress
use vanilla::LoadingProgress;

let mut loading_progress = LoadingProgress::new();
loading_progress.set_progress(0.5);
loading_progress.update(1.0 / 60.0);
let shown_progress = loading_progress.get_shown_progress();
assert!(shown_progress > 0.0 && shown_progress < 0.5);
loading_progress.set_progress(1.0);
for _ in 0..600 {
	loading_progress.update(1.0 / 60.0);
}
assert!(loading_progress.is_finished());
생성자constructorpub fn new() -> LoadingProgress#0.4.0 부터since 0.4.0소스source

생성. (따라가는 빠르기는 초당 남은 거리의 6 배)

Constructor. (follow rate is 6 times the remaining distance per second)

반환ReturnsLoadingProgress 알린 정도와 보이는 정도가 0 인 새 진행률.A new progress with reported and shown progress of 0.

짝Counterpart: vanilla.js LoadingProgress.constructor

메서드methodpub fn set_progress(&mut self, progress: f64)#0.4.0 부터since 0.4.0소스source

알려 준 정도 설정. (0 ~ 1 로 자르고, 앞서 알린 것보다 작거나 NaN 이면 무시한다)

Sets the reported progress. (clamped to 0 ~ 1, ignored if less than previously reported or NaN)

progressf64
알린 정도. (0 ~ 1)Reported progress. (0 ~ 1)

짝Counterpart: vanilla.js LoadingProgress.setProgress

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

알려 준 정도 반환.

Returns the reported progress.

반환Returnsf64 지금까지 알린 가장 큰 정도. (0 ~ 1)The largest progress reported so far. (0 ~ 1)

짝Counterpart: vanilla.js LoadingProgress.getProgress

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

보이는 정도 반환. (그릴 때 읽는다)

Returns the shown progress. (Read when drawing)

반환Returnsf64 알린 정도를 따라가는 중인 정도. (0 ~ 1)Progress currently following the reported progress. (0 ~ 1)

짝Counterpart: vanilla.js LoadingProgress.getShownProgress

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

갱신. (보이는 정도가 알려 준 정도를 따라간다. 시간이 0 이하이거나 유한하지 않으면 그대로)

Update. (the shown progress follows the reported progress. Unchanged if the time is 0 or less or not finite)

time_deltaf64
지난 시간. (초, 남은 거리의 1 - exp(-빠르기 * time_delta) 만큼 다가간다)Elapsed time. (seconds, closes 1 - exp(-rate * time_delta) of the remaining distance)

짝Counterpart: vanilla.js LoadingProgress.update

메서드methodpub fn set_follow_rate(&mut self, follow_rate: f64)#0.4.0 부터since 0.4.0소스source

따라가는 빠르기 설정. (초당 남은 거리의 비율, 0 보다 크고 유한해야 한다. 아니면 그대로 둔다)

Sets the follow rate. (ratio of the remaining distance per second, must be greater than 0 and finite. Otherwise unchanged)

follow_ratef64
새 빠르기. (기본 6)New rate. (default 6)

짝Counterpart: vanilla.js LoadingProgress.setFollowRate

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

따라가는 빠르기 반환.

Returns the follow speed.

반환Returnsf64 지금 빠르기. (초당 남은 거리의 비율)Current rate. (ratio of the remaining distance per second)

짝Counterpart: vanilla.js LoadingProgress.getFollowRate

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

보이는 정도가 끝(1)에 닿았는지.

Whether the shown progress has reached the end (1).

반환Returnsbool 보이는 정도가 1 이상이면 true.true if the shown progress is at least 1.

짝Counterpart: vanilla.js LoadingProgress.isFinished

메서드methodpub fn reset(&mut self)#0.4.0 부터since 0.4.0소스source

처음으로. (알려 준 정도와 보이는 정도를 0 으로)

Resets. (Sets the reported progress and the shown progress to 0)

짝Counterpart: vanilla.js LoadingProgress.reset