Skip to content

Commit

Permalink
README WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoburns committed Sep 23, 2023
1 parent dc0fcbc commit c00d2be
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions ctaffy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# C API for Taffy (ctaffy)

Taffy is a flexible, high-performance, cross-platform UI layout library written in Rust.

This directory contains C bindings for Taffy. The API is a pure C API (no C++ features are used), and is designed to be easy to build other language bindings on top of. In addition to the documentation below, you may to read through the header file (`include/taffy.h`).

## Examples

There are readable examples in the examples directory.

Assuming you have Rust and Cargo installed (and a C compiler), then this should work to run the basic example:

```bash
$ git clone https://github.com/DioxusLabs/taffy.git

Check failure on line 14 in ctaffy/README.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Dollar signs used before commands without showing output

ctaffy/README.md:14:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ git clone https://github.com..."] https://github.com/DavidAnson/markdownlint/blob/v0.30.0/doc/md014.md
$ cd taffy/ctaffy/examples

Check failure on line 15 in ctaffy/README.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Dollar signs used before commands without showing output

ctaffy/README.md:15:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ cd taffy/ctaffy/examples"] https://github.com/DavidAnson/markdownlint/blob/v0.30.0/doc/md014.md
$ ./compile-basic.sh

Check failure on line 16 in ctaffy/README.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Dollar signs used before commands without showing output

ctaffy/README.md:16:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ ./compile-basic.sh"] https://github.com/DavidAnson/markdownlint/blob/v0.30.0/doc/md014.md
$ ./basic

Check failure on line 17 in ctaffy/README.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Dollar signs used before commands without showing output

ctaffy/README.md:17:1 MD014/commands-show-output Dollar signs used before commands without showing output [Context: "$ ./basic"] https://github.com/DavidAnson/markdownlint/blob/v0.30.0/doc/md014.md
```

## Naming Conventions

- Everything in the Taffy C API is prefixed with `Taffy`, except enum variant names which are prefixed with `TAFFY_`
- Structs and Enums are named in UpperCamelCase (e.g. `TaffyTree`, `TaffyStyle`)
- Functions begin with the name of the struct they apply to, followed by an underscore, followed by the name of the function in UpperCamelCase (e.g. `TaffyTree_New`, `TaffyStyle_SetFlexBasis`)
- Enum variants are SCREAMING_SNAKE_CASE

## Error Handling

Error handling is managed by the use of return codes and "result" structs. All functions in the API return either an `enum TaffyReturnCode` or one of the `struct Taffy*Result` structs (or `void` in the case of infallible operations that don't return anything).

### Return codes

Error handling is managed by the use of an enum `TaffyReturnCode`:

```c
typedef enum TaffyReturnCode {
TAFFY_RETURN_CODE_OK,
TAFFY_RETURN_CODE_NULL_STYLE_POINTER,
TAFFY_RETURN_CODE_NULL_TREE_POINTER,
// ... (see header file for full definition)
} TaffyReturnCode;
```

`TAFFY_RETURN_CODE_OK` indicates that the operation succeeded. All other variant indicate

Check failure on line 44 in ctaffy/README.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Trailing spaces

ctaffy/README.md:44:90 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 1] https://github.com/DavidAnson/markdownlint/blob/v0.30.0/doc/md009.md

### Result structs

"Result structs" are used for functions that need to return another value in addition to a `TaffyReturnCode` indicating success/failure (such as style getters which need to return the relevant style value). As C doesn't support generic structs, there are several "Result structs": one for each type of value. But each struct follows the same structure as the following example (varying only in the name of the struct and the type of the `value` field):

<table>
<tr><th>TaffyIntResult</th><th>TaffyDimensionResult</th></tr>
<tr>
<td>

```c
typedef struct TaffyIntResult {
enum TaffyReturnCode return_code;
int32_t value;
} TaffyIntResult;</code></pre></td>
```

</td>
<td>

```c
typedef struct TaffyDimensionResult {
enum TaffyReturnCode return_code;
struct TaffyDimension value;
} TaffyDimensionResult;
```

</td>
</tr>
</table>

Functions that return Result structs will either return a `TAFFY_RETURN_CODE_OK` along with a meaningful value, or a error variant of `TaffyReturnCode` along with

Check failure on line 76 in ctaffy/README.md

View workflow job for this annotation

GitHub Actions / Markdown Lint

Files should end with a single newline character

ctaffy/README.md:76:162 MD047/single-trailing-newline Files should end with a single newline character https://github.com/DavidAnson/markdownlint/blob/v0.30.0/doc/md047.md

0 comments on commit c00d2be

Please sign in to comment.