vanilladocs
vanillapunch.com
API / ui/autolayout/layoutvariable

ui/autolayout/layoutvariable

레이아웃 솔버 미지수.

Layout solver unknown.

LayoutVariable

짝Counterpart: vanilla-engine LayoutVariable

레이아웃 솔버 미지수.

  • 외부 (사용자 코드) 가 식에 사용하는 변수.
  • 솔버가 풀고 나면 updateVariables() 호출 시 setValue 로 결과가 반영된다.

Layout solver unknown.

  • A variable that the outside (user code) uses in expressions.
  • After the solver solves, the result is applied through setValue when updateVariables() is called.
예제Example제약을 풀어 변수 값 읽기Solve a constraint and read the variable value
import { LayoutSolver, LayoutVariable, LayoutExpression } from "./build/vanilla.js";

const solver = new LayoutSolver();
const left = new LayoutVariable("left");
const leftExpression = LayoutExpression.fromVariable(left);
const leftConstraint = leftExpression.equalTo(24);
solver.addConstraint(leftConstraint);
const name = left.getName();
const valueBeforeUpdate = left.getValue();
solver.updateVariables();
const valueAfterUpdate = left.getValue();
console.log(name, valueBeforeUpdate, valueAfterUpdate);
생성자constructorconstructor(name)#0.2.1 부터since 0.2.1소스source

생성.

Constructor.

namestring
변수 이름. (문자열이 아니면 빈 글)Variable name. (empty string if not a string)

짝Counterpart: vanilla-engine LayoutVariable.new

메서드methodsetName(name)#0.2.1 부터since 0.2.1소스source

이름 설정.

Sets the name.

namestring
변수 이름.Variable name.

짝Counterpart: vanilla-engine LayoutVariable.set_name

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

이름 반환.

Returns the name.

반환Returnsstring 변수 이름.Variable name.

짝Counterpart: vanilla-engine LayoutVariable.get_name

메서드methodsetValue(value)#0.2.1 부터since 0.2.1소스source

값 설정. (솔버 내부에서 호출되며 외부 직접 호출은 권장하지 않는다.)

Sets the value. (Called inside the solver, direct external calls are not recommended.)

valuenumber
새 값.New value.

짝Counterpart: vanilla-engine LayoutVariable.set_value

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

값이 바뀔 때 부를 함수 설정. (솔버가 푼 값이 달라질 때만 부른다, 변수를 가진 쪽이 바뀐 것을 알아챈다. null 이면 부르지 않는다)

  • UINode 는 자기 자리와 크기 변수에 걸어 하위 트리 그리기 경계를 다시 셈하게 한다.

Sets the function called when the value changes. (Called only when the solved value differs, so the variable's owner notices the change; null calls nothing)

  • UINode hooks it on its position and size variables to recalculate subtree draw bounds.
valueChangedEvent((variable: LayoutVariable) => void) | null
바뀐 변수를 받는 함수.A function receiving the changed variable.

짝Counterpart: vanilla-engine LayoutVariable.set_value_changed_event

예제Example값이 바뀔 때 알기Knowing when the value changes
import { LayoutVariable } from "./build/vanilla.js";

const width = new LayoutVariable("width");
width.setValueChangedEvent((variable) => console.log(variable.getName(), variable.getValue()));
width.setValue(120);
width.setValue(120);
메서드methodgetValueChangedEvent()#0.4.0 부터since 0.4.0소스source

값이 바뀔 때 부를 함수 반환.

Returns the function called when the value changes.

반환Returns((variable: LayoutVariable) => void) | null 건 함수. (없으면 null)The hooked function. (null if none)

짝Counterpart: vanilla-engine LayoutVariable.get_value_changed_event

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

현재 값 반환. (updateVariables 후 유효)

Returns the current value. (Valid after updateVariables)

반환Returnsnumber 마지막 updateVariables 가 넣은 값. (처음은 0)Value set by the last updateVariables. (0 at first)

짝Counterpart: vanilla-engine LayoutVariable.get_value