core/pointercursor
마우스 커서. (vanilla.js core/pointercursor.js 의 PointerCursor)
- 엔진이 하나 든다. (Engine::get_pointer_cursor_mut) 켜면(set_enabled(true)) 엔진이 프레임 끝마다 창이나 캔버스의 커서를 정한다. 꺼져 있으면(기본) 아무것도 하지 않아 지금까지와 같다.
- UIButton 위(누르는 중 포함)면 단추의 커서(처음은 손가락 pointer), 아니면 화면이 set_screen_cursor 로 정한 커서다.
- 이름은 CSS cursor 이름이다. (pointer, crosshair, not-allowed, grab, grabbing, text, move, help, wait, progress, none, default) 데스크탑은 winit 의 커서 아이콘으로 바꿔 쓰고, 웹은 캔버스의 cursor 스타일에 쓴다.
- register_image_cursor 로 그림 커서를 더하면 웹은 그 그림(1 배와 2 배)을 CSS 값으로, 데스크탑은 그 그림 파일(애셋 폴더 기준)로 만든 창의 커서를 쓴다. (데스크탑은 만드는 동안과 그림을 못 읽으면 함께 준 CSS 커서)
- 손가락 기기(pointer: coarse)에서는 건드리지 않는다. 바뀔 때만 플랫폼에 넘긴다.
- 원본 apply 는 전역 엔진의 캔버스(readEngineCanvas)에 바로 쓴다. 러스트 판은 엔진이 take_cursor_change 로 바뀐 값을 받아 플랫폼에 넘긴다. (커서는 엔진이 쥔 플랫폼 창에 쓴다)
Mouse cursor. (PointerCursor of vanilla.js core/pointercursor.js)
- The engine holds one. (Engine::get_pointer_cursor_mut) When on (set_enabled(true)), the engine sets the cursor of the window or canvas at the end of every frame. When off (default), it does nothing, same as before.
- Over a UIButton (including while pressing), it is the button's cursor (initially the pointer hand), otherwise the cursor the screen set with set_screen_cursor.
- Names are CSS cursor names. (pointer, crosshair, not-allowed, grab, grabbing, text, move, help, wait, progress, none, default) Desktop converts them to winit cursor icons, and the web writes them to the canvas cursor style.
- When an image cursor is added with register_image_cursor, the web uses that image (1x and 2x) as a CSS value, and desktop uses a window cursor made from that image file (relative to the asset folder). (on desktop, the CSS cursor given with it while it is being made and if the image cannot be read)
- Not touched on finger devices (pointer: coarse). Passed to the platform only when it changes.
- The original apply writes directly to the global engine's canvas (readEngineCanvas). In the Rust version the engine receives the changed value with take_cursor_change and passes it to the platform. (the cursor is written to the platform window the engine holds)
use vanilla::{Engine, EngineConfiguration};
let engine = Engine::new(EngineConfiguration::new());
let mut pointer_cursor = engine.get_pointer_cursor_mut();
pointer_cursor.set_enabled(true);
pointer_cursor.set_screen_cursor("crosshair");
drop(pointer_cursor);
assert_eq!(engine.get_pointer_cursor().get_screen_cursor(), "crosshair");CursorValuestruct traits Clone, PartialEq, Debug
플랫폼에 넘길 커서. (웹의 CSS 값, 데스크탑이 쓸 CSS 이름, 그림 커서면 그림 주소와 핫스팟)
Cursor to pass to the platform. (the CSS value for the web, the CSS name for desktop, the image URL and hotspot for an image cursor)
use vanilla::PointerCursor;
let mut pointer_cursor = PointerCursor::new();
pointer_cursor.register_image_cursor("icon", "examples/assets/atlas/icons.png", "", 3.4, 2.6, "pointer");
let image_cursor_value = pointer_cursor.read_cursor_value("icon");
assert_eq!(image_cursor_value.css_value, "url(\"examples/assets/atlas/icons.png\") 3 3, pointer");
assert_eq!(image_cursor_value.fallback_name, "pointer");
assert_eq!((image_cursor_value.hotspot_x, image_cursor_value.hotspot_y), (3.0, 3.0));
let css_cursor_value = pointer_cursor.read_cursor_value("grab");
assert_eq!(css_cursor_value.css_value, "grab");
assert!(css_cursor_value.image_url.is_empty());
assert_eq!(pointer_cursor.read_cursor_value("unknown").css_value, "");웹 캔버스의 cursor 스타일에 쓸 CSS 값. (그림 커서면 url 이나 -webkit-image-set 과 핫스팟과 CSS 커서, 기본 화살표면 빈 글)
CSS value for the web canvas cursor style. (url or -webkit-image-set with hotspot and CSS cursor for an image cursor, empty text for the default arrow)
반환ReturnsString
그림을 못 쓸 때와 데스크탑이 쓸 CSS 커서 이름. (기본 화살표면 빈 글)
CSS cursor name used when the image cannot be used and by desktop. (empty text for the default arrow)
반환ReturnsString
그림 커서의 1 배 그림 주소. (그림 커서가 아니면 빈 글)
1x image URL of the image cursor. (empty text if not an image cursor)
반환ReturnsString
그림 커서의 2 배 그림 주소. (없으면 빈 글)
2x image URL of the image cursor. (empty text if none)
반환ReturnsString
1 배 그림 기준 핫스팟. (원본처럼 반올림한 값)
Hotspot relative to the 1x image. (rounded like the original)
반환Returnsf64
1 배 그림 기준 핫스팟의 y. (픽셀, 원본처럼 반올림한 값, 그림 커서가 아니면 0)
y of the hotspot relative to the 1x image. (pixels, rounded like the original, 0 if not an image cursor)
반환Returnsf64
PointerCursorstruct traits Default
마우스 커서. (켜면 단추 위와 화면의 커서를 골라 바뀔 때만 플랫폼에 넘긴다, 엔진이 하나 든다)
Mouse cursor. (when on, picks the cursor over buttons and for the screen and passes it to the platform only when it changes, the engine holds one)
use vanilla::PointerCursor;
let mut pointer_cursor = PointerCursor::new();
assert_eq!(pointer_cursor.take_cursor_change(false), None);
pointer_cursor.set_enabled(true);
pointer_cursor.set_screen_cursor("crosshair");
assert_eq!(pointer_cursor.take_cursor_change(false).unwrap().css_value, "crosshair");
assert_eq!(pointer_cursor.take_cursor_change(false), None);
pointer_cursor.mark_over_button();
assert_eq!(pointer_cursor.take_cursor_change(false).unwrap().css_value, "pointer");생성.
Constructor.
반환ReturnsPointerCursor 꺼진 새 커서. (단추 위 pointer, 기본 default, 화면 default)New cursor, off. (pointer over buttons, default for the default, default for the screen)
짝Counterpart: vanilla.js PointerCursor.constructor
주된 손이 손가락인지. (원본 static isCoarsePointer, CSS 의 pointer: coarse. 데스크탑은 윈도우 태블릿 모드나 마우스 없는 터치 기기, 리눅스 터치스크린만 있는 기기면 참, 맥은 거짓)
Whether the primary pointer is a finger. (the original static isCoarsePointer, CSS pointer: coarse. On desktop, true in Windows tablet mode or on touch devices without a mouse and on Linux devices with only a touchscreen, false on macOS)
반환Returnsbool 주된 손이 손가락이면 true. (플랫폼의 is_coarse_pointer 를 그대로 돌려준다)true if the primary pointer is a finger. (returns the platform's is_coarse_pointer as is)
짝Counterpart: vanilla.js PointerCursor.isCoarsePointer
문서 요소의 커서 바라기. (이번 프레임만. 원본은 브라우저가 DOM 요소의 CSS cursor 를 보인다. 켜기 설정과 상관없이 보인다)
Requests a cursor for a document element. (this frame only. In the original the browser shows the CSS cursor of the DOM element. Shown regardless of the enabled setting)
- cursor_name&str
- 보일 CSS 커서 이름. (col-resize 같은 것, 그대로 플랫폼에 넘긴다)CSS cursor name to show. (such as col-resize, passed to the platform as is)
켜기 설정. (끄면 다음 프레임에 기본 커서로 돌린다)
Enabled setting. (when turned off, returns to the default cursor next frame)
- is_enabledbool
- true 면 엔진이 프레임 끝마다 커서를 정한다. (기본 false)true makes the engine set the cursor at the end of every frame. (default false)
짝Counterpart: vanilla.js PointerCursor.setEnabled
켜져 있는지.
Whether enabled.
반환Returnsbool set_enabled(true) 뒤면 true.true after set_enabled(true).
짝Counterpart: vanilla.js PointerCursor.isEnabled
마우스가 단추 위에 있다고 알리기. (올려 둔 단추가 매 프레임 부른다, 컴포넌트는 엔진을 빌려 읽기만 하므로 &self)
Reports that the mouse is over a button. (the hovered button calls it every frame, &self because components only borrow the engine to read)
짝Counterpart: vanilla.js PointerCursor.markOverButton
화면의 커서 설정. (단추 위가 아닐 때 보일 커서)
Sets the screen cursor. (The cursor shown when not over a button)
- cursor_name&str
- CSS 커서 이름이나 register_image_cursor 로 더한 이름. (default 면 기본의 커서)A CSS cursor name or a name added with register_image_cursor. (the default cursor if default)
짝Counterpart: vanilla.js PointerCursor.setScreenCursor
화면의 커서 반환.
Returns the screen cursor.
반환Returns&str 화면의 커서 이름. (기본 default)Screen cursor name. (default is default)
짝Counterpart: vanilla.js PointerCursor.getScreenCursor
단추 위와 기본의 커서 설정.
Sets the over-button and default cursors.
- button_cursor_name&str
- 단추 위(누르는 중 포함)에서 보일 커서 이름. (기본 pointer)Cursor name to show over buttons (including while pressing). (default pointer)
- default_cursor_name&str
- 화면의 커서가 default 일 때 대신 보일 커서 이름. (기본 default)Cursor name to show instead when the screen cursor is default. (default default)
짝Counterpart: vanilla.js PointerCursor.setCursorNames
단추 위의 커서 반환.
Returns the button-hover cursor.
반환Returns&str 단추 위의 커서 이름. (기본 pointer)Over-button cursor name. (default pointer)
짝Counterpart: vanilla.js PointerCursor.getButtonCursorName
기본의 커서 반환.
Returns the default cursor.
반환Returns&str 기본의 커서 이름. (기본 default)Default cursor name. (default default)
짝Counterpart: vanilla.js PointerCursor.getDefaultCursorName
pub fn register_image_cursor(&mut self, name: &str, url: &str, url_2x: &str, hotspot_x: f64, hotspot_y: f64, fallback_cursor_name: &str)#그림 커서 더하기. (1 배와 2 배 그림 주소, 1 배 그림 기준 핫스팟, 그림을 못 쓸 때와 데스크탑의 CSS 커서)
- 같은 이름으로 다시 더하면 바꾼다.
Adds an image cursor. (1x and 2x image URLs, hotspot relative to the 1x image, CSS cursor for when the image cannot be used and for desktop)
- Adding again with the same name replaces it.
- name&str
- 커서 이름. (set_screen_cursor, set_cursor_names 에 쓴다)Cursor name. (used for set_screen_cursor, set_cursor_names)
- url&str
- 1 배 그림 주소. (웹은 CSS url, 데스크탑은 애셋 폴더 기준 그림 파일)1x image URL. (CSS url on the web, an image file relative to the asset folder on desktop)
- url_2x&str
- 2 배 그림 주소. 빈 글이면 1 배 그림만 쓴다.2x image URL. Only the 1x image is used if empty.
- hotspot_xf64
- 1 배 그림 기준 핫스팟 x. (픽셀, 반올림한다)Hotspot x relative to the 1x image. (pixels, rounded)
- hotspot_yf64
- 1 배 그림 기준 핫스팟 y. (픽셀, 반올림한다)Hotspot y relative to the 1x image. (pixels, rounded)
- fallback_cursor_name&str
- 그림을 못 쓸 때와 데스크탑이 그림을 만드는 동안 보일 CSS 커서 이름.CSS cursor name to show when the image cannot be used and while desktop is making the image.
짝Counterpart: vanilla.js PointerCursor.registerImageCursor
use vanilla::PointerCursor;
let mut pointer_cursor = PointerCursor::new();
pointer_cursor.register_image_cursor("icon", "examples/assets/atlas/icons.png", "", 0.0, 0.0, "default");
pointer_cursor.set_enabled(true);
pointer_cursor.set_screen_cursor("icon");
let cursor_value = pointer_cursor.take_cursor_change(false).unwrap();
assert_eq!(cursor_value.image_url, "examples/assets/atlas/icons.png");커서 이름을 플랫폼에 넘길 값으로. (그림 커서면 그 값, 쓸 수 있는 CSS 이름이면 그대로, 아니면 기본 화살표)
Turns a cursor name into the value to pass to the platform. (that value for an image cursor, as is for a usable CSS name, otherwise the default arrow)
- cursor_name&str
- 커서 이름. (그림 커서 이름이나 CSS 커서 이름)Cursor name. (an image cursor name or a CSS cursor name)
반환ReturnsCursorValue 플랫폼에 넘길 값. (기본 화살표면 css_value 와 fallback_name 이 빈 글)Value to pass to the platform. (css_value and fallback_name are empty text for the default arrow)
짝Counterpart: vanilla.js PointerCursor.readCursorValue
이번 프레임의 커서가 바뀌었으면 꺼내기. (엔진이 프레임 끝마다 부른다, 단추 표시를 비운다)
- 문서 요소가 바란 커서가 먼저이고, 켜져 있으면 단추 위의 커서, 아니면 화면의 커서다.
Takes out this frame's cursor if it changed. (called by the engine at the end of every frame, clears the button mark)
- The cursor requested by a document element comes first, then the over-button cursor if enabled, otherwise the screen cursor.
- is_coarse_pointerbool
- 주된 손이 손가락인지. (true 면 아무것도 바꾸지 않는다)Whether the primary pointer is a finger. (true changes nothing)
반환ReturnsOption<CursorValue> 지난번에 넘긴 값과 다르면 새 값. 같거나, 손가락 기기이거나, 꺼져 있고 문서 요소 커서도 없었으면 None.The new value if it differs from the value passed last time. None if the same, on a finger device, or off with no document element cursor either.