Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_gui_md.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
47
48#ifndef N_GUI_MD_H
49#define N_GUI_MD_H
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55#include <allegro5/allegro.h>
56#include <allegro5/allegro_font.h>
57
58#include <nilorea/n_markdown.h>
59
60#include <stddef.h>
61
65typedef struct N_GUI_MD_FONTS {
67 ALLEGRO_FONT* regular;
69 ALLEGRO_FONT* bold;
71 ALLEGRO_FONT* italic;
73 ALLEGRO_FONT* bolditalic;
75 ALLEGRO_FONT* mono;
77 ALLEGRO_FONT* h1;
79 ALLEGRO_FONT* h2;
81 ALLEGRO_FONT* h3;
83
87typedef struct N_GUI_MD_STYLE {
89 ALLEGRO_COLOR text;
91 ALLEGRO_COLOR heading;
93 ALLEGRO_COLOR link;
95 ALLEGRO_COLOR code;
97 ALLEGRO_COLOR code_bg;
99 ALLEGRO_COLOR quote;
101 ALLEGRO_COLOR rule;
105 float indent;
107 float cell_pad;
109 float col_min;
113 unsigned parse_flags;
124
137void n_gui_md_style_default(N_GUI_MD_STYLE* out, ALLEGRO_COLOR text, ALLEGRO_COLOR background, float line_height);
138
151float n_gui_md_height(const N_GUI_MD_FONTS* fonts, const N_GUI_MD_STYLE* style, float width, const char* text);
152
166float n_gui_md_draw(const N_GUI_MD_FONTS* fonts, const N_GUI_MD_STYLE* style, float x, float y, float width, const char* text);
167
185int n_gui_md_link_at(const N_GUI_MD_FONTS* fonts, const N_GUI_MD_STYLE* style, float x, float y, float width, const char* text, float px, float py, char* url, size_t url_cap);
186
187#ifdef __cplusplus
188}
189#endif
190
191#endif /* N_GUI_MD_H */
static void background(float x, float y, float w, float h, void *user_data)
a background
ALLEGRO_COLOR heading
heading text
Definition n_gui_md.h:91
int hard_breaks
Non-zero to break a paragraph where its source breaks, which is what a chat message wants: somebody p...
Definition n_gui_md.h:122
float col_min
narrowest a table column may be squeezed to, in pixels
Definition n_gui_md.h:109
ALLEGRO_FONT * bold
bold
Definition n_gui_md.h:69
float cell_pad
padding inside a table cell, left and right
Definition n_gui_md.h:107
ALLEGRO_COLOR text
body text
Definition n_gui_md.h:89
ALLEGRO_COLOR quote
a blockquote's text, and its bar
Definition n_gui_md.h:99
ALLEGRO_COLOR link
link text
Definition n_gui_md.h:93
int n_gui_md_link_at(const N_GUI_MD_FONTS *fonts, const N_GUI_MD_STYLE *style, float x, float y, float width, const char *text, float px, float py, char *url, size_t url_cap)
the url of the link under (px, py), if there is one
Definition n_gui_md.c:663
ALLEGRO_FONT * regular
body text, and the fallback for every other face.
Definition n_gui_md.h:67
ALLEGRO_COLOR code_bg
the panel behind a fenced code block, and behind inline code
Definition n_gui_md.h:97
ALLEGRO_FONT * h1
"# " headings, ideally the bold face at a larger size
Definition n_gui_md.h:77
float n_gui_md_draw(const N_GUI_MD_FONTS *fonts, const N_GUI_MD_STYLE *style, float x, float y, float width, const char *text)
draw text as markdown at (x, y), wrapped to width
Definition n_gui_md.c:657
ALLEGRO_COLOR rule
the rule under a heading and under a table's header row
Definition n_gui_md.h:101
ALLEGRO_FONT * bolditalic
both at once
Definition n_gui_md.h:73
ALLEGRO_FONT * h3
"### " and deeper
Definition n_gui_md.h:81
unsigned parse_flags
n_markdown parse flags.
Definition n_gui_md.h:113
ALLEGRO_FONT * mono
code and fenced code blocks
Definition n_gui_md.h:75
ALLEGRO_FONT * h2
"## " headings
Definition n_gui_md.h:79
ALLEGRO_FONT * italic
italic
Definition n_gui_md.h:71
ALLEGRO_COLOR code
code and code block text
Definition n_gui_md.h:95
float indent
how far a quote, a list item's text and a code block are indented
Definition n_gui_md.h:105
float block_gap
vertical space between two blocks, in pixels
Definition n_gui_md.h:103
void n_gui_md_style_default(N_GUI_MD_STYLE *out, ALLEGRO_COLOR text, ALLEGRO_COLOR background, float line_height)
fill a style from two colours and a line height
Definition n_gui_md.c:622
float n_gui_md_height(const N_GUI_MD_FONTS *fonts, const N_GUI_MD_STYLE *style, float width, const char *text)
height of text laid out as markdown at width, in pixels
Definition n_gui_md.c:651
The faces a render uses.
Definition n_gui_md.h:65
Colours and metrics.
Definition n_gui_md.h:87
Parse a SAFE, strict subset of Markdown into a block / styled-span model.