vanilladocs
vanillapunch.com
API / platform/desktop

platform/desktop

데스크탑 플랫폼. (윈도우, 맥, 리눅스)

  • 창(winit)과 GL 3.3 코어 컨텍스트(glutin)를 만들고, 창의 다시 그리기 요청마다 엔진 프레임을 하나 돈다.
  • 창 이벤트를 입력 관리자 꼴로 바꿔 넣는다. (키는 W3C KeyboardEvent.code 와 같은 이름, 마우스 단추는 원본처럼 어느 것이든 터치, 왼쪽만으로 바꿀 수 있다)
  • 엔진 본체(EngineRunner)는 창을 모른다. 여기서 프레임을 부르고, 그린 뒤 화면을 넘긴다.
  • 글 입력(키 글자, 편집 키, IME 조합)과 클립보드는 desktop/textinput.rs 가 맡는다. 오른쪽 단추는 입력 필드 문맥 메뉴 요청이다.
  • 맥의 게임패드 진동은 desktop/gamepadhaptics.rs 가 맡는다. (GameController 와 CoreHaptics, 다른 OS 는 gilrs 가 떤다)
  • 마지막으로 쓴 장치를 키, 마우스, 손가락 이벤트마다 적는다. 막을 키(set_prevented_keys)와 오른쪽 클릭 메뉴 막기는 창에 막을 브라우저 기본 동작이 없어 쓰지 않는다. (크롬에서 막은 것과 같은 결과다. winit 은 윈도우에서 메뉴가 없는 창의 WM_SYSKEYUP 을 DefWindowProc 에 넘기지 않아 Alt, F10 도 시스템 메뉴로 들어가지 않는다)
  • 페이지 이벤트: 창이 가려짐(Occluded, 맥과 X11 이 알린다), 최소화(크기 0 이나 is_minimized, 윈도우가 이것으로 알린다), 앱 멈춤(suspended, 모바일), 웨이랜드 프레임 콜백이 3 초 넘게 오지 않음(크롬 리눅스 웨이랜드의 가려짐, desktop/waylandframecallback.rs) 가운데 하나라도 맞으면 Hidden, 모두 풀리면 Visible 과 on_page_visibility_restored. 포커스는 Focused / Blurred, 마우스 단추와 손가락 누름은 PointerDown. 웨이랜드의 xdg_toplevel suspended 상태는 winit 이 쥐고 알리지 않아 받지 못한다.
  • 웨이랜드 수직 동기: EGL 스왑 간격을 0 으로 두고 넘기기 전에 지난 프레임 콜백을 1/20 초까지 기다린다. (메사는 간격 1 이면 가려진 창에서 스왑 안에 멈춘다)
  • 캔버스 크기(auto_resize_on_window_resize): 창은 캔버스가 창을 가득 채운 페이지와 같다. 켜면 원본처럼 visualViewport(창에서 화면 키보드가 가린 아래를 뺀 것)에 맞추고 ignore_virtual_keyboard_resize 와 캔버스 비 상한을 건다. 끄면 창 크기 그대로다.
  • 화면 키보드: 윈도우는 크롬처럼 손가락으로 플랫폼 입력 필드에 포커스하면 터치 키보드(InputPane)를 띄우고 가린 영역을 visualViewport 에서 뺀다. (desktop/windowsinputpane.rs) 맥과 리눅스는 크롬처럼 뷰포트를 줄이지 않는다.
  • 드로잉 버퍼 남기기(preserve_drawing_buffer): 다 그린 프레임을 떠 두고 다음 프레임 첫머리에 되그린다. (desktop/preserveddrawingbuffer.rs)
  • 페이지 프로세스 복원(on_page_process_restored, 원본 Chromium freeze 뒤 resume 과 bfcache): suspended 뒤 resumed, 그리고 시스템 잠자기에서 깬 것. 윈도우는 창을 서브클래싱해 WM_POWERBROADCAST 의 PBT_APMRESUMEAUTOMATIC 을 받는다. (desktop/windowsplatform.rs, 윈도우의 단조 시계는 잠든 동안에도 흘러 시계로는 못 가린다) 맥과 리눅스는 두 프레임 사이에 벽시계(SystemTime)가 단조 시계(Instant)보다 SYSTEM_SLEEP_GAP_SECONDS 넘게 더 흘렀으면 깬 것으로 본다. (러스트 Instant 는 맥에서 CLOCK_UPTIME_RAW, 리눅스에서 CLOCK_MONOTONIC 이라 잠든 동안 멈춘다. 러스트는 이것을 보장하지 않는다고 적어 두었다)
  • 주된 손이 손가락인지(is_coarse_pointer): 윈도우는 크로미엄의 (pointer: coarse) 판정을 옮겨 태블릿 모드나 마우스 없는 터치 기기면 참이다. 맥은 크로미엄도 늘 마우스로 보아 거짓이다. 리눅스와 그 밖의 유닉스는 크로미엄처럼 화면 서버(웨이랜드 wl_seat 능력, X11 XInput 장치 목록)에서 터치스크린과 마우스, 터치패드를 읽어 터치스크린만 있으면 참이다. (desktop/linuxplatform.rs, 읽은 값은 2 초 동안 쓴다)
  • 키 이름: winit 의 SuperLeft, SuperRight 는 W3C 의 MetaLeft, MetaRight, winit 의 Meta 는 W3C 의 Super 로 바꿔 넣는다.
  • 그림 커서(PointerCursor.register_image_cursor): 그림 파일을 읽어 winit 의 CustomCursor 로 만든다. 맥은 그림 크기가 그대로 포인트 크기라 1 배 그림을, 윈도우와 리눅스는 물리 픽셀이라 창 배율에 맞춰(2 배 그림이 있으면 그것을) 늘인 그림과 핫스팟을 쓴다. 만드는 동안과 못 만들면 함께 준 CSS 커서다.
  • 렌더 배율 상한(ViewManager.set_max_render_pixel_ratio): 그 배율로 줄인 크기로 그리고 프레임 끝에 창 크기로 늘인다. (desktop/renderscaler.rs) 입력 좌표는 창의 배율로 논리 좌표로 바꾸므로 렌더 크기와 상관없다.
  • 캔버스 비 상한(EngineConfiguration.max_canvas_aspect_ratio): 창이 그보다 길쭉하면 캔버스(그리는 영역)를 원본처럼 줄여 창 가운데에 두고 나머지는 검다. 입력 좌표에서 캔버스의 왼쪽 위를 빼고, read_canvas_client_position 이 그 자리를 돌려준다.
  • 페이지 주소의 쿼리 값(read_page_query_value)은 환경 변수 VANILLA_ 뒤에 이름을 대문자 뱀꼴로 붙인 것으로 읽는다. (safeArea → VANILLA_SAFE_AREA)
  • 찍기 모드(VANILLA_CAPTURE_PATH)는 창을 숨기고 돈다. 숨긴 창은 다시 그리기 요청과 수직 동기가 없어 about_to_wait 에서 프레임을 바로 돌고 주사율로 빠르기를 맞춘다. 가려짐 알림은 받지 않는다. 맥은 독 아이콘과 포커스도 가져가지 않는다. 창을 보려면 VANILLA_CAPTURE_SHOW_WINDOW=1.

