vanilladocs
vanillapunch.com
API / ui/uiimageview

ui/uiimageview

UI 이미지 뷰. (원본 ui/uiimageview.js 의 UIImageView)

  • 표시 전용 위젯. 스프라이트의 이미지 / 색 / 뒤집기 / 출력 방식 / 블렌드 / 나인슬라이스를 노출한다.
  • 원본은 attach 때 호스트에 Sprite 를 붙이고 참조를 든다. 러스트 판은 Sprite 를 품는다. (UILabel 이 Text 를 품는 것과 같은 까닭) 품은 Sprite 는 원본처럼 get_sprite / get_sprite_mut 로 꺼낸다. 이미지 뷰 노드의 get_component::<Sprite>() 는 None 이다. UI 문서는 원본처럼 품은 Sprite 를 UIImageView 다음 Sprite 로 쓰고 읽는다. (uidocument.rs)
  • 그림 경로(get_image_path)는 원본 imageView.imagePath 처럼 품은 Sprite 의 경로(원본 Sprite 의 imagePath)와 따로 든다.
  • 원본 setImage 는 이미지 요소와 ImageAsset 을 함께 받는다. 러스트 판은 set_image(Option<Rc<Image>>) 와 set_image_asset 으로 나눴다.
  • 배경색(UIView)은 스프라이트보다 먼저 그린다. (원본도 UIImageView 가 먼저 붙고 attach 에서 Sprite 를 뒤에 붙여 같은 차례다)

UI image view. (UIImageView of the original ui/uiimageview.js)

  • A display-only widget. Exposes the sprite's image / color / flip / draw mode / blend / nine-slice.
  • The original attaches a Sprite to the host on attach and holds a reference. The Rust version embeds the Sprite. (for the same reason UILabel embeds Text) The embedded Sprite is taken out with get_sprite / get_sprite_mut as in the original. get_component::<Sprite>() on the image view node is None. The UI document writes and reads the embedded Sprite as a Sprite after UIImageView, as in the original. (uidocument.rs)
  • The image path (get_image_path) is held separately from the embedded Sprite's path (the original Sprite's imagePath), like the original imageView.imagePath.
  • The original setImage takes both an image element and an ImageAsset. The Rust version splits it into set_image(Option<Rc<Image>>) and set_image_asset.
  • The background color (UIView) is drawn before the sprite. (in the original too, UIImageView is attached first and attach adds the Sprite after, so the order is the same)

UIImageViewstruct traits Default, Component

짝Counterpart: vanilla.js UIImageView소스source

UI 이미지 뷰.

  • Sprite 를 품고 이미지, 색, 뒤집기, 출력 방식, 블렌드, 나인슬라이스를 넘겨준다. 배경색을 먼저, 스프라이트를 그 위에 그린다.

UI image view.

  • Embeds a Sprite and passes through the image, color, flip, draw mode, blend, and nine-slice. Draws the background color first and the sprite on top.
예제Example코드로 만든 그림을 나인슬라이스로 늘려 보이기Stretch an image made in code with nine-slice
use vanilla::{Image, NodeTree, Rect, Sprite, SpriteDrawMode, UIImageView, Vector2};

let image = Image::create_from_pixels(32, 32, vec![255u8; 32 * 32 * 4]);
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let frame_id = node_tree.create_child(root_id, "frame");
node_tree[frame_id].set_content_size(Vector2::create(160.0, 96.0));
let image_view = node_tree.add_component(frame_id, UIImageView::create_with_image(image)).unwrap();
image_view.set_draw_mode(SpriteDrawMode::Sliced);
image_view.set_nine_slice(Rect::create(8.0, 8.0, 8.0, 8.0));
assert!(image_view.get_image().is_some());
assert_eq!(image_view.get_sprite().get_sprite_draw_mode(), SpriteDrawMode::Sliced);
assert!(node_tree[frame_id].get_component::<Sprite>().is_none());
생성자constructorpub fn new() -> UIImageView#0.3.2 부터since 0.3.2소스source

