Skip to content

api.json Improvements #116

@Parzival-3141

Description

@Parzival-3141

This is a list of changes to api.json I compiled while working on the Zig bindings. I've split them into two categories: "Improvements" for straightforward fixes, and "Proposals" for bigger changes I'd like feedback on. Also, I'm preemptively volunteering myself to do all the work accepted in this issue.

Improvements

  • Json format documentation
  • Json format and API versioning
    • Include the version of the format and API (in that order) before any modules.
    • Including the API version helps consumers validate contents and explicitly handle older or newer versions.
    • Giving the json format a version helps binding generators for the same reasons as above. It's worth doing this future-proofing now rather than later.
  • Change module brief field to doc for consistency
  • Remove unnamed enums, use const kind instead
  • Add missing OC_UNICODE_RANGE values
    • These could be added in the same manner as OC_UI_THEMEs.
  • Add missing oc_clock API
    • Some orca samples (e.g. clock) are impossible to port correctly without this API.
  • Add missing oc_window API
    • oc_window typename is referenced in the API but not declared.
  • Create oc_mat2x3 oc_mat2x3_scale(f32 x, f32 y)
    • This one isn't even in the C API. It's useful enough that it really should be included.
  • Add documentation for UI API

Proposals

  • Specify pointer attributes in api.json #117
  • Merge *_enum types with their "parents"
    • E.g. convert oc_file_perm into an enum type and remove oc_file_perm_enum. This simplifies the API surface while still allowing consumers to separate them if desired. It would also prevent the backing integer of the enum straying from the "parent" integer type, as is the case with oc_file_perm (though that issue can be resolved regardless of this proposal).
  • Differentiate bitflag enum types from normal enums
    • Consumers could implement flags using a more suitable primitive without defining overrides for each typename. E.g. A Zig bindings generator would automatically generate packed structs.
  • Document what errors can be triggered from individual IO API functions
    • Documented errors should be the superset of possible errors for every platform.
    • This would allow consumers to confidently handle all possible error cases. The Zig bindings would use this to create error sets, adding additional type safety.

The rest of these are organizational changes to modules and their contents. They're more nitpick-y but IMO feel more natural. I don't expect them to break anyone's code.

  • Remove Utility module and move it's children into the root
    • Utility is a poor name due to it's vagueness and redundancy (all code in the API has utility, or else it wouldn't be included). This is already reflected in function names, as none have them have an oc_util_ prefix. The name "utility" usually also implies the contents are small helpers for the main API, yet it encompasses half the API surface.
  • Move UI module contents (not Core or Widgets) into Application module, and move UI Core & Widgets under UI
    • i.e. Move UI/* -> Application/Input, and UI (Core|Widgets) -> UI/(Core|Widgets)
    • Just from looking at the API, it seems like all this is really general application state.
  • Move oc_font (+ metrics), oc_color, and oc_image (+ region and atlas) types and functions into the Graphics module
    • These types are consumed by the Canvas API, but don't really belong to it (i.e. none of them are created or manipulated via Canvas functions). However their "usage" functions (e.g. oc_set_color or oc_image_draw) should remain in Canvas.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions