ui/autolayout/layoutstrength
레이아웃 제약 강도. (원본 ui/autolayout/layoutstrength.js 의 LayoutStrength)
- Cassowary, Kiwi 의 표준 강도 체계. 제약이 부딪힐 때 어느 쪽을 먼저 지킬지 정한다.
- REQUIRED 는 반드시 지켜야 하고, 솔버가 못 풀면 오류를 돌려준다.
- STRONG, MEDIUM, WEAK 는 되도록 지키되 부딪히면 강도 차례로 양보한다.
- create_strength(a, b, c, weight) 로 강도를 합성한다.
- 원본의 정적 필드는 연관 상수, 정적 함수는 연관 함수다. 생략할 수 있던 weight 는 Option 으로 받는다.
Layout constraint strength. (LayoutStrength of the original ui/autolayout/layoutstrength.js)
- The Cassowary, Kiwi standard strength system. Decides which side to keep first when constraints conflict.
- REQUIRED must be kept, and an error is returned if the solver cannot solve it.
- STRONG, MEDIUM, WEAK are kept as much as possible, but yield in order of strength on conflict.
- Strengths are composed with create_strength(a, b, c, weight).
- The original's static fields are associated constants, and its static functions are associated functions. weight, which could be omitted, is taken as an Option.
LayoutStrengthstruct
레이아웃 제약 강도.
- 값을 품지 않는 이름 자리다. 연관 상수와 연관 함수만 쓴다. 강도는 f64 다.
Layout constraint strength.
- A name slot holding no value. Use only the associated constants and associated functions. Strengths are f64.
use vanilla::{LayoutExpression, LayoutSolver, LayoutStrength, LayoutVariable};
let solver = LayoutSolver::new();
let x = LayoutVariable::new("x");
solver.add_constraint(&LayoutExpression::from_variable(&x).equal_to(10).with_strength(LayoutStrength::WEAK)).unwrap();
solver.add_constraint(&LayoutExpression::from_variable(&x).equal_to(50).with_strength(LayoutStrength::STRONG)).unwrap();
solver.update_variables();
assert!((x.get_value() - 50.0).abs() < 1e-6);반드시 지켜야 하는 강도. (create_strength(1000, 1000, 1000) 과 같은 1001001000)
Strength that must be kept. (1001001000, same as create_strength(1000, 1000, 1000))
반환Returnsf64
짝Counterpart: vanilla.js LayoutStrength.required
강함. (create_strength(1, 0, 0) 과 같은 1000000)
Strong. (1000000, same as create_strength(1, 0, 0))
반환Returnsf64
짝Counterpart: vanilla.js LayoutStrength.strong
보통. (create_strength(0, 1, 0) 과 같은 1000)
Medium. (1000, same as create_strength(0, 1, 0))
반환Returnsf64
짝Counterpart: vanilla.js LayoutStrength.medium
약함. (create_strength(0, 0, 1) 과 같은 1)
Weak. (1, same as create_strength(0, 0, 1))
반환Returnsf64
짝Counterpart: vanilla.js LayoutStrength.weak
강도 합성.
- 세 자리 성분 (a, b, c) 에 weight(없으면 1)를 곱한 뒤 각각 0 ~ 1000 으로 자른다.
- 결과는 0 ~ REQUIRED 범위다.
Composes a strength.
- Multiplies the three components (a, b, c) by weight (1 if absent), then clamps each to 0 ~ 1000.
- The result is in the 0 ~ REQUIRED range.
- af64
- strong 자리 성분. (weight 를 곱해 0 ~ 1000 으로 자른 뒤 1000000 을 곱한다)strong component. (multiplied by weight, clamped to 0 ~ 1000, then multiplied by 1000000)
- bf64
- medium 자리 성분. (weight 를 곱해 0 ~ 1000 으로 자른 뒤 1000 을 곱한다)medium component. (multiplied by weight, clamped to 0 ~ 1000, then multiplied by 1000)
- cf64
- weak 자리 성분. (weight 를 곱해 0 ~ 1000 으로 자른다)weak component. (multiplied by weight and clamped to 0 ~ 1000)
- weightOption<f64>
- 세 성분에 곱할 가중치. None 이면 1.Weight to multiply the three components by. 1 if None.
반환Returnsf64 세 자리를 더한 강도. (0 ~ REQUIRED)Strength summing the three components. (0 ~ REQUIRED)
짝Counterpart: vanilla.js LayoutStrength.createStrength
use vanilla::LayoutStrength;
assert_eq!(LayoutStrength::create_strength(1.0, 0.0, 0.0, None), LayoutStrength::STRONG);
assert_eq!(LayoutStrength::create_strength(0.0, 2.0, 0.0, Some(3.0)), 6000.0);
assert_eq!(LayoutStrength::create_strength(2000.0, 0.0, 5.0, None), 1000000000.0 + 5.0);강도 자르기. (0 ~ REQUIRED)
Clamps a strength. (0 ~ REQUIRED)
- strengthf64
- 자를 강도.Strength to clamp.
반환Returnsf64 0 ~ REQUIRED 로 자른 강도.Strength clamped to 0 ~ REQUIRED.
짝Counterpart: vanilla.js LayoutStrength.clipStrength
UIKit 의 우선순위(1 ~ 1000)를 강도로 바꾼다.
- 1000 이상은 REQUIRED, 1 ~ 999 는 medium 단의 가중치(750 이면 750000), 0 이하는 0 이다.
Turns a UIKit priority (1 ~ 1000) into a strength.
- 1000 or more is REQUIRED, 1 ~ 999 is a medium tier weight (750000 for 750), and 0 or less is 0.
- priorityf64
- UIKit 꼴 우선순위. (LayoutPriority 의 값, 1 ~ 1000)UIKit-style priority. (a LayoutPriority value, 1 ~ 1000)
반환Returnsf64 강도. (1000 이상이면 REQUIRED, 0 이하면 0, 그 사이는 priority * 1000)Strength. (REQUIRED if 1000 or more, 0 if 0 or less, priority * 1000 in between)
짝Counterpart: vanilla.js LayoutStrength.fromPriority
use vanilla::{LayoutPriority, LayoutStrength};
assert_eq!(LayoutStrength::from_priority(LayoutPriority::REQUIRED), LayoutStrength::REQUIRED);
assert_eq!(LayoutStrength::from_priority(LayoutPriority::DEFAULT_HIGH), 750000.0);
assert_eq!(LayoutStrength::from_priority(-10.0), 0.0);