# ui/autolayout/layoutterm (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/ui/autolayout/layoutterm/

One term of an expression. (LayoutTerm of the original ui/autolayout/layoutterm.js, coefficient * variable)
- A value making up a LayoutExpression. It does not change.
- Differences from the original:
  - The original can be created without a variable (null, value 0) and the solver skips such terms. The Rust version always takes a variable, so there are no such terms.
  - coefficient, which could be omitted (default 1), is required.

## LayoutTerm (struct) (Clone, Debug)

One term of an expression.

Example: Building an expression from a half-width term

```rust
use vanilla::{LayoutExpression, LayoutTerm, LayoutVariable};

let width = LayoutVariable::new("width");
width.set_value(80.0);
let half_width = LayoutTerm::new(width.clone(), 0.5);
assert_eq!(half_width.get_variable(), &width);
assert_eq!(half_width.get_value(), 40.0);

let expression = LayoutExpression::from(half_width).add(10);
assert_eq!(expression.get_value(), 50.0);
```

- `pub fn new(variable: LayoutVariable, coefficient: f64) -> LayoutTerm` (constructor, since 0.4.0): Constructor.
  - `variable` LayoutVariable: The term's variable. (holds the handle as is)
  - `coefficient` f64: Coefficient to multiply the variable by.
  - returns LayoutTerm: New term.
- `pub fn get_variable(&self) -> &LayoutVariable` (method, since 0.4.0): Returns the variable.
  - returns &LayoutVariable: Reference to the variable handle the term holds.
- `pub fn get_coefficient(&self) -> f64` (method, since 0.4.0): Returns the coefficient.
  - returns f64: Coefficient.
- `pub fn get_value(&self) -> f64` (method, since 0.4.0): Returns the evaluated value. (coefficient * variable value)
  - returns f64: Coefficient * current variable value.