Desktop platform. (Windows, Mac, Linux)

  • Creates the window (winit) and a GL 3.3 core context (glutin), and runs one engine frame per window redraw request.
  • Converts window events into the input manager's form. (keys use the same names as W3C KeyboardEvent.code, any mouse button is a touch as in the original, can be changed to left only)
  • The engine core (EngineRunner) does not know about the window. Frames are called here, and the screen is presented after drawing.
  • Text input (key characters, editing keys, IME composition) and the clipboard are handled by desktop/textinput.rs. The right button is a context menu request for input fields.
  • Gamepad vibration on Mac is handled by desktop/gamepadhaptics.rs. (GameController and CoreHaptics, on other OSes gilrs vibrates)
  • The last used device is recorded on every key, mouse and finger event. Keys to prevent (set_prevented_keys) and blocking the right-click menu are not used, since a window has no browser default actions to block. (same result as blocking them in Chrome. On Windows winit does not pass WM_SYSKEYUP of a menuless window to DefWindowProc, so Alt and F10 do not enter the system menu either)
  • Page events: the window is occluded (Occluded, reported by Mac and X11), minimized (size 0 or is_minimized, which is how Windows reports it), the app is suspended (suspended, mobile), the Wayland frame callback has not come for over 3 seconds (occlusion on Chrome Linux Wayland, desktop/waylandframecallback.rs) If any one of these holds, Hidden; once all clear, Visible and on_page_visibility_restored. Focus is Focused / Blurred, mouse button and finger presses are PointerDown. Wayland's xdg_toplevel suspended state is held by winit and not reported, so it cannot be received.
  • Wayland vertical sync: sets the EGL swap interval to 0 and waits up to 1/20 second for the previous frame callback before presenting. (with interval 1, Mesa stalls inside the swap on an occluded window)
  • Canvas size (auto_resize_on_window_resize): the window is like a page whose canvas fills the window. When on, it fits visualViewport (the window minus the bottom covered by the on-screen keyboard) as in the original and applies ignore_virtual_keyboard_resize and the canvas aspect ratio limit. When off, it is the window size as is.
  • On-screen keyboard: on Windows, like Chrome, focusing a platform input field with a finger shows the touch keyboard (InputPane) and removes the covered area from visualViewport. (desktop/windowsinputpane.rs) Mac and Linux do not shrink the viewport, like Chrome.
  • Preserving the drawing buffer (preserve_drawing_buffer): captures the finished frame and redraws it at the start of the next frame. (desktop/preserveddrawingbuffer.rs)
  • Page process restore (on_page_process_restored, the original resume after a Chromium freeze and bfcache): resumed after suspended, and waking from system sleep. Windows subclasses the window to receive PBT_APMRESUMEAUTOMATIC of WM_POWERBROADCAST. (desktop/windowsplatform.rs, the Windows monotonic clock keeps running during sleep so the clock cannot tell) Mac and Linux treat it as woken if between two frames the wall clock (SystemTime) advanced more than SYSTEM_SLEEP_GAP_SECONDS beyond the monotonic clock (Instant). (Rust Instant is CLOCK_UPTIME_RAW on Mac and CLOCK_MONOTONIC on Linux, so it stops during sleep. Rust notes that it does not guarantee this)
  • Whether the primary input is a finger (is_coarse_pointer): Windows ports Chromium's (pointer: coarse) check and is true in tablet mode or on a touch device without a mouse. Mac is false, since Chromium always treats it as a mouse too. Linux and other Unixes, like Chromium, read touchscreens and mice and touchpads from the display server (Wayland wl_seat capabilities, X11 XInput device list) and are true if there is only a touchscreen. (desktop/linuxplatform.rs, the value read is used for 2 seconds)
  • Key names: winit's SuperLeft, SuperRight become W3C's MetaLeft, MetaRight, and winit's Meta becomes W3C's Super.
  • Image cursors (PointerCursor.register_image_cursor): reads the image file and makes a winit CustomCursor. On Mac the image size is the point size as is, so the 1x image is used; Windows and Linux use physical pixels, so the image and hotspot are scaled to the window scale (using the 2x image if present). While creating, or if creation fails, the CSS cursor given with it is used.
  • Render scale upper limit (ViewManager.set_max_render_pixel_ratio): draws at the size reduced to that scale and stretches to the window size at the end of the frame. (desktop/renderscaler.rs) Input coordinates are converted to logical coordinates with the window's scale, so they do not depend on the render size.
  • Canvas aspect ratio limit (EngineConfiguration.max_canvas_aspect_ratio): if the window is more elongated than that, the canvas (drawing area) is shrunk as in the original and centered in the window, and the rest is black. The canvas top-left is subtracted from input coordinates, and read_canvas_client_position returns that position.
  • Query values of the page address (read_page_query_value) are read from the environment variable VANILLA_ followed by the name in upper snake case. (safeArea → VANILLA_SAFE_AREA)
  • Capture mode (VANILLA_CAPTURE_PATH) runs with the window hidden. A hidden window has no redraw requests or vertical sync, so frames run right away in about_to_wait and pace themselves to the refresh rate. Occlusion notifications are not received. On Mac it does not take the Dock icon or focus either. To see the window, VANILLA_CAPTURE_SHOW_WINDOW=1.