생성.

Constructor.

반환ReturnsUIImageView 이미지가 없는 새 이미지 뷰. (content 노드는 트리에 붙일 때 만든다)New image view with no image. (the content node is created when attached to a tree)

짝Counterpart: vanilla.js UIImageView.constructor

정적staticpub fn create_with_image(image: Rc<Image>) -> UIImageView#0.3.2 부터since 0.3.2소스source

이미지와 함께 생성.

Constructor with an image.

imageRc<Image>
보일 이미지.Image to show.

반환ReturnsUIImageView 그 이미지를 건 새 이미지 뷰.New image view with that image set.

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

품은 뷰 반환.

Returns the embedded view.

반환Returns&UIView 품은 UIView 의 참조.Reference to the embedded UIView.

메서드methodpub fn get_uiview_mut(&mut self) -> &mut UIView#0.3.2 부터since 0.3.2소스source

품은 뷰 반환. (변경용)

Returns the embedded view. (mutable)

반환Returns&mut UIView 품은 UIView 의 바꿀 수 있는 참조.Mutable reference to the embedded UIView.

메서드methodpub fn get_content(&self) -> Option<NodeId>#0.3.2 부터since 0.3.2소스source

컨텐트 노드 핸들.

Content node handle.

반환ReturnsOption<NodeId> content 노드. 트리에 붙기 전이면 None.content node. None before being attached to a tree.

짝Counterpart: vanilla.js UIView.getContent

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

배경색 설정.

Sets the background color.

background_colorimpl Into<Color>
배경색. (스프라이트보다 먼저 그린다, 알파가 0 이면 칠하지 않는다)Background color. (drawn before the sprite, not painted if alpha is 0)

짝Counterpart: vanilla.js UIView.setBackgroundColor

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

배경색 반환.

Returns the background color.

반환ReturnsColor 배경색. (기본은 알파 0 인 흰색)Background color. (default is white with alpha 0)

짝Counterpart: vanilla.js UIView.getBackgroundColor

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

품은 Sprite 반환. (세밀한 제어가 필요할 때)

Returns the embedded Sprite. (when fine control is needed)

반환Returns&Sprite 품은 Sprite 의 참조.Reference to the contained Sprite.

짝Counterpart: vanilla.js UIImageView.getSprite

메서드methodpub fn get_sprite_mut(&mut self) -> &mut Sprite#0.3.2 부터since 0.3.2소스source

품은 Sprite 반환. (변경용)

Returns the contained Sprite. (mutable)

반환Returns&mut Sprite 품은 Sprite 의 바꿀 수 있는 참조.Mutable reference to the embedded Sprite.

짝Counterpart: vanilla.js UIImageView.getSprite

메서드methodpub fn set_image(&mut self, image: Option<Rc<Image>>)#0.3.2 부터since 0.3.2소스source

이미지 설정.

Sets the image.

imageOption<Rc<Image>>
보일 이미지. None 이면 비운다.Image to show. None clears it.

짝Counterpart: vanilla.js UIImageView.setImage

메서드methodpub fn set_image_asset(&mut self, image_asset: &mut ImageAsset)#0.3.2 부터since 0.3.2소스source

이미지 애셋으로 이미지 설정. (아직 읽히지 않았으면 비운다)

Sets the image from an image asset. (clears it if not loaded yet)

image_asset&mut ImageAsset
이미지를 꺼낼 애셋. (다 읽히기 전이거나 풀기에 실패했으면 이미지가 None 이 된다)Asset to take the image from. (the image becomes None if not fully loaded or decoding failed)
메서드methodpub fn get_image(&self) -> Option<&Rc<Image>>#0.3.2 부터since 0.3.2소스source

이미지 반환.

Returns the image.

반환ReturnsOption<&Rc<Image>> 건 이미지. 없으면 None.The set image. None if none.

짝Counterpart: vanilla.js UIImageView.getImage

메서드methodpub fn set_image_rect(&mut self, image_rect: Rect)#0.3.2 부터since 0.3.2소스source

