axui-growth-chamber/src/ax.h

107 lines
3.5 KiB
C

#pragma once
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
struct ax_ctxt;
struct ax_theme;
struct ax_window;
#define AX_OK 0
/* -----------------------------------------------------------------------------
* Context
* -------------------------------------------------------------------------- */
struct ax_ctxt* ax_new(void);
void ax_free(struct ax_ctxt* ax);
const char* ax_get_error(struct ax_ctxt* ax);
void ax_set_logger(struct ax_ctxt* ax, int fd, bool auto_close);
void ax_log(struct ax_ctxt* ax, const char* string);
/* -----------------------------------------------------------------------------
* Themes
* -------------------------------------------------------------------------- */
void ax_begin_theme(struct ax_ctxt* ax);
void ax_end_theme(struct ax_ctxt* ax, struct ax_theme** out_thm);
void ax_set_theme_color(
struct ax_ctxt* ax, const char* cat, int64_t rgb);
void ax_set_theme_font(
struct ax_ctxt* ax, const char* cat, const char* fnt_path, size_t fnt_size);
void ax_set_theme_iconset(
struct ax_ctxt* ax, const char* iconset_dir);
int ax_select_theme(struct ax_ctxt* ax, struct ax_theme* thm);
#define AX_ERR_THEME_LOADING 1
#define AX_ERR_THEME_INVALID 2
/* -----------------------------------------------------------------------------
* Windows
* -------------------------------------------------------------------------- */
void ax_begin_window(struct ax_ctxt* ax);
void ax_set_window_title(struct ax_ctxt* ax, const char* text);
void ax_set_window_size(struct ax_ctxt* ax, uint64_t w, uint64_t h, bool resize);
int ax_end_window(struct ax_ctxt* ax, struct ax_window** out_win);
void ax_select_window(struct ax_ctxt* ax, struct ax_window* win);
/* -----------------------------------------------------------------------------
* Cursor
* -------------------------------------------------------------------------- */
bool ax_is_cursor_valid(struct ax_ctxt* ax);
void ax_root(struct ax_ctxt* ax);
int ax_up(struct ax_ctxt* ax);
int ax_down(struct ax_ctxt* ax, size_t child_idx);
int ax_commit(struct ax_ctxt* ax);
/* -----------------------------------------------------------------------------
* Nodes
* -------------------------------------------------------------------------- */
void ax_container(struct ax_ctxt* ax);
void ax_text(struct ax_ctxt* ax,
struct ax_theme* thm,
const char* fnt_cat,
const char* text);
void ax_icon(struct ax_ctxt* ax,
struct ax_theme* thm,
const char* icn_name);
int ax_set_i(struct ax_ctxt* ax, int prop, int64_t v);
int ax_set_s(struct ax_ctxt* ax, int prop, const char* v);
int ax_unset(struct ax_ctxt* ax, int prop);
// general properties
#define AX_PROP_HORI_PADDING 0x001 // default = 0
#define AX_PROP_VERT_PADDING 0x002 // default = 0
#define AX_PROP_COLUMNS 0x003 // default = (none)
#define AX_PROP_GROW 0x004 // default = 0
#define AX_PROP_SHRINK 0x005 // default = 12
#define AX_PROP_BG_COLOR 0x006 // default = (none)
#define AX_PROP_FG_COLOR 0x007 // default = "#000000"
// container properties
#define AX_PROP_N_COLUMNS 0x101 // default = (none)
#define AX_PROP_COLUMN_SEP 0x102 // default = 0
// text properties
#define AX_PROP_TEXT_ALIGN 0x201 // default = left
#define AX_PROP_TEXT_WRAP_COLS 0x202 // default = (none)
#define AX_TEXT_ALIGN_LEFT 0
#define AX_TEXT_ALIGN_RIGHT 1
#define AX_TEXT_ALIGN_CENTER 2
// icon properties
#define AX_PROP_ICON_SCALE 0x401 // default = 24