libcss
Loading...
Searching...
No Matches
Macros | Functions
calc.c File Reference
#include "libcss/hint.h"
#include "select/calc.h"
#include "select/helpers.h"
#include "select/unit.h"
#include "utils/utils.h"

Macros

#define DEFAULT_STACK_SIZE   32
 
#define CANARY   "A css_calculator has leaked"
 
#define CANARY_SLEN   SLEN(CANARY)
 
#define CALC_PUSH(unit, value)
 
#define CALC_POP(unit, value)
 

Functions

css_error css_calculator_create (css_calculator **out)
 
css_calculatorcss_calculator_ref (css_calculator *calc)
 
void css_calculator_unref (css_calculator *calc)
 
css_error css_calculator_calculate (css_calculator *calc, const css_unit_ctx *unit_ctx, int32_t available, lwc_string *expr, const css_computed_style *style, css_unit *unit_out, css_fixed *value_out)
 

Macro Definition Documentation

◆ CALC_POP

#define CALC_POP (   unit,
  value 
)
Value:
do { \
ret = css__calculator_pop(calc, &unit, &value); \
if (ret != CSS_OK) { \
return ret; \
} \
} while (0)
unit
Definition bytecode.h:49
@ CSS_OK
Definition errors.h:19

◆ CALC_PUSH

#define CALC_PUSH (   unit,
  value 
)
Value:
do { \
ret = css__calculator_push(calc, unit, value); \
if (ret != CSS_OK) { \
return ret; \
} \
} while (0)

◆ CANARY

#define CANARY   "A css_calculator has leaked"

◆ CANARY_SLEN

#define CANARY_SLEN   SLEN(CANARY)

◆ DEFAULT_STACK_SIZE

#define DEFAULT_STACK_SIZE   32

The default number of entries on a calculator stack

Function Documentation

◆ css_calculator_calculate()

css_error css_calculator_calculate ( css_calculator calc,
const css_unit_ctx unit_ctx,
int32_t  available,
lwc_string *  expr,
const css_computed_style style,
css_unit unit_out,
css_fixed value_out 
)

Perform a calculation

To resolve the value of a calc() property, call this function. This will interpret the bytecode in the given expression, with the given display context and available space, and will fill out the computed unit and value.

Parameters
calcThe calculator to use
unit_ctxThe display context for resolving units
availableThe available space (for percentages)
styleThe style from which the expression was derived
exprThe expression to compute
unit_outThe computed unit is placed here
value_outThe computed value is placed here
Returns
CSS_OK if computation succeeded, otherwise likely CSS_INVALID or CSS_NOMEM

◆ css_calculator_create()

css_error css_calculator_create ( css_calculator **  out)

Create a new CSS calculator

This creates a new CSS calculator with a reference count of one.

The caller is responsible for calling css_calculator_unref when it is done with this calculator.

Parameters
outThe created calculator in saved here
Returns
CSS_OK if no problems were encountered, likely CSS_NOMEM if there were

◆ css_calculator_ref()

css_calculator * css_calculator_ref ( css_calculator calc)

Add a ref to a CSS calculator

If you are storing a calculator in more than one place you should ref it when storing it into a new place. You will neeed to call css_calculator_unref to match any call to this.

Parameters
calcThe calculator to add a reference to
Returns
The same calculator pointer for ease of use

◆ css_calculator_unref()

void css_calculator_unref ( css_calculator calc)

Unref a CSS calculator

Every call to css_calculator_create or css_calculator_ref must be matched with a call to this function. When the last ref is removed then the underlying calculator is freed.

Parameters
calcThe calculator to unref