이미지 부분 영역 설정.

Sets the image sub-area.

image_rectRect
이미지 안의 그릴 영역. (픽셀, 빈 사각형이면 이미지 전체. Sliced 출력 방식에서는 쓰지 않는다)Area of the image to draw. (pixels, the whole image if an empty rectangle. not used in the Sliced draw mode)

짝Counterpart: vanilla.js UIImageView.setImageRect

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

색상 설정. (스프라이트 틴트)

Sets the color. (sprite tint)

colorimpl Into<Color>
스프라이트 색. (이미지가 있으면 알파가 0 보다 클 때 이미지 실루엣 안쪽을 덮는 틴트, 없으면 채우기 색)Sprite color. (with an image, a tint that covers the inside of the image silhouette when alpha is greater than 0, otherwise the fill color)

짝Counterpart: vanilla.js UIImageView.setColor

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

색상 반환.

Returns the color.

반환ReturnsColor 스프라이트 색.Sprite color.

짝Counterpart: vanilla.js UIImageView.getColor

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

좌우 뒤집기 설정.

Sets the horizontal flip.

is_horizontal_flipbool
true 면 좌우를 뒤집어 그린다.If true, draws flipped horizontally.

짝Counterpart: vanilla.js UIImageView.setHorizontalFlip

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

상하 뒤집기 설정.

Sets the vertical flip.

is_vertical_flipbool
true 면 상하를 뒤집어 그린다.If true, draws flipped vertically.

짝Counterpart: vanilla.js UIImageView.setVerticalFlip

메서드methodpub fn set_draw_mode(&mut self, sprite_draw_mode: SpriteDrawMode)#0.3.2 부터since 0.3.2소스source

출력 방식 설정. (simple / sliced / tiled)

Sets the draw mode. (simple / sliced / tiled)

sprite_draw_modeSpriteDrawMode
출력 방식. (Simple, Sliced, Tiled)Draw mode. (Simple, Sliced, Tiled)

짝Counterpart: vanilla.js UIImageView.setDrawMode

메서드methodpub fn set_blend_mode(&mut self, sprite_blend_mode: SpriteBlendMode)#0.3.2 부터since 0.3.2소스source

블렌드 모드 설정.

Sets the blend mode.

sprite_blend_modeSpriteBlendMode
블렌드 모드.Blend mode.

짝Counterpart: vanilla.js UIImageView.setBlendMode

메서드methodpub fn set_nine_slice(&mut self, nine_slice: Rect)#0.3.2 부터since 0.3.2소스source

나인슬라이스 영역 설정.

Sets the nine-slice region.

nine_sliceRect
나인슬라이스 테두리. (position.x, position.y, size.x, size.y 가 왼쪽, 위, 오른쪽, 아래 두께, 픽셀. 출력 방식이 Sliced 일 때 쓰고, 노드 content 크기가 테두리 합보다 작으면 그리지 않는다)Nine-slice border. (position.x, position.y, size.x, size.y are the left, top, right, bottom thickness, pixels. used when the draw mode is Sliced, not drawn if the node's content size is smaller than the sum of the borders)

짝Counterpart: vanilla.js UIImageView.setNineSlice

메서드methodpub fn set_image_path(&mut self, image_path: &str)#0.4.0 부터since 0.4.0소스source

그림 경로 설정. (원본 imageView.imagePath, UI 문서가 적고 읽는다)

Sets the image path. (original imageView.imagePath, written and read by the UI document)

image_path&str
그림 경로. (이미지를 불러오지는 않는다, 품은 Sprite 의 경로와 따로 든다)Image path. (does not load the image, held separately from the embedded Sprite's path)

짝Counterpart: vanilla.js UIImageView.setImagePath

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

그림 경로 반환.

Returns the image path.

반환Returns&str 그림 경로. (정하지 않았으면 빈 글)Image path. (empty string if not set)

짝Counterpart: vanilla.js UIImageView.getImagePath