nandi/cosmicnimpublic Fork 0
main
Commits
Clone
git clone https://git.rickub.com/nandi/cosmicnim.git
git clone ssh://git@rickub.com/nandi/cosmicnim.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

cosmic_ffi.h · 100 lines · 3.7 KBC Blame HistoryRaw
  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
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
/* 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 <math.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;

/* `width`/`height` are the pixels actually available, which is not the size
   requested in CosmicConfig when a tiling compositor has its own ideas. */
typedef void (*cosmic_on_view)(void *ctx, CosmicBuilder *builder, float width,
                               float height);
typedef void (*cosmic_on_press)(void *ctx, int32_t id);

/* Each key press, as NUL-terminated UTF-8: the typed character for ordinary
   keys ("7", "+"), otherwise the key's name ("Enter", "Backspace",
   "Escape", "ArrowLeft"). Valid for the duration of the call only. */
typedef void (*cosmic_on_key)(void *ctx, const char *key);

typedef struct {
  const char *title;
  cosmic_on_view on_view;
  cosmic_on_press on_press;
  cosmic_on_key on_key;   /* may be NULL */
  void *ctx;
  uint32_t width;  /* 0 for a default */
  uint32_t height; /* 0 for a default */
} CosmicConfig;

/* Bumped whenever anything here changes meaning: a new export, or a changed
   callback signature. A signature change leaves every symbol resolvable, so
   without checking this a mismatched library reads its arguments from
   whatever is in the registers. Check it before cosmic_run. */
#define COSMIC_ABI_VERSION 6
uint32_t cosmic_abi_version(void);

/* 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);

/* Size the NEXT leaf, in pixels. COSMIC_FILL takes the space on offer, and
   siblings that all ask for it share the axis equally; a negative dimension
   leaves that axis natural. Applies to one leaf only, then resets. */
#define COSMIC_FILL ((float)INFINITY)
void cosmic_size(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