vanilladocs
vanillapunch.com
API / ui/autolayout/layoutstrength

ui/autolayout/layoutstrength

레이아웃 제약 강도.

Layout constraint strength.

LayoutStrength

짝Counterpart: vanilla-engine LayoutStrength

레이아웃 제약 강도.

  • Cassowary / Kiwi 표준 강도 체계.
  • 강도는 제약 충돌 시 어느 쪽을 우선 만족시킬지 결정한다.
  • required 는 반드시 만족되어야 하며, 솔버가 못 풀면 예외를 던진다.
  • strong / medium / weak 는 가능한 한 만족시키되, 충돌 시 강도 순으로 양보한다.
  • createStrength(a, b, c, weight) 로 사용자 정의 강도 합성 가능.

Layout constraint strength.

  • Cassowary / Kiwi standard strength system.
  • Strength decides which side to satisfy first when constraints conflict.
  • required must be satisfied, and an exception is thrown if the solver cannot solve it.
  • strong / medium / weak are satisfied as much as possible, but yield in order of strength on conflict.
  • Custom strengths can be composed with createStrength(a, b, c, weight).
예제Example강한 제약이 약한 제약을 이기기A strong constraint beats a weak constraint
import { LayoutSolver, LayoutVariable, LayoutExpression, LayoutStrength } from "./build/vanilla.js";

const solver = new LayoutSolver();
const width = new LayoutVariable("width");
const widthExpression = LayoutExpression.fromVariable(width);
const preferredConstraint = widthExpression.equalTo(200);
const strongConstraint = preferredConstraint.withStrength(LayoutStrength.strong);
const fallbackConstraint = widthExpression.equalTo(100);
const weakConstraint = fallbackConstraint.withStrength(LayoutStrength.weak);
solver.addConstraint(strongConstraint);
solver.addConstraint(weakConstraint);
solver.updateVariables();
const widthValue = width.getValue();
console.log(widthValue);
정적staticstatic required = 1001001000#0.2.1 부터since 0.2.1소스source

표준 강도 상수.

Standard strength constants.

반환Returnsnumber

짝Counterpart: vanilla-engine LayoutStrength.REQUIRED

정적staticstatic strong = 1000000#0.2.1 부터since 0.2.1소스source

강한 강도. (1000000, createStrength(1, 0, 0) 과 같다)

Strong strength. (1000000, same as createStrength(1, 0, 0))

반환Returnsnumber

짝Counterpart: vanilla-engine LayoutStrength.STRONG

정적staticstatic medium = 1000#0.2.1 부터since 0.2.1소스source

보통 강도. (1000, createStrength(0, 1, 0) 과 같다)

Medium strength. (1000, same as createStrength(0, 1, 0))

반환Returnsnumber

짝Counterpart: vanilla-engine LayoutStrength.MEDIUM

정적staticstatic weak = 1#0.2.1 부터since 0.2.1소스source

약한 강도. (1, createStrength(0, 0, 1) 과 같다)

Weak strength. (1, same as createStrength(0, 0, 1))

반환Returnsnumber

짝Counterpart: vanilla-engine LayoutStrength.WEAK

정적staticstatic createStrength(a, b, c, weight)#0.2.1 부터since 0.2.1소스source

사용자 정의 강도 합성.

  • 세 자리 강도 성분 (a, b, c) 와 가중치 (weight) 로 합성한다.
  • 각 성분은 weight 곱한 뒤 0 ~ 1000 범위로 클램프된다.
  • 합성 결과는 0 ~ required (1001001000) 범위가 된다.

Composes a custom strength.

  • Composed from three strength components (a, b, c) and a weight (weight).
  • Each component is multiplied by weight and then clamped to the 0 ~ 1000 range.
  • The composed result is in the 0 ~ required (1001001000) range.
anumber
강한 자리 성분. (weight 를 곱해 0 ~ 1000 으로 자른 뒤 1000000 배)Strong place component. (multiplied by weight, clamped to 0 ~ 1000, then times 1000000)
bnumber
보통 자리 성분. (weight 를 곱해 0 ~ 1000 으로 자른 뒤 1000 배)Medium place component. (multiplied by weight, clamped to 0 ~ 1000, then times 1000)
cnumber
약한 자리 성분. (weight 를 곱해 0 ~ 1000 으로 자른다)Weak place component. (multiplied by weight and clamped to 0 ~ 1000)
weightnumber
세 성분에 곱할 가중치. (생략하거나 null 이면 1)Weight multiplied into the three components. (1 if omitted or null)

반환Returnsnumber 합친 강도. (0 ~ 1001001000)Combined strength. (0 ~ 1001001000)

짝Counterpart: vanilla-engine LayoutStrength.create_strength

예제Example보통과 강함 사이의 강도 만들기Make a strength between medium and strong
import { LayoutStrength } from "./build/vanilla.js";

const betweenMediumAndStrong = LayoutStrength.createStrength(0, 500, 0);
const halfStrong = LayoutStrength.createStrength(1, 0, 0, 0.5);
const medium = LayoutStrength.medium;
const strong = LayoutStrength.strong;
console.log(betweenMediumAndStrong, halfStrong, medium, strong);
정적staticstatic clipStrength(strength)#0.2.1 부터since 0.2.1소스source

강도 클램프. (0 ~ required)

Clamps a strength. (0 ~ required)

strengthnumber
자를 강도.Strength to clamp.

반환Returnsnumber 0 ~ required 로 자른 강도.Strength clamped to 0 ~ required.

짝Counterpart: vanilla-engine LayoutStrength.clip_strength

정적staticstatic fromPriority(priority)#0.2.1 부터since 0.2.1소스source

UIKit 의 UILayoutPriority (1 ~ 1000) 를 LayoutStrength 으로 변환.

  • priority >= 1000 (required) 은 LayoutStrength.required 로 매핑.
  • 1 ~ 999 는 medium tier 의 weight 로 매핑 (priority 750 → 750000).
  • 0 이하는 0 으로 매핑.

Converts UIKit's UILayoutPriority (1 ~ 1000) to LayoutStrength.

  • priority >= 1000 (required) maps to LayoutStrength.required.
  • 1 ~ 999 maps to the weight of the medium tier (priority 750 → 750000).
  • 0 or below maps to 0.
prioritynumber
UIKit 꼴 우선순위. (1 ~ 1000, LayoutPriority 값)UIKit style priority. (1 ~ 1000, a LayoutPriority value)

반환Returnsnumber 강도. (1000 이상은 required, 0 이하는 0, 그 사이는 priority * 1000)Strength. (required at 1000 or above, 0 at 0 or below, priority * 1000 in between)

짝Counterpart: vanilla-engine LayoutStrength.from_priority

예제Example우선순위를 강도로 바꾸기Convert priorities to strengths
import { LayoutStrength, LayoutPriority } from "./build/vanilla.js";

const requiredStrength = LayoutStrength.fromPriority(LayoutPriority.required);
const highStrength = LayoutStrength.fromPriority(LayoutPriority.defaultHigh);
const zeroStrength = LayoutStrength.fromPriority(0);
console.log(requiredStrength === LayoutStrength.required, highStrength, zeroStrength);