-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathimhtml.hpp
More file actions
129 lines (109 loc) · 3.19 KB
/
Copy pathimhtml.hpp
File metadata and controls
129 lines (109 loc) · 3.19 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#pragma once
#include <functional>
#include <map>
#include <string>
#include "imgui.h"
#include "imgui_internal.h"
#ifdef IMHTML_DEBUG_PRINTF
#define IMHTML_PRINTF(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define IMHTML_PRINTF(fmt, ...)
#endif
namespace ImHTML {
/**
* Font styles (only used internally)
*/
enum class FontStyle : unsigned char { Regular, Bold, Italic, BoldItalic };
/**
* Meta data for an image
*/
struct ImageMeta {
int Width;
int Height;
};
/**
* A font family, containing different styles of the same font.
*/
struct FontFamily {
ImFont *Regular = nullptr;
ImFont *Bold = nullptr;
ImFont *Italic = nullptr;
ImFont *BoldItalic = nullptr;
};
/**
* Configuration for the HTML renderer
*/
struct Config {
bool AllowHrefTooltips = true;
bool AllowImgAltTooltips = true;
float BaseFontSize = 16.0f;
// fallback when not found in FontFamilies, or no specific family provided
FontFamily DefaultFont;
// CSS font-family name -> family
std::map<std::string, FontFamily> FontFamilies;
std::function<void(const char *src, const char *baseurl)> LoadImage;
std::function<ImageMeta(const char *src, const char *baseurl)> GetImageMeta;
std::function<ImTextureID(const char *src, const char *baseurl)> GetImageTexture;
std::function<std::string(const char *url, const char *baseurl)> LoadCSS;
};
/**
* A custom element draw function
*
* @param bounds The available bounds of the parent element. This is the usable space for the custom element.
* @param attributes The attributes of the element
*/
typedef std::function<void(ImRect bounds, std::map<std::string, std::string> attributes)> CustomElementDrawFunction;
/**
* Default file loader for loading CSS files
*
* @param url Expects a relative local path to the CSS file
* @param baseurl The base URL of the CSS file (not used)
* @return The content of the CSS file
*/
std::string DefaultFileLoader(const char *url, const char *baseurl);
/**
* Get the current configuration
*
* @return The current configuration
*/
Config *GetConfig();
/**
* Set the configuration
*
* @param config The new configuration
*/
void SetConfig(const Config &config);
/**
* Push the configuration
*
* @param config The new configuration
*/
void PushConfig(const Config &config);
/**
* Pop the configuration
*/
void PopConfig();
/**
* Register a custom element. The draw function will be called with the position and attributes of the element.
*
* @param tagName The tag name of the custom element (e.g. <custom arg="value"></custom>)
* @param draw The draw function
*/
void RegisterCustomElement(const char *tagName, CustomElementDrawFunction draw);
/**
* Unregister a custom element.
*
* @param tagName The tag name of the custom element (e.g. <custom arg="value"></custom>)
*/
void UnregisterCustomElement(const char *tagName);
/**
* Render the HTML
*
* @param id The ID of the canvas
* @param html The HTML to render
* @param width The width of the canvas (0.0f for using available space)
* @param clickedURL The URL that was clicked (if any)
* @return True if any link was clicked, false otherwise
*/
bool Canvas(const char *id, const char *html, float width = 0.0f, std::string *clickedURL = nullptr);
}; // namespace ImHTML