Skip to content

Commit

Permalink
API: computed: Change css_computed_width getter function names
Browse files Browse the repository at this point in the history
Now `css_computed_width()` is unchanged from how it always was.
And `css_computed_width_px()` is the new function to convert to
device pixels.

Also improve `css_computed_width_px()` API documentation.
  • Loading branch information
tlsa committed May 27, 2024
1 parent 1cd7202 commit d991ff1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
15 changes: 10 additions & 5 deletions include/libcss/computed.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,23 +280,28 @@ uint8_t css_computed_max_width(
css_fixed *length, css_unit *unit);

/**
* Get the width property value in device pixels.
*
* \note If available_px is set to a negative number (invalid) then,
* if the computation would have required a valid available
* width, it will return CSS_WIDTH_AUTO.
*
* This will resolve `calc()` expressions to used values.
*
* \param[in] style A computed style.
* \param[in] unit_ctx Unit conversion context.
* \param[in] available_px The available width in pixels.
* If set to a negative number (invalid) then if the
* computation would have required a valid available
* width, then it will return CSS_WIDTH_AUTO.
* \param[out] px_out Returns width in pixels if and only if the
* call returns CSS_WIDTH_SET.
* \return CSS_WIDTH_SET or CSS_WIDTH_AUTO.
*/
uint8_t css_computed_width(
uint8_t css_computed_width_px(
const css_computed_style *style,
const css_unit_ctx *unit_ctx,
int available_px,
int *px_out);

uint8_t css_computed_width_static(const css_computed_style *style,
uint8_t css_computed_width(const css_computed_style *style,
css_fixed *length, css_unit *unit);

uint8_t css_computed_empty_cells(
Expand Down
4 changes: 2 additions & 2 deletions src/select/computed.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ uint8_t css_computed_max_width(const css_computed_style *style,
return get_max_width(style, length, unit);
}

uint8_t css_computed_width(
uint8_t css_computed_width_px(
const css_computed_style *style,
const css_unit_ctx *unit_ctx,
int available_px,
Expand Down Expand Up @@ -753,7 +753,7 @@ uint8_t css_computed_width(
return type;
}

uint8_t css_computed_width_static(const css_computed_style *style,
uint8_t css_computed_width(const css_computed_style *style,
css_fixed *length, css_unit *unit)
{
css_fixed_or_calc length_ = {.value = 0};
Expand Down
4 changes: 2 additions & 2 deletions test/dump_computed.h
Original file line number Diff line number Diff line change
Expand Up @@ -3147,9 +3147,9 @@ static void dump_computed_style(const css_computed_style *style, char *buf,

/* width */
#ifdef USE_DEVICE
val = css_computed_width(style, unit_ctx, 1024, &pixels);
val = css_computed_width_px(style, unit_ctx, 1024, &pixels);
#else
val = css_computed_width_static(style, &len1, &unit1);
val = css_computed_width(style, &len1, &unit1);
#endif
switch (val) {
case CSS_WIDTH_INHERIT:
Expand Down

0 comments on commit d991ff1

Please sign in to comment.