vanilladocs
vanillapunch.com
API / ui/uiview

ui/uiview

뷰 컴포넌트.

View component.

UIViewextends Component

짝Counterpart: vanilla-engine UIView

뷰 컴포넌트.

  • ScrollView, SnapScrollView 등 모든 뷰 컴포넌트의 기반 클래스.
  • 타입으로 하위 뷰 컴포넌트를 한번에 조회할 수 있다. 예: node.getComponent(View)
  • 컨테이너 역할을 하므로 UIControl 을 상속하지 않고 Component 직접 상속. 대신 UIControl 이 갖던 setEngine/getEngine 를 자체적으로 보유한다.

View component.

  • Base class of all view components such as ScrollView, SnapScrollView.
  • Lower view components can be queried at once by type. e.g.: node.getComponent(View)
  • Since it acts as a container, it inherits Component directly instead of UIControl. Instead, it has its own setEngine/getEngine that UIControl had.
예제Example배경색이 있는 판에 라벨 담기Put a label on a panel with a background color
import { Engine, EngineConfiguration, UIScene, UIView, UILabel, WorldNode, Pivot, Vector2, Color } from "./build/vanilla.js";

class MainScene extends UIScene {
	constructor() {
		super();
		this.setLoadingMinDurationMs(0);
	}

	initialize(engine) {
		super.initialize(engine);
		const panelNode = new WorldNode();
		panelNode.setPivot(Pivot.topLeft);
		panelNode.setAnchor(Pivot.topLeft);
		panelNode.setLocalPosition(Vector2.create(40, 40));
		panelNode.setContentSize(Vector2.create(240, 160));
		const view = panelNode.addComponent(UIView);
		view.setBackgroundColor(new Color(0.1, 0.12, 0.16, 1));

		const labelNode = new WorldNode();
		labelNode.setPivot(Pivot.topLeft);
		labelNode.setAnchor(Pivot.topLeft);
		labelNode.setLocalPosition(Vector2.create(16, 16));
		labelNode.setContentSize(Vector2.create(208, 32));
		const label = labelNode.addComponent(UILabel);
		label.setText("Panel");
		label.setFontSize(20);
		const content = view.getContent();
		content.addChild(labelNode);

		const root = this.getRoot();
		root.addChild(panelNode);
	}
}

const engineConfiguration = new EngineConfiguration();
engineConfiguration.canvasId = "mainCanvas";
engineConfiguration.referenceResolutionSize = Vector2.create(640, 360);
engineConfiguration.autoResizeOnWindowResize = true;
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());
생성자constructorconstructor()#0.2.0 부터since 0.2.0소스source

생성.

Constructor.

짝Counterpart: vanilla-engine UIView.new

메서드methodsetEngine(engine)#0.2.1 부터since 0.2.1소스source

엔진 설정. (구 UIComponent 에서 이관)

Sets the engine. (moved from the former UIComponent)

engineEngine
엔진.Engine.
메서드methodgetEngine()#0.2.1 부터since 0.2.1소스source

엔진 반환. (구 UIComponent 에서 이관)

Returns the engine. (moved from the former UIComponent)

반환ReturnsEngine | null setEngine 으로 준 엔진. (주지 않았으면 null)The engine given with setEngine. (null if not given)

짝Counterpart: vanilla-engine UIView.get_engine

메서드methodattach(node)#0.2.0 부터since 0.2.0소스source

노드에 붙음.

Attached to a node.

nodeComponentNode
붙을 노드.Node to attach to.
메서드methoddetach(node)#0.2.0 부터since 0.2.0소스source

노드에서 떨어짐.

Detached from a node.

nodeComponentNode
떨어질 노드.Node being detached from.
메서드methodisDrawnInsideContent()#0.4.0 부터since 0.4.0소스source

내용 영역 안에서만 그리는지 반환. (배경은 내용 크기의 사각형만 칠한다, 화면 밖과 자르기 밖 거르기가 쓴다)

  • draw 를 덮어쓴 하위 클래스는 어디에 그리는지 모르므로 false. (그 클래스가 이 함수도 덮어써 알린다)

Returns whether it draws only inside the content area. (the background fills only the content-size rectangle; used by off-screen and outside-clip culling)

  • Subclasses that override draw return false because where they draw is unknown. (such a class overrides this function too to report it)

반환Returnsboolean 내용 영역 안에서만 그리면 참.True if drawing only inside the content area.

메서드methodwriteGeometryKey(geometryKey)#0.4.0 부터since 0.4.0소스source

그리기 입력을 기하 캐시 열쇠에 적기. (배경색, 내용 크기)

  • draw 를 덮어쓴 하위 클래스는 무엇을 읽는지 모르므로 false. (그 클래스가 이 함수도 덮어써 알린다)