예제Example페이지 쿼리 값, 세이프 에어리어, 주된 손 읽기 (데스크탑은 환경 변수, 0, 페이지 없음)Read page query values, safe area and primary input (on desktop: environment variables, 0, no page)
use vanilla::platform;

let quality = platform::read_page_query_value("quality").unwrap_or_else(|| String::from("high"));
let safe_area_insets = platform::read_safe_area_insets();
let is_touch_first = platform::is_coarse_pointer();
println!("{} {:?} {}", quality, safe_area_insets, is_touch_first);
assert_eq!(safe_area_insets, [0.0, 0.0, 0.0, 0.0]);
assert_eq!(platform::read_client_native_size(), None);
assert!(!platform::is_text_field_focused());

PlatformWindowtype

소스source

엔진이 들고 있는 창 손잡이. (커서, 제목을 바꿀 때)

Window handle held by the engine. (for changing the cursor and title)

pub type PlatformWindow = Rc<Window>

함수Functions

함수functionpub fn run(engine_runner: EngineRunner) -> Result<(), String>#0.3.2 부터since 0.3.2소스source

시작. (창을 닫거나 exit_application 을 부를 때까지 돌아오지 않는다)

Starts. (does not return until the window is closed or exit_application is called)

engine_runnerEngineRunner
엔진 실행자. (Engine::run 이 엔진과 첫 씬으로 만들어 넘긴다)Engine runner. (Engine::run makes it with the engine and the first scene and passes it)

