vanilladocs
vanillapunch.com
API / ui/uinode

ui/uinode

UI 노드. (원본 ui/uinode.js 의 UINode)

  • 영역을 솔버 변수 8 개(left, right, top, bottom, width, height, 파생 center_x, center_y)로 나타내고, 사용자가 LayoutSolver 에 제약을 걸어 그 값들을 정한다. 본질 제약 4 개(right == left + width, bottom == top + height, center_x == left + width / 2, center_y == top + height / 2)는 스스로 등록한다.
  • 사용자 제약은 add_constraint 로 등록한다. 솔버는 set_solver 로 붙인다. (UISceneBase 는 트리의 UINode 에 씬의 솔버를 스스로 붙인다)
  • intrinsic content size, content hugging, compression resistance, layout margins, layout margins guide 는 UIKit 의 같은 이름 API 와 같은 생각이다.
  • 솔버 변수(left, top)는 UI 트리 뿌리가 놓인 좌표계 기준의 절대 위치다. 부모도 UINode 면 자식은 (left - 부모 left, top - 부모 top) 만큼 떨어져 놓인다. 회전, 배율, 투명도는 노드의 것을 그대로 쓴다.
  • 사용:
let node_id = node_tree.create_child(parent_id, "title");
node_tree.add_component(node_id, UINode::new());
node_tree.with_component_mut::<UINode, _>(node_id, |ui_node, _tree| {
    ui_node.add_constraint(&ui_node.left_anchor().equal_to(screen_node.left_anchor().add(16))).unwrap();
});
  • 원본과 다른 것:
  • 원본은 TransformNode 를 상속한 따로 된 노드이고 pushTransform 에서 솔버 값으로 옮긴다. 러스트 판은 노드가 WorldNode 하나뿐이라 WorldNode 에 붙는 컴포넌트이고, 솔버 값을 노드의 자리(local_position, 피봇과 앵커는 왼쪽 위)와 content_size 로 옮긴다. 옮기는 때는 컴포넌트 tick 과 apply_layout_in_tree(UISceneBase 가 솔버를 푼 바로 뒤에 부른다)다. 원본은 그릴 때마다 읽는다.
  • 원본 getIntrinsicContentSize 는 노드의 컴포넌트 가운데 그 함수가 있는 것(Text, RichText)의 값을 모은다. 러스트 판은 Component::get_intrinsic_content_size 를 모은다. 원본 UILabel 은 글이 바뀔 때 노드의 invalidateIntrinsicContentSize 를 부른다. 러스트 판의 컴포넌트는 노드의 다른 컴포넌트를 부를 수 없어서, UINode 가 tick(과 UISceneBase 의 솔버 붙이기)마다 컴포넌트들의 값을 다시 읽어 바뀌었으면 스스로 invalidate 한다.
  • 원본이 예외를 던지는 곳(솔버의 겹친 제약, 만족할 수 없는 required 제약)은 Result<(), LayoutError> 를 돌려준다. (add_constraint, remove_constraint, set_solver, set_layout_margins, invalidate_intrinsic_content_size)
  • 앵커는 원본의 게터 속성(leftAnchor) 대신 함수(left_anchor)다. 축 인자는 문자열 대신 LayoutConstraintAxis 열거라 "지원되지 않는 축" 예외가 없다.
  • layout margins guide 는 원본처럼 트리에 들지 않는 UINode 다. 러스트 판은 이 UINode 가 Box 로 품는다.