Writes the draw inputs to the geometry cache key. (background color, content size)

  • A subclass that overrides draw returns false because what it reads is unknown. (that class overrides this function too to report them)
geometryKeyGeometryKey
입력을 적을 열쇠.Key to write the inputs to.

반환Returnsboolean 입력을 적었으면 참.True if the inputs were written.

메서드methoddraw(graphic)#0.2.0 부터since 0.2.0소스source

출력. (배경색이 설정된 경우 스크롤뷰 영역에 배경을 그린다)

Draw. (draws the background in the scroll view area if a background color is set)

graphicGraphic
그래픽.Graphics.
메서드methodsetBackdropBlur(blurRadius)#0.4.0 부터since 0.4.0소스source

뒤 화면 흐림 설정. (CSS backdrop-filter: blur(), 언리얼 UMG BackgroundBlur 와 같은 뜻)

  • 켜면 이 뷰가 그려질 때, 그보다 먼저 그려진 화면을 이 뷰의 내용 영역만 흐리고 그 위에 배경색(반투명)을 얹는다.
  • 인자는 CSS backdrop-filter: blur(Npx) 의 N 과 같은 표준편차다. (노드 좌표 단위, 화면에서는 변환 배율을 곱한 기기 픽셀)
  • 흐림은 ScreenEffect 의 gaussianBlur(분리형 가우스, 선형 샘플링, 3 시그마까지, 모서리는 거울 접기)다. 크롬의 backdrop-filter 와 같다.
  • 화면에 그릴 때만 된다. (렌더 타겟에 그리는 중이면 흐리지 않는다) 켜진 동안은 기하 캐시를 쓰지 않는다. (매 그리기마다 화면을 읽는다)

Sets the backdrop blur. (same meaning as CSS backdrop-filter: blur() and Unreal UMG BackgroundBlur)

  • When on, as this view is drawn it blurs what was drawn before it, only inside this view's content area, then lays the (translucent) background color on top.
  • The argument is the standard deviation, the same as the N of CSS backdrop-filter: blur(Npx). (in node coordinate units, on screen multiplied by the transform scale into device pixels)
  • The blur is ScreenEffect's gaussianBlur (separable Gaussian, linear sampling, up to 3 sigma, edges folded as a mirror). It matches Chrome's backdrop-filter.
  • It works only when drawing to the screen. (it does not blur while drawing into a render target) While on, the geometry cache is not used. (the screen is read on every draw)
blurRadiusnumber
흐림 표준편차. (CSS blur(Npx) 의 N, 노드 좌표 단위, 0 이하면 끈다, 처음은 0)Blur standard deviation. (the N of CSS blur(Npx), in node coordinate units, 0 or less turns it off, initially 0)

짝Counterpart: vanilla-engine UIView.set_backdrop_blur

예제Example반투명 패널 뒤를 흐리기Blurring behind a translucent panel
import { UIView, Color } from "./build/vanilla.js";

const view = new UIView();
view.setBackgroundColor(new Color(1, 1, 1, 0.25));
view.setBackdropBlur(6);
console.log(view.getBackdropBlur());
메서드methodsetBackdropCornerRadius(cornerRadius)#0.4.0 부터since 0.4.0소스source

뒤 화면 흐림과 바탕색의 둥근 모서리 설정. (CSS border-radius 와 같은 뜻)

  • 흐림이 켜져 있을 때 흐림 영역과 바탕색이 이 반지름의 둥근 사각형 안에만 깔린다. (모서리 바깥은 뒤 화면 그대로)

Sets the rounded corners of the backdrop blur and background color. (same meaning as CSS border-radius)

  • While the blur is on, the blur area and the background color are laid only inside a rounded rectangle of this radius. (outside the corners the screen behind stays as it is)
cornerRadiusnumber
모서리 반지름. (노드 좌표 단위, 0 이하면 사각형, 처음은 0)Corner radius. (in node coordinate units, 0 or less makes a rectangle, initially 0)
예제Example둥근 단추 모양으로 뒤 흐리기Blurring behind a rounded button shape
import { UIView, Color } from "./build/vanilla.js";

const view = new UIView();
view.setBackgroundColor(new Color(1, 1, 1, 0.25));
view.setBackdropBlur(6);
view.setBackdropCornerRadius(12);
console.log(view.getBackdropCornerRadius());
메서드methodgetBackdropCornerRadius()#0.4.0 부터since 0.4.0소스source

뒤 화면 흐림의 둥근 모서리 반지름 반환.

Returns the rounded corner radius of the backdrop blur.

반환Returnsnumber 모서리 반지름. (노드 좌표 단위, 0 이면 사각형)Corner radius. (in node coordinate units, 0 makes a rectangle)

메서드methodgetBackdropBlur()#0.4.0 부터since 0.4.0소스source

뒤 화면 흐림 반지름 반환.

Returns the backdrop blur radius.

