ui/autolayout/layoutconstraint
레이아웃 제약. (원본 ui/autolayout/layoutconstraint.js 의 LayoutConstraint)
- 꼴: 식 { ==, <=, >= } 0
- 보통 LayoutExpression 의 equal_to, less_than_or_equal_to, greater_than_or_equal_to 가 만든다.
- 강도는 부딪힐 때의 우선순위다. 만들 때 0 ~ REQUIRED 로 자른다.
- 원본과 다른 것:
- 원본은 객체 동일성으로 솔버에 등록된 제약을 가린다. 러스트 판은 Rc 를 품은 값싼 Clone 핸들이라 복제한 핸들은 같은 제약이고, 같음과 해시는 핸들이 가리키는 제약으로 가린다. (식이 같아도 따로 만들면 다른 제약)
- 생략할 수 있던 strength(기본 REQUIRED)는 꼭 받는다.
Layout constraint. (LayoutConstraint of the original ui/autolayout/layoutconstraint.js)
- Form: expression { ==, <=, >= } 0
- Usually created by LayoutExpression's equal_to, less_than_or_equal_to, greater_than_or_equal_to.
- Strength is the priority on conflict. Clamped to 0 ~ REQUIRED at creation.
- Differences from the original:
- The original tells constraints registered in the solver apart by object identity. The Rust version is a cheap Clone handle holding an Rc, so cloned handles are the same constraint, and equality and hashing go by the constraint the handle points to. (created separately, they are different constraints even with the same expression)
- strength, which could be omitted (default REQUIRED), is required.
LayoutConstraintstruct traits Clone, PartialEq, Eq, Hash, fmt::Debug
레이아웃 제약. (복제해도 같은 제약을 가리킨다)
Layout constraint. (clones point to the same constraint)
use vanilla::{LayoutExpression, LayoutRelation, LayoutSolver, LayoutStrength, LayoutVariable};
let solver = LayoutSolver::new();
let width = LayoutVariable::new("width");
let minimum_width = LayoutExpression::from_variable(&width).greater_than_or_equal_to(120);
assert_eq!(minimum_width.get_relation(), LayoutRelation::GreaterThanOrEqual);
assert_eq!(minimum_width.get_strength(), LayoutStrength::REQUIRED);
solver.add_constraint(&minimum_width).unwrap();
solver.add_constraint(&LayoutExpression::from_variable(&width).equal_to(80).with_strength(LayoutStrength::STRONG)).unwrap();
solver.update_variables();
assert!((width.get_value() - 120.0).abs() < 1e-6);
assert!(solver.has_constraint(&minimum_width.clone()));pub fn new(expression: LayoutExpression, relation: LayoutRelation, strength: f64) -> LayoutConstraint#생성. (강도는 0 ~ REQUIRED 로 자른다)
Constructor. (strength is clamped to 0 ~ REQUIRED)
- expressionLayoutExpression
- 제약 식. (식 관계 0 꼴의 왼쪽)Constraint expression. (the left side of the expression relation 0 form)
- relationLayoutRelation
- 식과 0 의 관계.Relation between the expression and 0.
- strengthf64
- 강도. (0 ~ LayoutStrength::REQUIRED 로 자른다)Strength. (clamped to 0 ~ LayoutStrength::REQUIRED)
반환ReturnsLayoutConstraint 새 제약 핸들.New constraint handle.
짝Counterpart: vanilla.js LayoutConstraint.constructor
use vanilla::{LayoutConstraint, LayoutExpression, LayoutRelation, LayoutStrength, LayoutVariable};
let width = LayoutVariable::new("width");
let expression = LayoutExpression::from_variable(&width).subtract(100);
let constraint = LayoutConstraint::new(expression, LayoutRelation::GreaterThanOrEqual, LayoutStrength::STRONG);
assert_eq!(constraint.get_strength(), LayoutStrength::STRONG);
assert_eq!(constraint.get_expression().get_constant(), -100.0);
let clipped = LayoutConstraint::new(LayoutExpression::from_variable(&width), LayoutRelation::Equal, 5e9);
assert_eq!(clipped.get_strength(), LayoutStrength::REQUIRED);식 반환.
Returns the expression.
반환Returns&LayoutExpression 제약 식의 참조. (비교 함수로 만들었으면 self - 상대 식)Reference to the constraint expression. (self - other expression if created with a comparison function)
짝Counterpart: vanilla.js LayoutConstraint.getExpression
관계 반환.
Returns the relation.
반환ReturnsLayoutRelation 식과 0 의 관계.Relation between the expression and 0.
짝Counterpart: vanilla.js LayoutConstraint.getRelation
강도 반환.
Returns the strength.
반환Returnsf64 강도. (만들 때 0 ~ REQUIRED 로 자른 값)Strength. (the value clamped to 0 ~ REQUIRED at creation)
짝Counterpart: vanilla.js LayoutConstraint.getStrength
강도만 다른 새 제약 반환. (우선순위만 바꿔 다시 등록할 때)
Returns a new constraint differing only in strength. (for registering again with only the priority changed)
- new_strengthf64
- 새 강도. (0 ~ LayoutStrength::REQUIRED 로 자른다)New strength. (clamped to 0 ~ LayoutStrength::REQUIRED)
반환ReturnsLayoutConstraint 식과 관계가 같고 강도만 다른 새 제약. (따로 만든 제약이라 self 와 같지 않다)A new constraint with the same expression and relation but a different strength. (a separately created constraint, so not equal to self)
짝Counterpart: vanilla.js LayoutConstraint.withStrength
use vanilla::{LayoutExpression, LayoutSolver, LayoutStrength, LayoutVariable};
let solver = LayoutSolver::new();
let x = LayoutVariable::new("x");
let preferred = LayoutExpression::from_variable(&x).equal_to(100).with_strength(LayoutStrength::WEAK);
solver.add_constraint(&preferred).unwrap();
let stronger = preferred.with_strength(LayoutStrength::STRONG);
assert_ne!(stronger, preferred);
solver.remove_constraint(&preferred).unwrap();
solver.add_constraint(&stronger).unwrap();
assert!(solver.has_constraint(&stronger));
assert!(!solver.has_constraint(&preferred));