diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2022-12-05 19:34:09 +0000 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2022-12-05 23:25:12 +0000 |
| commit | ea223a23503c80759d5579626285eda0e617d6b4 (patch) | |
| tree | c0efcb64e92694d776d778a751f54746c15acd08 | |
| parent | e5b0bcae5615d8829c8b5af2e3127397e7b72d8c (diff) | |
| download | puzzles-ea223a23503c80759d5579626285eda0e617d6b4.zip puzzles-ea223a23503c80759d5579626285eda0e617d6b4.tar.gz puzzles-ea223a23503c80759d5579626285eda0e617d6b4.tar.bz2 puzzles-ea223a23503c80759d5579626285eda0e617d6b4.tar.xz | |
js: Put the puzzle background colour in a CSS variable
It's sometimes useful to be able to have an HTML element that visually
forms an extension of the puzzle's border. By putting the puzzle's
colour 0 (which we assume to be its background) into a CSS variable,
such elements can do something like "background-color:
var(--puzzle-background)" to get that effect even if the puzzle uses a
non-default background colour.
| -rw-r--r-- | emcc.c | 3 | ||||
| -rw-r--r-- | emcclib.js | 11 |
2 files changed, 14 insertions, 0 deletions
@@ -51,6 +51,7 @@ extern void js_add_preset(int menuid, const char *name, int value); extern int js_add_preset_submenu(int menuid, const char *name); extern int js_get_selected_preset(void); extern void js_select_preset(int n); +extern void js_set_background_colour(const char *bg); extern void js_get_date_64(unsigned *p); extern void js_update_permalinks(const char *desc, const char *seed); extern void js_enable_undo_redo(bool undo, bool redo); @@ -1007,6 +1008,8 @@ int main(int argc, char **argv) (unsigned)(0.5 + 255 * colours[i*3+2])); colour_strings[i] = dupstr(col); } + /* Put the background colour in a CSS variable. */ + js_set_background_colour(colour_strings[0]); /* * Request notification when the game ids change (e.g. if the user @@ -144,6 +144,17 @@ mergeInto(LibraryManager.library, { }, /* + * void js_set_background_colour(const char *bg); + * + * Record the puzzle background colour in a CSS variable so + * the style sheet can use it if it wants. + */ + js_set_background_colour: function(bgptr) { + document.documentElement.style.setProperty("--puzzle-background", + UTF8ToString(bgptr)); + }, + + /* * void js_get_date_64(unsigned *p); * * Return the current date, in milliseconds since the epoch |