ui/uiview
뷰 컴포넌트. (원본 ui/uiview.js 의 UIView)
- 모든 UI 위젯의 바탕. 노드(호스트)에 붙으면 호스트 아래에 "content" 자식 노드를 만든다. (피봇 왼쪽 위, 앵커 0,0, 자리 0,0)
- 배경색의 알파가 0 보다 크면 호스트 content_size 영역을 그 색으로 칠한다.
- 원본은 UILabel, UIButton 같은 위젯이 UIView 를 상속한다. 러스트 판은 위젯이 UIView 를 품고(ui_view 필드) content, 배경색을 넘겨준다. 그래서 원본의 node.get_component(UIView) 로 하위 위젯까지 한 번에 찾는 쓰임은 없다. (
get_component::<UIButton>()처럼 구체 타입으로 찾는다) - content 노드는 attach_to_tree 에서 만든다. node_tree.add_component(node_id, UIView::new()) 로 붙여야 한다.
- 원본의 setEngine / get_engine 은 옮기지 않았다. 엔진은 tick / 터치 때 ComponentContext::get_engine 으로 얻는다.
- 원본 setBackgroundColor(null) 은 배경을 지운다. (처음 값인 알파 0 흰색으로 돌린다) 러스트 판은 None 자리가 없어 알파 0 색(처음 값이나 Color::transparent())을 준다.
View component. (UIView of the original ui/uiview.js)
- The base of all UI widgets. When attached to a node (host), creates a "content" child node under the host. (top-left pivot, anchor 0,0, position 0,0)
- If the background color's alpha is greater than 0, paints the host's content_size area with that color.
- In the original, widgets like UILabel and UIButton inherit UIView. In the Rust version, widgets embed UIView (ui_view field) and pass through content and the background color. So the original usage of finding subclass widgets at once with node.get_component(UIView) does not exist. (look them up by concrete type, like
get_component::<UIButton>()) - The content node is created in attach_to_tree. It must be attached with node_tree.add_component(node_id, UIView::new()).
- The original setEngine / get_engine were not ported. The engine is obtained with ComponentContext::get_engine during tick / touch.
- The original setBackgroundColor(null) clears the background. (returns to the initial value, white with alpha 0) The Rust version has no None, so give a color with alpha 0 (the initial value or Color::transparent()).
UIViewstruct traits Default, Component
뷰 컴포넌트.
- 노드에 붙이면 호스트 아래 content 자식 노드를 만들고, 배경색으로 호스트 content_size 영역을 칠한다.
View component.
- When attached to a node, creates a content child node under the host and paints the host's content_size area with the background color.
use vanilla::{Color, NodeTree, UIView, Vector2};
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let panel_id = node_tree.create_child(root_id, "panel");
node_tree[panel_id].set_content_size(Vector2::create(200.0, 100.0));
let panel_view = node_tree.add_component(panel_id, UIView::new()).unwrap();
panel_view.set_background_color(Color::create(0.1, 0.1, 0.2, 0.8));
let content_id = panel_view.get_content().unwrap();
assert_eq!(node_tree.get_parent_id(content_id), Some(panel_id));
assert_eq!(node_tree[content_id].get_name(), "content");생성. (배경은 투명한 흰색)
Constructor. (the background is transparent white)
반환ReturnsUIView 새 뷰. (content 노드는 트리에 붙일 때 만든다)New view. (the content node is created when attached to a tree)
짝Counterpart: vanilla.js UIView.constructor
컨텐트 노드 만들기. (호스트의 자식, 왼쪽 위 정렬. 이미 있으면 그대로 둔다)
Creates the content node. (a child of the host, aligned to the top left. left as is if it already exists)
- node_tree&mut NodeTree
- 호스트가 든 트리.Tree that holds the host.
- node_idNodeId
- 호스트 노드. (content 노드가 이 노드의 자식이 된다)Host node. (the content node becomes a child of this node)
뒤 화면 흐림 설정. (CSS backdrop-filter: blur(), 언리얼 UMG BackgroundBlur 와 같은 뜻, 원본 setBackdropBlur)
- 켜면 이 뷰가 그려질 때, 그보다 먼저 그려진 화면을 이 뷰의 내용 영역만 흐리고 그 위에 배경색(반투명)을 얹는다.
- 인자는 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, original setBackdropBlur)
- 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)
- blur_radiusf64
- 흐림 표준편차. (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, default 0)
짝Counterpart: vanilla.js UIView.setBackdropBlur
use vanilla::{Color, UIView};
let mut view = UIView::new();
view.set_background_color(Color::create(1.0, 1.0, 1.0, 0.25));
view.set_backdrop_blur(6.0);
assert_eq!(view.get_backdrop_blur(), 6.0);뒤 화면 흐림과 바탕색의 둥근 모서리 설정. (CSS border-radius 와 같은 뜻, 원본 setBackdropCornerRadius)
- 흐림이 켜져 있을 때 흐림 영역과 바탕색이 이 반지름의 둥근 사각형 안에만 깔린다. (모서리 바깥은 뒤 화면 그대로)
Sets the rounded corners of the backdrop blur and background color. (same meaning as CSS border-radius, original setBackdropCornerRadius)
- 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)
- corner_radiusf64
- 모서리 반지름. (노드 좌표 단위, 0 이하면 사각형, 기본 0)Corner radius. (in node coordinate units, 0 or less makes a rectangle, default 0)
짝Counterpart: vanilla.js UIView.setBackdropCornerRadius
use vanilla::{Color, UIView};
let mut view = UIView::new();
view.set_background_color(Color::create(1.0, 1.0, 1.0, 0.25));
view.set_backdrop_blur(6.0);
view.set_backdrop_corner_radius(12.0);
assert_eq!(view.get_backdrop_corner_radius(), 12.0);뒤 화면 흐림의 둥근 모서리 반지름 반환.
Returns the rounded corner radius of the backdrop blur.
반환Returnsf64 모서리 반지름. (노드 좌표 단위, 0 이면 사각형)Corner radius. (in node coordinate units, 0 makes a rectangle)
짝Counterpart: vanilla.js UIView.getBackdropCornerRadius
뒤 화면 흐림 반지름 반환.
Returns the backdrop blur radius.
반환Returnsf64 흐림 표준편차. (CSS blur(Npx) 의 N, 0 이면 꺼짐)Blur standard deviation. (the N of CSS blur(Npx), 0 means off)
짝Counterpart: vanilla.js UIView.getBackdropBlur
컨텐트 노드 핸들. (자식 노드를 여기에 붙이면 스크롤 대상이 된다. 트리에 붙기 전이면 None)
Content node handle. (child nodes attached here become scroll targets. None before being attached to a tree)
반환ReturnsOption<NodeId> content 노드. 트리에 붙기 전이면 None.content node. None before being attached to a tree.
짝Counterpart: vanilla.js UIView.getContent
배경색 설정. (알파가 0 이면 그리지 않는다. 원본 null 처럼 배경을 지우려면 알파 0 색을 준다)
Sets the background color. (not drawn if alpha is 0. To clear the background like the original null, give a color with alpha 0)
- background_colorimpl Into<Color>
- 배경색. (Color 나 "#rrggbb" 같은 글, 알파가 0 이면 칠하지 않는다)Background color. (a Color or text like "#rrggbb", not painted if alpha is 0)
짝Counterpart: vanilla.js UIView.setBackgroundColor
배경색 반환.
Returns the background color.
반환ReturnsColor 배경색. (기본은 알파 0 인 흰색)Background color. (default is white with alpha 0)
짝Counterpart: vanilla.js UIView.getBackgroundColor
pub fn get_engine(&self) -> Result<&'static crate::core::engine::Engine, crate::core::globalengine::EngineAccessError>#엔진 반환. (원본 getEngine, 원본 setEngine 으로 준 엔진 자리. 러스트 판은 엔진이 하나라 전역 엔진을 준다)
- Engine::get_engine 과 같다. 엔진을 만든 직후부터 어디서나 꺼낸다.
Returns the engine. (the original getEngine, in place of the engine given with the original setEngine. The Rust version has one engine, so it gives the global engine)
- The same as Engine::get_engine. It is taken anywhere right after the engine is created.
반환ReturnsResult<&'static crate::core::engine::Engine, crate::core::globalengine::EngineAccessError> 전역 엔진, 못 꺼내면 그 까닭.The global engine, or the reason it could not be taken.
짝Counterpart: vanilla.js UIView.getEngine
배경 출력. (투명한 바탕은 그리지 않는다. 보이지 않는 드로우가 묶어 그리기를 끊지 않게)
Draws the background. (a transparent background is not drawn, so invisible draws do not break batching)
- transform&NodeTransform
- 호스트 노드의 변환. (content_size 영역 (0, 0) ~ (너비, 높이) 를 칠한다)Transform of the host node. (paints the content_size area (0, 0) ~ (width, height))
- graphic&mut Graphic
- 그릴 그래픽.Graphic to draw with.
함수Functions
pub fn is_view_position_inside_node(node_tree: &NodeTree, node_id: NodeId, view_position: Vector2) -> bool#뷰 좌표의 점이 노드 content_size 영역 안에 있는지. (원본 WorldNode.contains)
Whether a point in view coordinates is inside the node's content_size area. (original WorldNode.contains)
- node_tree&NodeTree
- 노드가 든 트리.Tree holding the node.
- node_idNodeId
- 볼 노드.Node to look at.
- view_positionVector2
- 뷰 좌표의 점. (픽셀)Point in view coordinates. (pixels)
반환Returnsbool 노드까지 누적한 월드 행렬로 본 노드 content_size 영역 안이면 true. 노드가 없으면 false.true if inside the node's content_size area as seen through the world matrix accumulated down to the node. false if there is no node.
짝Counterpart: vanilla.js isViewPositionInsideNode
use vanilla::ui::uiview::is_view_position_inside_node;
use vanilla::{NodeTree, Vector2};
let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let button_id = node_tree.create_child(root_id, "button");
node_tree[button_id].set_local_position(Vector2::create(100.0, 100.0));
node_tree[button_id].set_content_size(Vector2::create(40.0, 20.0));
assert!(is_view_position_inside_node(&node_tree, button_id, Vector2::create(100.0, 100.0)));
assert!(is_view_position_inside_node(&node_tree, button_id, Vector2::create(81.0, 91.0)));
assert!(!is_view_position_inside_node(&node_tree, button_id, Vector2::create(79.0, 100.0)));