UI node. (UINode of the original ui/uinode.js)

  • Represents its area with 8 solver variables (left, right, top, bottom, width, height, derived center_x, center_y), and the user adds constraints to a LayoutSolver to determine those values. It registers the 4 intrinsic constraints (right == left + width, bottom == top + height, center_x == left + width / 2, center_y == top + height / 2) itself.
  • User constraints are registered with add_constraint. The solver is attached with set_solver. (UISceneBase attaches the scene's solver to the UINodes in the tree by itself)
  • intrinsic content size, content hugging, compression resistance, layout margins, layout margins guide are the same concepts as UIKit's APIs of the same names.
  • Solver variables (left, top) are absolute positions in the coordinate system where the UI tree root is placed. If the parent is also a UINode, the child is placed offset by (left - parent left, top - parent top). Rotation, scale and opacity use the node's own as is.
  • Usage:
let node_id = node_tree.create_child(parent_id, "title");
node_tree.add_component(node_id, UINode::new());
node_tree.with_component_mut::<UINode, _>(node_id, |ui_node, _tree| {
    ui_node.add_constraint(&ui_node.left_anchor().equal_to(screen_node.left_anchor().add(16))).unwrap();
});
  • Differences from the original:
  • In the original it is a separate node inheriting TransformNode and moves to the solver values in pushTransform. In the Rust version the only node is WorldNode, so it is a component attached to WorldNode, and moves the solver values to the node's position (local_position, with pivot and anchor at the top left) and content_size. The moves happen in the component tick and in apply_layout_in_tree (called by UISceneBase right after solving). The original reads them on every draw.
  • The original getIntrinsicContentSize gathers the values of the node's components that have that function (Text, RichText). The Rust version gathers Component::get_intrinsic_content_size. The original UILabel calls the node's invalidateIntrinsicContentSize when the text changes. Components in the Rust version cannot call the node's other components, so UINode reads the components' values again every tick (and on UISceneBase's solver attaching) and invalidates by itself if they changed.
  • Where the original throws exceptions (duplicate constraints in the solver, unsatisfiable required constraints), it returns Result<(), LayoutError>. (add_constraint, remove_constraint, set_solver, set_layout_margins, invalidate_intrinsic_content_size)
  • Anchors are functions (left_anchor) instead of the original's getter properties (leftAnchor). The axis argument is the LayoutConstraintAxis enum instead of a string, so there is no "unsupported axis" exception.
  • The layout margins guide is a UINode not in the tree, as in the original. In the Rust version this UINode holds it in a Box.

LayoutMarginsstruct traits Clone, Copy, Debug, PartialEq

소스source

레이아웃 여백. (UIKit 의 UIView.layoutMargins, 원본 { top, left, bottom, right })

  • 만드는 함수의 인자 차례는 위, 왼쪽, 아래, 오른쪽이다.

Layout margins. (UIKit's UIView.layoutMargins, original { top, left, bottom, right })

  • The argument order of the creating function is top, left, bottom, right.
예제Example여백 만들기와 UINode 의 기본 여백Creating margins and the UINode default margins
use vanilla::{LayoutMargins, UINode};

let margins = LayoutMargins::create(4.0, 12.0, 4.0, 12.0);
assert_eq!(margins.top, 4.0);
assert_eq!(margins.left, 12.0);
assert_eq!(UINode::new().get_layout_margins(), LayoutMargins::create(8.0, 8.0, 8.0, 8.0));
정적staticpub fn create(top: f64, left: f64, bottom: f64, right: f64) -> LayoutMargins#0.4.0 부터since 0.4.0소스source

생성.

Constructor.

topf64
위 여백. (픽셀)Top margin. (pixels)
leftf64
왼쪽 여백. (픽셀)Left margin. (pixels)
bottomf64
아래 여백. (픽셀)Bottom margin. (pixels)
rightf64
오른쪽 여백. (픽셀)Right margin. (pixels)

반환ReturnsLayoutMargins 새 여백.New margins.

필드fieldpub top: f64#0.4.0 부터since 0.4.0소스source

위 여백. (픽셀)

Top margin. (pixels)

반환Returnsf64

필드fieldpub left: f64#0.4.0 부터since 0.4.0소스source

왼쪽 여백. (픽셀)

Left margin. (pixels)

반환Returnsf64

필드fieldpub bottom: f64#0.4.0 부터since 0.4.0소스source

아래 여백. (픽셀)

Bottom margin. (pixels)

반환Returnsf64

필드fieldpub right: f64#0.4.0 부터since 0.4.0소스source

오른쪽 여백. (픽셀)

Right margin. (pixels)

반환Returnsf64

UINodestruct traits Default, Component

짝Counterpart: vanilla.js UINode소스source

UI 노드.

  • 노드에 붙는 컴포넌트다. 솔버 변수 8 개와 본질 제약 4 개를 들고, 사용자 제약을 기억해 두었다가 솔버에 건다.

UI node.

  • A component attached to a node. Holds 8 solver variables and 4 intrinsic constraints, and remembers user constraints to add them to the solver.
예제Example화면 가이드에서 16 픽셀 안쪽에 놓인 제목 띠A title band placed 16 pixels inside the screen guide
use vanilla::{LayoutSolver, NodeTree, UINode, Vector2};

let solver = LayoutSolver::new();
let mut screen_node = UINode::new();
screen_node.set_solver(Some(solver.clone())).unwrap();
screen_node.add_constraint(&screen_node.left_anchor().equal_to(0)).unwrap();
screen_node.add_constraint(&screen_node.top_anchor().equal_to(0)).unwrap();
screen_node.add_constraint(&screen_node.width_anchor().equal_to(800)).unwrap();
screen_node.add_constraint(&screen_node.height_anchor().equal_to(600)).unwrap();

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let title_id = node_tree.create_child(root_id, "title");
node_tree.add_component(title_id, UINode::new());
node_tree.with_component_mut::<UINode, _>(title_id, |title, _tree| {
	title.set_solver(Some(solver.clone())).unwrap();
	title.add_constraint(&title.left_anchor().equal_to(screen_node.left_anchor().add(16))).unwrap();
	title.add_constraint(&title.top_anchor().equal_to(screen_node.top_anchor().add(16))).unwrap();
	title.add_constraint(&title.right_anchor().equal_to(screen_node.right_anchor().subtract(16))).unwrap();
	title.add_constraint(&title.height_anchor().equal_to(48)).unwrap();
});
solver.update_variables();
UINode::apply_layout_in_tree(&mut node_tree, root_id);
assert_eq!(node_tree[title_id].get_local_position(), Vector2::create(16.0, 16.0));
assert_eq!(node_tree[title_id].get_content_size(), Vector2::create(768.0, 48.0));
생성자constructorpub fn new() -> UINode#0.4.0 부터since 0.4.0소스source

생성. (본질 제약 4 개를 만든다, hug 250, 압축 저항 750, 여백 8)

Constructor. (creates the 4 intrinsic constraints, hug 250, compression resistance 750, margins 8)

반환ReturnsUINode 솔버가 없는 새 UI 노드. (본질 제약은 지어 두고 솔버를 붙일 때 건다)A new UI node without a solver. (the intrinsic constraints are built in advance and added when a solver is attached)

짝Counterpart: vanilla.js UINode.constructor

정적staticpub fn collect_intrinsic_content_size(node: &WorldNode) -> Vector2#0.4.0 부터since 0.4.0소스source

노드 컴포넌트들의 intrinsic content size 모으기. (원본 getIntrinsicContentSize 기본 구현, 정적)

Gathers the intrinsic content size of the node's components. (the original getIntrinsicContentSize default implementation, static)

node&WorldNode
컴포넌트를 볼 노드.Node whose components to look at.

반환ReturnsVector2 컴포넌트들의 get_intrinsic_content_size 를 축마다 큰 쪽으로 모은 값. (모두 선호가 없거나 컴포넌트가 없으면 NO_INTRINSIC_METRIC)The components' get_intrinsic_content_size gathered by the larger value on each axis. (NO_INTRINSIC_METRIC if none have a preference or there are no components)

정적staticpub fn apply_layout_in_tree(node_tree: &mut NodeTree, node_id: NodeId)#0.4.0 부터since 0.4.0소스source

노드 아래 모든 UINode 의 솔버 값을 노드에 옮기기. (UISceneBase 가 솔버를 푼 바로 뒤에 부른다, 정적)

Moves the solver values of all UINodes under the node onto the nodes. (called by UISceneBase right after solving, static)

node_tree&mut NodeTree
노드가 든 트리.Tree holding the node.
node_idNodeId
옮기기를 시작할 노드. (이 노드와 그 아래 모든 노드)Node to start moving from. (this node and all nodes under it)
정적staticpub fn attach_pending_in_tree(node_tree: &mut NodeTree, node_id: NodeId, solver: &LayoutSolver)#0.4.0 부터since 0.4.0소스source

노드 아래 솔버가 없는 UINode 에 솔버를 붙이고 intrinsic content size 를 다시 읽기. (UISceneBase 가 tick 마다 부른다, 원본 attachPendingUINodes)

Attaches the solver to UINodes under the node that have no solver, and reads the intrinsic content size again. (called by UISceneBase every tick, original attachPendingUINodes)

node_tree&mut NodeTree
노드가 든 트리.Tree holding the node.
node_idNodeId
찾기를 시작할 노드. (이 노드와 그 아래 모든 노드)Node to start searching from. (this node and all nodes under it)
solver&LayoutSolver
솔버가 없는 UINode 에 붙일 솔버. (붙이거나 intrinsic content size 를 다시 걸다 생긴 오류는 버린다)Solver to attach to UINodes without a solver. (errors from attaching or adding the intrinsic content size again are discarded)
예제Example솔버 없이 제약만 걸어 둔 노드에 나중에 솔버를 붙여 놓기Attaching a solver later to a node that only had constraints added without a solver, and laying it out
use vanilla::{LayoutSolver, NodeTree, UINode, Vector2};

let mut node_tree = NodeTree::new();
let root_id = node_tree.get_root_id();
let box_id = node_tree.create_child(root_id, "box");
node_tree.add_component(box_id, UINode::new());
node_tree.with_component_mut::<UINode, _>(box_id, |ui_node, _tree| {
	ui_node.add_constraint(&ui_node.left_anchor().equal_to(10)).unwrap();
	ui_node.add_constraint(&ui_node.top_anchor().equal_to(20)).unwrap();
	ui_node.add_constraint(&ui_node.width_anchor().equal_to(30)).unwrap();
	ui_node.add_constraint(&ui_node.height_anchor().equal_to(40)).unwrap();
});
let solver = LayoutSolver::new();
UINode::attach_pending_in_tree(&mut node_tree, root_id, &solver);
solver.update_variables();
UINode::apply_layout_in_tree(&mut node_tree, root_id);
assert_eq!(node_tree[box_id].get_local_position(), Vector2::create(10.0, 20.0));
assert_eq!(node_tree[box_id].get_content_size(), Vector2::create(30.0, 40.0));
메서드methodpub fn get_content_size(&self) -> Vector2#0.4.0 부터since 0.4.0소스source

컨텐트 크기 반환. (솔버가 푼 width, height)

Returns the content size. (width, height solved by the solver)

반환ReturnsVector2 (width, height) 의 f64 값. (update_variables 뒤에 맞는 값)f64 values of (width, height). (correct after update_variables)

짝Counterpart: vanilla.js UINode.getContentSize

메서드methodpub fn build_intrinsic_constraints(&self) -> Vec<LayoutConstraint>#0.4.0 부터since 0.4.0소스source

본질 제약 4 개 생성.

  • right == left + width, bottom == top + height, center_x == left + width / 2, center_y == top + height / 2

Creates the 4 intrinsic constraints.

  • right == left + width, bottom == top + height, center_x == left + width / 2, center_y == top + height / 2

반환ReturnsVec<LayoutConstraint> 본질 제약 4 개. (부를 때마다 새로 만든 제약이라 솔버에 건 것과 같은 제약이 아니다)The 4 intrinsic constraints. (newly created on every call, so not the same constraints as those added to the solver)

짝Counterpart: vanilla.js UINode.buildIntrinsicConstraints

메서드methodpub fn build_intrinsic_size_constraints(&self) -> Vec<LayoutConstraint>#0.4.0 부터since 0.4.0소스source

intrinsic content size 기반 제약(hug, compression resistance) 생성. (축의 값이 NO_INTRINSIC_METRIC 이면 그 축은 만들지 않는다)

  • hug: width <= intrinsic_width @ hugging, compression: width >= intrinsic_width @ compression resistance

Creates intrinsic content size based constraints (hug, compression resistance). (an axis whose value is NO_INTRINSIC_METRIC is not created)

  • hug: width <= intrinsic_width @ hugging, compression: width >= intrinsic_width @ compression resistance

반환ReturnsVec<LayoutConstraint> 선호가 있는 축마다 hug 와 압축 저항 제약 2 개씩, 0 ~ 4 개. (새로 만든 제약)Two constraints, hug and compression resistance, for each axis with a preference, 0 ~ 4 in total. (newly created constraints)

짝Counterpart: vanilla.js UINode.buildIntrinsicSizeConstraints

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

intrinsic content size 반환. (노드 컴포넌트들의 값의 큰 쪽, 마지막으로 읽은 값. 축마다 NO_INTRINSIC_METRIC 이면 선호 없음)

Returns the intrinsic content size. (the larger of the node components' values, the last read value. No preference on an axis that is NO_INTRINSIC_METRIC)

반환ReturnsVector2 마지막으로 읽은 intrinsic content size. (처음은 두 축 모두 NO_INTRINSIC_METRIC)The last read intrinsic content size. (initially NO_INTRINSIC_METRIC on both axes)

짝Counterpart: vanilla.js UINode.getIntrinsicContentSize

메서드methodpub fn set_intrinsic_content_size(&mut self, intrinsic_content_size: Vector2) -> Result<(), LayoutError>#0.4.0 부터since 0.4.0소스source

intrinsic content size 를 바꾸고 바뀌었으면 제약을 다시 건다. (UISceneBase 와 tick 이 노드 컴포넌트에서 읽어 부른다)

Changes the intrinsic content size and adds the constraints again if it changed. (UISceneBase and tick read it from the node components and call this)

intrinsic_content_sizeVector2
새 intrinsic content size. (픽셀, 축마다 NO_INTRINSIC_METRIC 이면 선호 없음)New intrinsic content size. (pixels, no preference on an axis that is NO_INTRINSIC_METRIC)

반환ReturnsResult<(), LayoutError> Ok(()). 값이 같으면 아무것도 하지 않는다. 솔버에서 옛 제약을 빼거나 새 제약을 걸다 실패하면 그 LayoutError.Ok(()). Does nothing if the value is the same. The LayoutError if removing the old constraints from the solver or adding the new ones fails.

예제Example다른 제약이 없으면 너비와 높이가 자연 크기를 따른다Without other constraints, width and height follow the natural size
use vanilla::{LayoutSolver, UINode, Vector2};

let solver = LayoutSolver::new();
let mut label = UINode::new();
label.set_solver(Some(solver.clone())).unwrap();
label.add_constraint(&label.left_anchor().equal_to(10)).unwrap();
label.add_constraint(&label.top_anchor().equal_to(5)).unwrap();
label.set_intrinsic_content_size(Vector2::create(120.0, 30.0)).unwrap();
solver.update_variables();
assert!((label.get_width() - 120.0).abs() < 0.001);
assert!((label.get_height() - 30.0).abs() < 0.001);
메서드methodpub fn invalidate_intrinsic_content_size(&mut self) -> Result<(), LayoutError>#0.4.0 부터since 0.4.0소스source

intrinsic content size 무효화. (UIKit 의 invalidateIntrinsicContentSize, 솔버의 옛 제약을 빼고 새 값으로 다시 건다)

Invalidates the intrinsic content size. (UIKit's invalidateIntrinsicContentSize, removes the solver's old constraints and adds them again with the new value)

반환ReturnsResult<(), LayoutError> Ok(()). 솔버가 없으면 제약만 다시 짓는다. 솔버에서 옛 제약을 빼거나 새 제약을 걸다 실패하면 그 LayoutError.Ok(()). Without a solver, only rebuilds the constraints. The LayoutError if removing the old constraints from the solver or adding the new ones fails.

짝Counterpart: vanilla.js UINode.invalidateIntrinsicContentSize

메서드methodpub fn get_content_hugging_priority(&self, axis: LayoutConstraintAxis) -> f64#0.4.0 부터since 0.4.0소스source

content hugging 우선순위 반환. (UIKit 의 contentHuggingPriority(for:))

Returns the content hugging priority. (UIKit's contentHuggingPriority(for:))

axisLayoutConstraintAxis
볼 축.Axis to check.

반환Returnsf64 그 축의 hug 우선순위. (기본 250)Hug priority of that axis. (default 250)

짝Counterpart: vanilla.js UINode.getContentHuggingPriority

메서드methodpub fn set_content_hugging_priority(&mut self, priority: f64, axis: LayoutConstraintAxis) -> Result<(), LayoutError>#0.4.0 부터since 0.4.0소스source

content hugging 우선순위 설정. (intrinsic size 제약을 바로 다시 건다)

Sets the content hugging priority. (adds the intrinsic size constraints again right away)

priorityf64
hug 우선순위. (UIKit 꼴 1 ~ 1000, LayoutStrength::from_priority 로 강도가 된다)Hug priority. (UIKit-style 1 ~ 1000, becomes a strength through LayoutStrength::from_priority)
axisLayoutConstraintAxis
바꿀 축.Axis to change.

반환ReturnsResult<(), LayoutError> Ok(()). intrinsic size 제약을 다시 걸다 실패하면 그 LayoutError.Ok(()). The LayoutError if adding the intrinsic size constraints again fails.

짝Counterpart: vanilla.js UINode.setContentHuggingPriority

예제Examplehug 를 바라는 너비(우선순위 500)보다 높이면 자연 너비로 줄어든다Raising hug above the desired width (priority 500) shrinks it to the natural width
use vanilla::{LayoutConstraintAxis, LayoutSolver, LayoutStrength, UINode, Vector2};

let solver = LayoutSolver::new();
let mut label = UINode::new();
label.set_solver(Some(solver.clone())).unwrap();
label.add_constraint(&label.left_anchor().equal_to(0)).unwrap();
label.add_constraint(&label.top_anchor().equal_to(0)).unwrap();
label.set_intrinsic_content_size(Vector2::create(120.0, 30.0)).unwrap();
label.add_constraint(&label.width_anchor().equal_to(200).with_strength(LayoutStrength::from_priority(500.0))).unwrap();
solver.update_variables();
assert!((label.get_width() - 200.0).abs() < 0.001);

label.set_content_hugging_priority(600.0, LayoutConstraintAxis::Horizontal).unwrap();
solver.update_variables();
assert!((label.get_width() - 120.0).abs() < 0.001);
메서드methodpub fn get_content_compression_resistance_priority(&self, axis: LayoutConstraintAxis) -> f64#0.4.0 부터since 0.4.0소스source

content compression resistance 우선순위 반환.

Returns the content compression resistance priority.

axisLayoutConstraintAxis
볼 축.Axis to check.

반환Returnsf64 그 축의 압축 저항 우선순위. (기본 750)Compression resistance priority of that axis. (default 750)

짝Counterpart: vanilla.js UINode.getContentCompressionResistancePriority

메서드methodpub fn set_content_compression_resistance_priority(&mut self, priority: f64, axis: LayoutConstraintAxis) -> Result<(), LayoutError>#0.4.0 부터since 0.4.0소스source

content compression resistance 우선순위 설정. (intrinsic size 제약을 바로 다시 건다)

Sets the content compression resistance priority. (adds the intrinsic size constraints again right away)

priorityf64
압축 저항 우선순위. (UIKit 꼴 1 ~ 1000, LayoutStrength::from_priority 로 강도가 된다)Compression resistance priority. (UIKit-style 1 ~ 1000, becomes a strength through LayoutStrength::from_priority)
axisLayoutConstraintAxis
바꿀 축.Axis to change.

반환ReturnsResult<(), LayoutError> Ok(()). intrinsic size 제약을 다시 걸다 실패하면 그 LayoutError.Ok(()). The LayoutError if adding the intrinsic size constraints again fails.

짝Counterpart: vanilla.js UINode.setContentCompressionResistancePriority

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

layout margins 반환. (UIKit 의 UIView.layoutMargins)

Returns the layout margins. (UIKit's UIView.layoutMargins)

반환ReturnsLayoutMargins 여백. (기본은 네 쪽 모두 8)Margins. (default 8 on all four sides)

짝Counterpart: vanilla.js UINode.getLayoutMargins

메서드methodpub fn set_layout_margins(&mut self, layout_margins: LayoutMargins) -> Result<(), LayoutError>#0.4.0 부터since 0.4.0소스source

layout margins 설정. (가이드가 이미 있으면 가이드 제약을 바로 다시 건다)

Sets the layout margins. (if the guide already exists, adds the guide constraints again right away)

layout_marginsLayoutMargins
새 여백.New margins.

반환ReturnsResult<(), LayoutError> Ok(()). 가이드가 아직 없으면 값만 바꾼다. 가이드 제약을 다시 걸다 실패하면 그 LayoutError.Ok(()). If the guide does not exist yet, only changes the value. The LayoutError if adding the guide constraints again fails.

짝Counterpart: vanilla.js UINode.setLayoutMargins

메서드methodpub fn get_layout_margins_guide(&mut self) -> &UINode#0.4.0 부터since 0.4.0소스source

layout margins guide 반환. (UIKit 의 UIView.layoutMarginsGuide, 처음 부를 때 만들고 여백 제약 4 개를 건다)

  • 가이드는 트리에 들지 않아 그려지지 않고 앵커만 쓴다. 여백 제약이 솔버와 부딪히면 가이드는 만들되 그 제약은 걸리지 않는다.

Returns the layout margins guide. (UIKit's UIView.layoutMarginsGuide, created on the first call with 4 margin constraints added)

  • The guide is not in the tree, so it is not drawn and only its anchors are used. If the margin constraints conflict with the solver, the guide is created but those constraints are not added.

반환Returns&UINode 여백 가이드 UINode 의 참조. (앵커와 변수만 쓴다)Reference to the margins guide UINode. (only its anchors and variables are used)

짝Counterpart: vanilla.js UINode.getLayoutMarginsGuide

예제Example300 x 200 판의 여백 가이드Margins guide of a 300 x 200 panel
use vanilla::{LayoutMargins, LayoutSolver, UINode};

let solver = LayoutSolver::new();
let mut panel = UINode::new();
panel.set_solver(Some(solver.clone())).unwrap();
panel.add_constraint(&panel.left_anchor().equal_to(0)).unwrap();
panel.add_constraint(&panel.top_anchor().equal_to(0)).unwrap();
panel.add_constraint(&panel.width_anchor().equal_to(300)).unwrap();
panel.add_constraint(&panel.height_anchor().equal_to(200)).unwrap();
panel.set_layout_margins(LayoutMargins::create(10.0, 20.0, 10.0, 20.0)).unwrap();
let guide_left = panel.get_layout_margins_guide().get_left_variable().clone();
let guide_right = panel.get_layout_margins_guide().get_right_variable().clone();
solver.update_variables();
assert!((guide_left.get_value() - 20.0).abs() < 1e-6);
assert!((guide_right.get_value() - 280.0).abs() < 1e-6);
메서드methodpub fn rebuild_layout_margins_guide_constraints(&mut self) -> Result<(), LayoutError>#0.4.0 부터since 0.4.0소스source

layout margins guide 의 여백 제약 4 개를 다시 짓는다. (옛 제약을 빼고 지금 여백으로 지어 다시 건다)

Rebuilds the 4 margin constraints of the layout margins guide. (removes the old constraints, builds them with the current margins and adds them again)

반환ReturnsResult<(), LayoutError> Ok(()). 가이드가 없으면 아무것도 하지 않는다. 솔버에서 옛 제약을 빼거나 새 제약을 걸다 실패하면 그 LayoutError.Ok(()). Does nothing if there is no guide. The LayoutError if removing the old constraints from the solver or adding the new ones fails.

짝Counterpart: vanilla.js UINode.rebuildLayoutMarginsGuideConstraints

메서드methodpub fn set_solver(&mut self, solver: Option<LayoutSolver>) -> Result<(), LayoutError>#0.4.0 부터since 0.4.0소스source

솔버 설정, 변경, 해제. (옛 솔버에서 이 노드의 제약을 모두 빼고 새 솔버에 다시 건다, 가이드도 함께 옮긴다. None 이면 빼기만 한다)

Sets, changes or clears the solver. (removes all this node's constraints from the old solver and adds them again to the new solver, moving the guide along too. None only removes)

solverOption<LayoutSolver>
붙일 솔버. (값싼 핸들 복제를 준다) None 이면 옛 솔버에서 떼기만 한다.Solver to attach. (give a cheap handle clone) None only detaches from the old solver.

반환ReturnsResult<(), LayoutError> Ok(()). 옛 솔버에서 제약을 빼거나 새 솔버에 걸다 실패하면 그 LayoutError.Ok(()). The LayoutError if removing constraints from the old solver or adding them to the new solver fails.

짝Counterpart: vanilla.js UINode.setSolver

예제Example솔버를 붙이면 기억해 둔 제약이 걸리고, 떼면 빠진다Attaching a solver adds the remembered constraints, detaching removes them
use vanilla::{LayoutSolver, UINode};

let solver = LayoutSolver::new();
let mut ui_node = UINode::new();
let width_constraint = ui_node.width_anchor().equal_to(100);
ui_node.add_constraint(&width_constraint).unwrap();
assert!(!solver.has_constraint(&width_constraint));
ui_node.set_solver(Some(solver.clone())).unwrap();
assert!(solver.has_constraint(&width_constraint));
ui_node.set_solver(None).unwrap();
assert!(!solver.has_constraint(&width_constraint));
assert!(ui_node.get_solver().is_none());
메서드methodpub fn get_solver(&self) -> Option<&LayoutSolver>#0.4.0 부터since 0.4.0소스source

솔버 반환.

Returns the solver.

반환ReturnsOption<&LayoutSolver> 붙인 솔버. 없으면 None.The attached solver. None if none.

짝Counterpart: vanilla.js UINode.getSolver

메서드methodpub fn add_constraint(&mut self, constraint: &LayoutConstraint) -> Result<(), LayoutError>#0.4.0 부터since 0.4.0소스source

사용자 제약 추가. (솔버가 있으면 바로 건다)

  • 솔버가 받지 않으면(이미 더한 제약, 모순 제약) 그 오류를 돌려주고 목록에도 남기지 않는다.

Adds a user constraint. (adds it right away if there is a solver)

  • If the solver does not accept it (a constraint already added, a contradictory constraint), returns that error and does not keep it in the list either.
constraint&LayoutConstraint
걸 제약. (핸들 복제를 사용자 제약 목록에 두었다가 솔버를 바꿀 때 옮겨 건다)Constraint to add. (a handle clone is kept in the user constraint list and moved over when the solver changes)

반환ReturnsResult<(), LayoutError> Ok(()). 솔버에 걸다 실패하면 그 LayoutError. (실패해도 사용자 제약 목록에는 남는다)Ok(()). The LayoutError if adding to the solver fails. (it stays in the user constraint list even on failure)

짝Counterpart: vanilla.js UINode.addConstraint

메서드methodpub fn remove_constraint(&mut self, constraint: &LayoutConstraint) -> Result<(), LayoutError>#0.4.0 부터since 0.4.0소스source

사용자 제약 빼기. (솔버에서도 뺀다)

Removes a user constraint. (also removes it from the solver)

constraint&LayoutConstraint
뺄 제약. (건 핸들이나 그 복제)Constraint to remove. (the added handle or its clone)

반환ReturnsResult<(), LayoutError> Ok(()). 목록에 없거나 솔버에 걸려 있지 않아도 Ok. 솔버에서 빼다 실패하면 그 LayoutError.Ok(()). Ok even if not in the list or not added to the solver. The LayoutError if removing from the solver fails.

짝Counterpart: vanilla.js UINode.removeConstraint

메서드methodpub fn get_constraints(&self) -> Vec<LayoutConstraint>#0.4.0 부터since 0.4.0소스source

등록한 사용자 제약 목록. (사본)

List of registered user constraints. (copy)

반환ReturnsVec<LayoutConstraint> 사용자 제약 목록의 사본. (핸들 복제라 솔버에 건 제약과 같은 제약이다)Copy of the user constraint list. (handle clones, so the same constraints as those added to the solver)

짝Counterpart: vanilla.js UINode.getConstraints

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

왼쪽 변수 반환. (식 밖의 쓰임에 변수가 필요할 때)

Returns the left variable. (when a variable is needed outside an expression)

반환Returns&LayoutVariable 왼쪽 변수 핸들의 참조.Reference to the left variable handle.

짝Counterpart: vanilla.js UINode.getLeftVariable

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

오른쪽 변수 반환.

Returns the right variable.

반환Returns&LayoutVariable 오른쪽 변수 핸들의 참조.Reference to the right variable handle.

짝Counterpart: vanilla.js UINode.getRightVariable

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

위 변수 반환.

Returns the top variable.

반환Returns&LayoutVariable 위 변수 핸들의 참조.Reference to the top variable handle.

짝Counterpart: vanilla.js UINode.getTopVariable

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

아래 변수 반환.

Returns the bottom variable.

반환Returns&LayoutVariable 아래 변수 핸들의 참조.Reference to the bottom variable handle.

짝Counterpart: vanilla.js UINode.getBottomVariable

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

너비 변수 반환.

Returns the width variable.

반환Returns&LayoutVariable 너비 변수 핸들의 참조.Reference to the width variable handle.

짝Counterpart: vanilla.js UINode.getWidthVariable

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

높이 변수 반환.

Returns the height variable.

반환Returns&LayoutVariable 높이 변수 핸들의 참조.Reference to the height variable handle.

짝Counterpart: vanilla.js UINode.getHeightVariable

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

가로 중심 변수 반환.

Returns the horizontal center variable.

반환Returns&LayoutVariable 가로 중심 변수 핸들의 참조.Reference to the horizontal center variable handle.

짝Counterpart: vanilla.js UINode.getCenterXVariable

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

세로 중심 변수 반환.

Returns the vertical center variable.

반환Returns&LayoutVariable 세로 중심 변수 핸들의 참조.Reference to the vertical center variable handle.

짝Counterpart: vanilla.js UINode.getCenterYVariable

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

왼쪽 앵커 식. (UIKit 의 leftAnchor, 부를 때마다 새 식)

Left anchor expression. (UIKit's leftAnchor, a new expression on every call)

반환ReturnsLayoutExpression 1 * 왼쪽 변수 식.Expression 1 * left variable.

짝Counterpart: vanilla.js UINode.leftAnchor

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

오른쪽 앵커 식.

Right anchor expression.

반환ReturnsLayoutExpression 1 * 오른쪽 변수 식. (새 식)Expression 1 * right variable. (new expression)

짝Counterpart: vanilla.js UINode.rightAnchor

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

위 앵커 식.

Top anchor expression.

반환ReturnsLayoutExpression 1 * 위 변수 식. (새 식)Expression 1 * top variable. (new expression)

짝Counterpart: vanilla.js UINode.topAnchor

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

아래 앵커 식.

Bottom anchor expression.

반환ReturnsLayoutExpression 1 * 아래 변수 식. (새 식)Expression 1 * bottom variable. (new expression)

짝Counterpart: vanilla.js UINode.bottomAnchor

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

너비 앵커 식.

Width anchor expression.

반환ReturnsLayoutExpression 1 * 너비 변수 식. (새 식)Expression 1 * width variable. (new expression)

짝Counterpart: vanilla.js UINode.widthAnchor

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

높이 앵커 식.

Height anchor expression.

반환ReturnsLayoutExpression 1 * 높이 변수 식. (새 식)Expression 1 * height variable. (new expression)

짝Counterpart: vanilla.js UINode.heightAnchor

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

가로 중심 앵커 식.

Horizontal center anchor expression.

반환ReturnsLayoutExpression 1 * 가로 중심 변수 식. (새 식)Expression 1 * horizontal center variable. (new expression)

짝Counterpart: vanilla.js UINode.centerXAnchor

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

세로 중심 앵커 식.

Vertical center anchor expression.

반환ReturnsLayoutExpression 1 * 세로 중심 변수 식. (새 식)Expression 1 * vertical center variable. (new expression)

짝Counterpart: vanilla.js UINode.centerYAnchor

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

시작 앵커 식. (UIKit 의 leadingAnchor, 원본처럼 오른쪽에서 왼쪽을 다루지 않아 늘 left_anchor)

Leading anchor expression. (UIKit's leadingAnchor, always left_anchor since right-to-left is not handled, as in the original)

반환ReturnsLayoutExpression left_anchor 와 같은 식.Same expression as left_anchor.

짝Counterpart: vanilla.js UINode.leadingAnchor

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

끝 앵커 식. (UIKit 의 trailingAnchor, 늘 right_anchor)

Trailing anchor expression. (UIKit's trailingAnchor, always right_anchor)

반환ReturnsLayoutExpression right_anchor 와 같은 식.Same expression as right_anchor.

짝Counterpart: vanilla.js UINode.trailingAnchor

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

첫 기준선 앵커 식. (글이 없는 노드는 top_anchor)

First baseline anchor expression. (top_anchor for nodes without text)

반환ReturnsLayoutExpression top_anchor 와 같은 식.Same expression as top_anchor.

짝Counterpart: vanilla.js UINode.firstBaselineAnchor

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

마지막 기준선 앵커 식. (글이 없는 노드는 bottom_anchor)

Last baseline anchor expression. (bottom_anchor for nodes without text)

반환ReturnsLayoutExpression bottom_anchor 와 같은 식.Same expression as bottom_anchor.

짝Counterpart: vanilla.js UINode.lastBaselineAnchor

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

왼쪽 위치. (LayoutSolver::update_variables 뒤에 맞는 값)

Left position. (correct after LayoutSolver::update_variables)

반환Returnsf64 왼쪽 변수의 지금 값. (UI 트리 뿌리 좌표계의 절대 위치, 픽셀)Current value of the left variable. (absolute position in the UI tree root coordinate system, pixels)

짝Counterpart: vanilla.js UINode.getLeft

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

오른쪽 위치.

Right position.

반환Returnsf64 오른쪽 변수의 지금 값. (절대 위치, 픽셀)Current value of the right variable. (absolute position, pixels)

짝Counterpart: vanilla.js UINode.getRight

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

위 위치.

Top position.

반환Returnsf64 위 변수의 지금 값. (절대 위치, 픽셀)Current value of the top variable. (absolute position, pixels)

짝Counterpart: vanilla.js UINode.getTop

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

아래 위치.

Bottom position.

반환Returnsf64 아래 변수의 지금 값. (절대 위치, 픽셀)Current value of the bottom variable. (absolute position, pixels)

짝Counterpart: vanilla.js UINode.getBottom

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

너비.

Width.

반환Returnsf64 너비 변수의 지금 값. (픽셀)Current value of the width variable. (pixels)

짝Counterpart: vanilla.js UINode.getWidth

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

높이.

Height.

반환Returnsf64 높이 변수의 지금 값. (픽셀)Current value of the height variable. (pixels)

짝Counterpart: vanilla.js UINode.getHeight

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

가로 중심 위치.

Horizontal center position.

반환Returnsf64 가로 중심 변수의 지금 값. (절대 위치, 픽셀)Current value of the horizontal center variable. (absolute position, pixels)

짝Counterpart: vanilla.js UINode.getCenterX

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

세로 중심 위치.

Vertical center position.

반환Returnsf64 세로 중심 변수의 지금 값. (절대 위치, 픽셀)Current value of the vertical center variable. (absolute position, pixels)

짝Counterpart: vanilla.js UINode.getCenterY

상수Constants

상수constantpub const NO_INTRINSIC_METRIC: f64 = -1.0#0.4.0 부터since 0.4.0소스source

intrinsic 선호가 없다는 값. (UIKit 의 UIView.noIntrinsicMetric, 원본 UINode.noIntrinsicMetric)

Value meaning there is no intrinsic preference. (UIKit's UIView.noIntrinsicMetric, original UINode.noIntrinsicMetric)

반환Returnsf64