반환Returnsnumber 흐림 표준편차. (CSS blur(Npx) 의 N, 0 이면 꺼짐)Blur standard deviation. (the N of CSS blur(Npx), 0 means off)

짝Counterpart: vanilla-engine UIView.get_backdrop_blur

메서드methodtouchPress(viewInputPosition)#0.2.0 부터since 0.2.0소스source

터치 누름. (TouchRaycaster → WorldNode)

Touch press. (TouchRaycaster → WorldNode)

viewInputPositionVector2
누른 자리. (뷰 좌표)Press position. (view coordinates)
메서드methodtouchMove(viewInputPosition)#0.2.0 부터since 0.2.0소스source

터치 이동. (TouchRaycaster → WorldNode)

Touch move. (TouchRaycaster → WorldNode)

viewInputPositionVector2
옮긴 자리. (뷰 좌표)Moved position. (view coordinates)
메서드methodtouchRelease(viewInputPosition)#0.2.0 부터since 0.2.0소스source

터치 뗌. (TouchRaycaster → WorldNode)

Touch release. (TouchRaycaster → WorldNode)

viewInputPositionVector2
뗀 자리. (뷰 좌표)Release position. (view coordinates)
메서드methodtouchCancel(viewInputPosition)#0.2.0 부터since 0.2.0소스source

터치 취소. (TouchRaycaster → WorldNode)

Touch cancel. (TouchRaycaster → WorldNode)

viewInputPositionVector2
취소된 때의 자리. (뷰 좌표)Position at cancel. (view coordinates)
메서드methodgetContent()#0.2.0 부터since 0.2.0소스source

콘텐츠 노드 반환. (자식 노드를 이 노드에 추가하면 스크롤 대상이 됨)

Returns the content node. (child nodes added to this node become scroll targets)

반환ReturnsWorldNode 컨텐트 노드. (노드에 붙기 전이면 null)Content node. (null before being attached to a node)

짝Counterpart: vanilla-engine UIButton.get_content

메서드methodsetBackgroundColor(backgroundColor)#0.2.0 부터since 0.2.0소스source

배경색 설정. (null 이면 배경을 지운다)

Sets the background color. (null clears the background)

backgroundColorColor | null
배경색. (사본을 담는다, 알파가 0 이면 그리지 않는다, null 이나 undefined 면 처음 값인 알파 0 흰색으로 돌려 그리지 않는다)Background color. (A copy is kept, nothing is drawn when alpha is 0, null or undefined resets it to the initial transparent white so nothing is drawn)

짝Counterpart: vanilla-engine UIControl.set_background_color

예제Example배경을 칠했다가 지우기Paint a background and clear it
import { UIView, Color } from "./build/vanilla.js";

const view = new UIView();
view.setBackgroundColor(new Color(0.1, 0.12, 0.16, 1));
const paintedColor = view.getBackgroundColor();
view.setBackgroundColor(null);
const clearedColor = view.getBackgroundColor();
console.log(paintedColor.alpha, clearedColor.alpha);
메서드methodgetBackgroundColor()#0.2.0 부터since 0.2.0소스source

배경색 반환.

Returns the background color.

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

짝Counterpart: vanilla-engine UIControl.get_background_color

함수Functions

함수functionisViewPositionInsideNode(node, viewPosition)#0.4.0 부터since 0.4.0소스source

뷰 좌표의 점이 노드 내용 영역 안인지. (부모들의 변환을 모두 거친 네 귀퉁이로 본다, 러스트 판 ui::uiview::is_view_position_inside_node)

Whether a point in view coordinates is inside the node's content area. (Tested with the four corners after all parent transforms, Rust edition ui::uiview::is_view_position_inside_node)

nodeWorldNode | null
볼 노드. (없으면 거짓)Node to test. (false if none)
viewPositionVector2
뷰 좌표의 점. (픽셀)A point in view coordinates. (pixels)

반환Returnsboolean 노드 contentSize 영역 안이면 참.True if inside the node's contentSize area.

짝Counterpart: vanilla-engine is_view_position_inside_node

예제Example가운데 피봇(기본)인 40 x 20 노드의 안과 밖Inside and outside a 40 x 20 node with the center pivot (default)
import { isViewPositionInsideNode, Vector2, WorldNode } from "./build/vanilla.js";

const rootNode = new WorldNode();
const buttonNode = new WorldNode();
rootNode.addChild(buttonNode);
buttonNode.setLocalPosition(Vector2.create(100, 100));
buttonNode.setContentSize(Vector2.create(40, 20));
console.log(isViewPositionInsideNode(buttonNode, Vector2.create(100, 100)));
console.log(isViewPositionInsideNode(buttonNode, Vector2.create(81, 91)));
console.log(isViewPositionInsideNode(buttonNode, Vector2.create(79, 100)));