반환ReturnsResult<(), String> 창이 닫히고 이벤트 루프가 끝나면 Ok. 이벤트 루프를 만들거나 돌리지 못했거나 창, GL 컨텍스트를 만들다 실패했으면 Err(까닭 글).Ok when the window closes and the event loop ends. Err(reason text) if the event loop could not be created or run, or creating the window or GL context failed.

함수functionpub fn set_cursor_visible(platform_window: Option<&PlatformWindow>, is_visible: bool)#0.3.2 부터since 0.3.2소스source

커서 보이기 설정.

Sets cursor visibility.

platform_windowOption<&PlatformWindow>
창 손잡이. (None 이면 아무것도 하지 않는다)Window handle. (does nothing if None)
is_visiblebool
보이려면 true.true to show it.
함수functionpub fn set_cursor(platform_window: Option<&PlatformWindow>, cursor_value: &CursorValue)#0.4.0 부터since 0.4.0소스source

커서 모양 설정. (CSS 커서 이름을 winit 커서 아이콘으로, none 이면 감춤, 모르는 이름은 기본 화살표)

  • 그림 커서는 만들어 둔 것이 있으면 그것을 건다. 아직 없으면 이벤트 루프가 만들도록 부탁해 두고 그동안은 함께 준 CSS 커서를 쓴다.

Sets the cursor shape. (CSS cursor name to a winit cursor icon, hidden if none, unknown names are the default arrow)

  • For an image cursor, sets the one already made if there is one. If not yet, asks the event loop to make it and uses the CSS cursor given with it in the meantime.
platform_windowOption<&PlatformWindow>
창 손잡이. (None 이면 아무것도 하지 않는다)Window handle. (does nothing if None)
cursor_value&CursorValue
커서 값. (image_url 이 있으면 그림 커서, 아니면 fallback_name 의 CSS 커서 이름)Cursor value. (an image cursor if image_url is present, otherwise the CSS cursor name in fallback_name)
함수functionpub fn is_coarse_pointer() -> bool#0.4.0 부터since 0.4.0소스source

주된 손이 손가락인지. (윈도우는 크로미엄처럼 태블릿 모드나 마우스 없는 터치 기기면 참, 리눅스는 크로미엄처럼 마우스, 터치패드 없이 터치스크린만 있으면 참, 맥은 마우스가 주된 손으로 본다)

Whether the primary input is a finger. (Windows, like Chromium, is true in tablet mode or on a touch device without a mouse, Linux, like Chromium, is true if there is only a touchscreen without a mouse or touchpad, Mac treats the mouse as the primary input)

반환Returnsbool 주된 손이 손가락이면 true. (맥은 늘 false)true if the primary pointer is a finger. (always false on Mac)

함수functionpub fn is_text_field_focused() -> bool#0.4.0 부터since 0.4.0소스source

문서의 초점이 글자 입력칸에 있는지. (데스크탑에는 문서가 없어 늘 false, 엔진 입력 필드는 입력 매니저가 따로 본다)

Whether the document's focus is on a text input. (desktop has no document so always false, the input manager checks engine input fields separately)

반환Returnsbool 늘 false.Always false.

함수functionpub fn read_page_query_value(name: &str) -> Option<String>#0.4.0 부터since 0.4.0소스source

