1// The C surface of crates/mobile; see its lib.rs and library.rs for each call's contract.
2#pragma once
3
4#include <stdbool.h>
5#include <stddef.h>
6#include <stdint.h>
7
8typedef struct Library Library;
9typedef struct Share Share;
10typedef struct Section Section;
11typedef struct View View;
12
13void sb_string_free(char *text);
14
15bool sb_crash_start(const char *path, const char *build, const char *system);
16const char *sb_crash_address(void);
17char *sb_crash_report(void);
18void sb_crash_forget(void);
19
20typedef void (*sb_coordinator)(const char *path, bool write, void (*body)(void *), void *context);
21void sb_set_coordinator(sb_coordinator coordinator);
22void sb_set_sync_wake(void (*wake)(void));
23typedef void (*sb_versions)(const char *path, void (*found)(void *, const char *id, const char *device), void *context);
24typedef bool (*sb_retire)(const char *path, const char *id, bool keep);
25void sb_set_versions(sb_versions versions, sb_retire retire);
26char *sb_tags(void);
27char *sb_pens(uint32_t section);
28bool sb_tag_icon(uint16_t shape, bool checked, uint32_t pixels, uint8_t *rgba);
29
30const Library *sb_library_open(const char *path, const char *cache, bool local, char **error);
31const Library *sb_library_server(const char *address, const char *share, const char *user, const char *password,
32 const char *domain, const char *root, const char *cache, char **error);
33bool sb_notebook_create(const char *path, const char *cache, const char *author, const char *date, const char *time,
34 char **error);
35bool sb_notebook_moved(const char *cache, const char *from, const char *to, char **error);
36char *sb_library_sections(const Library *library);
37int32_t sb_library_color(const Library *library);
38char *sb_library_new_section(const Library *library, const char *folder, const char *name, const char *author,
39 const char *date, const char *time);
40char *sb_library_move_page(const Library *library, const char *from, const char *id, const char *to, const char *before,
41 uint32_t level, const char *discard, const char *author, const char *date, const char *time);
42char *sb_library_place(const Library *library, const char *path, const char *folder, const char *paths);
43char *sb_search(const Library *const *libraries, size_t count, const char *section, const char *query);
44char *sb_library_tagged(const Library *library);
45bool sb_library_unlock(const Library *library, const char *path, const char *password);
46void sb_library_lock_all(const Library *library);
47char *sb_library_sync_status(const Library *library);
48void sb_library_set_offline(const Library *library, bool offline);
49void sb_library_touched(const Library *library, const char *path);
50void sb_library_sync_now(const Library *library);
51bool sb_library_close(const Library *library, double seconds, char **error);
52void sb_library_free(const Library *library);
53
54Share *sb_share_connect(const char *address, const char *share, const char *user, const char *password,
55 const char *domain, char **error);
56char *sb_share_list(const Share *share, const char *path);
57void sb_share_free(Share *share);
58
59typedef void (*sb_wake)(uintptr_t token);
60Section *sb_section_open(const Library *library, const char *path, const char *author, sb_wake wake,
61 uintptr_t token, char **error);
62char *sb_section_pages(const Section *section);
63uint32_t sb_section_poll(const Section *section, uint8_t *status);
64char *sb_section_new_page(const Section *section, const char *parent, const char *date, const char *time);
65bool sb_section_delete_page(const Section *section, const char *id, const char *date, const char *time);
66bool sb_section_arrange(const Section *section, const char *order, const char *moved);
67char *sb_section_themes(const Section *section, const char *id);
68bool sb_section_set_theme(const Section *section, const char *id, uint8_t scope, const char *theme);
69bool sb_section_flush(const Section *section, double seconds);
70void sb_section_wake(const Section *section);
71void sb_section_set_author(const Section *section, const char *author);
72void sb_section_free(Section *section);
73
74View *sb_view_new(void *layer, const Section *section, const char *id, float width, float height, float scale);
75void sb_view_free(View *view);
76void sb_view_resize(View *view, float width, float height, float scale);
77bool sb_view_render(View *view);
78bool sb_view_frame_pending(const View *view);
79void sb_view_set_dark(View *view, bool dark);
80bool sb_view_read_only(const View *view);
81char *sb_view_reading(const View *view, float width);
82bool sb_view_set_reading(View *view, float width);
83bool sb_view_reload(View *view, bool discard);
84void sb_view_focus(View *view, bool focused);
85void sb_view_content(View *view, float bounds[4]);
86bool sb_view_block(const View *view, float x, float y, float rect[4]);
87void sb_view_set_transform(View *view, float zoom, float x, float y);
88uint8_t sb_view_target(const View *view, float x, float y);
89void sb_view_pressure(View *view, float pressure);
90void sb_set_snap_to_grid(bool on);
91void sb_set_default_font(const char *face, float size);
92void sb_set_markdown_shortcuts(bool on);
93bool sb_view_press(View *view, float x, float y);
94bool sb_view_drag(View *view, float x, float y);
95bool sb_view_release(View *view);
96bool sb_view_undo(View *view, bool redo);
97bool sb_view_can_undo(const View *view, bool redo);
98uint64_t sb_view_format(const View *view);
99bool sb_view_apply(View *view, uint8_t command);
100bool sb_view_style(View *view, uint8_t place);
101int32_t sb_view_style_place(const View *view);
102char *sb_view_correction(const View *view);
103bool sb_view_correct(View *view, uint8_t command, const char *text);
104char *sb_view_title(const View *view);
105bool sb_view_focus_title(View *view);
106bool sb_view_find(View *view, const char *query);
107bool sb_view_select_paragraph(View *view, const char *id);
108char *sb_view_copy(View *view, bool cut);
109void sb_view_insert_space(View *view);
110void sb_view_set_tool(View *view, uint8_t tool, uint8_t detail, uint32_t section);
111bool sb_view_cancel(View *view);
112bool sb_view_ink_selection(const View *view, float rect[4]);
113char *sb_view_paper(const View *view);
114bool sb_view_set_paper(View *view, int16_t red, uint8_t green, uint8_t blue, int8_t ruled);
115bool sb_view_set_art(View *view, const char *name);
116char *sb_view_page_text(const View *view);
117uint8_t *sb_view_pdf(const View *view, float width, float height, const char *section, size_t *length);
118void sb_bytes_free(uint8_t *bytes, size_t length);
119int8_t sb_view_date_request(View *view, int64_t *seconds);
120bool sb_view_change_date(View *view, int64_t seconds, const char *date, const char *time);
121bool sb_view_insert_picture(View *view, const uint8_t *bytes, size_t length, float width, float height);
122
123typedef struct Movie Movie;
124uint32_t sb_recording_rate(void);
125bool sb_view_start_recording(View *view, bool video, const char *date, const char *time);
126int64_t sb_view_recording(const View *view, bool *paused);
127void sb_view_pause_recording(View *view, bool paused);
128bool sb_view_finish_recording(View *view, const uint8_t *bytes, size_t length, bool video);
129char *sb_view_play_request(View *view, const char *folder);
130bool sb_view_played(View *view, int64_t at_ms);
131Movie *sb_movie_new(void);
132void sb_movie_picture(Movie *movie, uint64_t at_us, const uint8_t *bgra, uint32_t width, uint32_t height,
133 size_t stride);
134void sb_movie_sound(Movie *movie, const uint8_t *pcm, size_t length);
135uint8_t *sb_movie_finish(Movie *movie, uint64_t duration_us, size_t *length);
136
137uint32_t sb_text_length(const View *view);
138char *sb_text(const View *view, uint32_t start, uint32_t end);
139void sb_selection(const View *view, uint32_t range[2]);
140bool sb_select(View *view, uint32_t start, uint32_t end);
141bool sb_select_more(View *view);
142bool sb_marked(const View *view, uint32_t range[2]);
143bool sb_set_marked(View *view, const char *text, uint32_t selected_start, uint32_t selected_end);
144void sb_unmark(View *view);
145bool sb_insert(View *view, const char *text);
146bool sb_replace(View *view, uint32_t start, uint32_t end, const char *text);
147bool sb_paste(View *view, const char *text, const char *language);
148bool sb_delete_backward(View *view);
149bool sb_caret_rect(const View *view, uint32_t offset, float rect[4]);
150size_t sb_range_rects(const View *view, uint32_t start, uint32_t end, float (*rects)[4], size_t capacity);
151uint32_t sb_closest(const View *view, float x, float y);