1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
/* C ABI over libcosmic. See src/lib.rs for the contract.
The host owns the state and the shape of the window. Each frame libcosmic
calls `on_view`, and the host describes its widget tree by calling the
builder functions below on the handle it is given. Presses come back
through `on_press` carrying the id the host put on the button. */
#ifndef COSMIC_FFI_H
#define COSMIC_FFI_H
#include <stddef.h>
#include <stdint.h>
/* Opaque. Valid only for the duration of the on_view call it arrived with. */
typedef struct CosmicBuilder CosmicBuilder;
typedef void (*cosmic_on_view)(void *ctx, CosmicBuilder *builder);
typedef void (*cosmic_on_press)(void *ctx, int32_t id);
typedef struct {
const char *title;
cosmic_on_view on_view;
cosmic_on_press on_press;
void *ctx;
uint32_t width; /* 0 for a default */
uint32_t height; /* 0 for a default */
} CosmicConfig;
/* Opens the window and blocks until it closes. 0 on success.
Must be called from the main thread. */
int32_t cosmic_run(const CosmicConfig *config);
/* --- containers: each open must be matched by a cosmic_end --- */
void cosmic_column(CosmicBuilder *b);
void cosmic_row(CosmicBuilder *b);
void cosmic_container(CosmicBuilder *b);
void cosmic_end(CosmicBuilder *b);
/* --- attributes of the innermost open container --- */
void cosmic_spacing(CosmicBuilder *b, float px);
void cosmic_padding(CosmicBuilder *b, float px);
void cosmic_align_center(CosmicBuilder *b);
void cosmic_fill(CosmicBuilder *b);
/* --- leaves --- */
#define COSMIC_TEXT_BODY 0
#define COSMIC_TEXT_TITLE1 1
#define COSMIC_TEXT_TITLE2 2
#define COSMIC_TEXT_TITLE3 3
#define COSMIC_TEXT_TITLE4 4
#define COSMIC_TEXT_HEADING 5
#define COSMIC_TEXT_CAPTION 6
#define COSMIC_TEXT_MONOTEXT 7
void cosmic_text(CosmicBuilder *b, int32_t style, const char *text);
#define COSMIC_BUTTON_STANDARD 0
#define COSMIC_BUTTON_SUGGESTED 1
#define COSMIC_BUTTON_DESTRUCTIVE 2
#define COSMIC_BUTTON_TEXT 3
#define COSMIC_BUTTON_LINK 4
/* A negative id makes the button inert, i.e. disabled. */
void cosmic_button(CosmicBuilder *b, int32_t style, const char *label,
int32_t id);
void cosmic_space(CosmicBuilder *b, float w, float h);
/* --- the active theme's spacing scale, for laying out in COSMIC's rhythm --- */
#define COSMIC_SPACE_NONE 0
#define COSMIC_SPACE_XXXS 1
#define COSMIC_SPACE_XXS 2
#define COSMIC_SPACE_XS 3
#define COSMIC_SPACE_S 4
#define COSMIC_SPACE_M 5
#define COSMIC_SPACE_L 6
#define COSMIC_SPACE_XL 7
float cosmic_space_unit(int32_t step);
#endif
|