페이지 주소의 쿼리 값. (데스크탑에는 주소가 없어 환경 변수 VANILLA_ 뒤에 이름을 대문자 뱀꼴로 붙인 것을 읽는다, 없으면 None)

  • safeArea → VANILLA_SAFE_AREA, quality → VANILLA_QUALITY

Query value of the page address. (desktop has no address, so it reads the environment variable VANILLA_ followed by the name in upper snake case, None if missing)

  • safeArea → VANILLA_SAFE_AREA, quality → VANILLA_QUALITY
name&str
쿼리 이름. (낙타꼴, safeArea 같은)Query name. (camel case, such as safeArea)

반환ReturnsOption<String> 그 환경 변수의 값. 없거나 유니코드가 아니면 None.Value of that environment variable. None if missing or not Unicode.

함수functionpub fn read_canvas_client_position() -> Vector2#0.4.0 부터since 0.4.0소스source

화면(client) 좌표에서 캔버스의 왼쪽 위. (데스크탑은 창의 논리 좌표가 client 좌표다, 캔버스 비 상한으로 가운데에 둘 때만 0 이 아니다)

Top-left of the canvas in screen (client) coordinates. (on desktop the window's logical coordinates are client coordinates, nonzero only when centered by the canvas aspect ratio limit)

반환ReturnsVector2 창 안에서 캔버스의 왼쪽 위 자리. (논리 픽셀, 처음은 0, 0)Top-left position of the canvas inside the window. (logical pixels, initially 0, 0)

함수functionpub fn save_capture_file(output_path: &str, png_bytes: &[u8]) -> Result<(), String>#0.4.0 부터since 0.4.0소스source

검증용 화면 저장. (파일로 쓴다)

Saves the screen for verification. (writes it to a file)

output_path&str
쓸 파일 경로. (VANILLA_CAPTURE_PATH, 있으면 덮어쓴다)File path to write. (VANILLA_CAPTURE_PATH, overwritten if it exists)
png_bytes&[u8]
PNG 파일 바이트.PNG file bytes.

반환ReturnsResult<(), String> 썼으면 Ok. 파일을 쓰지 못했으면 Err(입출력 오류 글).Ok if written. Err(I/O error text) if the file could not be written.

함수functionpub fn read_client_native_size() -> Option<Vector2>#0.4.0 부터since 0.4.0소스source

페이지 전체 크기. (원본 window.innerWidth, innerHeight, 데스크탑에는 페이지가 없어 None 이고 ViewManager 가 창 안쪽 크기를 쓴다)

Full page size. (the original window.innerWidth, innerHeight, None on desktop since there is no page, and ViewManager uses the window's inner size)

반환ReturnsOption<Vector2> 늘 None.Always None.

함수functionpub fn read_safe_area_insets() -> [f64; 4]#0.4.0 부터since 0.4.0소스source

CSS env(safe-area-inset-*) 세이프 에어리어 인셋. (데스크탑은 0)

  • 크롬 데스크탑도 0 이다. 0 이 아닌 인셋은 WebContentsImpl::SetDisplayCutoutSafeArea 로만 들어오는데, 이 함수는 #if BUILDFLAG(IS_ANDROID) 안에 있고 안드로이드(web_contents_android.cc)만 부른다. 그 밖에는 블링크 기본값 "0px" 이다. (style_environment_variables.cc, 노치가 있는 맥북의 전체 화면도 같다)

CSS env(safe-area-inset-*) safe area insets. (0 on desktop)

  • Chrome desktop is 0 too. Nonzero insets only come in through WebContentsImpl::SetDisplayCutoutSafeArea, and this function is inside #if BUILDFLAG(IS_ANDROID) and only Android (web_contents_android.cc) calls it. Elsewhere it is the Blink default "0px". (style_environment_variables.cc, the same for full screen on a MacBook with a notch)

반환Returns[f64; 4] 늘 [0, 0, 0, 0]. (웹과 같은 차례 위, 오른쪽, 아래, 왼쪽)Always [0, 0, 0, 0]. (same order as web: top, right, bottom, left)

함수functionpub fn read_heap_usage() -> Option<(f64, f64)>#0.4.0 부터since 0.4.0소스source

힙 사용량. (바이트, (쓰는 중, 잡아 둔 것), 못 읽으면 None. 개발자 도구의 메모리 칸, 원본 performance.memory 의 usedJSHeapSize, totalJSHeapSize 자리)

  • 데스크탑에는 자바스크립트 힙이 없어 러스트가 쓰는 시스템 할당자의 힙을 읽는다. (러스트 System 할당자는 맥과 리눅스는 malloc, 윈도우는 프로세스 힙의 HeapAlloc)
  • 맥: malloc_zone_statistics(모든 영역)의 size_in_use, size_allocated.
  • 윈도우: 프로세스 힙의 HeapSummary 의 cbAllocated, cbCommitted.
  • 리눅스(glibc): mallinfo2 의 uordblks + hblkhd(쓰는 중, mmap 으로 잡은 큰 덩어리 포함), arena + hblkhd(잡아 둔 것). glibc 2.33 부터라 실행할 때 찾고, 없으면 None.
  • 그 밖의 OS 는 None 이다.

Heap usage. (bytes, (in use, reserved), None if it cannot be read. The memory pane of the developer tools, in place of usedJSHeapSize, totalJSHeapSize of the original performance.memory)

  • Desktop has no JavaScript heap, so it reads the heap of the system allocator Rust uses. (the Rust System allocator is malloc on Mac and Linux, HeapAlloc on the process heap on Windows)
  • Mac: size_in_use, size_allocated of malloc_zone_statistics (all zones).
  • Windows: cbAllocated, cbCommitted of HeapSummary of the process heap.
  • Linux (glibc): uordblks + hblkhd of mallinfo2 (in use, including large blocks reserved with mmap), arena + hblkhd (reserved). Available from glibc 2.33, so it is looked up at run time, and None if missing.
  • Other OSes are None.

반환ReturnsOption<(f64, f64)> (쓰는 중인 바이트, 잡아 둔 바이트). 윈도우에서 HeapSummary 가 실패했거나, 리눅스에 mallinfo2 가 없거나, 그 밖의 OS 면 None.(bytes in use, bytes reserved). None if HeapSummary failed on Windows, mallinfo2 is missing on Linux, or on other OSes.

예제Example힙 사용량을 메가바이트로 찍기Print heap usage in megabytes
use vanilla::platform::desktop::read_heap_usage;

if let Some((used_bytes, reserved_bytes)) = read_heap_usage() {
	assert!(used_bytes > 0.0);
	println!("{:.1} / {:.1} MB", used_bytes / 1048576.0, reserved_bytes / 1048576.0);
}
함수functionpub fn read_heap_size_limit() -> Option<f64>#0.4.0 부터since 0.4.0소스source

힙 한도. (바이트, 힙이 자랄 수 있는 상한, 못 읽으면 None. 개발자 도구의 메모리 칸, 원본 performance.memory 의 jsHeapSizeLimit 자리)

  • 데스크탑에는 자바스크립트 힙의 상한이 없어 운영체제가 이 프로세스의 힙에 허락하는 상한을 읽는다.
  • 맥, 리눅스: 프로세스 자료 영역 한도(getrlimit RLIMIT_DATA 의 rlim_cur)가 정해져 있으면 그것, 없으면(무한) 물리 메모리 크기. (맥은 sysctl hw.memsize, 리눅스는 sysconf 의 _SC_PHYS_PAGES 곱하기 _SC_PAGESIZE)
  • 윈도우: GlobalMemoryStatusEx 의 물리 메모리 크기(ullTotalPhys)와 이 프로세스가 쓸 수 있는 가상 주소 크기(ullTotalVirtual) 가운데 작은 것.
  • 그 밖의 OS 는 None 이다.

Heap limit. (Bytes, the upper bound the heap can grow to, None if it cannot be read. The developer tools memory field, where the original has jsHeapSizeLimit of performance.memory)

  • The desktop has no JavaScript heap limit, so it reads the upper bound the operating system allows for this process's heap.
  • macOS, Linux: the process data segment limit (rlim_cur of getrlimit RLIMIT_DATA) if one is set, otherwise (infinite) the physical memory size. (macOS uses sysctl hw.memsize, Linux uses _SC_PHYS_PAGES times _SC_PAGESIZE from sysconf)
  • Windows: the smaller of the physical memory size (ullTotalPhys) and the virtual address size this process can use (ullTotalVirtual) from GlobalMemoryStatusEx.
  • Other OSes give None.

반환ReturnsOption<f64> 힙 한도 바이트. 운영체제 함수가 실패했거나 그 밖의 OS 면 None.Heap limit in bytes. None if the operating system function failed or on other OSes.

예제Example힙 한도를 메가바이트로 찍기Printing the heap limit in megabytes
use vanilla::platform::desktop::read_heap_size_limit;

if let Some(limit_bytes) = read_heap_size_limit() {
	assert!(limit_bytes > 0.0);
	println!("{:.1} MB", limit_bytes / 1048576.0);
}
함수functionpub fn exit_application()#0.4.0 부터since 0.4.0소스source

응용 프로그램 종료. (데스크탑은 엔진의 종료 요청을 보고 이벤트 루프가 끝나므로 따로 할 일이 없다)

Exits the application. (on desktop the event loop ends on seeing the engine's exit request, so there is nothing else to do)

함수functionpub fn open_url(url: &str) -> bool#0.4.0 부터since 0.4.0소스source

바깥 주소 열기. (원본 Engine.openUrl, 운영체제의 기본 프로그램으로 연다)

  • 맥은 LaunchServices 를 쓰는 open, 윈도우는 ShellExecuteW, 그 밖의 유닉스는 xdg-open 이다.
  • 열 수 있는 것은 http, https, mailto, tel 뿐이다. (is_openable_url) 그 밖의 꼴은 열지 않고 false.

Opens an outside URL. (original Engine.openUrl, opens with the OS default program)

  • macOS uses open, which goes through LaunchServices; Windows uses ShellExecuteW; other Unix uses xdg-open.
  • Only http, https, mailto and tel can be opened. (is_openable_url) Other forms are not opened and return false.
url&str
열 주소. (http, https, mailto, tel 꼴)URL to open. (http, https, mailto or tel)

반환Returnsbool 운영체제에 열기를 넘겼으면 true.True if the open was handed to the OS.

함수functionpub fn read_local_time(minute_offset: f64) -> crate::platform::LocalTime#0.4.0 부터since 0.4.0소스source

현지 시각 읽기. (원본 Engine.readLocalTime, 지금에서 분 오프셋만큼 더한 때를 이 기계의 시간대로 본 달력 시각)

  • 맥과 리눅스는 localtime_r, 윈도우는 SystemTimeToTzSpecificLocalTime 이다. 더한 때의 일광 절약 시간까지 반영한다. (원본 new Date(Date.now() + 오프셋) 과 같다)

Read the local time. (same as the original Engine.readLocalTime, the calendar time of now plus a minute offset in this machine's time zone)

  • Mac and Linux use localtime_r, Windows uses SystemTimeToTzSpecificLocalTime. Daylight saving time at the shifted moment is applied. (same as the original's new Date(Date.now() + offset))
minute_offsetf64
지금에 더할 분. (음수는 과거, 0 이면 지금)Minutes to add to now. (negative is the past, 0 is now)

반환Returnscrate::platform::LocalTime 더한 때를 이 기계의 시간대로 본 달력 시각.The calendar time of the shifted moment in this machine's time zone.

함수functionpub fn set_title(platform_window: Option<&PlatformWindow>, title: &str)#0.3.2 부터since 0.3.2소스source

창 제목 설정.

Sets the window title.

platform_windowOption<&PlatformWindow>
창 손잡이. (None 이면 아무것도 하지 않는다)Window handle. (does nothing if None)
title&str
제목 글.Title text.
함수functionpub fn request_asset_bytes(asset_location: String, load_handle: AssetLoadHandle, _is_no_cache: bool)#0.3.2 부터since 0.3.2소스source

애셋 바이트 읽기. (파일을 그 자리에서 읽고 끝낸다. 엔진 캐시 없이 늘 새로 읽어 is_no_cache 를 켠 웹 fetch 처럼 지금 내용이다. 읽은 파일은 리소스 사용량에 적는다)

Reads asset bytes. (reads the file on the spot and finishes. It always reads anew without an engine cache, so it is the current content like a web fetch with is_no_cache on. Files read are recorded in resource usage)

asset_locationString
읽을 파일 경로. (엔진이 애셋 경로로 만든 것)File path to read. (made from the asset path by the engine)
load_handleAssetLoadHandle
다 읽으면 바이트나 오류 글로 끝낼 손잡이.Handle to finish with the bytes or error text once read.
_is_no_cachebool
캐시를 거르지 않고 읽을지. (데스크탑은 늘 거르지 않아 보지 않아도 같다)Whether to read bypassing the cache. (desktop always bypasses it, so ignoring it is the same)